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.atlassian.connect.spring.test.ContextModelAttributesTest.java
@Test public void shouldReturnAllJsModelAttributeForAnonymous() throws Exception { mvc.perform(get("/model-public").param("xdm_e", "http://some-host.com").param("cp", "/context-path") .accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andExpect(jsonPath("$.['atlassian-connect-all-js-url']") .value(is("http://some-host.com/context-path/atlassian-connect/all-debug.js"))); }
From source file:fr.mael.microrss.web.CategoryControllerTest.java
@Test public void testTree() throws Exception { mockMvc.perform(get("/category/").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andExpect(jsonPath("$[0].user").doesNotExist()).andExpect(jsonPath("$[1].user").doesNotExist()) .andExpect(jsonPath("$[0].title").value("Category 1")) .andExpect(jsonPath("$[1].title").value("Category 2")) .andExpect(jsonPath("$[0].categories[?(@.id == 3)].feeds[0].title").value("Blog@Case")) .andExpect(jsonPath("$[0].categories[?(@.id == 3)].feeds[0].user").doesNotExist()) .andExpect(jsonPath("$[0].feeds[0].title").value("Blog de Mael")) .andExpect(jsonPath("$[0].feeds[0].user").doesNotExist()); }
From source file:org.zalando.github.spring.IssuesTemplateTest.java
@Test public void createIssue() throws Exception { mockServer.expect(requestTo("https://api.github.com/repos/klaus/simple/issues")) .andExpect(method(HttpMethod.POST)).andExpect(content().contentType(MediaType.APPLICATION_JSON)) // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN")) .andRespond(withSuccess(new ClassPathResource("createIssue.json", getClass()), MediaType.APPLICATION_JSON)); Issue issue = issuesTemplate.createIssue(new IssueRequest("issueTitle"), "klaus", "simple"); Assertions.assertThat(issue).isNotNull(); Assertions.assertThat(issue.getId()).isEqualTo(1); }
From source file:net.gbmb.collector.rest.HttpRecordMessageConverter.java
@Override public List<MediaType> getSupportedMediaTypes() { List<MediaType> ret = new ArrayList<MediaType>(1); ret.add(MediaType.APPLICATION_JSON); return ret;/*from ww w . ja v a 2s. c o m*/ }
From source file:cz.muni.fi.mushroomhunter.restclient.LocationUpdateSwingWorker.java
@Override protected Integer doInBackground() throws Exception { DefaultTableModel model = (DefaultTableModel) restClient.getTblLocation().getModel(); int selectedRow = restClient.getTblLocation().getSelectedRow(); String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); List<MediaType> mediaTypeList = new ArrayList<>(); mediaTypeList.add(MediaType.ALL);//from w ww . ja va 2 s . c o m headers.setAccept(mediaTypeList); headers.add("Authorization", "Basic " + base64Creds); HttpEntity request = new HttpEntity<>(headers); ResponseEntity<LocationDto> responseEntity = restTemplate.exchange( RestClient.SERVER_URL + "pa165/rest/location/" + RestClient.getLocationIDs().get(selectedRow), HttpMethod.GET, request, LocationDto.class); LocationDto locationDto = responseEntity.getBody(); locationDto.setName(restClient.getTfLocationName().getText()); locationDto.setDescription(restClient.getTfLocationDescription().getText()); locationDto.setNearCity(restClient.getTfLocationNearCity().getText()); ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(locationDto); request = new HttpEntity(json, headers); restTemplate.exchange(RestClient.SERVER_URL + "pa165/rest/location", HttpMethod.PUT, request, LocationDto.class); return selectedRow; }
From source file:edu.fing.tagsi.db4o.business.CiudadesController.java
public Recorrido ObtenerRecorrido(Ciudad origen, Ciudad destino) { RestTemplate restTemplate = new RestTemplate(); RequestRecorrido req = new RequestRecorrido(origen.getNombre(), destino.getNombre()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<RequestRecorrido> entity = new HttpEntity<>(req, headers); RecorridoREST recorrido = restTemplate.postForObject(URL, entity, RecorridoREST.class); if (recorrido.getCiudades() != null) { NodoCamino[] ciudades = new NodoCamino[recorrido.getCiudades().length]; for (int i = 0; i < ciudades.length; i++) { if (i == 0) { ciudades[i] = new NodoCamino(ObtenerCiudad(recorrido.getCiudades()[i].getName()), true, 0, null);//from w w w. j a va 2 s . c o m } else { Tramo tramo = recorrido.getRutas()[i - 1]; ciudades[i] = new NodoCamino(ObtenerCiudad(recorrido.getCiudades()[i].getName()), false, tramo.getDistancia(), tramo.getRutas()); } } Recorrido resultado = new Recorrido(recorrido.getDistanciaTotal(), ciudades); return resultado; } else { return null; } }
From source file:fi.helsinki.opintoni.web.rest.privateapi.portfolio.PrivateSummaryResourcePermissionTest.java
@Test public void thatUserCannotUpdateSummaryThatSheDoesNotOwn() throws Exception { UpdateSummaryRequest request = new UpdateSummaryRequest(); mockMvc.perform(post(RESOURCE_URL).with(securityContext(teacherSecurityContext())) .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON) .content(WebTestUtils.toJsonBytes(request)).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isNotFound()); }
From source file:com.example.mockmvc.Hypermedia.java
public void explicitExtractor() throws Exception { this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) //tag::explicit-extractor[] .andDo(document("index", links(halLinks(), // <1> linkWithRel("alpha").description("Link to the alpha resource"), linkWithRel("bravo").description("Link to the bravo resource")))); // end::explicit-extractor[] }
From source file:com.ushahidi.swiftriver.core.api.controller.DropsControllerTest.java
@Test public void createDrops() throws Exception { String postBody = "[" + "{\"source\": {\"origin_id\": \"the original identity id\"}, " + "\"original_id\": \"the original\"," + "\"channel\":\"manual channel\", " + "\"rivers\":[1], " + "\"channel_ids\":[2], " + "\"title\":\"the title\", " + "\"content\":\"the content\", " + "\"date_published\":\"Tue, 7 Mar 2013 03:08:45 +0000\", " + "\"original_url\":\"http://gizmodo.com/5995191/is-anyone-actually-going-to-buy-an-ibeetle\"" + "}]"; this.mockMvc//from w w w .jav a 2s . c om .perform(post("/v1/drops").content(postBody).contentType(MediaType.APPLICATION_JSON) .principal(getAuthentication("admin"))) .andExpect(status().isOk()).andExpect(jsonPath("$[0].id").value(11)) .andExpect(jsonPath("$.[0].original_url") .value("http://gizmodo.com/5995191/is-anyone-actually-going-to-buy-an-ibeetle")); }
From source file:fi.helsinki.opintoni.web.rest.privateapi.NewsResourceTest.java
@Test public void thatStudentNewsAreReturned() throws Exception { flammaServer.expectStudentNews();/*ww w.j av a 2 s.c o m*/ mockMvc.perform(get("/api/private/v1/news/student").with(securityContext(studentSecurityContext())) .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON).locale(new Locale("fi")) .accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andExpect(content().contentType(WebConstants.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$").isArray()).andExpect(jsonPath("$", hasSize(2))) .andExpect(jsonPath("$[0].title").value("Ajatusten vaihtoa ja vertaistukea verkossa")) .andExpect(jsonPath("$[0].url").value("https://flamma.helsinki.fi/portal/home/sisalto1")) .andExpect(jsonPath("$[0].content").value("Content")) .andExpect(jsonPath("$[1].title").value("Reflekta palkittiin parhaana opiskelijakilpailussa")) .andExpect(jsonPath("$[1].url").value("https://flamma.helsinki.fi/portal/home/sisalto2")) .andExpect(jsonPath("$[1].content").value("Content")); }