use of io.restassured.itest.java.objects.Greeting in project rest-assured by rest-assured.
the class TypeObjectExceptionMappingITest method shouldSeeExceptionWhenMappingTypeForJAXB.
@Test(expected = RuntimeException.class)
public void shouldSeeExceptionWhenMappingTypeForJAXB() {
final Greeting greeting = new Greeting();
greeting.setFirstName("John");
greeting.setLastName("Doe");
Type type = new TypeToken<Map<String, String>>() {
}.getType();
given().contentType("application/xml").body(greeting, JAXB).post("/reflect").as(type, JAXB);
}
use of io.restassured.itest.java.objects.Greeting in project rest-assured by rest-assured.
the class LoggingITest method logsMultiPartParamsOnLogAll.
@Test
public void logsMultiPartParamsOnLogAll() throws Exception {
// Given
final byte[] bytes = IOUtils.toByteArray(getClass().getResourceAsStream("/car-records.xsd"));
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
InputStream powermock = getClass().getResourceAsStream("/powermock-easymock-junit-1.4.12.zip");
// When
Greeting greeting = new Greeting();
greeting.setFirstName("John");
greeting.setLastName("Doe");
given().filter(logResponseTo(captor)).multiPart("file", "myFile", bytes).multiPart("something", "testing", "text/plain").multiPart("powermock", "powermock-1.4.12", powermock).multiPart("json", greeting, "application/json").when().post("/multipart/file").then().statusCode(200).body(is(new String(bytes)));
assertThat(writer.toString(), equalTo("HTTP/1.1 200 OK\nContent-Type: text/plain;charset=utf-8\nContent-Length: 1512\nServer: Jetty(9.3.2.v20150730)\n\n<!--\n ~ Copyright 2013 the original author or authors.\n ~\n ~ Licensed under the Apache License, Version 2.0 (the \"License\");\n ~ you may not use this file except in compliance with the License.\n ~ You may obtain a copy of the License at\n ~\n ~ http://www.apache.org/licenses/LICENSE-2.0\n ~\n ~ Unless required by applicable law or agreed to in writing, software\n ~ distributed under the License is distributed on an \"AS IS\" BASIS,\n ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n ~ See the License for the specific language governing permissions and\n ~ limitations under the License.\n -->\n<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\">\n <xs:element name=\"records\">\n <xs:complexType>\n <xs:sequence>\n <xs:element maxOccurs=\"unbounded\" ref=\"car\"/>\n </xs:sequence>\n </xs:complexType>\n </xs:element>\n <xs:element name=\"car\">\n <xs:complexType>\n <xs:sequence>\n <xs:element ref=\"country\"/>\n <xs:element ref=\"record\"/>\n </xs:sequence>\n <xs:attribute name=\"make\" use=\"required\" type=\"xs:NCName\"/>\n <xs:attribute name=\"name\" use=\"required\"/>\n <xs:attribute name=\"year\" use=\"required\" type=\"xs:integer\"/>\n </xs:complexType>\n </xs:element>\n <xs:element name=\"country\" type=\"xs:string\"/>\n <xs:element name=\"record\">\n <xs:complexType mixed=\"true\">\n <xs:attribute name=\"type\" use=\"required\" type=\"xs:NCName\"/>\n </xs:complexType>\n </xs:element>\n</xs:schema>" + LINE_SEPARATOR));
}
use of io.restassured.itest.java.objects.Greeting in project rest-assured by rest-assured.
the class MultiPartUploadITest method multiPartUploadingWorksForXmlObjectsWhenMimeTypeIsSpecified.
@Test
public void multiPartUploadingWorksForXmlObjectsWhenMimeTypeIsSpecified() throws Exception {
// Given
final Greeting greeting = new Greeting();
greeting.setFirstName("John");
greeting.setLastName("Doe");
// When
given().multiPart("text", greeting, "application/some+xml").expect().statusCode(200).body(endsWith("<greeting><firstName>John</firstName><lastName>Doe</lastName></greeting>")).when().post("/multipart/text");
}
use of io.restassured.itest.java.objects.Greeting in project rest-assured by rest-assured.
the class MultiPartUploadITest method multiPartObjectMapperTypeHavePrecedenceOverMimeType.
@Test
public void multiPartObjectMapperTypeHavePrecedenceOverMimeType() throws Exception {
// Given
final Greeting greeting = new Greeting();
greeting.setFirstName("John");
greeting.setLastName("Doe");
// When
given().multiPart(new MultiPartSpecBuilder(greeting, ObjectMapperType.JAXB).fileName("RoleBasedAccessFeaturePlan.csv").controlName("text").mimeType("application/json").build()).when().post("/multipart/text").then().statusCode(200).body(containsString("John"), containsString("Doe"), containsString("<"));
}
use of io.restassured.itest.java.objects.Greeting in project rest-assured by rest-assured.
the class ObjectMappingITest method whenRequestContentTypeIsXmlAndDefaultCharsetIsUtf16ThenRestAssuredSerializesToJSON.
@Test
public void whenRequestContentTypeIsXmlAndDefaultCharsetIsUtf16ThenRestAssuredSerializesToJSON() throws Exception {
RestAssured.config = RestAssuredConfig.config().encoderConfig(encoderConfig().defaultContentCharset("UTF-16"));
try {
final Greeting object = new Greeting();
object.setFirstName("John");
object.setLastName("Doe");
final Greeting actual = given().contentType("application/xml").and().body(object).when().post("/reflect").as(Greeting.class);
assertThat(object, equalTo(actual));
} finally {
RestAssured.reset();
}
}
Aggregations