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:com.parivero.swagger.demo.controller.PersonaControllerTest.java
@Test public void alta_conRecursoInValido_retornaBadRequest() throws Exception { this.mockMvc// ww w . j a va2 s . c o m .perform(post("/personas").contentType(MediaType.APPLICATION_JSON) .content("{\"id\":0\"nombre\":\"Coco\"}")) .andDo(print()).andExpect(status().isBadRequest()); }
From source file:fi.helsinki.opintoni.server.OodiServer.java
public void expectTeacherCoursesRequest(String teacherNumber, String sinceDateString) { server.expect(requestTo(teachingUrl(teacherNumber, sinceDateString))).andExpect(method(HttpMethod.GET)) .andRespond(withSuccess(SampleDataFiles.toText("oodi/teachercourses.json"), MediaType.APPLICATION_JSON)); }
From source file:org.cloudfoundry.identity.uaa.login.feature.ImplicitGrantIT.java
@Test public void testDefaultScopes() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); LinkedMultiValueMap<String, String> postBody = new LinkedMultiValueMap<>(); postBody.add("client_id", "cf"); postBody.add("redirect_uri", "https://uaa.cloudfoundry.com/redirect/cf"); postBody.add("response_type", "token"); postBody.add("source", "credentials"); postBody.add("username", testAccounts.getUserName()); postBody.add("password", testAccounts.getPassword()); ResponseEntity<Void> responseEntity = restOperations.exchange(baseUrl + "/oauth/authorize", HttpMethod.POST, new HttpEntity<>(postBody, headers), Void.class); Assert.assertEquals(HttpStatus.FOUND, responseEntity.getStatusCode()); UriComponents locationComponents = UriComponentsBuilder.fromUri(responseEntity.getHeaders().getLocation()) .build();/*w ww. j a va 2 s . com*/ Assert.assertEquals("uaa.cloudfoundry.com", locationComponents.getHost()); Assert.assertEquals("/redirect/cf", locationComponents.getPath()); MultiValueMap<String, String> params = parseFragmentParams(locationComponents); Assert.assertThat(params.get("jti"), not(empty())); Assert.assertEquals("bearer", params.getFirst("token_type")); Assert.assertThat(Integer.parseInt(params.getFirst("expires_in")), Matchers.greaterThan(40000)); String[] scopes = UriUtils.decode(params.getFirst("scope"), "UTF-8").split(" "); Assert.assertThat(Arrays.asList(scopes), containsInAnyOrder("scim.userids", "password.write", "cloud_controller.write", "openid", "cloud_controller.read")); Jwt access_token = JwtHelper.decode(params.getFirst("access_token")); Map<String, Object> claims = new ObjectMapper().readValue(access_token.getClaims(), new TypeReference<Map<String, Object>>() { }); Assert.assertThat((String) claims.get("jti"), is(params.getFirst("jti"))); Assert.assertThat((String) claims.get("client_id"), is("cf")); Assert.assertThat((String) claims.get("cid"), is("cf")); Assert.assertThat((String) claims.get("user_name"), is(testAccounts.getUserName())); Assert.assertThat(((List<String>) claims.get("scope")), containsInAnyOrder(scopes)); Assert.assertThat(((List<String>) claims.get("aud")), containsInAnyOrder("cf", "scim", "openid", "cloud_controller", "password")); }
From source file:net.orpiske.tcs.service.rest.controller.ReferenceCreateIntegrationTest.java
/** * Tests the ability to return a cloud for all CSPs * @throws Exception/*w ww . j a v a2 s . c o m*/ */ @Test public void testTagCloud() throws Exception { when(tagCloudService.createReference(any(RequestCreateReference.class))).thenReturn(tagCloudUpdateEvent()); logger.debug("Sending JSON = " + REQUEST_JSON); mockMvc.perform(post("/references").content(REQUEST_JSON).contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isOk()); }
From source file:fi.helsinki.opintoni.web.rest.publicapi.PublicImageResourceTest.java
@Test public void thatBackgroundImagesAreReturned() throws Exception { mockMvc.perform(get("/api/public/v1/images/backgrounds").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andExpect(content().contentType(WebConstants.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$").isArray()).andExpect(jsonPath("$", hasSize(12))) .andExpect(jsonPath("$", hasItems("Profile_1.jpg", "Profile_2.jpg", "Profile_3.jpg", "Profile_4.jpg", "Profile_5.jpg", "Profile_6.jpg", "Profile_7.jpg", "Profile_8.jpg", "Profile_9.jpg", "Profile_10.jpg", "Profile_11.jpg", "Profile_12.jpg"))); }
From source file:curly.artifactory.ArtifactResourceControllerTests.java
@Test public void testArtifactResource() throws Exception { String id = artifact.getId(); mockMvc.perform(asyncDispatch(mockMvc.perform(get("/arts/{id}", id)).andExpect(status().isOk()) .andExpect(request().asyncStarted()).andExpect(request().asyncResult(ResponseEntity.ok(artifact))) .andReturn())).andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().json(json(artifact, messageConverter))); }
From source file:org.codeqinvest.web.sonar.SonarControllerTest.java
@Test public void badRequestWhenUrlParameterIsMalformedForReachableRoute() throws Exception { mockMvc.perform(/*w w w. j a va2 s . c om*/ put("/sonar/reachable").contentType(MediaType.APPLICATION_JSON).content("{\"url\": \"localhost\"}")) .andExpect(status().isBadRequest()); }
From source file:org.makersoft.mvc.unit.FormatHandlerMethodReturnValueHandlerTests.java
@Test public void testIncludes() throws Exception { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); mockMvc.perform(get("/account/user/includes/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("$.password").doesNotExist()) .andExpect(jsonPath("$.dept").doesNotExist()).andExpect(jsonPath("$.roles").doesNotExist()); }
From source file:com.catalog.webapp.resources.ApplicationUserResourcesTest.java
@Test public void testAddApplicationUser() throws Exception { String applicationUserJsonTest = new ObjectMapper().writeValueAsString(getTestApplicationUser()); mockMvc.perform(post(ApplicationUserResource.POST_APPLICATION_USER_URL) .contentType(MediaType.APPLICATION_JSON).content(applicationUserJsonTest)) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id", is(APPLICATION_USER_ID))); verify(applicationUserService, times(1)).addApplicationUser(any(ApplicationUser.class)); verifyNoMoreInteractions(applicationUserService); }
From source file:com.demo.FakeAuthorizator.java
private void doGet(String url) { System.out.println("try to send to " + url); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<String>(headers); ResponseEntity<String> rese = restTemplate.exchange(url, HttpMethod.GET, entity, String.class); System.out.println("RESPONSE STRING " + rese.getBody()); }