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:com.autentia.web.rest.wadl.builder.RepresentationBuilderTest.java

@Test
public void givenVoidAsMethodReturnType_whenBuildRepresentation_thenDoNotAddAnything()
        throws NoSuchMethodException {
    final ApplicationContext appCtx = new ApplicationContext(IGNORED_METHOD_CONTEXT_ITERATOR,
            new GrammarsDiscoverer(new ClassTypeDiscoverer(new QNameBuilderFactory().getBuilder())));
    final MethodContext methodCtxMock = mock(MethodContext.class);

    doReturn(appCtx).when(methodCtxMock).getParentContext();
    doReturn(new HashSet<MediaType>() {
        {//from  w  w w .  j  a v  a2  s.  c om
            add(MediaType.APPLICATION_JSON);
        }
    }).when(methodCtxMock).getMediaTypes();
    doReturn(JavaMethod.WITHOUT_PARAMETERS).when(methodCtxMock).getJavaMethod();

    final Collection<Representation> representations = representationBuilder.build(methodCtxMock);

    assertThat(representations, Matchers.is(Matchers.empty()));
}

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

@Test
public void thatSummaryIsUpdated() throws Exception {
    UpdateSummaryRequest request = new UpdateSummaryRequest();
    request.summary = "New summary";

    mockMvc.perform(post("/api/private/v1/portfolio/2/summary").with(securityContext(studentSecurityContext()))
            .contentType(MediaType.APPLICATION_JSON).content(WebTestUtils.toJsonBytes(request)))
            .andExpect(status().isOk());

    assertThat(portfolioRepository.findOne(2L).summary).isEqualTo("New summary");
}

From source file:com.marklogic.samplestack.testing.ContributorControllerTestImpl.java

/**
 * tests /contributors POST /contributors GET /docs GET
 *///  w  ww .  j  a  va2 s. com
public void testContributorCRUD() throws Exception {
    login("joeUser@marklogic.com", "joesPassword");
    Contributor joeUser = Utils.getBasicUser();
    this.mockMvc.perform(
            post("/contributors").with(csrf()).session((MockHttpSession) session).locale(Locale.ENGLISH)
                    .contentType(MediaType.APPLICATION_JSON).content(mapper.writeValueAsString(joeUser)))
            .andExpect(status().isForbidden());

    login("maryAdmin@marklogic.com", "marysPassword");
    String returnedString = this.mockMvc
            .perform(post("/contributors").with(csrf()).session((MockHttpSession) session)
                    .locale(Locale.ENGLISH).contentType(MediaType.APPLICATION_JSON)
                    .content(mapper.writeValueAsString(joeUser)))
            .andExpect(status().isCreated()).andReturn().getResponse().getContentAsString();
    Contributor returnedUser = mapper.readValue(returnedString, Contributor.class);
    assertEquals("cgreer@marklogic.com", returnedUser.getUserName());

    String contributorsList = this.mockMvc
            .perform(get("/contributors?q=grechaw").session((MockHttpSession) session)).andReturn()
            .getResponse().getContentAsString();

    logger.info("contributors list" + contributorsList);
    assertTrue(contributorsList.contains("displayName"));

    Contributor getById = mapper
            .readValue(
                    this.mockMvc
                            .perform(get("/contributors/" + returnedUser.getId())
                                    .session((MockHttpSession) session).locale(Locale.ENGLISH))
                            .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(),
                    Contributor.class);

    assertEquals("Id name matches when get By ID", getById.getId(), returnedUser.getId());
}

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

