List of usage examples for org.springframework.http HttpHeaders ACCEPT
String ACCEPT
To view the source code for org.springframework.http HttpHeaders ACCEPT.
Click Source Link
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testGetV2_OK() throws Exception { mockServer.expect(requestTo(baseURL + "/v2")).andExpect(method(HttpMethod.GET)) .andExpect(header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)) .andRespond(withSuccess(Utils.loadResource("json/getV2Response.json"), MediaType.APPLICATION_JSON)); Map<String, String> endpoints = ngsiClient.getV2().get(); assertEquals(4, endpoints.size());// w w w .j ava2 s.c o m assertNotNull("/v2/entities", endpoints.get("entities_url")); }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testGetEntities_Defaults() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/entities")).andExpect(method(HttpMethod.GET)) .andExpect(header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)).andRespond(withSuccess( Utils.loadResource("json/getEntitiesResponse.json"), MediaType.APPLICATION_JSON)); Paginated<Entity> entities = ngsiClient.getEntities(null, null, null, null, 0, 0, false).get(); assertEquals(3, entities.getItems().size()); assertNotNull(entities.getItems().get(0)); assertNotNull(entities.getItems().get(1)); assertNotNull(entities.getItems().get(2)); assertEquals("DC_S1-D41", entities.getItems().get(0).getId()); assertEquals("Room", entities.getItems().get(0).getType()); assertEquals(35.6, entities.getItems().get(0).getAttributes().get("temperature").getValue()); assertEquals(0, entities.getOffset()); assertEquals(0, entities.getLimit()); assertEquals(0, entities.getTotal()); }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testGetEntities_Paginated() throws Exception { HttpHeaders responseHeader = new HttpHeaders(); responseHeader.add("X-Total-Count", "12"); mockServer.expect(requestTo(baseURL + "/v2/entities?offset=2&limit=10&options=count")) .andExpect(method(HttpMethod.GET)) .andExpect(header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)).andRespond( withSuccess(Utils.loadResource("json/getEntitiesResponse.json"), MediaType.APPLICATION_JSON) .headers(responseHeader)); Paginated<Entity> entities = ngsiClient.getEntities(null, null, null, null, 2, 10, true).get(); assertEquals(2, entities.getOffset()); assertEquals(10, entities.getLimit()); assertEquals(12, entities.getTotal()); }
From source file:com.netflix.genie.web.resources.handlers.GenieResourceHttpRequestHandlerUnitTests.java
/** * Make sure if the resource is a directory as HTML it's handled properly. * * @throws Exception On any error/*from www .j a v a 2s .co m*/ */ @Test public void canHandleRequestForDirectoryHtml() throws Exception { final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); final String path = UUID.randomUUID().toString(); Mockito.when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).thenReturn(path); Mockito.when(request.getHeader(HttpHeaders.ACCEPT)).thenReturn(MediaType.TEXT_HTML_VALUE); final String forwardedUrl = UUID.randomUUID().toString(); Mockito.when(request.getHeader(JobConstants.GENIE_FORWARDED_FROM_HEADER)).thenReturn(forwardedUrl); final Resource resource = Mockito.mock(Resource.class); Mockito.when(this.location.createRelative(Mockito.eq(path))).thenReturn(resource); Mockito.when(resource.exists()).thenReturn(true); final File file = Mockito.mock(File.class); Mockito.when(resource.getFile()).thenReturn(file); Mockito.when(file.isDirectory()).thenReturn(true); final String html = UUID.randomUUID().toString(); Mockito.when(this.directoryWriter.toHtml(Mockito.eq(file), Mockito.eq(forwardedUrl), Mockito.eq(false))) .thenReturn(html); final ServletOutputStream os = Mockito.mock(ServletOutputStream.class); Mockito.when(response.getOutputStream()).thenReturn(os); this.handler.handleRequest(request, response); Mockito.verify(response, Mockito.times(1)).setContentType(MediaType.TEXT_HTML_VALUE); Mockito.verify(response, Mockito.times(1)).getOutputStream(); Mockito.verify(this.directoryWriter, Mockito.times(1)).toHtml(Mockito.eq(file), Mockito.eq(forwardedUrl), Mockito.eq(false)); Mockito.verify(os, Mockito.times(1)).write(html.getBytes(Charset.forName("UTF-8"))); }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testGetEntities_AllParams() throws Exception { Collection<String> ids = Arrays.asList("room1", "house1"); String idPattern = "room.*"; Collection<String> types = Arrays.asList("Room", "House"); Collection<String> params = Arrays.asList("temp", "pressure", "humidity"); String query = "temp>10"; List<Coordinate> coords = Arrays.asList(new Coordinate(-10.5d, 30.5d), new Coordinate(-15.5d, 35.5d)); GeoQuery geoQuery = new GeoQuery(GeoQuery.Modifier.maxDistance, Float.parseFloat("1000"), GeoQuery.Geometry.point, coords); Collection<String> orderBy = Arrays.asList("temp", "!humidity"); mockServer.expect(requestTo(baseURL + "/v2/entities?id=room1,house1&idPattern=room.*&" + "type=Room,House&attrs=temp,pressure,humidity&query=temp%253E10&georel=near;maxDistance:1000.0&geometry=point&coords=-10.5,30.5;-15.5,35.5&" + "orderBy=temp,!humidity&" + "offset=2&limit=10")).andExpect(method(HttpMethod.GET)) .andExpect(header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)).andRespond(withSuccess( Utils.loadResource("json/getEntitiesResponse.json"), MediaType.APPLICATION_JSON)); ngsiClient.getEntities(ids, idPattern, types, params, query, geoQuery, orderBy, 2, 10, false).get(); }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testGetEntity_OK() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/entities/DC_S1-D41?type=Room&attrs=temperature,humidity")) .andExpect(method(HttpMethod.GET)) .andExpect(header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)).andRespond( withSuccess(Utils.loadResource("json/getEntityResponse.json"), MediaType.APPLICATION_JSON)); ngsiClient.getEntity("DC_S1-D41", "Room", Arrays.asList("temperature", "humidity")).get(); }
From source file:com.netflix.genie.web.resources.handlers.GenieResourceHttpRequestHandlerUnitTests.java
/** * Make sure if the resource is a directory as JSON it's handled properly. * * @throws Exception On any error/*w w w. ja va2 s . com*/ */ @Test public void canHandleRequestForDirectoryJson() throws Exception { final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); final String path = UUID.randomUUID().toString(); Mockito.when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).thenReturn(path); Mockito.when(request.getHeader(HttpHeaders.ACCEPT)).thenReturn(null); final String requestUrl = UUID.randomUUID().toString(); Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer(requestUrl)); final Resource resource = Mockito.mock(Resource.class); Mockito.when(this.location.createRelative(Mockito.eq(path))).thenReturn(resource); Mockito.when(resource.exists()).thenReturn(true); final File file = Mockito.mock(File.class); Mockito.when(resource.getFile()).thenReturn(file); Mockito.when(file.isDirectory()).thenReturn(true); final String html = UUID.randomUUID().toString(); Mockito.when(this.directoryWriter.toJson(Mockito.eq(file), Mockito.eq(requestUrl), Mockito.eq(false))) .thenReturn(html); final ServletOutputStream os = Mockito.mock(ServletOutputStream.class); Mockito.when(response.getOutputStream()).thenReturn(os); this.handler.handleRequest(request, response); Mockito.verify(response, Mockito.times(1)).setContentType(MediaType.APPLICATION_JSON_VALUE); Mockito.verify(response, Mockito.times(1)).getOutputStream(); Mockito.verify(this.directoryWriter, Mockito.times(1)).toJson(Mockito.eq(file), Mockito.eq(requestUrl), Mockito.eq(false)); Mockito.verify(os, Mockito.times(1)).write(html.getBytes(Charset.forName("UTF-8"))); }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testGetAttribute_OK() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/entities/DC_S1-D41/attrs/temperature?type=Room")) .andExpect(method(HttpMethod.GET)) .andExpect(header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)).andRespond(withSuccess( Utils.loadResource("json/getAttributeResponse.json"), MediaType.APPLICATION_JSON)); Attribute attribute = ngsiClient.getAttribute("DC_S1-D41", "Room", "temperature").get(); assertNotNull(attribute);//ww w . j av a 2s . c o m assertEquals(35.6, attribute.getValue()); assertEquals("urn:phenomenum:temperature", attribute.getType().get()); assertNotNull(attribute.getMetadata()); assertEquals("2015-06-04T07:20:27.378Z", attribute.getMetadata().get("timestamp").getValue()); assertEquals("date", attribute.getMetadata().get("timestamp").getType()); }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testGetAttributeValueAsString_Number() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/entities/room1/attrs/text/value?type=Room")) .andExpect(method(HttpMethod.GET)).andExpect(header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN_VALUE)) .andRespond(withSuccess("some random text", MediaType.TEXT_PLAIN)); String result = ngsiClient.getAttributeValueAsString("room1", "Room", "text").get(); assertEquals("some random text", result); }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testGetEntityTypes_OK() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/types")).andExpect(method(HttpMethod.GET)) .andExpect(header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)).andRespond(withSuccess( Utils.loadResource("json/getEntityTypesResponse.json"), MediaType.APPLICATION_JSON)); Paginated<EntityType> result = ngsiClient.getEntityTypes(0, 0, false).get(); assertNotNull(result.getItems());/*w w w. j a v a 2 s . c om*/ assertEquals(result.getItems().size(), 2); assertEquals(result.getItems().get(0).getType(), "Car"); assertNotNull(result.getItems().get(0).getAttrs()); assertEquals(result.getItems().get(0).getAttrs().size(), 3); assertEquals(result.getItems().get(0).getAttrs().get("speed").getType(), "none"); }