List of usage examples for org.springframework.http MediaType APPLICATION_JSON
MediaType APPLICATION_JSON
To view the source code for org.springframework.http MediaType APPLICATION_JSON.
Click Source Link
From source file:fi.helsinki.opintoni.web.rest.privateapi.portfolio.PrivatePortfolioAttainmentResourcePermissionTest.java
@Test public void thatUserCannotUpdateWhitelistToPortfolioSheDoesNotOwn() throws Exception { mockMvc.perform(//from w ww. j a v a2 s. com post(RESOURCE_URL).with(securityContext(teacherSecurityContext())).characterEncoding("UTF-8") .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isNotFound()); }
From source file:com.example.mockmvc.Payload.java
public void explicitType() throws Exception { this.mockMvc.perform(get("/user/5").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) // tag::explicit-type[] .andDo(document("index", responseFields(fieldWithPath("contact.email").type(JsonFieldType.STRING) // <1> .description("The user's email address")))); // end::explicit-type[] }
From source file:jetbrains.buildServer.vsoRooms.rest.impl.VSOTeamRoomsAPIConnectionImpl.java
@Nullable public TeamRoomMessage sendMessageToRoom(@NotNull String account, @NotNull Long roomId, @NotNull String messageContent) { final HttpHeaders requestHeaders = getRequestHeaders(); requestHeaders.setContentType(MediaType.APPLICATION_JSON); final HttpEntity<String> request = new HttpEntity<String>(getMessageBody(messageContent), requestHeaders); final ResponseEntity<TeamRoomMessage> responseEntity = myRestTemplate .postForEntity(getRoomMessagesUrl(account, roomId), request, TeamRoomMessage.class); return responseEntity.getBody(); }
From source file:org.zalando.github.spring.MembersTemplateTest.java
@Test public void listMembers() throws Exception { mockServer.expect(requestTo("https://api.github.com/orgs/zalando-stups/members?per_page=25")) .andExpect(method(HttpMethod.GET)) // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN")) .andRespond(withSuccess(new ClassPathResource("listMembers.json", getClass()), MediaType.APPLICATION_JSON)); List<User> issueList = membersTemplate.listMembers("zalando-stups"); Assertions.assertThat(issueList).isNotNull(); Assertions.assertThat(issueList.size()).isEqualTo(1); }
From source file:com.gtp.tradeapp.rest.GreetingControllerITest.java
@Test public void greetingUnauthorized() throws Exception { mockMvc.perform(get("/greeting").accept(MediaType.APPLICATION_JSON)).andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.error", is("unauthorized"))); }
From source file:com.ushahidi.swiftriver.core.api.controller.FormsControllerTest.java
@Test public void createForm() throws Exception { String postBody = "{\"name\":\"Dangerous Speech Categorisation\",\"fields\":[{\"title\":\"Language\",\"description\":\"Language the audience is being addressed in\",\"type\":\"multiple\",\"required\":false,\"options\":[\"English\",\"Swahili\",\"Luo\",\"Kalenjin\",\"Luhya\",\"Kikuyu\",\"Sheng\",\"Other\"]},{\"title\":\"Speaker\",\"description\":\"Description of the speaker\",\"type\":\"select\",\"required\":false,\"options\":[\"Politician\",\"Journalist\",\"Blogger\",\"Community Leader\",\"Anonymous Commenter\",\"Identifiable Commenter\",\"Public Figure\"]},{\"title\":\"Target Audience\",\"description\":\"Audience most likely to react to this statement/article\",\"type\":\"text\",\"required\":true}]}"; this.mockMvc/*from w ww.ja v a 2 s . c o m*/ .perform(post("/v1/forms").content(postBody).contentType(MediaType.APPLICATION_JSON) .principal(getAuthentication("user1"))) .andExpect(status().isOk()).andExpect(jsonPath("$.id").exists()); }
From source file:fi.helsinki.opintoni.server.CoursePageServer.java
public void expectCourseImplementationRequest(String courseImplementationId) { server.expect(requestTo(courseImplementationUrl(courseImplementationId))).andExpect(method(HttpMethod.GET)) .andRespond(// w w w .j av a 2 s.c om withSuccess(SampleDataFiles.toText("coursepage/courses.json"), MediaType.APPLICATION_JSON)); }
From source file:uk.ac.ebi.ep.ebeye.EbeyeRestServiceTest.java
/** * Test of ebeyeAutocompleteSearch method, of class EbeyeRestService. */// w w w .j ava 2 s . co m @Test public void testEbeyeAutocompleteSearch() { try { LOGGER.info("ebeyeAutocompleteSearch"); String searchTerm = "phos"; String url = ebeyeIndexUrl.getDefaultSearchIndexUrl() + "/autocomplete?term=" + searchTerm + "&format=json"; String filename = "suggestions.json"; String json = getJsonFile(filename); mockRestServer.expect(requestTo(url)).andExpect(method(HttpMethod.GET)) .andRespond(withSuccess(json, MediaType.APPLICATION_JSON)); EbeyeAutocomplete aut = restTemplate.getForObject(url.trim(), EbeyeAutocomplete.class); List<Suggestion> expResult = aut.getSuggestions().stream().sorted().collect(Collectors.toList()); List<Suggestion> result = ebeyeRestService.ebeyeAutocompleteSearch(searchTerm).stream().sorted() .collect(Collectors.toList()); Suggestion suggestion = expResult.stream().sorted().findAny().get(); mockRestServer.verify(); assertThat(result, hasItem(suggestion)); } catch (IOException ex) { LOGGER.error(ex.getMessage(), ex); } }
From source file:fi.helsinki.opintoni.web.rest.privateapi.portfolio.PrivateDegreeResourceTest.java
@Test public void thatDegreesAreUpdated() throws Exception { UpdateDegree updateDegree = new UpdateDegree(); updateDegree.title = "Degree Title"; updateDegree.description = "Degree description"; updateDegree.dateOfDegree = LocalDate.of(2016, 6, 6); mockMvc.perform(post("/api/private/v1/portfolio/2/degree").with(securityContext(studentSecurityContext())) .content(WebTestUtils.toJsonBytes(newArrayList(updateDegree))) .contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andExpect(jsonPath("$").isArray()).andExpect(jsonPath("$", hasSize(1))) .andExpect(jsonPath("$[0].title").value("Degree Title")) .andExpect(jsonPath("$[0].description").value("Degree description")) .andExpect(jsonPath("$[0].dateOfDegree[0]").value(2016)) .andExpect(jsonPath("$[0].dateOfDegree[1]").value(6)) .andExpect(jsonPath("$[0].dateOfDegree[2]").value(6)); }
From source file:com.opensearchserver.hadse.index.IndexTest.java
@Test public void t02_createDefaultIndex() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); RestTemplate template = new RestTemplate(); ResponseEntity<String> entity = template.exchange("http://localhost:8080/my_index", HttpMethod.PUT, null, String.class); assertEquals(HttpStatus.CREATED, entity.getStatusCode()); }