APISonar


io.restassured.http.ContentType.XML

> io > restassured > http > ContentType > XML
io APIs restassured APIs http APIs ContentType APIs XML APIs

Example 1
@Test public void
    prettifying_empty_xml_body_doesnt_log_premature_end_of_file() {
        final StringWriter writer = new StringWriter();
        final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);

        given().
                filter(new ResponseLoggingFilter(LogDetail.ALL, true, captor)).
                filter((requestSpec, responseSpec, ctx) -> new ResponseBuilder().setStatusCode(200).setContentType(ContentType.XML).setBody("").build()).
        when().
                get("/xml-empty-body").
        then().
                statusCode(200);

        assertThat(writer.toString(), equalTo(String.format("200%nContent-Type: application/xml%n")));
    }
Example 2
public void
	content_type_is_not_overwritten_when_not_defined_in_specification() {
		// Given
		WebTestClientRequestSpecification specToMerge = new WebTestClientRequestSpecBuilder()
				.addQueryParam("param1", "value1").build();

		// When
		WebTestClientRequestSpecification spec = RestAssuredWebTestClient.given().contentType(ContentType.XML)
				.spec(specToMerge);

		// Then
		Assertions.assertThat(implementation(spec).getRequestContentType()).isEqualTo(ContentType.XML.toString());
		Assertions.assertThat(implementation(spec).getQueryParams()).containsOnly(entry("param1", "value1"));
	}
Example 3
public void whenRequestContentTypeIsXmlThenRestAssuredSerializesToXML() throws Exception {
        final Greeting object = new Greeting();
        object.setFirstName("John");
        object.setLastName("Doe");
        final Greeting actual = given().contentType(ContentType.XML).and().body(object).when().post("/reflect").as(Greeting.class);
        assertThat(object, equalTo(actual));
    }
Example 4
@Test public void
    content_type_is_overwritten_when_defined_in_specification() {
        // Given
        MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setContentType(ContentType.JSON).build();

        // When
        MockMvcRequestSpecification spec = RestAssuredMockMvc.given().contentType(ContentType.XML).spec(specToMerge);

        // Then
        Assertions.assertThat(implOf(spec).getRequestContentType()).isEqualTo(ContentType.JSON.toString());
    }