Example usage for org.springframework.http MediaType APPLICATION_JSON_UTF8_VALUE

List of usage examples for org.springframework.http MediaType APPLICATION_JSON_UTF8_VALUE

Introduction

In this page you can find the example usage for org.springframework.http MediaType APPLICATION_JSON_UTF8_VALUE.

Prototype

String APPLICATION_JSON_UTF8_VALUE

To view the source code for org.springframework.http MediaType APPLICATION_JSON_UTF8_VALUE.

Click Source Link

Document

A String equivalent of MediaType#APPLICATION_JSON_UTF8 .

Usage

From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtTargetResourceTest.java

@Test
@Description("Ensures that a metadata update through API is reflected by the repository.")
public void updateMetadata() throws Exception {
    final String knownControllerId = "targetIdWithMetadata";

    // prepare and create metadata for update
    final String knownKey = "knownKey";
    final String knownValue = "knownValue";
    final String updateValue = "valueForUpdate";

    setupTargetWithMetadata(knownControllerId, knownKey, knownValue);

    final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue);

    mvc.perform(put("/rest/v1/targets/{targetId}/metadata/{key}", knownControllerId, knownKey)
            .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON)
            .content(jsonObject.toString())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
            .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue)));

    final TargetMetadata updatedTargetMetadata = targetManagement
            .getMetaDataByControllerId(knownControllerId, knownKey).get();
    assertThat(updatedTargetMetadata.getValue()).isEqualTo(updateValue);

}

From source file:org.springframework.cloud.gateway.test.GatewayIntegrationTests.java

@Test
public void complexContentTypeWorks() {
    Mono<Map> result = webClient.get().uri("/headers").contentType(MediaType.APPLICATION_JSON_UTF8)
            .header("Host", "www.complexcontenttype.org").exchange()
            .then(response -> response.body(toMono(Map.class)));

    StepVerifier.create(result).consumeNextWith(response -> {
        Map<String, Object> headers = getMap(response, "headers");
        assertThat(headers).containsEntry(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE);
    }).expectComplete().verify(DURATION);
}

From source file:ren.hankai.cordwood.web.support.MultiReadHttpServletRequestTest.java

@Test
public void testGetInputStream() throws Exception {
    final String requestBody = "{\"name\": \"\"}";

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
    request.setContent(requestBody.getBytes("UTF-8"));

    final MultiReadHttpServletRequest wr = new MultiReadHttpServletRequest(request);
    final InputStream inputStream = wr.getInputStream();
    Assert.assertNotNull(inputStream);//ww  w .j av a2 s.  co  m
    ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
    IOUtils.copy(inputStream, byteOutStream);
    Assert.assertEquals(requestBody, byteOutStream.toString("UTF-8"));
    Assert.assertTrue(inputStream instanceof CachedServletInputStream);
    final CachedServletInputStream cis = (CachedServletInputStream) inputStream;
    Assert.assertTrue(cis.isFinished());
    Assert.assertTrue(cis.isReady());
    cis.setReadListener(null);// ??

    /* ? */
    // ?
    final BufferedReader reader = wr.getReader();
    final StringWriter writer = new StringWriter();
    IOUtils.copy(reader, writer);
    Assert.assertEquals(requestBody, byteOutStream.toString("UTF-8"));

    // ?
    byteOutStream = new ByteArrayOutputStream();
    IOUtils.copy(wr.getInputStream(), byteOutStream);
    Assert.assertEquals(requestBody, byteOutStream.toString("UTF-8"));
}