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:info.losd.galen.api.TestPostHealthCheckRequest.java
@Test public void it_runs_the_posted_api_request() throws Exception { String json = "{\"tag\":\"test_api\",\"url\":\"http://localhost:9090/test\", \"method\": \"GET\",\"headers\": {\"header1\": \"value1\"}}"; ArgumentCaptor<ApiRequest> argumentCaptor = ArgumentCaptor.forClass(ApiRequest.class); ApiResponse response = ApiResponse.statusCode(200).body(null).build(); when(client.execute(argumentCaptor.capture())).thenReturn(response); MvcResult mvcResult = mockMvc// www . j av a 2s . c o m .perform(post("/healthchecks").contentType(MediaType.APPLICATION_JSON).content(json)) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); HealthcheckApiResult result = gson.fromJson(mvcResult.getResponse().getContentAsString(), HealthcheckApiResult.class); assertThat(result.getStatusCode(), is(200)); ApiRequest captured = argumentCaptor.getValue(); assertThat(captured.getTag(), is(equalTo("test_api"))); assertThat(captured.getMethod(), is(equalTo(ApiMethod.GET))); assertThat(captured.getUrl(), is(equalTo("http://localhost:9090/test"))); assertThat(captured.getHeaders(), IsMapContaining.hasEntry("header1", "value1")); }
From source file:org.zalando.github.spring.UsersTemplatePublicKeyTest.java
@Test public void getPublicKeysForUser() throws Exception { mockServer.expect(requestTo("https://api.github.com/users/klaus/keys")).andExpect(method(HttpMethod.GET)) // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN")) .andRespond(withSuccess(new ClassPathResource("listPublicKeysForUser.json", getClass()), MediaType.APPLICATION_JSON)); List<PubKey> pubKeyList = usersTemplate.listPublicKeys("klaus"); Assertions.assertThat(pubKeyList).isNotNull(); Assertions.assertThat(pubKeyList.size()).isEqualTo(1); Assertions.assertThat(pubKeyList.get(0).getKey()).isEqualTo("ssh-rsa AAA..."); }
From source file:org.openwms.tms.ChangeStateDocumentation.java
public @Test void turnBackState() throws Exception { // setup .../*from w w w. j a va2s.c om*/ CreateTransportOrderVO vo = createTO(); postTOAndValidate(vo, NOTLOGGED); vo.setState(TransportOrderState.INITIALIZED.toString()); given(commonGateway.getTransportUnit(KNOWN)) .willReturn(Optional.of(new TransportUnit(KNOWN, INIT_LOC, ERR_LOC_STRING))); // test ... mockMvc.perform(patch(TMSConstants.ROOT_ENTITIES).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(vo))).andExpect(status().isBadRequest()) .andExpect(jsonPath("messageKey", is(TMSMessageCodes.TO_STATE_CHANGE_BACKWARDS_NOT_ALLOWED))) .andDo(document("to-patch-state-change-back")); }
From source file:com.ushahidi.swiftriver.core.api.controller.RiversControllerTest.java
@Test public void createRiver() throws Exception { String postBody = "{\"name\":\"Viva Riva\",\"description\":\"Like the movie\",\"public\":true}"; this.mockMvc//from w ww .ja v a 2 s.c o m .perform(post("/v1/rivers").content(postBody).contentType(MediaType.APPLICATION_JSON) .principal(getAuthentication("user1"))) .andExpect(status().isOk()).andExpect(jsonPath("$.id").exists()); }
From source file:fi.helsinki.opintoni.web.rest.restrictedapi.portfolio.RestrictedPortfolioResourcePermissionTest.java
@Test public void thatUserCanLoadPublicPortfolioFromRestrictedApi() throws Exception { Portfolio portfolio = portfolioRepository .findByPathAndPortfolioRole("olli-opiskelija", PortfolioRole.STUDENT).get(); portfolio.visibility = PortfolioVisibility.PUBLIC; portfolioRepository.save(portfolio); mockMvc.perform(get("/api/restricted/v1/portfolio/student/olli-opiskelija") .with(securityContext(studentSecurityContext())).characterEncoding("UTF-8") .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); }
From source file:fi.helsinki.opintoni.web.rest.privateapi.SearchResourceTest.java
@Test public void thatEmptyResultsAreReturned() throws Exception { leikiServer.expectSearchResults("nohits", "emptysearchresults.json"); mockMvc.perform(get("/api/private/v1/search?searchTerm=nohits") .with(securityContext(studentSecurityContext())).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andExpect(jsonPath("$").isArray()).andExpect(jsonPath("$", hasSize(0))); }
From source file:org.cloudfoundry.identity.uaa.integration.ClientInfoEndpointIntegrationTests.java
@Test public void testImplicitClientInfo() throws Exception { HttpHeaders headers = new HttpHeaders(); ImplicitResourceDetails app = testAccounts.getDefaultImplicitResource(); headers.set("Authorization", testAccounts.getAuthorizationHeader(app.getClientId(), "")); 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.kixeye.chassis.transport.SpringMvcConfiguration.java
@Override protected void configureContentNegotiation(ContentNegotiationConfigurer configurer) { // default to JSON configurer.defaultContentType(MediaType.APPLICATION_JSON); }
From source file:com.nebhale.letsmakeadeal.web.GamesControllerIntegrationTest.java
@Test public void playAGame() throws Exception { String gameLocation = this.mockMvc.perform(post("/games")) // .andExpect(status().isCreated()) // .andReturn().getResponse().getHeader("Location"); String doorsLocation = getLinkedLocation(gameLocation, "doors"); this.mockMvc.perform(put(getDoorLocation(doorsLocation, 1)) // .contentType(MediaType.APPLICATION_JSON) // .content(getBytes("{ \"status\": \"SELECTED\"}"))) // .andExpect(status().isOk()); if ("CLOSED".equals(getDoorStatus(doorsLocation, 0))) { this.mockMvc.perform(put(getDoorLocation(doorsLocation, 0)) // .contentType(MediaType.APPLICATION_JSON) // .content(getBytes("{ \"status\": \"OPEN\"}"))) // .andExpect(status().isOk()); } else {// w w w . java 2 s .c o m this.mockMvc.perform(post(getDoorLocation(doorsLocation, 2)) // .contentType(MediaType.APPLICATION_JSON) // .content(getBytes("{ \"status\": \"OPEN\"}"))) // .andExpect(status().isOk()); } String gameStatus = getGameStatus(gameLocation); assertTrue("WON".equals(gameStatus) || "LOST".equals(gameStatus)); }
From source file:com.nebhale.springone2013.web.GamesControllerIntegrationTest.java
@Test public void playAGame() throws Exception { String gameLocation = this.mockMvc.perform(post("/games")) // .andExpect(status().isCreated()) // .andReturn().getResponse().getHeader("Location"); String doorsLocation = getLinkedLocation(gameLocation, "doors"); this.mockMvc.perform(put(getDoorLocation(doorsLocation, 1)) // .contentType(MediaType.APPLICATION_JSON) // .content(getBytes("{ \"status\": \"SELECTED\"}"))) // .andExpect(status().isOk()); if ("CLOSED".equals(getDoorStatus(doorsLocation, 0))) { this.mockMvc.perform(put(getDoorLocation(doorsLocation, 0)) // .contentType(MediaType.APPLICATION_JSON) // .content(getBytes("{ \"status\": \"OPEN\"}"))) // .andExpect(status().isOk()); } else {// www. j ava2 s . co m this.mockMvc.perform(put(getDoorLocation(doorsLocation, 2)) // .contentType(MediaType.APPLICATION_JSON) // .content(getBytes("{ \"status\": \"OPEN\"}"))) // .andExpect(status().isOk()); } String gameStatus = getGameStatus(gameLocation); assertTrue("WON".equals(gameStatus) || "LOST".equals(gameStatus)); }