Example usage for org.springframework.http MediaType APPLICATION_JSON

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

Introduction

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

Prototype

MediaType APPLICATION_JSON

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

Click Source Link

Document

Public constant media type for application/json .

Usage

From source file:net.orpiske.tcs.service.config.RestDomainIntegrationTest.java

@Test
public void addNewReferenceToTheSystem() throws Exception {
    mockMvc.perform(post("/references/").content(REQUEST_JSON).contentType(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isOk());
}

From source file:fi.helsinki.opintoni.web.rest.privateapi.portfolio.PrivatePortfolioResourcePermissionTest.java

@Test
public void thatUserCannotUpdatePortfolioThatSheDoesNotOwn() throws Exception {
    mockMvc.perform(put(PORTFOLIO_PATH + "/" + PORTFOLIO_ID).with(securityContext(studentSecurityContext()))
            .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON)
            .content(WebTestUtils.toJsonBytes(new PortfolioDto())).accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNotFound());
}

From source file:ch.ralscha.extdirectspring.controller.RouterControllerFormPostJsonTest.java

@Test
public void testCallExistsFormPostMethod() throws Exception {
    MockHttpServletRequestBuilder request = post("/router").accept(MediaType.ALL)
            .contentType(MediaType.APPLICATION_JSON).characterEncoding("UTF-8");

    request.param("extTID", "14");
    request.param("extAction", "formInfoController3");
    request.param("extMethod", "updateInfoJson");
    request.param("extType", "rpc");

    mockMvc.perform(request).andExpect(status().isOk());
}

From source file:io.spring.initializr.service.InitializrServiceSmokeTests.java

@Test
public void configurationCanBeSerialized() throws URISyntaxException {
    RequestEntity<Void> request = RequestEntity.get(new URI("/metadata/config"))
            .accept(MediaType.APPLICATION_JSON).build();
    ResponseEntity<String> response = this.restTemplate.exchange(request, String.class);
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
    InitializrMetadata actual = InitializrMetadataBuilder.create()
            .withInitializrMetadata(new ByteArrayResource(response.getBody().getBytes())).build();
    assertThat(actual).isNotNull();/*from w w  w  .j a v  a2s . com*/
    InitializrMetadata expected = this.metadataProvider.get();
    assertThat(actual.getDependencies().getAll().size()).isEqualTo(expected.getDependencies().getAll().size());
    assertThat(actual.getConfiguration().getEnv().getBoms().size())
            .isEqualTo(expected.getConfiguration().getEnv().getBoms().size());
}

From source file:com.epam.ta.reportportal.ws.resolver.JacksonViewAwareSerializationTest.java

@Test
public void testWithNoView() throws HttpMessageNotWritableException, IOException {
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    converter.write(bean, MediaType.APPLICATION_JSON, outputMessage);
    Assert.assertThat(outputMessage.getBodyAsString(), containsString(NO_VIEW_THERE));
    Assert.assertThat(outputMessage.getBodyAsString(), containsString(FIELD_WITH_VIEW));
}

From source file:io.github.proxyprint.kitchen.utils.NotificationManager.java

public void sendNotification(String username, Notification notification) {
    Consumer consumer = this.consumers.findByUsername(username);
    notification = notifications.save(notification);
    consumer.addNotifications(notification);
    consumers.save(consumer);/*from   www  .j  a va  2s  .  com*/

    if (this.subscriptions.containsKey(username)) {
        for (SseEmitter sse : this.subscriptions.get(username)) {
            try {
                sse.send(notification, MediaType.APPLICATION_JSON);
            } catch (IOException ex) {
                this.logger.warn("Broken SSE Emitter..discarding it...");
            }
        }
    }
}

From source file:info.losd.galen.api.TestGetHealthcheckList.java

@Test
public void it_gets_a_list_of_healthchecks() throws Exception {
    List<Healthcheck> healthcheckList = new LinkedList<>();
    healthcheckList.add(new info.losd.galen.repository.dto.Healthcheck("healthcheck1"));
    healthcheckList.add(new info.losd.galen.repository.dto.Healthcheck("healthcheck2"));
    healthcheckList.add(new info.losd.galen.repository.dto.Healthcheck("healthcheck3"));

    when(repo.getHealthchecks()).thenReturn(healthcheckList);

    MvcResult mvcResult = mockMvc.perform(get("/healthchecks")).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();

    Type type = new TypeToken<List<HealthcheckApiDTO>>() {
    }.getType();//from w  ww.  j  ava  2 s  .co m

    List<HealthcheckApiDTO> result = gson.fromJson(mvcResult.getResponse().getContentAsString(), type);

    assertThat(result, is(IsCollectionWithSize.hasSize(3)));
    assertThat(result.get(0).getName(), is(equalTo("healthcheck1")));

    checkHealthcheck(result.get(0), "healthcheck1");
    checkHealthcheck(result.get(1), "healthcheck2");
    checkHealthcheck(result.get(2), "healthcheck3");
}

From source file:net.bafeimao.umbrella.web.test.controller.CaptchaControllerTests.java

/**
 * ???/*ww  w . ja  v  a 2 s  .co m*/
 */
@Test
public void testUnmatchedCaptcha() throws Exception {
    this.mockMvc.perform(get("/captcha/match?text=xxx").sessionAttr(Constants.KAPTCHA_SESSION_KEY, "yyy"))
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andExpect(jsonPath("$.result").value(false));
}

From source file:application.controllers.RestControllerTest.java

protected String json(Object o) throws IOException {
    MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
    this.mappingJackson2HttpMessageConverter.write(o, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
    return mockHttpOutputMessage.getBodyAsString();
}

From source file:fi.helsinki.opintoni.web.rest.privateapi.portfolio.PrivateJobSearchResourceTest.java

private void deleteJobSearch() throws Exception {
    mockMvc.perform(delete(RESOURCE_URL + "/1").with(securityContext(studentSecurityContext()))
            .characterEncoding("UTF-8").accept(MediaType.APPLICATION_JSON)).andExpect(status().isNoContent());
}