use of io.restassured.builder.MultiPartSpecBuilder in project rest-assured by rest-assured.
the class MultiPartITest method defaultControlNameIsUsedWhenNoControlNameIsDefinedInMultiPartSpecBuilder.
@Test
public void defaultControlNameIsUsedWhenNoControlNameIsDefinedInMultiPartSpecBuilder() throws Exception {
// Given
final InputStream is = getClass().getResourceAsStream("/car-records.xsd");
// When
given().queryParam("controlName", "file2").config(RestAssuredConfig.config().multiPartConfig(multiPartConfig().defaultControlName("file2"))).multiPart(new MultiPartSpecBuilder(is).build()).when().post("/multipart/file").then().statusCode(200).body(is(IOUtils.toString(getClass().getResourceAsStream("/car-records.xsd"))));
}
use of io.restassured.builder.MultiPartSpecBuilder in project rest-assured by rest-assured.
the class MultiPartITest method controlNameInMultiPartSpecBuilderHasPrecedenceOverDefaultWhenConfigured.
@Test
public void controlNameInMultiPartSpecBuilderHasPrecedenceOverDefaultWhenConfigured() throws Exception {
// Given
final InputStream is = getClass().getResourceAsStream("/car-records.xsd");
// When
given().config(RestAssuredConfig.config().multiPartConfig(multiPartConfig().defaultControlName("something-else"))).queryParam("controlName", "file2").multiPart(new MultiPartSpecBuilder(is).controlName("file2").build()).when().post("/multipart/file").then().statusCode(200).body(is(IOUtils.toString(getClass().getResourceAsStream("/car-records.xsd"))));
}
use of io.restassured.builder.MultiPartSpecBuilder in project rest-assured by rest-assured.
the class MockMvcRequestSenderImpl method logRequestIfApplicable.
private void logRequestIfApplicable(HttpMethod method, String uri, String originalPath, Object[] unnamedPathParams) {
if (requestLoggingFilter == null) {
return;
}
final RequestSpecificationImpl reqSpec = new RequestSpecificationImpl("http://localhost", RestAssured.UNDEFINED_PORT, "", new NoAuthScheme(), Collections.<Filter>emptyList(), null, true, ConfigConverter.convertToRestAssuredConfig(config), logRepository, null);
reqSpec.setMethod(method.toString());
reqSpec.path(uri);
reqSpec.buildUnnamedPathParameterTuples(unnamedPathParams);
if (params != null) {
new ParamLogger(params) {
protected void logParam(String paramName, Object paramValue) {
reqSpec.param(paramName, paramValue);
}
}.logParams();
}
if (queryParams != null) {
new ParamLogger(queryParams) {
protected void logParam(String paramName, Object paramValue) {
reqSpec.queryParam(paramName, paramValue);
}
}.logParams();
}
if (formParams != null) {
new ParamLogger(formParams) {
protected void logParam(String paramName, Object paramValue) {
reqSpec.formParam(paramName, paramValue);
}
}.logParams();
}
if (headers != null) {
for (Header header : headers) {
reqSpec.header(header);
}
}
if (cookies != null) {
for (Cookie cookie : cookies) {
reqSpec.cookie(cookie);
}
}
if (requestBody != null) {
if (requestBody instanceof byte[]) {
reqSpec.body((byte[]) requestBody);
} else if (requestBody instanceof File) {
String contentType = findContentType();
String charset = null;
if (StringUtils.isNotBlank(contentType)) {
charset = CharsetExtractor.getCharsetFromContentType(contentType);
}
if (charset == null) {
charset = Charset.defaultCharset().toString();
}
String string = fileToString((File) requestBody, charset);
reqSpec.body(string);
} else {
reqSpec.body(requestBody);
}
}
if (multiParts != null) {
for (MockMvcMultiPart multiPart : multiParts) {
reqSpec.multiPart(new MultiPartSpecBuilder(multiPart.getContent()).controlName(multiPart.getControlName()).fileName(multiPart.getFileName()).mimeType(multiPart.getMimeType()).build());
}
}
String uriPath = PathSupport.getPath(uri);
String originalUriPath = PathSupport.getPath(originalPath);
requestLoggingFilter.filter(reqSpec, null, new FilterContextImpl(uri, originalUriPath, uriPath, uri, uri, new Object[0], method.toString(), null, Collections.<Filter>emptyList().iterator(), new HashMap<String, Object>()));
}
use of io.restassured.builder.MultiPartSpecBuilder in project rest-assured by rest-assured.
the class MultiPartITest method byteArrayUploadingWhenUsingMultiPartSpecification.
@Test
public void byteArrayUploadingWhenUsingMultiPartSpecification() throws Exception {
// Given
final byte[] bytes = IOUtils.toByteArray(getClass().getResourceAsStream("/car-records.xsd"));
// When
given().multiPart(new MultiPartSpecBuilder(bytes).build()).expect().statusCode(200).body(is(new String(bytes))).when().post("/multipart/file");
}
use of io.restassured.builder.MultiPartSpecBuilder in project rest-assured by rest-assured.
the class MultiPartITest method fileNameInMultiPartSpecBuilderHasPrecedenceOverDefaultWhenConfigured.
@Test
public void fileNameInMultiPartSpecBuilderHasPrecedenceOverDefaultWhenConfigured() throws Exception {
// Given
final InputStream is = getClass().getResourceAsStream("/car-records.xsd");
// When
given().config(RestAssuredConfig.config().multiPartConfig(multiPartConfig().defaultFileName("something-else"))).multiPart(new MultiPartSpecBuilder(is).fileName("file2.txt").build()).when().post("/multipart/filename").then().statusCode(200).body(equalTo("file2.txt"));
;
}
Aggregations