Ngsi2Client { public ListenableFuture<Void> bulkUpdate(BulkUpdateRequest bulkUpdateRequest) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/op/update"); return adapt(request(HttpMethod.POST, builder.toUriString(), bulkUpdateRequest, Void.class)); } 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 testBulkUpdate_Append() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/op/update")) .andExpect(method(HttpMethod.POST)) .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE)) .andExpect(jsonPath("$.actionType").value("APPEND")) .andExpect(jsonPath("$.entities[0].id").value("room1")) .andExpect(jsonPath("$.entities[0].type").value("Room")) .andExpect(jsonPath("$.entities[0].temp.value").value(22)) .andRespond(withNoContent()); Entity e = new Entity("room1", "Room"); e.setAttributes(Collections.singletonMap("temp", new Attribute(22))); BulkUpdateRequest request = new BulkUpdateRequest(BulkUpdateRequest.Action.APPEND, Collections.singletonList(e)); ngsiClient.bulkUpdate(request).get(); }
@Test public void testBulkUpdate_AppendStrict() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/op/update")) .andExpect(method(HttpMethod.POST)) .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE)) .andExpect(jsonPath("$.actionType").value("APPEND_STRICT")) .andExpect(jsonPath("$.entities[0].id").value("room1")) .andExpect(jsonPath("$.entities[0].type").value("Room")) .andExpect(jsonPath("$.entities[0].temp.value").value(22)) .andRespond(withNoContent()); Entity e = new Entity("room1", "Room"); e.setAttributes(Collections.singletonMap("temp", new Attribute(22))); BulkUpdateRequest request = new BulkUpdateRequest(BulkUpdateRequest.Action.APPEND_STRICT, Collections.singletonList(e)); ngsiClient.bulkUpdate(request).get(); }
@Test public void testBulkUpdate_Update() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/op/update")) .andExpect(method(HttpMethod.POST)) .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE)) .andExpect(jsonPath("$.actionType").value("UPDATE")) .andExpect(jsonPath("$.entities[0].id").value("room1")) .andExpect(jsonPath("$.entities[0].type").value("Room")) .andExpect(jsonPath("$.entities[0].temp.value").value(22)) .andRespond(withNoContent()); Entity e = new Entity("room1", "Room"); e.setAttributes(Collections.singletonMap("temp", new Attribute(22))); BulkUpdateRequest request = new BulkUpdateRequest(BulkUpdateRequest.Action.UPDATE, Collections.singletonList(e)); ngsiClient.bulkUpdate(request).get(); }
@Test public void testBulkUpdate_Delete() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/op/update")) .andExpect(method(HttpMethod.POST)) .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE)) .andExpect(jsonPath("$.actionType").value("DELETE")) .andExpect(jsonPath("$.entities[0].id").value("room1")) .andExpect(jsonPath("$.entities[0].type").value("Room")) .andExpect(jsonPath("$.entities[0].temp.value").value(22)) .andRespond(withNoContent()); Entity e = new Entity("room1", "Room"); e.setAttributes(Collections.singletonMap("temp", new Attribute(22))); BulkUpdateRequest request = new BulkUpdateRequest(BulkUpdateRequest.Action.DELETE, Collections.singletonList(e)); ngsiClient.bulkUpdate(request).get(); }