Ngsi2Client { public ListenableFuture<Paginated<Entity>> getEntities(Collection<String> ids, String idPattern, Collection<String> types, Collection<String> attrs, int offset, int limit, boolean count) { return getEntities(ids, idPattern, types, attrs, null, null, null, offset, limit, count); } private  Ngsi2Client();  Ngsi2Client(AsyncRestTemplate asyncRestTemplate, String baseURL); ListenableFuture<Map<String, String>> getV2(); ListenableFuture<Paginated<Entity>> getEntities(Collection<String> ids, String idPattern,
            Collection<String> types, Collection<String> attrs,
            int offset, int limit, boolean count); ListenableFuture<Paginated<Entity>> getEntities(Collection<String> ids, String idPattern,
                                                           Collection<String> types, Collection<String> attrs,
                                                           String query, GeoQuery geoQuery,
                                                           Collection<String> orderBy,
                                                           int offset, int limit, boolean count); ListenableFuture<Void> addEntity(Entity entity); ListenableFuture<Entity> getEntity(String entityId, String type, Collection<String> attrs); ListenableFuture<Void> updateEntity(String entityId, String type, Map<String, Attribute> attributes, boolean append); ListenableFuture<Void> replaceEntity(String entityId, String type, Map<String, Attribute> attributes); ListenableFuture<Void> deleteEntity(String entityId, String type); ListenableFuture<Attribute> getAttribute(String entityId, String type, String attributeName); ListenableFuture<Void> updateAttribute(String entityId, String type, String attributeName, Attribute attribute); ListenableFuture<Attribute> deleteAttribute(String entityId, String type, String attributeName); ListenableFuture<Object> getAttributeValue(String entityId, String type, String attributeName); ListenableFuture<String> getAttributeValueAsString(String entityId, String type, String attributeName); ListenableFuture<Paginated<EntityType>> getEntityTypes(int offset, int limit, boolean count); ListenableFuture<EntityType> getEntityType(String entityType); ListenableFuture<List<Registration>> getRegistrations(); ListenableFuture<Void> addRegistration(Registration registration); ListenableFuture<Registration> getRegistration(String registrationId); ListenableFuture<Void> updateRegistration(String registrationId, Registration registration); ListenableFuture<Void> deleteRegistration(String registrationId); ListenableFuture<Paginated<Subscription>> getSubscriptions(int offset, int limit, boolean count); ListenableFuture<String> addSubscription(Subscription subscription); ListenableFuture<Subscription> getSubscription(String subscriptionId); ListenableFuture<Void> updateSubscription(String subscriptionId, Subscription subscription); ListenableFuture<Void> deleteSubscription(String subscriptionId); ListenableFuture<Void> bulkUpdate(BulkUpdateRequest bulkUpdateRequest); ListenableFuture<Paginated<Entity>> bulkQuery(BulkQueryRequest bulkQueryRequest, Collection<String> orderBy, int offset, int limit, boolean count); ListenableFuture<String[]> bulkRegister(BulkRegisterRequest bulkRegisterRequest); ListenableFuture<Paginated<Registration>> bulkDiscover(BulkQueryRequest bulkQueryRequest, int offset, int limit, boolean count); HttpHeaders getHttpHeaders();  }
@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(); }
@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()); }
@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()); }