@Test
public void thatStudentEventsAreReturned() throws Exception {
    expectEvents();/*from w  w w  .j  a  v  a 2  s. c  o  m*/

    mockMvc.perform(
            get("/api/private/v1/students/enrollments/events").with(securityContext(studentSecurityContext()))
                    .characterEncoding("UTF-8").accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk()).andExpect(content().contentType(WebConstants.APPLICATION_JSON_UTF8))
            .andExpect(jsonPath("$").isArray()).andExpect(jsonPath("$", hasSize(5)))
            .andExpect(jsonPath("$[0].realisationId").value(123456789))
            .andExpect(jsonPath("$[0].endDate").isArray()).andExpect(jsonPath("$[0].endDate[0]").value(2014))
            .andExpect(jsonPath("$[0].endDate[1]").value(10)).andExpect(jsonPath("$[0].endDate[2]").value(27))
            .andExpect(jsonPath("$[0].endDate[3]").value(13)).andExpect(jsonPath("$[0].endDate[4]").value(45))
            .andExpect(jsonPath("$[0].locations").value("Prakennus, sali 1, Viikinkaari 11"))
            .andExpect(jsonPath("$[0].startDate").isArray())
            .andExpect(jsonPath("$[0].startDate[0]").value(2014))
            .andExpect(jsonPath("$[0].startDate[1]").value(10))
            .andExpect(jsonPath("$[0].startDate[2]").value(27))
            .andExpect(jsonPath("$[0].startDate[3]").value(12))
            .andExpect(jsonPath("$[0].startDate[4]").value(15))
            .andExpect(jsonPath("$[0].locations").value("Prakennus, sali 1, Viikinkaari 11"))
            .andExpect(jsonPath("$[0].title").value("Formulat... Harjoitus (en)"))
            .andExpect(jsonPath("$[0].type").value(EventDto.Type.DEFAULT.name()))
            .andExpect(jsonPath("$[0].source").value(EventDto.Source.OODI.name()))
            .andExpect(jsonPath("$[0].courseMaterial.courseMaterialUri")
                    .value("https://dev.student.helsinki" + ".fi/tvt?group-imp-material"))
            .andExpect(jsonPath("$[0].courseMaterial.courseMaterialType")
                    .value(CourseMaterialDto.CourseMaterialType.COURSE_PAGE.toString()))
            .andExpect(jsonPath("$[0].building.street").value("Viikinkaari 11"))
            .andExpect(jsonPath("$[0].building.zipCode").value("00790"))
            .andExpect(jsonPath("$[0].hasMaterial").value(true))
            .andExpect(jsonPath("$[3].title").value("Tentti"))
            .andExpect(jsonPath("$[3].source").value(EventDto.Source.COURSE_PAGE.name()))
            .andExpect(jsonPath("$[3].type").value(EventDto.Type.EXAM.name()));
}

From source file:org.cloudfoundry.identity.uaa.integration.ClientInfoEndpointIntegrationTests.java

@Test
public void testGetClientInfo() throws Exception {

    HttpHeaders headers = new HttpHeaders();
    AuthorizationCodeResourceDetails app = testAccounts.getDefaultAuthorizationCodeResource();
    headers.set("Authorization", testAccounts.getAuthorizationHeader(app.getClientId(), app.getClientSecret()));
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response = serverRunning.getForObject("/clientinfo", Map.class, headers);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertEquals(app.getClientId(), response.getBody().get("client_id"));

}

From source file:com.bugbusters.lajarus.controller.ItemControllerTest.java

@Test
public void createItemTest() throws Exception {
    String uri = "/item/create/id/name/description/type/value/5/price/10";
    MvcResult result = mvc.perform(MockMvcRequestBuilders.get(uri).accept(MediaType.APPLICATION_JSON))
            .andReturn();//from   www .  j a v a2  s. c  om

    String content = result.getResponse().getContentAsString();
    int status = result.getResponse().getStatus();

    Assert.assertEquals("failure - expected HTTP status 200", 200, status);
    Assert.assertTrue("failure - expected HTTP response body to have a value", content.trim().length() > 0);

}

From source file:com.hybris.integration.tmall.controller.TradeControllerTest.java

/**
 * initialazeorders/*from  w w  w  .  ja va 2  s  .  c  om*/
 *
 * @throws Exception
 */
@Test(enabled = false)
public void initialazeorders() throws Exception {

    final String requestBody = "{\"batchSize\": 200,\"status\":\"WAIT_BUYER_PAY\",\"startCreated\":\"2015-10-12 00:00:00\",\"endCreated\":\"2015-10-13 23:59:59\"}";
    final MvcResult result = mockMvc
            .perform(post("/biz/trade/initialazeorders/{integrationId}", accessToken.getIntegrationId())
                    .contentType(MediaType.APPLICATION_JSON).content(requestBody)
                    .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk()).andReturn();
    Assert.assertEquals(200, result.getResponse().getStatus());
}

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

@Test
public void thatUserCannotDeleteJobSearchFromPortfolioSheDoesNotOwn() throws Exception {
    mockMvc.perform(delete(RESOURCE_URL + "/1").with(securityContext(teacherSecurityContext()))
            .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_JSON)).andExpect(status().isNotFound());
}

From source file:io.pivotal.strepsirrhini.chaoslemur.task.TaskManagerTest.java

@Test
public void read() throws Exception {
    this.mockMvc.perform(get("/task/0").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
            .andExpect(jsonPath("$.links").value(hasSize(1)))
            .andExpect(jsonPath("$.links[?(@.rel == 'self')].href").value("http://localhost/task/0"));
}

From source file:example.users.UserControllerIntegrationTests.java

@Test
public void handlesJsonPayloadWithNestedProperties() throws Exception {
    postAndExpect("{ \"user\" : { \"firstname\" : \"Dave\", \"lastname\" : \"Matthews\" } }",
            MediaType.APPLICATION_JSON);
}