Best Webtau code snippet using org.testingisdocumenting.webtau.http.multipart.MultiPartFormField
Source:Http.java
...37import org.testingisdocumenting.webtau.http.json.JsonRequestBody;38import org.testingisdocumenting.webtau.http.listener.HttpListeners;39import org.testingisdocumenting.webtau.http.multipart.MultiPartFile;40import org.testingisdocumenting.webtau.http.multipart.MultiPartFormData;41import org.testingisdocumenting.webtau.http.multipart.MultiPartFormField;42import org.testingisdocumenting.webtau.http.operationid.HttpOperationIdProviders;43import org.testingisdocumenting.webtau.http.request.EmptyRequestBody;44import org.testingisdocumenting.webtau.http.request.HttpApplicationMime;45import org.testingisdocumenting.webtau.http.request.HttpQueryParams;46import org.testingisdocumenting.webtau.http.request.HttpRequestBody;47import org.testingisdocumenting.webtau.http.request.HttpTextMime;48import org.testingisdocumenting.webtau.http.text.TextRequestBody;49import org.testingisdocumenting.webtau.http.validation.*;50import org.testingisdocumenting.webtau.persona.Persona;51import org.testingisdocumenting.webtau.reporter.StepReportOptions;52import org.testingisdocumenting.webtau.reporter.WebTauStep;53import org.testingisdocumenting.webtau.reporter.stacktrace.StackTraceUtils;54import org.testingisdocumenting.webtau.time.Time;55import org.testingisdocumenting.webtau.utils.CollectionUtils;56import org.testingisdocumenting.webtau.utils.JsonParseException;57import org.testingisdocumenting.webtau.utils.JsonUtils;58import java.io.IOException;59import java.io.InputStream;60import java.io.UncheckedIOException;61import java.lang.reflect.Field;62import java.net.*;63import java.nio.charset.StandardCharsets;64import java.nio.file.Path;65import java.util.*;66import java.util.function.Supplier;67import java.util.zip.GZIPInputStream;68import javax.net.ssl.HttpsURLConnection;69import org.apache.commons.io.IOUtils;70import org.testingisdocumenting.webtau.utils.UrlUtils;71import sun.net.www.protocol.https.HttpsURLConnectionImpl;72public class Http {73 private static final HttpResponseValidatorWithReturn EMPTY_RESPONSE_VALIDATOR = (header, body) -> null;74 public static final Http http = new Http();75 public final HttpDocumentation doc = new HttpDocumentation();76 private final ThreadLocal<HttpValidationResult> lastValidationResult = new ThreadLocal<>();77 public final HttpApplicationMime application = new HttpApplicationMime();78 public final HttpTextMime text = new HttpTextMime();79 public boolean ping(String url) {80 return ping(url, HttpQueryParams.EMPTY, HttpHeader.EMPTY);81 }82 public boolean ping(String url, HttpQueryParams queryParams) {83 return ping(url, queryParams, HttpHeader.EMPTY);84 }85 public boolean ping(String url, HttpHeader header) {86 return ping(url, HttpQueryParams.EMPTY, header);87 }88 public boolean ping(String url, HttpQueryParams queryParams, HttpHeader header) {89 String fullUrl = WebTauHttpConfigurations.fullUrl(queryParams.attachToUrl(url));90 WebTauStep step = WebTauStep.createStep(91 tokenizedMessage(action("pinging"), urlValue(fullUrl)),92 () -> tokenizedMessage(action("pinged"), urlValue(fullUrl)),93 () -> HttpValidationHandlers.withDisabledHandlers(() -> {94 HttpOperationIdProviders.withDisabledProviders(() -> {95 http.get(url, header);96 return null;97 });98 return null;99 })100 );101 try {102 step.execute(StepReportOptions.REPORT_ALL);103 } catch (Throwable e) {104 return false;105 }106 return true;107 }108 public String concatUrl(String baseUrl, String relativeUrl) {109 return UrlUtils.concat(baseUrl, relativeUrl);110 }111 public HttpRequestBody json(String firstKey, Object firstValue, Object... rest) {112 return application.json(firstKey, firstValue, rest);113 }114 public HttpRequestBody json(String json) {115 return application.json(json);116 }117 public <E> E get(String url,118 HttpQueryParams queryParams,119 HttpHeader header,120 HttpResponseValidatorWithReturn validator) {121 return executeAndValidateHttpCall("GET", queryParams.attachToUrl(url),122 this::getToFullUrl,123 header, null, validator);124 }125 public <E> E get(String url, Map<CharSequence, ?> queryParams, HttpHeader header, HttpResponseValidatorWithReturn validator) {126 return get(url, new HttpQueryParams(queryParams), header, validator);127 }128 public void get(String url, HttpQueryParams queryParams, HttpHeader header, HttpResponseValidator validator) {129 get(url, queryParams, header, new HttpResponseValidatorIgnoringReturn(validator));130 }131 public void get(String url, Map<CharSequence, ?> queryParams, HttpHeader header, HttpResponseValidator validator) {132 get(url, queryParams, header, new HttpResponseValidatorIgnoringReturn(validator));133 }134 public void get(String url, HttpQueryParams queryParams, HttpHeader header) {135 get(url, queryParams, header, EMPTY_RESPONSE_VALIDATOR);136 }137 public void get(String url, Map<CharSequence, ?> queryParams, HttpHeader header) {138 get(url, queryParams, header, EMPTY_RESPONSE_VALIDATOR);139 }140 public <E> E get(String url, Map<CharSequence, ?> queryParams, HttpResponseValidatorWithReturn validator) {141 return get(url, queryParams, HttpHeader.EMPTY, validator);142 }143 public <E> E get(String url, HttpQueryParams queryParams, HttpResponseValidatorWithReturn validator) {144 return get(url, queryParams, HttpHeader.EMPTY, validator);145 }146 public void get(String url, Map<CharSequence, ?> queryParams, HttpResponseValidator validator) {147 get(url, queryParams, HttpHeader.EMPTY, new HttpResponseValidatorIgnoringReturn(validator));148 }149 public void get(String url, HttpQueryParams queryParams, HttpResponseValidator validator) {150 get(url, queryParams, HttpHeader.EMPTY, new HttpResponseValidatorIgnoringReturn(validator));151 }152 public void get(String url, Map<CharSequence, ?> queryParams) {153 get(url, queryParams, HttpHeader.EMPTY, EMPTY_RESPONSE_VALIDATOR);154 }155 public void get(String url, HttpQueryParams queryParams) {156 get(url, queryParams, HttpHeader.EMPTY, EMPTY_RESPONSE_VALIDATOR);157 }158 public <E> E get(String url, HttpHeader header, HttpResponseValidatorWithReturn validator) {159 return get(url, HttpQueryParams.EMPTY, header, validator);160 }161 public void get(String url, HttpHeader header, HttpResponseValidator validator) {162 get(url, HttpQueryParams.EMPTY, header, new HttpResponseValidatorIgnoringReturn(validator));163 }164 public void get(String url, HttpHeader header) {165 get(url, HttpQueryParams.EMPTY, header, EMPTY_RESPONSE_VALIDATOR);166 }167 public <E> E get(String url, HttpResponseValidatorWithReturn validator) {168 return get(url, HttpQueryParams.EMPTY, HttpHeader.EMPTY, validator);169 }170 public void get(String url, HttpResponseValidator validator) {171 get(url, HttpQueryParams.EMPTY, HttpHeader.EMPTY, new HttpResponseValidatorIgnoringReturn(validator));172 }173 public void get(String url) {174 get(url, HttpQueryParams.EMPTY, HttpHeader.EMPTY, EMPTY_RESPONSE_VALIDATOR);175 }176 public <E> E patch(String url, HttpQueryParams queryParams, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {177 return executeAndValidateHttpCall(178 "PATCH",179 queryParams.attachToUrl(url),180 (fullUrl, fullHeader) -> patchToFullUrl(fullUrl, fullHeader, requestBody),181 header,182 requestBody,183 validator);184 }185 public <E> E patch(String url, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {186 return patch(url, HttpQueryParams.EMPTY, header, requestBody, validator);187 }188 public void patch(String url, HttpQueryParams queryParams, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidator validator) {189 patch(url, queryParams, header, requestBody, new HttpResponseValidatorIgnoringReturn(validator));190 }191 public void patch(String url, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidator validator) {192 patch(url, header, requestBody, new HttpResponseValidatorIgnoringReturn(validator));193 }194 public <E> E patch(String url, HttpQueryParams queryParams, HttpHeader header, HttpResponseValidatorWithReturn validator) {195 return patch(url, queryParams, header, EmptyRequestBody.INSTANCE, validator);196 }197 public <E> E patch(String url, HttpHeader header, HttpResponseValidatorWithReturn validator) {198 return patch(url, header, EmptyRequestBody.INSTANCE, validator);199 }200 public void patch(String url, HttpQueryParams queryParams, HttpHeader header, HttpResponseValidator validator) {201 patch(url, queryParams, header, EmptyRequestBody.INSTANCE, new HttpResponseValidatorIgnoringReturn(validator));202 }203 public void patch(String url, HttpHeader header, HttpResponseValidator validator) {204 patch(url, header, EmptyRequestBody.INSTANCE, new HttpResponseValidatorIgnoringReturn(validator));205 }206 public <E> E patch(String url, HttpQueryParams queryParams, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {207 return patch(url, queryParams, HttpHeader.EMPTY, requestBody, validator);208 }209 public <E> E patch(String url, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {210 return patch(url, HttpHeader.EMPTY, requestBody, validator);211 }212 public void patch(String url, HttpQueryParams queryParams, HttpRequestBody requestBody, HttpResponseValidator validator) {213 patch(url, queryParams, requestBody, new HttpResponseValidatorIgnoringReturn(validator));214 }215 public void patch(String url, HttpRequestBody requestBody, HttpResponseValidator validator) {216 patch(url, requestBody, new HttpResponseValidatorIgnoringReturn(validator));217 }218 public <E> E patch(String url, HttpQueryParams queryParams, HttpHeader header, Map<String, ?> requestBody,219 HttpResponseValidatorWithReturn validator) {220 return patch(url, queryParams, header, new JsonRequestBody(requestBody), validator);221 }222 public <E> E patch(String url, HttpQueryParams queryParams, HttpHeader header, Collection<?> requestBody,223 HttpResponseValidatorWithReturn validator) {224 return patch(url, queryParams, header, new JsonRequestBody(requestBody), validator);225 }226 public <E> E patch(String url, HttpHeader header, Map<String, ?> requestBody, HttpResponseValidatorWithReturn validator) {227 return patch(url, header, new JsonRequestBody(requestBody), validator);228 }229 public <E> E patch(String url, HttpHeader header, Collection<?> requestBody, HttpResponseValidatorWithReturn validator) {230 return patch(url, header, new JsonRequestBody(requestBody), validator);231 }232 public void patch(String url, HttpQueryParams queryParams, HttpHeader header, Map<String, ?> requestBody,233 HttpResponseValidator validator) {234 patch(url, queryParams, header, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));235 }236 public void patch(String url, HttpQueryParams queryParams, HttpHeader header, Collection<?> requestBody,237 HttpResponseValidator validator) {238 patch(url, queryParams, header, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));239 }240 public void patch(String url, HttpHeader header, Map<String, ?> requestBody, HttpResponseValidator validator) {241 patch(url, header, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));242 }243 public void patch(String url, HttpHeader header, Collection<?> requestBody, HttpResponseValidator validator) {244 patch(url, header, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));245 }246 public <E> E patch(String url, HttpQueryParams queryParams, Map<String, ?> requestBody, HttpResponseValidatorWithReturn validator) {247 return patch(url, queryParams, HttpHeader.EMPTY, new JsonRequestBody(requestBody), validator);248 }249 public <E> E patch(String url, HttpQueryParams queryParams, Collection<?> requestBody, HttpResponseValidatorWithReturn validator) {250 return patch(url, queryParams, HttpHeader.EMPTY, new JsonRequestBody(requestBody), validator);251 }252 public <E> E patch(String url, Map<String, ?> requestBody, HttpResponseValidatorWithReturn validator) {253 return patch(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), validator);254 }255 public <E> E patch(String url, Collection<?> requestBody, HttpResponseValidatorWithReturn validator) {256 return patch(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), validator);257 }258 public void patch(String url, HttpQueryParams queryParams, Map<String, ?> requestBody, HttpResponseValidator validator) {259 patch(url, queryParams, HttpHeader.EMPTY, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));260 }261 public void patch(String url, HttpQueryParams queryParams, Collection<?> requestBody, HttpResponseValidator validator) {262 patch(url, queryParams, HttpHeader.EMPTY, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));263 }264 public void patch(String url, Map<String, ?> requestBody, HttpResponseValidator validator) {265 patch(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));266 }267 public void patch(String url, Collection<?> requestBody, HttpResponseValidator validator) {268 patch(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));269 }270 public void patch(String url, Map<String, ?> requestBody) {271 patch(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);272 }273 public void patch(String url, Collection<?> requestBody) {274 patch(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);275 }276 public <E> E patch(String url, HttpQueryParams queryParams, HttpResponseValidatorWithReturn validator) {277 return patch(url, queryParams, EmptyRequestBody.INSTANCE, validator);278 }279 public <E> E patch(String url, HttpResponseValidatorWithReturn validator) {280 return patch(url, EmptyRequestBody.INSTANCE, validator);281 }282 public void patch(String url, HttpQueryParams queryParams, HttpResponseValidator validator) {283 patch(url, queryParams, EmptyRequestBody.INSTANCE, new HttpResponseValidatorIgnoringReturn(validator));284 }285 public void patch(String url, HttpResponseValidator validator) {286 patch(url, EmptyRequestBody.INSTANCE, new HttpResponseValidatorIgnoringReturn(validator));287 }288 public void patch(String url, HttpQueryParams queryParams, HttpHeader header) {289 patch(url, queryParams, header, EMPTY_RESPONSE_VALIDATOR);290 }291 public void patch(String url, HttpHeader header) {292 patch(url, header, EMPTY_RESPONSE_VALIDATOR);293 }294 public void patch(String url, HttpQueryParams queryParams) {295 patch(url, queryParams, EMPTY_RESPONSE_VALIDATOR);296 }297 public void patch(String url) {298 patch(url, EMPTY_RESPONSE_VALIDATOR);299 }300 public void patch(String url, HttpQueryParams queryParams, HttpRequestBody requestBody) {301 patch(url, queryParams, requestBody, EMPTY_RESPONSE_VALIDATOR);302 }303 public void patch(String url, HttpRequestBody requestBody) {304 patch(url, requestBody, EMPTY_RESPONSE_VALIDATOR);305 }306 public <E> E post(String url, HttpQueryParams queryParams, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {307 return executeAndValidateHttpCall("POST", queryParams.attachToUrl(url),308 (fullUrl, fullHeader) -> postToFullUrl(fullUrl, fullHeader, requestBody),309 header,310 requestBody,311 validator);312 }313 public <E> E post(String url, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {314 return post(url, HttpQueryParams.EMPTY, header, requestBody, validator);315 }316 public void post(String url, HttpQueryParams queryParams, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidator validator) {317 post(url, queryParams, header, requestBody, new HttpResponseValidatorIgnoringReturn(validator));318 }319 public void post(String url, HttpQueryParams queryParams, HttpHeader header, HttpRequestBody requestBody) {320 post(url, queryParams, header, requestBody, EMPTY_RESPONSE_VALIDATOR);321 }322 public void post(String url, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidator validator) {323 post(url, header, requestBody, new HttpResponseValidatorIgnoringReturn(validator));324 }325 public void post(String url, HttpHeader header, HttpRequestBody requestBody) {326 post(url, header, requestBody, EMPTY_RESPONSE_VALIDATOR);327 }328 public <E> E post(String url, HttpQueryParams queryParams, HttpHeader header, HttpResponseValidatorWithReturn validator) {329 return post(url, queryParams, header, EmptyRequestBody.INSTANCE, validator);330 }331 public <E> E post(String url, HttpHeader header, HttpResponseValidatorWithReturn validator) {332 return post(url, header, EmptyRequestBody.INSTANCE, validator);333 }334 public void post(String url, HttpQueryParams queryParams, HttpHeader header, HttpResponseValidator validator) {335 post(url, queryParams, header, EmptyRequestBody.INSTANCE, new HttpResponseValidatorIgnoringReturn(validator));336 }337 public void post(String url, HttpHeader header, HttpResponseValidator validator) {338 post(url, header, EmptyRequestBody.INSTANCE, new HttpResponseValidatorIgnoringReturn(validator));339 }340 public <E> E post(String url, HttpQueryParams queryParams, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {341 return post(url, queryParams, HttpHeader.EMPTY, requestBody, validator);342 }343 public <E> E post(String url, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {344 return post(url, HttpHeader.EMPTY, requestBody, validator);345 }346 public void post(String url, HttpQueryParams queryParams, HttpRequestBody requestBody, HttpResponseValidator validator) {347 post(url, queryParams, requestBody, new HttpResponseValidatorIgnoringReturn(validator));348 }349 public void post(String url, HttpRequestBody requestBody, HttpResponseValidator validator) {350 post(url, requestBody, new HttpResponseValidatorIgnoringReturn(validator));351 }352 public <E> E post(String url, HttpQueryParams queryParams, HttpHeader header, Map<String, ?> requestBody, HttpResponseValidatorWithReturn validator) {353 return post(url, queryParams, header, new JsonRequestBody(requestBody), validator);354 }355 public <E> E post(String url, HttpQueryParams queryParams, HttpHeader header, Collection<?> requestBody, HttpResponseValidatorWithReturn validator) {356 return post(url, queryParams, header, new JsonRequestBody(requestBody), validator);357 }358 public <E> E post(String url, HttpHeader header, Map<String, ?> requestBody, HttpResponseValidatorWithReturn validator) {359 return post(url, header, new JsonRequestBody(requestBody), validator);360 }361 public <E> E post(String url, HttpHeader header, Collection<?> requestBody, HttpResponseValidatorWithReturn validator) {362 return post(url, header, new JsonRequestBody(requestBody), validator);363 }364 public void post(String url, HttpQueryParams queryParams, HttpHeader header, Map<String, ?> requestBody, HttpResponseValidator validator) {365 post(url, queryParams, header, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));366 }367 public void post(String url, HttpQueryParams queryParams, HttpHeader header, Collection<?> requestBody, HttpResponseValidator validator) {368 post(url, queryParams, header, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));369 }370 public void post(String url, HttpQueryParams queryParams, HttpHeader header, Map<String, ?> requestBody) {371 post(url, queryParams, header, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);372 }373 public void post(String url, HttpQueryParams queryParams, HttpHeader header, Collection<?> requestBody) {374 post(url, queryParams, header, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);375 }376 public void post(String url, HttpHeader header, Map<String, ?> requestBody, HttpResponseValidator validator) {377 post(url, header, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));378 }379 public void post(String url, HttpHeader header, Collection<?> requestBody, HttpResponseValidator validator) {380 post(url, header, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));381 }382 public void post(String url, HttpHeader header, Map<String, ?> requestBody) {383 post(url, header, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);384 }385 public void post(String url, HttpHeader header, Collection<?> requestBody) {386 post(url, header, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);387 }388 public <E> E post(String url, HttpQueryParams queryParams, Map<String, ?> requestBody, HttpResponseValidatorWithReturn validator) {389 return post(url, queryParams, HttpHeader.EMPTY, new JsonRequestBody(requestBody), validator);390 }391 public <E> E post(String url, HttpQueryParams queryParams, Collection<?> requestBody, HttpResponseValidatorWithReturn validator) {392 return post(url, queryParams, HttpHeader.EMPTY, new JsonRequestBody(requestBody), validator);393 }394 public <E> E post(String url, Map<String, ?> requestBody, HttpResponseValidatorWithReturn validator) {395 return post(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), validator);396 }397 public <E> E post(String url, Collection<?> requestBody, HttpResponseValidatorWithReturn validator) {398 return post(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), validator);399 }400 public void post(String url, HttpQueryParams queryParams, Map<String, ?> requestBody, HttpResponseValidator validator) {401 post(url, queryParams, HttpHeader.EMPTY, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));402 }403 public void post(String url, HttpQueryParams queryParams, Collection<?> requestBody, HttpResponseValidator validator) {404 post(url, queryParams, HttpHeader.EMPTY, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));405 }406 public void post(String url, HttpQueryParams queryParams, Map<String, ?> requestBody) {407 post(url, queryParams, HttpHeader.EMPTY, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);408 }409 public void post(String url, HttpQueryParams queryParams, Collection<?> requestBody) {410 post(url, queryParams, HttpHeader.EMPTY, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);411 }412 public void post(String url, Map<String, ?> requestBody, HttpResponseValidator validator) {413 post(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));414 }415 public void post(String url, Collection<?> requestBody, HttpResponseValidator validator) {416 post(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));417 }418 public void post(String url, Map<String, ?> requestBody) {419 post(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);420 }421 public void post(String url, Collection<?> requestBody) {422 post(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);423 }424 public <E> E post(String url, HttpQueryParams queryParams, HttpResponseValidatorWithReturn validator) {425 return post(url, queryParams, EmptyRequestBody.INSTANCE, validator);426 }427 public <E> E post(String url, HttpResponseValidatorWithReturn validator) {428 return post(url, EmptyRequestBody.INSTANCE, validator);429 }430 public void post(String url, HttpQueryParams queryParams, HttpResponseValidator validator) {431 post(url, queryParams, EmptyRequestBody.INSTANCE, new HttpResponseValidatorIgnoringReturn(validator));432 }433 public void post(String url, HttpResponseValidator validator) {434 post(url, EmptyRequestBody.INSTANCE, new HttpResponseValidatorIgnoringReturn(validator));435 }436 public void post(String url, HttpQueryParams queryParams, HttpHeader header) {437 post(url, queryParams, header, EMPTY_RESPONSE_VALIDATOR);438 }439 public void post(String url, HttpHeader header) {440 post(url, header, EMPTY_RESPONSE_VALIDATOR);441 }442 public void post(String url, HttpQueryParams queryParams) {443 post(url, queryParams, EMPTY_RESPONSE_VALIDATOR);444 }445 public void post(String url) {446 post(url, EMPTY_RESPONSE_VALIDATOR);447 }448 public void post(String url, HttpQueryParams queryParams, HttpRequestBody requestBody) {449 post(url, queryParams, requestBody, EMPTY_RESPONSE_VALIDATOR);450 }451 public void post(String url, HttpRequestBody requestBody) {452 post(url, requestBody, EMPTY_RESPONSE_VALIDATOR);453 }454 public <E> E put(String url, HttpQueryParams queryParams, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {455 return executeAndValidateHttpCall("PUT", queryParams.attachToUrl(url),456 (fullUrl, fullHeader) -> putToFullUrl(fullUrl, fullHeader, requestBody),457 header,458 requestBody,459 validator);460 }461 public void put(String url, HttpQueryParams queryParams, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidator validator) {462 put(url, queryParams, header, requestBody, new HttpResponseValidatorIgnoringReturn(validator));463 }464 public void put(String url, HttpQueryParams queryParams, HttpHeader header, Map<String, ?> requestBody, HttpResponseValidator validator) {465 put(url, queryParams, header, requestBody, new HttpResponseValidatorIgnoringReturn(validator));466 }467 public void put(String url, HttpQueryParams queryParams, HttpHeader header, Collection<?> requestBody, HttpResponseValidator validator) {468 put(url, queryParams, header, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));469 }470 public void put(String url, HttpQueryParams queryParams, HttpHeader header, HttpRequestBody requestBody) {471 put(url, queryParams, header, requestBody, EMPTY_RESPONSE_VALIDATOR);472 }473 public <E> E put(String url, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {474 return put(url, HttpQueryParams.EMPTY, header, requestBody, validator);475 }476 public void put(String url, HttpHeader header, HttpRequestBody requestBody, HttpResponseValidator validator) {477 put(url, header, requestBody, new HttpResponseValidatorIgnoringReturn(validator));478 }479 public void put(String url, HttpHeader header, HttpRequestBody requestBody) {480 put(url, header, requestBody, EMPTY_RESPONSE_VALIDATOR);481 }482 public <E> E put(String url, HttpQueryParams queryParams, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {483 return put(url, queryParams, HttpHeader.EMPTY, requestBody, validator);484 }485 public <E> E put(String url, HttpQueryParams queryParams, Map<String, ?> requestBody, HttpResponseValidatorWithReturn validator) {486 return put(url, queryParams, HttpHeader.EMPTY, requestBody, validator);487 }488 public <E> E put(String url, HttpQueryParams queryParams, Collection<?> requestBody, HttpResponseValidatorWithReturn validator) {489 return put(url, queryParams, HttpHeader.EMPTY, requestBody, validator);490 }491 public void put(String url, HttpQueryParams queryParams, HttpRequestBody requestBody, HttpResponseValidator validator) {492 put(url, queryParams, requestBody, new HttpResponseValidatorIgnoringReturn(validator));493 }494 public void put(String url, HttpQueryParams queryParams, Map<String, ?> requestBody, HttpResponseValidator validator) {495 put(url, queryParams, requestBody, new HttpResponseValidatorIgnoringReturn(validator));496 }497 public void put(String url, HttpQueryParams queryParams, Collection<?> requestBody, HttpResponseValidator validator) {498 put(url, queryParams, requestBody, new HttpResponseValidatorIgnoringReturn(validator));499 }500 public void put(String url, HttpQueryParams queryParams, HttpRequestBody requestBody) {501 put(url, queryParams, requestBody, EMPTY_RESPONSE_VALIDATOR);502 }503 public <E> E put(String url, HttpRequestBody requestBody, HttpResponseValidatorWithReturn validator) {504 return put(url, HttpHeader.EMPTY, requestBody, validator);505 }506 public void put(String url, HttpRequestBody requestBody, HttpResponseValidator validator) {507 put(url, requestBody, new HttpResponseValidatorIgnoringReturn(validator));508 }509 public void put(String url, HttpRequestBody requestBody) {510 put(url, requestBody, EMPTY_RESPONSE_VALIDATOR);511 }512 public <E> E put(String url, HttpQueryParams queryParams, HttpResponseValidatorWithReturn validator) {513 return put(url, queryParams, HttpHeader.EMPTY, EmptyRequestBody.INSTANCE, validator);514 }515 public void put(String url, HttpQueryParams queryParams, HttpResponseValidator validator) {516 put(url, queryParams, HttpHeader.EMPTY, EmptyRequestBody.INSTANCE, new HttpResponseValidatorIgnoringReturn(validator));517 }518 public void put(String url, HttpQueryParams queryParams) {519 put(url, queryParams, HttpHeader.EMPTY, EmptyRequestBody.INSTANCE, EMPTY_RESPONSE_VALIDATOR);520 }521 public <E> E put(String url, HttpResponseValidatorWithReturn validator) {522 return put(url, HttpHeader.EMPTY, EmptyRequestBody.INSTANCE, validator);523 }524 public void put(String url, HttpResponseValidator validator) {525 put(url, HttpHeader.EMPTY, EmptyRequestBody.INSTANCE, new HttpResponseValidatorIgnoringReturn(validator));526 }527 public void put(String url) {528 put(url, HttpHeader.EMPTY, EmptyRequestBody.INSTANCE, EMPTY_RESPONSE_VALIDATOR);529 }530 public <E> E put(String url, HttpQueryParams queryParams, HttpHeader header, Map<String, ?> requestBody, HttpResponseValidatorWithReturn validator) {531 return put(url, queryParams, header, new JsonRequestBody(requestBody), validator);532 }533 public <E> E put(String url, HttpQueryParams queryParams, HttpHeader header, Collection<?> requestBody, HttpResponseValidatorWithReturn validator) {534 return put(url, queryParams, header, new JsonRequestBody(requestBody), validator);535 }536 public <E> E put(String url, HttpHeader header, Map<String, ?> requestBody, HttpResponseValidatorWithReturn validator) {537 return put(url, header, new JsonRequestBody(requestBody), validator);538 }539 public <E> E put(String url, HttpHeader header, Collection<?> requestBody, HttpResponseValidatorWithReturn validator) {540 return put(url, header, new JsonRequestBody(requestBody), validator);541 }542 public void put(String url, HttpHeader header, Map<String, ?> requestBody, HttpResponseValidator validator) {543 put(url, header, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));544 }545 public void put(String url, HttpHeader header, Collection<?> requestBody, HttpResponseValidator validator) {546 put(url, header, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));547 }548 public void put(String url, HttpHeader header, Map<String, ?> requestBody) {549 put(url, header, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);550 }551 public void put(String url, HttpHeader header, Collection<?> requestBody) {552 put(url, header, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);553 }554 public void put(String url, HttpQueryParams queryParams, HttpHeader header, Map<String, ?> requestBody) {555 put(url, queryParams, header, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);556 }557 public void put(String url, HttpQueryParams queryParams, HttpHeader header, Collection<?> requestBody) {558 put(url, queryParams, header, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);559 }560 public <E> E put(String url, Map<String, ?> requestBody, HttpResponseValidatorWithReturn validator) {561 return put(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), validator);562 }563 public <E> E put(String url, Collection<?> requestBody, HttpResponseValidatorWithReturn validator) {564 return put(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), validator);565 }566 public void put(String url, Map<String, ?> requestBody, HttpResponseValidator validator) {567 put(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));568 }569 public void put(String url, Collection<?> requestBody, HttpResponseValidator validator) {570 put(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), new HttpResponseValidatorIgnoringReturn(validator));571 }572 public void put(String url, Map<String, ?> requestBody) {573 put(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);574 }575 public void put(String url, Collection<?> requestBody) {576 put(url, HttpHeader.EMPTY, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);577 }578 public void put(String url, HttpQueryParams queryParams, Map<String, ?> requestBody) {579 put(url, queryParams, HttpHeader.EMPTY, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);580 }581 public void put(String url, HttpQueryParams queryParams, Collection<?> requestBody) {582 put(url, queryParams, HttpHeader.EMPTY, new JsonRequestBody(requestBody), EMPTY_RESPONSE_VALIDATOR);583 }584 public <E> E put(String url, HttpQueryParams queryParams, HttpHeader header, HttpResponseValidatorWithReturn validator) {585 return put(url, queryParams, header, EmptyRequestBody.INSTANCE, validator);586 }587 public void put(String url, HttpQueryParams queryParams, HttpHeader header, HttpResponseValidator validator) {588 put(url, queryParams, header, new HttpResponseValidatorIgnoringReturn(validator));589 }590 public void put(String url, HttpQueryParams queryParams, HttpHeader header) {591 put(url, queryParams, header, EMPTY_RESPONSE_VALIDATOR);592 }593 public <E> E put(String url, HttpHeader header, HttpResponseValidatorWithReturn validator) {594 return put(url, header, EmptyRequestBody.INSTANCE, validator);595 }596 public void put(String url, HttpHeader header, HttpResponseValidator validator) {597 put(url, header, EmptyRequestBody.INSTANCE, new HttpResponseValidatorIgnoringReturn(validator));598 }599 public void put(String url, HttpHeader header) {600 put(url, header, EmptyRequestBody.INSTANCE, EMPTY_RESPONSE_VALIDATOR);601 }602 public <E> E delete(String url, HttpQueryParams queryParams, HttpHeader header, HttpResponseValidatorWithReturn validator) {603 return executeAndValidateHttpCall("DELETE", queryParams.attachToUrl(url),604 this::deleteToFullUrl,605 header,606 null,607 validator);608 }609 public void delete(String url, HttpQueryParams queryParams, HttpHeader header, HttpResponseValidator validator) {610 delete(url, queryParams, header, new HttpResponseValidatorIgnoringReturn(validator));611 }612 public <E> E delete(String url, HttpHeader header, HttpResponseValidatorWithReturn validator) {613 return delete(url, HttpQueryParams.EMPTY, header, validator);614 }615 public void delete(String url, HttpHeader header, HttpResponseValidator validator) {616 delete(url, HttpQueryParams.EMPTY, header, new HttpResponseValidatorIgnoringReturn(validator));617 }618 public <E> E delete(String url, HttpQueryParams queryParams, HttpResponseValidatorWithReturn validator) {619 return delete(url, queryParams, HttpHeader.EMPTY, validator);620 }621 public void delete(String url, HttpQueryParams queryParams, HttpResponseValidator validator) {622 delete(url, queryParams, HttpHeader.EMPTY, new HttpResponseValidatorIgnoringReturn(validator));623 }624 public <E> E delete(String url, HttpResponseValidatorWithReturn validator) {625 return delete(url, HttpQueryParams.EMPTY, HttpHeader.EMPTY, validator);626 }627 public void delete(String url, HttpResponseValidator validator) {628 delete(url, HttpQueryParams.EMPTY, HttpHeader.EMPTY, new HttpResponseValidatorIgnoringReturn(validator));629 }630 public void delete(String url, HttpQueryParams queryParams, HttpHeader header) {631 delete(url, queryParams, header, EMPTY_RESPONSE_VALIDATOR);632 }633 public void delete(String url, HttpHeader header) {634 delete(url, HttpQueryParams.EMPTY, header, EMPTY_RESPONSE_VALIDATOR);635 }636 public void delete(String url, HttpQueryParams queryParams) {637 delete(url, queryParams, HttpHeader.EMPTY, EMPTY_RESPONSE_VALIDATOR);638 }639 public void delete(String url) {640 delete(url, HttpQueryParams.EMPTY, HttpHeader.EMPTY, EMPTY_RESPONSE_VALIDATOR);641 }642 public HttpHeader header(CharSequence firstKey, CharSequence firstValue, CharSequence... restKv) {643 return new HttpHeader().with(firstKey, firstValue, restKv);644 }645 public HttpHeader header(Map<CharSequence, CharSequence> properties) {646 return new HttpHeader().with(properties);647 }648 public HttpQueryParams query(Map<?, ?> params) {649 return new HttpQueryParams(params);650 }651 public HttpQueryParams query(CharSequence firstKey, Object firstValue, Object... restKv) {652 return new HttpQueryParams(CollectionUtils.aMapOf(firstKey, firstValue, restKv));653 }654 public HttpRequestBody body(String mimeType, String content) {655 return TextRequestBody.withType(mimeType, content);656 }657 public HttpRequestBody body(String mimeType, byte[] content) {658 return BinaryRequestBody.withType(mimeType, content);659 }660 public MultiPartFormData formData(MultiPartFormField... fields) {661 MultiPartFormData formData = new MultiPartFormData();662 Arrays.stream(fields).forEach(formData::addField);663 return formData;664 }665 public MultiPartFormData formData(Map<String, ?> fields) {666 return new MultiPartFormData(fields);667 }668 public MultiPartFormField formField(byte[] fileContent) {669 return formField("file", fileContent, null);670 }671 public MultiPartFormField formField(String fieldName, byte[] fileContent) {672 return formField(fieldName, fileContent, null);673 }674 public MultiPartFormField formField(String fieldName, Path file) {675 return formField(fieldName, file, file.getFileName().toString());676 }677 public MultiPartFormField formField(String fieldName, Path file, String fileName) {678 return MultiPartFormField.fileFormField(fieldName, file, fileName);679 }680 public MultiPartFormField formField(String fieldName, byte[] fileContent, String fileName) {681 return MultiPartFormField.binaryFormField(fieldName, fileContent, fileName);682 }683 public MultiPartFormField formField(String fieldName, String textContent, String fileName) {684 return MultiPartFormField.textFormField(fieldName, textContent, fileName);685 }686 public MultiPartFormField formField(String fieldName, String textContent) {687 return formField(fieldName, textContent, null);688 }689 public MultiPartFile formFile(String fileName, byte[] fileContent) {690 return new MultiPartFile(fileName, fileContent);691 }692 public MultiPartFile formFile(String fileName, Path file) {693 return new MultiPartFile(fileName, file);694 }695 public HttpValidationResult getLastValidationResult() {696 return lastValidationResult.get();697 }698 public HttpResponse getToFullUrl(String fullUrl, HttpHeader requestHeader) {699 return request("GET", fullUrl, requestHeader, EmptyRequestBody.INSTANCE);700 }...
Source:MultiPartFormData.java
...22import java.util.Map;23import java.util.UUID;24public class MultiPartFormData implements HttpRequestBody {25 private final String boundary;26 private final List<MultiPartFormField> fields;27 public MultiPartFormData() {28 this.fields = new ArrayList<>();29 this.boundary = "webtau" + hashCode() + UUID.randomUUID();30 }31 public MultiPartFormData(Map<String, ?> fields) {32 this();33 fields.forEach((fieldName, content) -> {34 if (content instanceof MultiPartFile) {35 MultiPartFile file = (MultiPartFile) content;36 addField(MultiPartFormField.binaryFormField(fieldName, file.getContent(), file.getName()));37 } else if (content instanceof byte[]) {38 addField(MultiPartFormField.binaryFormField(fieldName, (byte[]) content, null));39 } else if (content instanceof String) {40 addField(MultiPartFormField.textFormField(fieldName, (String) content, null));41 } else if (content instanceof Path) {42 addField(MultiPartFormField.fileFormField(fieldName, (Path) content));43 } else {44 throw new UnsupportedOperationException("form field of type <" + content.getClass() + "> is not supported");45 }46 });47 }48 public void addField(MultiPartFormField field) {49 fields.add(field);50 }51 @Override52 public boolean isBinary() {53 return true;54 }55 @Override56 public String type() {57 return "multipart/form-data; boundary=" + boundary;58 }59 @Override60 public boolean isEmpty() {61 return false;62 }...
Source:MultiPartFormField.java
...15 */16package org.testingisdocumenting.webtau.http.multipart;17import org.testingisdocumenting.webtau.utils.FileUtils;18import java.nio.file.Path;19public class MultiPartFormField {20 private final byte[] content;21 private final String contentType;22 private final String fieldName;23 private final String fileName;24 public static MultiPartFormField binaryFormField(String fieldName, byte[] content, String fileName) {25 return new MultiPartFormField(fieldName, "application/octet-stream", content, fileName);26 }27 public static MultiPartFormField textFormField(String fieldName, String content, String fileName) {28 return new MultiPartFormField(fieldName, null, content.getBytes(), fileName);29 }30 public static MultiPartFormField fileFormField(String fieldName, Path file) {31 return fileFormField(fieldName, file, file.getFileName().toString());32 }33 public static MultiPartFormField fileFormField(String fieldName, Path file, String fileName) {34 return binaryFormField(fieldName, FileUtils.fileBinaryContent(file), fileName);35 }36 private MultiPartFormField(String fieldName, String contentType, byte[] content, String fileName) {37 this.content = content;38 this.contentType = contentType;39 this.fieldName = fieldName;40 this.fileName = fileName;41 }42 void writeRequest(MultiPartContentBuilder builder) {43 builder.writeHeader("Content-Disposition", "form-data");44 builder.write("; ");45 builder.writeAttr("name", fieldName);46 builder.write("; ");47 if (fileName != null) {48 builder.writeAttr("filename", fileName);49 builder.newLine();50 } else {...
MultiPartFormField
Using AI Code Generation
1package org.testingisdocumenting.webtau.http.multipart;2import org.testingisdocumenting.webtau.http.Http;3import org.testingisdocumenting.webtau.http.HttpUrl;4import org.testingisdocumenting.webtau.http.HttpValidationOptions;5import org.testingisdocumenting.webtau.http.datanode.DataNode;6import org.testingisdocumenting.webtau.http.datanode.DataNodeHandler;7import org.testingisdocumenting.webtau.http.datanode.DataNodeHandlers;8import org.testingisdocumenting.webtau.http.datanode.DataNodeHandlersRegistry;9import org.testingisdocumenting.webtau.http.datanode.DataNodePath;10import org.testingisdocumenting.webtau.http.datanode.DataNodeValue;11import org.testingisdocumenting.webtau.http.datanode.JsonNode;12import org.testingisdocumenting.webtau.http.datanode.XmlNode;13import java.io.File;14import java.util.List;15import static org.testingisdocumenting.webtau.http.datanode.DataNodeHandlersRegistry.registerDefaultHandlers;16public class MultiPartFormFieldsExample {17 public static void main(String[] args) {18 registerDefaultHandlers();19 DataNodeHandlersRegistry.register(new MyCustomDataNodeHandler());20 Http.post("/post", new MultiPartFormField("name", "John"),21 new MultiPartFormField("age", 42),22 new MultiPartFormField("married", true),23 new MultiPartFormField("address", new Address("123 Main St", "New York")),24 new MultiPartFormField("file", new File("some.file")),25 new MultiPartFormField("file", new File("some.file"), "some.file", "text/plain"),26 new MultiPartFormField("file", new File("some.file"), "some.file", "text/plain", "custom header"));27 Http.post("/post", new MultiPartFormField("name", "John"),28 new MultiPartFormField("age", 42),29 new MultiPartFormField("married", true),30 new MultiPartFormField("address", new Address("123 Main St", "New York")),31 new MultiPartFormField("file", new File("some.file")),32 new MultiPartFormField("file", new File("some.file"), "some.file", "text/plain"),33 new MultiPartFormField("file", new File("some.file"), "some.file", "text/plain", "custom header"));34 Http.post("/post", new MultiPartFormField("name", "John"),35 new MultiPartFormField("
MultiPartFormField
Using AI Code Generation
1package mypackage;2import org.testingisdocumenting.webtau.http.multipart.MultiPartFormField;3import org.testingisdocumenting.webtau.http.multipart.MultiPartFormData;4import java.io.File;5import static org.testingisdocumenting.webtau.Ddjt.http;6public class 1 {7 public static void main(String[] args) {8 MultiPartFormData multiPartFormData = new MultiPartFormData();9 multiPartFormData.add(new MultiPartFormField("field1", "value1"));10 multiPartFormData.add(new MultiPartFormField("field2", "value2"));11 multiPartFormData.add(new MultiPartFormField("file", new File("/Users/alex/test.txt")));12 http.post("/multipart", multiPartFormData);13 }14}15package mypackage;16import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFile;17import org.testingisdocumenting.webtau.http.multipart.MultiPartFormData;18import java.io.File;19import static org.testingisdocumenting.webtau.Ddjt.http;20public class 2 {21 public static void main(String[] args) {22 MultiPartFormData multiPartFormData = new MultiPartFormData();23 multiPartFormData.add(new MultiPartFormFile("file", new File("/Users/alex/test.txt")));24 http.post("/multipart", multiPartFormData);25 }26}27package mypackage;28import org.testingisdocumenting.webtau.http.multipart.MultiPartFormData;29import java.io.File;30import static org.testingisdocumenting.webtau.Ddjt.http;31public class 3 {32 public static void main(String[] args) {33 MultiPartFormData multiPartFormData = new MultiPartFormData();34 multiPartFormData.add("field1", "value1");35 multiPartFormData.add("field2", "value2");36 multiPartFormData.add("file", new File("/Users/alex/test.txt"));37 http.post("/multipart", multiPartFormData);38 }39}
MultiPartFormField
Using AI Code Generation
1import org.testingisdocumenting.webtau.WebTauDsl.*;2import org.testingisdocumenting.webtau.http.multipart.MultiPartFormField;3import static org.testingisdocumenting.webtau.WebTauDsl.*;4import static org.testingisdocumenting.webtau.http.Http.http;5http.get("/form/multipart")6http.post("/form/multipart",7 MultiPartFormField.of("field1", "value1"),8 MultiPartFormField.of("field2", "value2"))9http.post("/form/multipart",10 MultiPartFormField.of("field1", "value1"),11 MultiPartFormField.of("field2", "value2"),12 MultiPartFormField.of("field3", "value3"))13http.post("/form/multipart",14 MultiPartFormField.of("field1", "value1"),15 MultiPartFormField.of("field2", "value2"),16 MultiPartFormField.of("field3", "value3"),17 MultiPartFormField.of("field4", "value4"))18import org.testingisdocumenting.webtau.WebTauDsl.*;19import org.testingisdocumenting.webtau.http.multipart.MultiPartFormField;20import static org.testingisdocumenting.webtau.WebTauDsl.*;21import static org.testingisdocumenting.webtau.http.Http.http;22http.get("/form/multipart")23http.post("/form/multipart",24 MultiPartFormField.of("field1", "value1"),25 MultiPartFormField.of("field2", "value2"))26http.post("/form/multipart",27 MultiPartFormField.of("field1", "value1"),28 MultiPartFormField.of("field2", "value2"),29 MultiPartFormField.of("field3", "value3"))30http.post("/form/multipart",31 MultiPartFormField.of("field1", "value1"),32 MultiPartFormField.of("field2", "value2"),33 MultiPartFormField.of("field3", "value3"),34 MultiPartFormField.of("field4", "value4"))35import org.testingisdocumenting.webtau.WebTauDsl.*;36import org.testingisdocumenting.webtau.http.multipart.MultiPart
MultiPartFormField
Using AI Code Generation
1import org.testingisdocumenting.webtau.http.multipart.MultiPartFormField;2import org.testingisdocumenting.webtau.http.Http;3import org.testingisdocumenting.webtau.http.HttpData;4import org.testingisdocumenting.webtau.http.HttpHeader;5import org.testingisdocumenting.webtau.http.HttpRequestBody;6import org.testingisdocumenting.webtau.http.HttpResponse;7import java.util.Map;8public class 1 {9 public static void main(String[] args) {10 HttpData httpData = Http.post("/post", new HttpRequestBody()11 .withMultiPartFormData(12 new MultiPartFormField("name", "value"),13 new MultiPartFormField("name2", "value2")14 ));15 HttpResponse httpResponse = httpData.getResponse();16 HttpHeader httpHeader = httpData.getHeader();17 Map<String, Object> jsonBody = httpData.getJsonBody();18 System.out.println(httpResponse);19 System.out.println(httpHeader);20 System.out.println(jsonBody);21 }22}23import org.testingisdocumenting.webtau.http.multipart.MultiPartFormData;24import org.testingisdocumenting.webtau.http.Http;25import org.testingisdocumenting.webtau.http.HttpData;26import org.testingisdocumenting.webtau.http.HttpHeader;27import org.testingisdocumenting.webtau.http.HttpRequestBody;28import org.testingisdocumenting.webtau.http.HttpResponse;29import java.util.Map;30public class 2 {31 public static void main(String[] args) {32 HttpData httpData = Http.post("/post", new HttpRequestBody()33 .withMultiPartFormData(34 new MultiPartFormData()35 .withField("name", "value")36 .withField("name2", "value2")37 ));38 HttpResponse httpResponse = httpData.getResponse();39 HttpHeader httpHeader = httpData.getHeader();40 Map<String, Object> jsonBody = httpData.getJsonBody();41 System.out.println(httpResponse);42 System.out.println(httpHeader);43 System.out.println(jsonBody);44 }45}46import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFile;47import org.testingisdocumenting.web
MultiPartFormField
Using AI Code Generation
1import org.testingisdocumenting.webtau.http.multipart.MultiPartFormField;2import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFields;3import org.testingisdocumenting.webtau.http.Http;4Http.post("/someUrl", MultiPartFormFields.create(5 MultiPartFormField.of("field1", "value1"),6 MultiPartFormField.of("field2", "value2")));7import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFile;8import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFields;9import org.testingisdocumenting.webtau.http.Http;10Http.post("/someUrl", MultiPartFormFields.create(11 MultiPartFormFile.of("file1", "file1.txt", "text/plain"),12 MultiPartFormFile.of("file2", "file2.txt", "text/plain")));13import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFile;14import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFields;15import org.testingisdocumenting.webtau.http.Http;16Http.post("/someUrl", MultiPartFormFields.create(17 MultiPartFormFile.of("file1", "file1.txt", "text/plain", "content of file1"),18 MultiPartFormFile.of("file2", "file2.txt", "text/plain", "content of file2")));19import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFile;20import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFields;21import org.testingisdocumenting.webtau.http.Http;22Http.post("/someUrl", MultiPartFormFields.create(23 MultiPartFormFile.of("file1", "file1.txt", "text/plain", "content of file1"),24 MultiPartFormFile.of("file2", "file2
MultiPartFormField
Using AI Code Generation
1import org.testingisdocumenting.webtau.http.multipart.MultiPartFormField;2import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFile;3import org.testingisdocumenting.webtau.http.Http;4public class 1 {5 public static void main(String[] args) {6 MultiPartFormField name = MultiPartFormField.of("name", "John");7 MultiPartFormFile file = MultiPartFormFile.of("file", "1.txt");8 Http.multipartForm("/upload", name, file);9 }10}11import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFile;12import org.testingisdocumenting.webtau.http.Http;13public class 2 {14 public static void main(String[] args) {15 MultiPartFormFile file = MultiPartFormFile.of("file", "1.txt");16 Http.multipartForm("/upload", file);17 }18}19import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFile;20import org.testingisdocumenting.webtau.http.Http;21public class 3 {22 public static void main(String[] args) {23 MultiPartFormFile file = MultiPartFormFile.of("file", "1.txt");24 Http.multipartForm("/upload", file);25 }26}27import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFile;28import org.testingisdocumenting.webtau.http.Http;29public class 4 {30 public static void main(String[] args) {31 MultiPartFormFile file = MultiPartFormFile.of("file", "1.txt");32 Http.multipartForm("/upload", file);33 }34}35import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFile;36import org.testingisdocumenting.webtau.http.Http;37public class 5 {
MultiPartFormField
Using AI Code Generation
1package org.testingisdocumenting.examples.webtau.http.multipart;2import org.testingisdocumenting.webtau.Ddjt;3import org.testingisdocumenting.webtau.http.Http;4import org.testingisdocumenting.webtau.http.HttpHeader;5import org.testingisdocumenting.webtau.http.HttpValidationOptions;6import org.testingisdocumenting.webtau.http.multipart.MultiPartFormField;7import org.testingisdocumenting.webtau.http.multipart.MultiPartFormRequest;8import org.testingisdocumenting.webtau.http.multipart.MultiPartFormRequestBuilder;9import java.util.Collections;10import java.util.List;11import static org.testingisdocumenting.webtau.WebTauDsl.*;12import static org.testingisdocumenting.webtau.http.Http.http;13import static org.testingisdocumenting.webtau.http.HttpHeader.header;14import static org.testingisdocumenting.webtau.http.multipart.MultiPartFormField.field;15import static org.testingisdocumenting.webtau.http.multipart.MultiPartFormRequestBuilder.multipartForm;16public class MultiPartFormTest {17 public static void main(String[] args) {18 Ddjt.runTests(args, MultiPartFormTest.class);19 }20 public static void multipartFormRequest() {21 MultiPartFormField field1 = field("field1", "value1");22 MultiPartFormField field2 = field("field2", "value2");23 List<HttpHeader> headers = Collections.singletonList(header("Content-Type", "multipart/form-data; boundary=---------------------------9051914041544843365972754266"));24 MultiPartFormRequest request = multipartForm()25 .withField(field1)26 .withField(field2)27 .withHeaders(headers)28 .build();29 http.post(request);30 HttpValidationOptions options = new HttpValidationOptions();31 options.addHeader("Content-Type", "multipart/form-data; boundary=---------------------------9051914041544843365972754266");32 http.get("/multipart", options);33 }34}35Content-Type: multipart/form-data; boundary=---------------------------9051914041544843365972754266
MultiPartFormField
Using AI Code Generation
1public class MultiPartRequest {2 public void multiPartRequest() {3 Http http = Http.http();4 http.post("/multiPart", new MultiPartFormField("field1", "value1"),5 new MultiPartFormField("field2", "value2"),6 new MultiPartFormField("field3", "value3"));7 }8}9public class MultiPartRequest {10 public void multiPartRequest() {11 Http http = Http.http();12 http.post("/multiPart", new MultiPartFormFile("file1", "file1.txt", "text/plain", "file1".getBytes()),13 new MultiPartFormFile("file2", "file2.txt", "text/plain", "file2".getBytes()),14 new MultiPartFormFile("file3", "file3.txt", "text/plain", "file3".getBytes()));15 }16}17public class MultiPartRequest {18 public void multiPartRequest() {19 Http http = Http.http();20 http.post("/multiPart", new MultiPartForm()21 .field("field1", "value1")22 .field("field2", "value2")23 .field("field3", "value3")24 .file("file1", "file1.txt", "text/plain", "file1".getBytes())25 .file("file2", "file2.txt", "text/plain", "file2".getBytes())26 .file("file3", "file3.txt", "text/plain", "file3".getBytes()));27 }28}29public class MultiPartRequest {30 public void multiPartRequest() {31 Http http = Http.http();32 http.post("/multiPart", new MultiPartForm()33 .field("field1", "value1")34 .field("field2", "value2")35 .field("field3", "
MultiPartFormField
Using AI Code Generation
1import org.testingisdocumenting.webtau.http.Http;2import org.testingisdocumenting.webtau.http.multipart.MultiPartFormField;3import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFieldType;4import java.nio.file.Paths;5public class 1 {6 public static void main(String[] args) {7 MultiPartFormField fileField = MultiPartFormField.file("file", Paths.get("test.txt"));8 MultiPartFormField textField = MultiPartFormField.text("text", "hello");9 Http.post("/multipart", fileField, textField)10 .should(equalHttpResponse(200, "text", "hello"));11 }12}13import org.testingisdocumenting.webtau.http.Http;14import org.testingisdocumenting.webtau.http.multipart.MultiPartFormField;15import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFieldType;16import java.nio.file.Paths;17public class 2 {18 public static void main(String[] args) {19 MultiPartFormField fileField = MultiPartFormField.file("file", Paths.get("test.txt"));20 MultiPartFormField textField = MultiPartFormField.text("text", "hello");21 Http.post("/multipart", fileField, textField)22 .should(equalHttpResponse(200, "text", "hello"));23 }24}25import org.testingisdocumenting.webtau.http.Http;26import org.testingisdocumenting.webtau.http.multipart.MultiPartFormField;27import org.testingisdocumenting.webtau.http.multipart.MultiPartFormFieldType;28import java.nio.file.Paths;29public class 3 {30 public static void main(String[] args) {31 MultiPartFormField fileField = MultiPartFormField.file("file", Paths.get("test.txt"));32 MultiPartFormField textField = MultiPartFormField.text("text", "hello");33 Http.post("/multipart", fileField, textField)34 .should(equalHttpResponse
MultiPartFormField
Using AI Code Generation
1import org.testingisdocumenting.webtau.http.*;2import java.util.*;3import static org.testingisdocumenting.webtau.Ddjt.*;4Http http = http();5MultiPartFormField nameField = new MultiPartFormField("name", "John Doe");6MultiPartFormField ageField = new MultiPartFormField("age", "38");7MultiPartForm form = new MultiPartForm();8form.addFormField(nameField);9form.addFormField(ageField);10Map<String, Object> response = http.multipartForm("/form", form);11System.out.println(response);12import org.testingisdocumenting.webtau.http.*;13import java.util.*;14import static org.testingisdocumenting.webtau.Ddjt.*;15Http http = http();16MultiPartFile file1 = new MultiPartFile("file1", "src/test/resources/test1.txt");17MultiPartFile file2 = new MultiPartFile("file2", "src/test/resources/test2.txt");18MultiPartForm form = new MultiPartForm();19form.addFile(file1);20form.addFile(file2);21Map<String, Object> response = http.multipartForm("/form", form);22System.out.println(response);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!