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.jiwhiz.rest.user.PostCommentRestControllerTest.java

@Test
public void postComment_ShouldAddNewComment() throws Exception {
    final String NEW_COMMENT_TXT = "New comment test.";
    UserAccount user = getTestLoggedInUserWithAuthorRole();
    BlogPost blog = getTestSinglePublishedBlogPost();
    CommentPost comment = new CommentPost(user, blog, NEW_COMMENT_TXT);
    comment.setId("newCommId");

    when(userAccountServiceMock.getCurrentUser()).thenReturn(user);
    when(blogPostRepositoryMock.findOne(eq(BLOG_ID))).thenReturn(blog);
    when(commentPostServiceMock.postComment(eq(user), eq(blog), anyString())).thenReturn(comment);

    CommentForm newComment = new CommentForm();
    mockMvc.perform(request(HttpMethod.POST, API_ROOT + URL_USER_BLOGS_BLOG_COMMENTS, BLOG_ID)
            .contentType(MediaType.APPLICATION_JSON).content(TestUtils.convertObjectToJsonBytes(newComment)))
            .andExpect(status().isCreated())
            .andExpect(header().string("Location", endsWith(API_ROOT + URL_USER_COMMENTS + "/newCommId")))
            .andExpect(content().string(""));
}

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

@Test
public void thatTodoItemIsInserted() throws Exception {
    TodoItemDto todoItemDto = new TodoItemDto();
    todoItemDto.content = "Content";
    todoItemDto.status = TodoItem.Status.OPEN.name();

    mockMvc.perform(post("/api/private/v1/todoitems").with(securityContext(studentSecurityContext()))
            .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON)
            .content(WebTestUtils.toJsonBytes(todoItemDto)).accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk()).andExpect(content().contentType(WebConstants.APPLICATION_JSON_UTF8))
            .andExpect(jsonPath("$.id").value(any(Number.class)))
            .andExpect(jsonPath("$.createdDate").value(any(Number.class)))
            .andExpect(jsonPath("$.content").value("Content")).andExpect(jsonPath("$.status").value("OPEN"));

}

From source file:org.cloudfoundry.identity.uaa.error.JsonAwareAuthenticationEntryPointTests.java

@Test
public void testCommenceWithHtmlAndJsonAccept() throws Exception {
    request.addHeader("Accept", String.format("%s,%s", MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_JSON));
    entryPoint.commence(request, response, new BadCredentialsException("Bad"));
    assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
    assertEquals(null, response.getErrorMessage());
}

From source file:com.epam.ta.reportportal.auth.permissions.ProjectLeadPermissionTest.java

/**
 * Request from user which is not assigned to specified project
 *
 * @throws JsonProcessingException/*from  ww  w.ja va  2 s  . c om*/
 * @throws Exception
 */
@Test
public void userNotAssigned() throws Exception {
    Authentication vasia = AuthConstants.newAuthentication("Vasia", AuthConstants.USER_PASSWORD, true,
            new SimpleGrantedAuthority(UserRole.USER.name()));
    SecurityContextHolder.getContext().setAuthentication(vasia);
    this.mvcMock.perform(put("/project" + PROJECT_BASE_URL).principal(vasia)
            .content(objectMapper.writeValueAsBytes(getUpdateRequest()))
            .contentType(MediaType.APPLICATION_JSON)).andExpect(status().isForbidden());
}

From source file:doge.controller.UsersRestControllerTest.java

@Test
@Ignore/*from   ww w. jav  a 2 s . c  om*/
public void getUser() throws Exception {
    given(this.userRepository.findOne("1")).willReturn(new User("philwebb", "Phil Webb"));
    ResultActions result = this.mvc.perform(get("/users/philwebb").accept(MediaType.APPLICATION_JSON));
    result.andExpect(status().isOk());
    result.andExpect(content().string(containsString("Phil Webb")));
}

From source file:eu.cloudwave.wp5.common.rest.BaseRestClientTest.java

@Test
public void testWithoutHeaders() throws UnsupportedEncodingException, IOException {
    mockServer.expect(requestTo(ANY_URL)).andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess(getResponseStub(), MediaType.APPLICATION_JSON));

    final ResponseEntity<String> responseEntity = restClientMock.get(ANY_URL, String.class);
    assertThat(responseEntity.getBody()).isEqualTo(getResponseStub());
}

From source file:biz.dfch.activiti.wrapper.controller.ProcessInvocationControllerTest.java

@Test
public void invokeProcessWithInValidPayloadReturnsHttpStatusBadRequest() throws Exception {
    mvc.perform(MockMvcRequestBuilders.post("/process-invocation").accept(MediaType.APPLICATION_JSON)
            .contentType(MediaType.APPLICATION_JSON)
            .content("{" + "    \"assetId\": \"\"," + "    \"assetType\": \"System\","
                    + "    \"action\": \"create\"," + "    \"decisionId\": \"1234\","
                    + "    \"userId\": \"12345\"," + "    \"tenantId\": \"123456\","
                    + "    \"type\": \"PRE-ACTION\"," + "    \"bpeURI\": \"http://localhost\"" + "}"))
            .andExpect(status().isBadRequest());
}

From source file:com.hp.autonomy.frontend.find.idol.comparison.ComparisonServiceIT.java

@Test
public void basicUserNotAuthorised() throws Exception {
    final ComparisonRequest<String> comparisonRequest = new ComparisonRequest.Builder<String>()
            .setFirstQueryStateToken(twoDocStateToken).setSecondQueryStateToken(sixDocStateToken).build();

    final MockHttpServletRequestBuilder requestBuilder = post(
            ComparisonController.BASE_PATH + '/' + ComparisonController.COMPARE_PATH + '/')
                    .content(mapper.writeValueAsString(comparisonRequest))
                    .contentType(MediaType.APPLICATION_JSON).with(authentication(userAuth()));

    mockMvc.perform(requestBuilder).andExpect(status().is(403));
}

From source file:com.iata.ndc.trial.controllers.DefaultController.java

@RequestMapping(value = "/ba", method = RequestMethod.GET)
public String getCal() {

    RestTemplate restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.getObjectMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    converters.add(converter);/* w  w w.  j a v a2  s .  c o m*/
    restTemplate.setMessageConverters(converters);

    HttpHeaders headers = new HttpHeaders();
    headers.add("client-key", "zmd9apqgg2jwekf8zgqg5ybf");
    headers.setContentType(MediaType.APPLICATION_JSON);

    ResponseEntity<BALocationsResponseWrapper> baLocationsResponse = restTemplate.exchange(
            "https://api.ba.com/rest-v1/v1/balocations", HttpMethod.GET, new HttpEntity<Object>(headers),
            BALocationsResponseWrapper.class);
    System.out.println(baLocationsResponse.getBody().getGetBALocationsResponse().getCountry().size());
    return "index";
}