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.UserNotificationsResourceTest.java
@Test public void thatUserNotificationsAreReturned() throws Exception { expectNotifications();// w w w. jav a2s. co m mockMvc.perform(get("/api/private/v1/usernotifications").with(securityContext(studentSecurityContext())) .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$").isArray()) .andExpect(jsonPath("$", hasSize(2))).andExpect(jsonPath("$[0].notificationId").value("3")) .andExpect(jsonPath("$[0].courseName").value("Gene Technology")) .andExpect(jsonPath("$[0].notificationUri") .value("https://dev.student.helsinki.fi/tvt?group-course-messages")) .andExpect(jsonPath("$[0].avatarUri") .value("https://opi-1.student.helsinki.fi/assets/icons/avatar.png")) .andExpect(jsonPath("$[0].message").value("has written a message")) .andExpect(jsonPath("$[0].user").value("admin")).andExpect(jsonPath("$[0].read").value(false)) .andExpect(jsonPath("$[0].timestamp").isArray()) .andExpect(jsonPath("$[0].timestamp[0]").value(2015)) .andExpect(jsonPath("$[0].timestamp[1]").value(6)).andExpect(jsonPath("$[0].timestamp[2]").value(5)) .andExpect(jsonPath("$[0].timestamp[3]").value(11)) .andExpect(jsonPath("$[0].timestamp[4]").value(8)) .andExpect(jsonPath("$[0].timestamp[5]").value(6)); }
From source file:pl.eplan.config.WebMvcConfig.java
private void addJsonConverter(List<HttpMessageConverter<?>> converters) { MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter(objectMapper()); //jsonConverter.setPrefixJson(true); jsonConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON)); converters.add(jsonConverter);/*from w w w . jav a2s . co m*/ }
From source file:de.codecentric.boot.admin.registry.web.RegistryControllerTest.java
@Test public void test_register_twice_get_and_remove() throws Exception { MvcResult result = mvc//from ww w .j a v a 2 s . com .perform(post("/api/applications").contentType(MediaType.APPLICATION_JSON) .content(APPLICATION_TEST_JSON)) .andExpect(status().isCreated()).andExpect(jsonPath("$.name").value("test")) .andExpect(jsonPath("$.healthUrl").value("http://localhost/mgmt/health")) .andExpect(jsonPath("$.id").isNotEmpty()).andReturn(); String id = extractId(result); mvc.perform( post("/api/applications").contentType(MediaType.APPLICATION_JSON).content(APPLICATION_TWICE_JSON)) .andExpect(status().isCreated()).andExpect(jsonPath("$.name").value("twice")) .andExpect(jsonPath("$.healthUrl").value("http://localhost/mgmt/health")) .andExpect(jsonPath("$.id").value(id)); mvc.perform(get("/api/applications")).andExpect(status().isOk()).andExpect(jsonPath("$[0].id").value(id)); mvc.perform(get("/api/applications?name=twice")).andExpect(status().isOk()) .andExpect(jsonPath("$[0].id").value(id)); mvc.perform(get("/api/applications/{id}", id)).andExpect(status().isOk()) .andExpect(jsonPath("$.id").value(id)); mvc.perform(delete("/api/applications/{id}", id)).andExpect(status().isOk()) .andExpect(jsonPath("$.id").value(id)); mvc.perform(get("/api/applications/{id}", id)).andExpect(status().isNotFound()); }
From source file:org.shaigor.rest.retro.client.config.ClientWebMvcConfigurerAdapter.java
@Bean public ContentNegotiatingViewResolver contentViewResolver() throws Exception { ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver(); ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean(); contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON); contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject()); contentViewResolver.setDefaultViews(Arrays.<View>asList(new MappingJackson2JsonView())); return contentViewResolver; }
From source file:org.zalando.github.spring.IssuesTemplateTest.java
@Test public void listAllIssues() throws Exception { mockServer.expect(requestTo("https://api.github.com/issues?per_page=25")).andExpect(method(HttpMethod.GET)) // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN")) .andRespond(withSuccess(new ClassPathResource("listIssues.json", getClass()), MediaType.APPLICATION_JSON)); List<Issue> issueList = issuesTemplate.listAllIssues(); Assertions.assertThat(issueList).isNotNull(); Assertions.assertThat(issueList.size()).isEqualTo(1); Assertions.assertThat(issueList.get(0).getId()).isEqualTo(1); }
From source file:com.nebhale.devoxx2013.web.DoorControllerTest.java
@Test public void modifyDoorSelected() throws Exception { Game game = createGame();/*from w w w .j a v a2 s . c o m*/ Door door = createDoors(game).get(0); this.mockMvc .perform(put("/games/{game}/doors/{door}", game.getId(), door.getId()) .content("{ \"status\" : \"SELECTED\" }").contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); assertThat(door.getStatus(), equalTo(Door.DoorStatus.SELECTED)); }
From source file:org.zalando.github.spring.TeamsTemplateTest.java
@Test public void getTeam() throws Exception { mockServer.expect(requestTo("https://api.github.com/teams/1")).andExpect(method(HttpMethod.GET)) // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN")) .andRespond(//from w w w .j a va 2 s . c o m withSuccess(new ClassPathResource("getTeam.json", getClass()), MediaType.APPLICATION_JSON)); Team team = teamsTemplate.getTeam(1); Assertions.assertThat(team).isNotNull(); Assertions.assertThat(team.getId()).isEqualTo(1); Assertions.assertThat(team.getName()).isEqualTo("Justice League"); }
From source file:fi.helsinki.opintoni.server.OodiServer.java
public void expectStudentEventsRequest(String studentNumber) { server.expect(requestTo(eventsUrl(studentNumber))).andExpect(method(HttpMethod.GET)).andRespond( withSuccess(SampleDataFiles.toText("oodi/studentevents.json"), MediaType.APPLICATION_JSON)); }
From source file:org.makersoft.mvc.unit.FormatHandlerMethodReturnValueHandlerTests.java
@Test public void testExcludeEntityAttributes() throws Exception { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); mockMvc.perform(get("/account/user//exclude-entity-attributes/1").accept(MediaType.APPLICATION_JSON) .headers(httpHeaders)).andDo(print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(content().encoding("UTF-8")) .andExpect(jsonPath("$.id").value(1)).andExpect(jsonPath("$.dept.users").doesNotExist()) .andExpect(jsonPath("$.roles.users").doesNotExist()); }
From source file:com.catalog.webapp.resources.ApplicationUserResourcesTest.java
@Test public void testGetApplicationUser() throws Exception { when(applicationUserService.getApplicationUser(APPLICATION_USER_ID)).thenReturn(getTestApplicationUser()); mockMvc.perform(// w w w . j a v a 2s . co m MockMvcRequestBuilders.get(ApplicationUserResource.GET_APPLICATION_USER_URL.replace("{id}", "1")) .contentType(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$.id", Matchers.is(APPLICATION_USER_ID))); verify(applicationUserService, times(1)).getApplicationUser(APPLICATION_USER_ID); }