Search in sources :

Example 16 with Greeting

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);
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) Type(java.lang.reflect.Type) Map(java.util.Map) Test(org.junit.Test)

Example 17 with Greeting

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));
}
Also used : PrintStream(java.io.PrintStream) Greeting(io.restassured.itest.java.objects.Greeting) StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Example 18 with Greeting

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");
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) Test(org.junit.Test)

Example 19 with Greeting

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("<"));
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) MultiPartSpecBuilder(io.restassured.builder.MultiPartSpecBuilder) Test(org.junit.Test)

Example 20 with Greeting

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();
    }
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) Test(org.junit.Test)

Aggregations

Greeting (io.restassured.itest.java.objects.Greeting)24 Test (org.junit.Test)24 MultiPartSpecBuilder (io.restassured.builder.MultiPartSpecBuilder)6 PrintStream (java.io.PrintStream)2 StringWriter (java.io.StringWriter)2 Type (java.lang.reflect.Type)2 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 LogConfig (io.restassured.config.LogConfig)1 Jackson2Mapper (io.restassured.internal.mapping.Jackson2Mapper)1 DefaultJackson2ObjectMapperFactory (io.restassured.mapper.factory.DefaultJackson2ObjectMapperFactory)1 GsonObjectMapperFactory (io.restassured.mapper.factory.GsonObjectMapperFactory)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1