2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.rest;
22 import com.google.gson.JsonObject;
23 import com.google.gson.JsonParser;
24 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
25 import org.apache.tinkerpop.gremlin.structure.Vertex;
26 import org.janusgraph.core.JanusGraph;
27 import org.janusgraph.core.JanusGraphTransaction;
28 import org.javatuples.Pair;
29 import org.json.JSONObject;
30 import org.junit.After;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.junit.runners.Parameterized;
34 import org.mockito.Mockito;
35 import org.onap.aai.AAISetup;
36 import org.onap.aai.HttpTestUtil;
37 import org.onap.aai.PayloadUtil;
38 import org.onap.aai.db.props.AAIProperties;
39 import org.onap.aai.dbmap.AAIGraph;
40 import org.onap.aai.exceptions.AAIException;
41 import org.onap.aai.introspection.ModelType;
42 import org.onap.aai.rest.ueb.NotificationEvent;
43 import org.onap.aai.rest.ueb.UEBNotification;
44 import org.onap.aai.serialization.engines.QueryStyle;
45 import org.skyscreamer.jsonassert.JSONAssert;
46 import org.springframework.test.annotation.DirtiesContext;
48 import javax.ws.rs.core.Response;
49 import java.io.IOException;
50 import java.io.UnsupportedEncodingException;
53 import static org.hamcrest.CoreMatchers.*;
54 import static org.hamcrest.junit.MatcherAssert.assertThat;
55 import static org.junit.Assert.assertEquals;
57 @RunWith(value = Parameterized.class)
58 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
59 public class NotificationDmaapEventTest extends AAISetup {
61 @Parameterized.Parameter
62 public QueryStyle queryStyle;
64 @Parameterized.Parameters(name = "QueryStyle.{0}")
65 public static Collection<Object[]> data() {
66 return Arrays.asList(new Object[][] {
67 { QueryStyle.TRAVERSAL },
68 { QueryStyle.TRAVERSAL_URI }
73 public void testCreateWithPserverWithAllChildrenAndVerifyMultipleNotificationsWhenNotificationDepthIsZero() throws IOException, AAIException {
75 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
76 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
77 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
79 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
81 Response response = httpTestUtil.doGet(uri);
82 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
84 response = httpTestUtil.doPut(uri, resource);
85 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
87 int expectedCreateEvents = 17;
89 assertThat(notification.getEvents().size(), is(expectedCreateEvents));
91 // Verify all the events are create since its a new PUT
92 notification.getEvents().forEach((event) -> {
94 String header = event.getEventHeader().marshal(false);
97 event.getEventHeader().marshal(false),
98 containsString("\"CREATE\"")
103 containsString("\"top-entity-type\":\"pserver\"")
108 response = httpTestUtil.doGet(uri);
109 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
112 // Test existing pserver create new pinterface check dmaap event for pinterface is CREATE
114 public void testExistingPserverCreateNewChildPInterfaceAndCheckDmaapEventForPInterfaceIsCreateWhenNotificationDepthIsZero() throws IOException, AAIException {
116 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
117 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
118 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
120 String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
122 Response response = httpTestUtil.doGet(uri);
123 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
125 response = httpTestUtil.doPut(uri, pserverResource);
126 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
127 notification.clearEvents();
130 response = httpTestUtil.doGet(uri , "all");
131 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
133 JSONObject pserverJson = new JSONObject(response.getEntity().toString());
134 JSONObject pInterfaceObject = new JSONObject();
135 pInterfaceObject.put("interface-name", "p-interface-1");
137 pserverJson.getJSONObject("p-interfaces").getJSONArray("p-interface").put(pInterfaceObject);
139 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
140 response = httpTestUtil.doPut(uri, pserverJson.toString());
141 assertEquals("Expecting the pserver to be updated with a new p-interface", 200, response.getStatus());
143 response = httpTestUtil.doGet(uri + "/p-interfaces/p-interface/p-interface-1", "0");
144 assertEquals("Expecting the p-interface to be found", 200, response.getStatus());
146 List<NotificationEvent> events = notification.getEvents();
147 assertThat(events.size(), is(2));
149 String notificationEventHeader = events.get(1).getEventHeader().marshal(false);
150 String notificationEventBody = events.get(1).getObj().marshal(false);
152 assertThat(notificationEventHeader, containsString("\"action\":\"CREATE\""));
153 assertThat(notificationEventHeader, containsString("\"entity-type\":\"p-interface\""));
154 assertThat(notificationEventHeader, containsString("\"top-entity-type\":\"pserver\""));
156 String expectedNotificationHeader = PayloadUtil.getResourcePayload("notification-dmaap-events/depth-zero/expected-notification-header-create-child-on-existing-obj.json");
157 String expectedNotificationBody = PayloadUtil.getResourcePayload("notification-dmaap-events/depth-zero/expected-notification-body-create-child-on-existing-obj.json");
159 JSONAssert.assertEquals(expectedNotificationHeader, notificationEventHeader, false);
160 JSONAssert.assertEquals(expectedNotificationBody, notificationEventBody, false);
164 public void testExistingPserverCreateNewChildPInterfaceAndCheckDmaapEventForPserverIsSentWithNewPInterfaceWhenNotificationDepthIsAll() throws IOException, AAIException {
166 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
167 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
168 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
170 String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
172 Response response = httpTestUtil.doGet(uri);
173 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
175 response = httpTestUtil.doPut(uri, pserverResource);
176 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
178 response = httpTestUtil.doGet(uri , "all");
179 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
181 JSONObject pserverJson = new JSONObject(response.getEntity().toString());
182 String pserverResourceVersion = pserverJson.getString("resource-version");
184 JSONObject pInterfaceObject = new JSONObject();
185 pInterfaceObject.put("interface-name", "p-interface-1");
187 pserverJson.getJSONObject("p-interfaces").getJSONArray("p-interface").put(pInterfaceObject);
189 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
190 response = httpTestUtil.doPut(uri, pserverJson.toString());
191 assertEquals("Expecting the pserver to be updated with a new p-interface", 200, response.getStatus());
193 response = httpTestUtil.doGet(uri + "/p-interfaces/p-interface/p-interface-1", "0");
194 assertEquals("Expecting the p-interface to be found", 200, response.getStatus());
196 List<NotificationEvent> events = notification.getEvents();
197 assertThat(events.size(), is(1));
199 String notificationEventHeader = events.get(0).getEventHeader().marshal(false);
200 String notificationEventBody = events.get(0).getObj().marshal(false);
202 assertThat(notificationEventHeader, containsString("\"action\":\"UPDATE\""));
203 assertThat(notificationEventHeader, containsString("\"entity-type\":\"pserver\""));
204 assertThat(notificationEventHeader, containsString("\"top-entity-type\":\"pserver\""));
206 String expectedNotificationHeader = PayloadUtil.getResourcePayload("notification-dmaap-events/depth-all/expected-notification-header-create-child-on-existing-obj.json");
207 String expectedNotificationBody = PayloadUtil.getResourcePayload("notification-dmaap-events/depth-all/expected-notification-body-create-child-on-existing-obj.json");
209 JSONAssert.assertEquals(expectedNotificationHeader, notificationEventHeader, false);
210 JSONAssert.assertEquals(expectedNotificationBody, notificationEventBody, false);
212 response = httpTestUtil.doGet(uri, "0");
213 pserverJson = new JSONObject(response.getEntity().toString());
214 String newPserverResourceVersion = pserverJson.getString("resource-version");
216 // After an pserver's p-interface is updated on the pserver, even though
217 // the pserver nothing changed, expecting the pserver resource version to be changed
219 "Expecting the new pserver resource version and old resource version to be not same",
220 newPserverResourceVersion,
221 is(not(pserverResourceVersion))
223 assertEquals("Expecting the p-interface to be found", 200, response.getStatus());
226 // Test Bulk Scenario
228 public void testBulkScenarioWhereMultipleCreatesAndEnsureNoDuplicationInDmaapEventsWhenNotificationDepthIsZero() throws UnsupportedEncodingException, AAIException {
230 String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/random-pserver";
231 String cloudRegionUri = "/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/random-cloud-region-owner/random-cloud-region-id";
233 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
234 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
236 Map<String, String> uriPayload = new LinkedHashMap<>();
238 uriPayload.put(pserverUri, "{}");
239 uriPayload.put(cloudRegionUri, "{}");
241 Response response = httpTestUtil.doPut(uriPayload);
242 assertThat(response.getStatus(), is(201));
244 int numberOfEventsActual = notification.getEvents().size();
245 int expectedEvents = 2;
247 assertThat("Expecting the number of dmaap events to be 2", numberOfEventsActual, is(expectedEvents));
249 notification.getEvents().forEach((event) -> {
250 String notificationEventHeader = event.getEventHeader().marshal(false);
251 assertThat(notificationEventHeader, containsString("\"CREATE\""));
257 public void testBulkScenarioWhereMultipleCreatesAndEnsureNoDuplicationInDmaapEventsWhenNotificationDepthIsAll() throws UnsupportedEncodingException, AAIException {
259 String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/random-pserver";
260 String cloudRegionUri = "/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/random-cloud-region-owner/random-cloud-region-id";
262 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
263 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
265 Map<String, String> uriPayload = new LinkedHashMap<>();
267 uriPayload.put(pserverUri, "{}");
268 uriPayload.put(cloudRegionUri, "{}");
270 Response response = httpTestUtil.doPut(uriPayload);
271 assertThat(response.getStatus(), is(201));
273 int numberOfEventsActual = notification.getEvents().size();
274 int expectedEvents = 2;
276 assertThat("Expecting the number of dmaap events to be 2", numberOfEventsActual, is(expectedEvents));
278 notification.getEvents().forEach((event) -> {
279 String notificationEventHeader = event.getEventHeader().marshal(false);
280 assertThat(notificationEventHeader, containsString("\"CREATE\""));
285 public void testDeleteOnExistingPserverAndCheckIfNotificationDepthIsZeroThatAllEventsHaveDeleteAndThatDepthIsZeroOnEachNotificationEvent() throws IOException, AAIException {
286 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
287 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
288 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
290 String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
292 Response response = httpTestUtil.doGet(uri);
293 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
295 response = httpTestUtil.doPut(uri, pserverResource);
296 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
298 response = httpTestUtil.doGet(uri , "all");
299 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
301 JSONObject pserverObject = new JSONObject(response.getEntity().toString());
302 String resourceVersion = pserverObject.getString("resource-version");
304 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
305 response = httpTestUtil.doDelete(uri, resourceVersion);
306 assertEquals("Expecting the pserver to be deleted", 204, response.getStatus());
308 List<NotificationEvent> notificationEvents = notification.getEvents();
309 assertThat(notificationEvents.size(), is(17));
311 notificationEvents.forEach((event) -> {
313 String header = event.getEventHeader().marshal(false);
316 event.getEventHeader().marshal(false),
317 containsString("\"DELETE\"")
322 containsString("\"top-entity-type\":\"pserver\"")
329 public void testDeleteOnExistingResourceVersionMismatchNoEventGenerated() throws IOException, AAIException {
330 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
331 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
332 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
334 String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
336 Response response = httpTestUtil.doGet(uri);
337 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
339 response = httpTestUtil.doPut(uri, pserverResource);
340 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
342 response = httpTestUtil.doGet(uri , "all");
343 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
345 JSONObject pserverObject = new JSONObject(response.getEntity().toString());
346 String resourceVersion = pserverObject.getString("resource-version");
348 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
349 response = httpTestUtil.doDelete(uri, resourceVersion+"123");
350 assertEquals("Resource version mismatch exception", 412, response.getStatus());
352 List<NotificationEvent> notificationEvents = notification.getEvents();
353 assertThat(notificationEvents.size(), is(0));
357 // Test notification depth set to all
358 // Scenario for testing the creation of pserver with children, grandchildren
359 // Default behaviour is for one event to be sent out
360 // which includes all the children and grandchildren, etc
362 public void testCreateWithPserverWithAllChildrenAndVerifyOneNotificationWhenNotificationDepthIsAll() throws IOException, AAIException {
364 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
365 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
366 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
368 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
370 Response response = httpTestUtil.doGet(uri);
371 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
373 response = httpTestUtil.doPut(uri, resource);
374 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
376 assertThat(notification.getEvents().size(), is(1));
378 NotificationEvent notificationEvent = notification.getEvents().get(0);
380 // Verify all the events are create since its a new PUT
381 String header = notificationEvent.getEventHeader().marshal(false);
385 containsString("\"CREATE\"")
390 containsString("\"entity-type\":\"pserver\"")
395 containsString("\"top-entity-type\":\"pserver\"")
400 containsString("\"entity-link\":\"" + uri + "\"")
403 response = httpTestUtil.doGet(uri);
404 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
406 JSONAssert.assertEquals(response.getEntity().toString(), notificationEvent.getObj().marshal(false), false);
410 public void testPatchExistingPserverWithChildrenAndModifyOnlyOneObjectAndVerifyThatOnlyOneNotificationEventNoChildrenWhenNotificationDepthIsZero() throws IOException, AAIException {
412 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
413 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
414 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
416 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
418 Response response = httpTestUtil.doGet(uri);
419 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
421 response = httpTestUtil.doPut(uri, resource);
422 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
424 response = httpTestUtil.doGet(uri);
425 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
427 JSONObject pserverObject = new JSONObject();
428 pserverObject.put("equip-type", "new-equip-patch-type");
430 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
431 response = httpTestUtil.doPatch(uri, pserverObject.toString());
432 assertThat(response.getStatus(), is(200));
434 response = httpTestUtil.doGet(uri, "0");
435 assertThat(response.getEntity().toString(), containsString("new-equip-patch-type"));
437 assertThat(notification.getEvents().size(), is(1));
438 String updateNotificationEvent = notification.getEvents().get(0).getObj().marshal(true);
440 // Check that everything in notification event is also response body
441 // Not comparing the other way as notification only includes parents main properties
442 JSONAssert.assertEquals(updateNotificationEvent, response.getEntity().toString(), false);
446 public void testPatchExistingPserverWithChildrenAndModifyOnlyOneObjectAndVerifyThatOnlyOneNotificationEventIncludeChildrenWhenNotificationDepthIsAll() throws IOException, AAIException {
448 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
449 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
450 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
452 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
454 Response response = httpTestUtil.doGet(uri);
455 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
457 response = httpTestUtil.doPut(uri, resource);
458 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
460 response = httpTestUtil.doGet(uri);
461 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
463 JSONObject pserverObject = new JSONObject();
464 pserverObject.put("equip-type", "new-equip-patch-type");
466 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
467 response = httpTestUtil.doPatch(uri, pserverObject.toString());
468 assertThat(response.getStatus(), is(200));
470 response = httpTestUtil.doGet(uri, "all");
471 assertThat(response.getEntity().toString(), containsString("new-equip-patch-type"));
473 assertThat(notification.getEvents().size(), is(1));
474 String updateNotificationEvent = notification.getEvents().get(0).getObj().marshal(true);
476 // Check that everything in notification event is also response body
477 // Not comparing the other way as notification only includes parents main properties
478 JSONAssert.assertEquals(updateNotificationEvent, response.getEntity().toString(), false);
481 // Test notification depth set to all
482 // Scenario where we are only updating one field in p-interface
483 // Make sure the parent and children are included
485 public void testUpdateExistingPserverWithChildrenAndModifyOnlyOneObjectAndVerifyThatOnlyOneNotificationEventIncludingChildrenWhenNotificationDepthIsAll() throws IOException, AAIException {
487 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
488 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
489 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
491 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
493 Response response = httpTestUtil.doGet(uri);
494 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
496 response = httpTestUtil.doPut(uri, resource);
497 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
499 response = httpTestUtil.doGet(uri);
500 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
502 response = httpTestUtil.doGet(uri + "/p-interfaces/p-interface/example-interface-name-val-46147", "0");
503 assertEquals("Expecting the p-interface to be found", 200, response.getStatus());
505 JSONObject pInterfaceObject = new JSONObject(response.getEntity().toString());
506 pInterfaceObject.put("equipment-identifier", "new-equipment-identifier");
508 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
509 response = httpTestUtil.doPut(uri + "/p-interfaces/p-interface/example-interface-name-val-46147", pInterfaceObject.toString());
510 assertThat(response.getStatus(), is(200));
512 // Get the parent uri as the notification event json has parent structure it makes it easy to compare
513 response = httpTestUtil.doGet(uri);
514 assertThat(response.getEntity().toString(), containsString("new-equipment-identifier"));
516 assertThat(notification.getEvents().size(), is(1));
517 String updateNotificationEvent = notification.getEvents().get(0).getObj().marshal(true);
519 // Check that everything in notification event is also response body
520 // Not comparing the other way as notification only includes parents main properties
521 JSONAssert.assertEquals(updateNotificationEvent, response.getEntity().toString(), false);
524 // Test notification depth set to 0
525 // Scenario where we are only updating one field in p-interface
527 public void testUpdateExistingPserverWithChildrenAndModifyOnlyPInterfaceAndVerifyThatOnlyOneNotificationForPInterfaceIsCreatedWhenNotificationDepthIsZero() throws IOException, AAIException {
529 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
530 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
531 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
533 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
535 Response response = httpTestUtil.doGet(uri);
536 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
538 response = httpTestUtil.doPut(uri, resource);
539 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
541 response = httpTestUtil.doGet(uri);
542 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
544 response = httpTestUtil.doGet(uri + "/p-interfaces/p-interface/example-interface-name-val-46147", "0");
545 assertEquals("Expecting the p-interface to be found", 200, response.getStatus());
547 JSONObject pInterfaceObject = new JSONObject(response.getEntity().toString());
548 pInterfaceObject.put("equipment-identifier", "new-equipment-identifier");
550 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
551 response = httpTestUtil.doPut(uri + "/p-interfaces/p-interface/example-interface-name-val-46147", pInterfaceObject.toString());
552 assertThat(response.getStatus(), is(200));
554 response = httpTestUtil.doGet(uri);
555 assertThat(notification.getEvents().size(), is(1));
556 String updateNotificationEvent = notification.getEvents().get(0).getObj().marshal(true);
557 System.out.println("Update notification " + updateNotificationEvent);
559 // Check that everything in notification event is also response body
560 // Not comparing the other way as notification only includes parents main properties
561 JSONAssert.assertEquals(updateNotificationEvent, response.getEntity().toString(), false);
565 public void testExistingPserverWithChildAndGenericVnfAndCreateEdgeBetweenThemAndCheckNoChildWhenNotificationDepthIsZero() throws IOException, AAIException {
567 String hostname = "example-hostname-val-85598";
569 String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/" + hostname;
570 String genericVnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/generic-vnf-notification";
572 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
573 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
575 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
576 String genericVnfResource = PayloadUtil.getResourcePayload("generic-vnf-notification.json");
578 Response response = httpTestUtil.doGet(pserverUri);
579 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
581 response = httpTestUtil.doPut(pserverUri, resource);
582 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
584 response = httpTestUtil.doGet(pserverUri);
585 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
587 response = httpTestUtil.doGet(genericVnfUri);
588 assertEquals("Expecting the generic-vnf to be not found", 404, response.getStatus());
590 response = httpTestUtil.doPut(genericVnfUri, genericVnfResource);
591 assertEquals("Expecting the generic-vnf to be created", 201, response.getStatus());
593 response = httpTestUtil.doGet(genericVnfUri);
594 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
595 assertThat(response.getEntity().toString(), not(containsString(hostname)));
597 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
599 String relationship = PayloadUtil.getResourcePayload("pserver-to-gvnf-relationship-notification.json");
601 response = httpTestUtil.doPut(pserverUri + "/relationship-list/relationship", relationship);
602 assertEquals("Expecting the pserver to generic-vnf relationship to be created", 200, response.getStatus());
604 List<NotificationEvent> notificationEvents = notification.getEvents();
605 assertThat(notificationEvents.size(), is(2));
607 String expectedNotificationHeader = PayloadUtil.getResourcePayload("notification-dmaap-events/depth-zero/expected-notification-header-create-edge-between-pserver-and-generic-vnf.json");
608 String expectedNotificationBody = PayloadUtil.getResourcePayload("notification-dmaap-events/depth-zero/expected-notification-body-create-edge-between-pserver-and-generic-vnf.json");
610 JSONAssert.assertEquals(expectedNotificationHeader, notificationEvents.get(0).getEventHeader().marshal(false), false);
611 JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getObj().marshal(false), false);
613 response = httpTestUtil.doGet(genericVnfUri);
615 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
616 assertThat(response.getEntity().toString(), containsString(hostname));
620 public void testExistingPserverWithChildAndGenericVnfAndCreateEdgeBetweenThemAndCheckChildrenIncludedWhenNotificationDepthIsAll() throws IOException, AAIException {
622 String hostname = "example-hostname-val-85598";
624 String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/" + hostname;
625 String genericVnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/generic-vnf-notification";
627 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
628 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
630 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
631 String genericVnfResource = PayloadUtil.getResourcePayload("generic-vnf-notification.json");
633 Response response = httpTestUtil.doGet(pserverUri);
634 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
636 response = httpTestUtil.doPut(pserverUri, resource);
637 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
639 response = httpTestUtil.doGet(pserverUri);
640 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
642 response = httpTestUtil.doGet(genericVnfUri);
643 assertEquals("Expecting the generic-vnf to be not found", 404, response.getStatus());
645 response = httpTestUtil.doPut(genericVnfUri, genericVnfResource);
646 assertEquals("Expecting the generic-vnf to be created", 201, response.getStatus());
648 response = httpTestUtil.doGet(genericVnfUri);
649 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
650 assertThat(response.getEntity().toString(), not(containsString(hostname)));
652 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
654 String relationship = PayloadUtil.getResourcePayload("pserver-to-gvnf-relationship-notification.json");
656 response = httpTestUtil.doPut(pserverUri + "/relationship-list/relationship", relationship);
657 assertEquals("Expecting the pserver to generic-vnf relationship to be created", 200, response.getStatus());
659 List<NotificationEvent> notificationEvents = notification.getEvents();
660 assertThat(notificationEvents.size(), is(2));
662 String expectedNotificationHeader = PayloadUtil.getResourcePayload("notification-dmaap-events/depth-all/expected-notification-header-create-edge-between-pserver-and-generic-vnf.json");
663 String expectedNotificationBody = PayloadUtil.getResourcePayload("notification-dmaap-events/depth-all/expected-notification-body-create-edge-between-pserver-and-generic-vnf.json");
665 System.out.println("Notification Body: " + notificationEvents.get(0).getObj().marshal(false));
666 JSONAssert.assertEquals(expectedNotificationHeader, notificationEvents.get(0).getEventHeader().marshal(false), false);
667 JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getObj().marshal(false), false);
669 response = httpTestUtil.doGet(genericVnfUri);
671 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
672 assertThat(response.getEntity().toString(), containsString(hostname));
676 public void testExistingPserverWithChildAndGenericVnfAndExistingEdgeBetweenThemAndDeleteEdgeAndCheckNoChildWhenNotificationDepthIsZero() throws IOException, AAIException {
678 String hostname = "example-hostname-val-85598";
680 String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/" + hostname;
681 String genericVnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/generic-vnf-notification";
683 String relationship = PayloadUtil.getResourcePayload("pserver-to-gvnf-relationship-notification.json");
685 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
686 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
688 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
689 String genericVnfResource = PayloadUtil.getResourcePayload("generic-vnf-notification.json");
691 Response response = httpTestUtil.doGet(pserverUri);
692 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
694 response = httpTestUtil.doPut(pserverUri, resource);
695 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
697 response = httpTestUtil.doGet(pserverUri);
698 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
700 response = httpTestUtil.doGet(genericVnfUri);
701 assertEquals("Expecting the generic-vnf to be not found", 404, response.getStatus());
703 response = httpTestUtil.doPut(genericVnfUri, genericVnfResource);
704 assertEquals("Expecting the generic-vnf to be created", 201, response.getStatus());
706 response = httpTestUtil.doGet(genericVnfUri);
707 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
708 assertThat(response.getEntity().toString(), not(containsString(hostname)));
711 response = httpTestUtil.doPut(pserverUri + "/relationship-list/relationship", relationship);
712 assertEquals("Expecting the pserver to generic-vnf relationship to be created", 200, response.getStatus());
714 response = httpTestUtil.doGet(genericVnfUri);
716 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
717 assertThat(response.getEntity().toString(), containsString(hostname));
719 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
720 assertThat(response.getEntity().toString(), containsString(hostname));
722 response = httpTestUtil.doGet(pserverUri);
723 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
725 JSONObject pserverJson = new JSONObject(response.getEntity().toString());
726 String resourceVersion = pserverJson.getString("resource-version");
728 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
730 response = httpTestUtil.doDelete(pserverUri + "/relationship-list/relationship", resourceVersion, relationship);
731 assertThat("Expected the pserver relationship to generic-vnf to be deleted", response.getStatus(), is(204));
733 List<NotificationEvent> notificationEvents = notification.getEvents();
735 assertThat(notificationEvents.size(), is(2));
737 String expectedNotificationHeader = PayloadUtil.getResourcePayload("notification-dmaap-events/depth-zero/expected-notification-header-delete-edge-between-pserver-and-generic-vnf.json");
738 String expectedNotificationBody = PayloadUtil.getResourcePayload("notification-dmaap-events/depth-zero/expected-notification-body-delete-edge-between-pserver-and-generic-vnf.json");
740 JSONAssert.assertEquals(expectedNotificationHeader, notificationEvents.get(0).getEventHeader().marshal(false), false);
741 JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getObj().marshal(false), false);
746 public void testExistingPserverWithChildAndGenericVnfAndExistingEdgeBetweenThemAndDeleteEdgeAndCheckChildrenWhenNotificationDepthIsAll() throws IOException, AAIException {
748 String hostname = "example-hostname-val-85598";
750 String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/" + hostname;
751 String genericVnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/generic-vnf-notification";
753 String relationship = PayloadUtil.getResourcePayload("pserver-to-gvnf-relationship-notification.json");
755 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
756 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
758 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
759 String genericVnfResource = PayloadUtil.getResourcePayload("generic-vnf-notification.json");
761 Response response = httpTestUtil.doGet(pserverUri);
762 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
764 response = httpTestUtil.doPut(pserverUri, resource);
765 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
767 response = httpTestUtil.doGet(pserverUri);
768 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
770 response = httpTestUtil.doGet(genericVnfUri);
771 assertEquals("Expecting the generic-vnf to be not found", 404, response.getStatus());
773 response = httpTestUtil.doPut(genericVnfUri, genericVnfResource);
774 assertEquals("Expecting the generic-vnf to be created", 201, response.getStatus());
776 response = httpTestUtil.doGet(genericVnfUri);
777 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
778 assertThat(response.getEntity().toString(), not(containsString(hostname)));
781 response = httpTestUtil.doPut(pserverUri + "/relationship-list/relationship", relationship);
782 assertEquals("Expecting the pserver to generic-vnf relationship to be created", 200, response.getStatus());
784 response = httpTestUtil.doGet(genericVnfUri);
786 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
787 assertThat(response.getEntity().toString(), containsString(hostname));
789 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
790 assertThat(response.getEntity().toString(), containsString(hostname));
792 response = httpTestUtil.doGet(pserverUri);
793 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
795 JSONObject pserverJson = new JSONObject(response.getEntity().toString());
796 String resourceVersion = pserverJson.getString("resource-version");
798 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
800 response = httpTestUtil.doDelete(pserverUri + "/relationship-list/relationship", resourceVersion, relationship);
801 assertThat("Expected the pserver relationship to generic-vnf to be deleted", response.getStatus(), is(204));
803 List<NotificationEvent> notificationEvents = notification.getEvents();
804 assertThat(notificationEvents.size(), is(2));
806 String expectedNotificationHeader = PayloadUtil.getResourcePayload("notification-dmaap-events/depth-all/expected-notification-header-delete-edge-between-pserver-and-generic-vnf.json");
807 String expectedNotificationBody = PayloadUtil.getResourcePayload("notification-dmaap-events/depth-all/expected-notification-body-delete-edge-between-pserver-and-generic-vnf.json");
809 JSONAssert.assertEquals(expectedNotificationHeader, notificationEvents.get(0).getEventHeader().marshal(false), false);
810 JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getObj().marshal(false), false);
815 public void testDeleteOnExistingResourceVersionMismatchNoEventGeneratedFullDepth() throws IOException, AAIException {
816 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
817 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
818 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
820 String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
822 Response response = httpTestUtil.doGet(uri);
823 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
825 response = httpTestUtil.doPut(uri, pserverResource);
826 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
828 response = httpTestUtil.doGet(uri , "all");
829 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
831 JSONObject pserverObject = new JSONObject(response.getEntity().toString());
832 String resourceVersion = pserverObject.getString("resource-version");
834 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
835 response = httpTestUtil.doDelete(uri, resourceVersion+"123");
836 assertEquals("Resource version mismatch exception", 412, response.getStatus());
838 List<NotificationEvent> notificationEvents = notification.getEvents();
839 assertThat(notificationEvents.size(), is(0));
843 public void testCreateVnfWithChildrenCreateCustomerWithChildrenAndCousinBetweenVlanAndServiceInstanceThenDeleteCustomerVerifyingVlanRV() throws IOException, AAIException {
844 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
845 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
847 JsonObject paylaods = new JsonParser().parse(
848 PayloadUtil.getResourcePayload("customer_with_children_and_generic-vnf_with_children_and_edge_between_service-instance_vlan.json"))
850 String gvnfPaylaod = paylaods.get("generic-vnf").toString();
851 String custPaylaod = paylaods.get("customer").toString();
852 String gvnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/gvnf";
853 String custUri = "/aai/v14/business/customers/customer/cust";
854 String vlanUri = "/aai/v14/network/generic-vnfs/generic-vnf/gvnf/l-interfaces/l-interface/lint/vlans/vlan/vlan";
857 Response response = httpTestUtil.doGet(gvnfUri);
858 assertEquals("Expecting the generic-vnf to be not found", 404, response.getStatus());
859 response = httpTestUtil.doPut(gvnfUri, gvnfPaylaod);
860 assertEquals("Expecting the generic-vnf to be created", 201, response.getStatus());
861 response = httpTestUtil.doGet(gvnfUri , "all");
862 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
863 response = httpTestUtil.doGet(vlanUri , "all");
864 assertEquals("Expecting the vlan to be found", 200, response.getStatus());
865 String vlanResourceVersion = new JSONObject(response.getEntity().toString()).getString("resource-version");
867 //Setup customer with service instance relation to vlan
868 response = httpTestUtil.doGet(custUri);
869 assertEquals("Expecting the customer to be not found", 404, response.getStatus());
870 response = httpTestUtil.doPut(custUri, custPaylaod);
871 assertEquals("Expecting the customer to be created", 201, response.getStatus());
872 response = httpTestUtil.doGet(custUri , "all");
873 assertEquals("Expecting the customer to be found", 200, response.getStatus());
874 String custResourceVersion = new JSONObject(response.getEntity().toString()).getString("resource-version");
876 //Verify vlan rv was updated
877 response = httpTestUtil.doGet(vlanUri , "all");
878 assertEquals("Expecting the vlan to be found", 200, response.getStatus());
879 String vlanResourceVersionAfterCustPut = new JSONObject(response.getEntity().toString()).getString("resource-version");
880 assertThat("Expecting the vlan resource version to be updated", vlanResourceVersionAfterCustPut, not(is(vlanResourceVersion)));
883 notification.clearEvents();
884 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
885 response = httpTestUtil.doDelete(custUri, custResourceVersion);
886 assertEquals("Expecting customer to be deleted", 204, response.getStatus());
888 //Verify vlan rv was updated
889 response = httpTestUtil.doGet(vlanUri , "all");
890 assertEquals("Expecting the vlan to be found", 200, response.getStatus());
891 String vlanResourceVersionAfterDelete = new JSONObject(response.getEntity().toString()).getString("resource-version");
892 assertThat("Expecting the vlan resource version to be updated", vlanResourceVersionAfterDelete, not(is(vlanResourceVersionAfterCustPut)));
894 List<NotificationEvent> notificationEvents = notification.getEvents();
895 assertThat("Expect the delete to generate 4 events customer, its children and vlan", notificationEvents.size(), is(4));
900 public void testBulkCreateOfComplexAndPserverWithRelationshipThenBulkDeleteBoth() throws IOException, AAIException {
901 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
902 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
904 JsonObject paylaods = new JsonParser().parse(
905 PayloadUtil.getResourcePayload("complex_pserver_with_relation.json"))
907 String complexPaylaod = paylaods.get("complex").toString();
908 String pserverPaylaod = paylaods.get("pserver").toString();
909 String complexUri = "/aai/v14/cloud-infrastructure/complexes/complex/complex-1";
910 String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/pserver-1";
912 Response response = httpTestUtil.doGet(complexUri);
913 assertEquals("Expecting the complex to be not found", 404, response.getStatus());
914 response = httpTestUtil.doGet(pserverUri);
915 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
917 Map<String,String> puts = new LinkedHashMap<>();
918 puts.put(complexUri, complexPaylaod);
919 puts.put(pserverUri, pserverPaylaod);
921 response = httpTestUtil.doPut(puts);
922 assertEquals("Expecting the puts request to succeed", 201, response.getStatus());
923 assertEquals("Expect 2 messages to be created", 2, notification.getEvents().size());
924 response = httpTestUtil.doGet(complexUri , "all");
925 assertEquals("Expecting the complex to be found", 200, response.getStatus());
926 String complexRV = new JSONObject(response.getEntity().toString()).getString("resource-version");
927 response = httpTestUtil.doGet(pserverUri , "all");
928 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
929 String pserverRv = new JSONObject(response.getEntity().toString()).getString("resource-version");
930 assertThat("Resource versions match", complexRV, is(pserverRv));
932 Map<String, Pair<String, String>> deletes = new LinkedHashMap<>();
933 deletes.put(pserverUri, new Pair<>(pserverRv, null));
934 deletes.put(complexUri, new Pair<>(complexRV, null));
935 notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
936 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
937 httpTestUtil.doDelete(deletes);
939 response = httpTestUtil.doGet(complexUri);
940 assertEquals("Expecting the complex to be not found", 404, response.getStatus());
941 response = httpTestUtil.doGet(pserverUri);
942 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
946 public void testCreateVnfWithChildrenCreateCustomerWithChildrenAndCousinBetweenVlanAndServiceInstanceThenImplicitDeleteVlanVerifyingServiceInstanceRV() throws IOException, AAIException {
947 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
948 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
950 JsonObject paylaods = new JsonParser().parse(
951 PayloadUtil.getResourcePayload("customer_with_children_and_generic-vnf_with_children_and_edge_between_service-instance_vlan.json"))
953 String gvnfPaylaod = paylaods.get("generic-vnf").toString();
954 String custPaylaod = paylaods.get("customer").toString();
955 String custUri = "/aai/v14/business/customers/customer/cust";
956 String ssUri = custUri + "/service-subscriptions/service-subscription/ss";
957 String siUri = ssUri + "/service-instances/service-instance/si";
958 String gvnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/gvnf";
959 String lintUri = gvnfUri + "/l-interfaces/l-interface/lint";
960 String vlanUri = lintUri + "/vlans/vlan/vlan";
963 Response response = httpTestUtil.doGet(gvnfUri);
964 assertEquals("Expecting the generic-vnf to be not found", 404, response.getStatus());
965 response = httpTestUtil.doPut(gvnfUri, gvnfPaylaod);
966 assertEquals("Expecting the generic-vnf to be created", 201, response.getStatus());
967 response = httpTestUtil.doGet(gvnfUri , "all");
968 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
969 response = httpTestUtil.doGet(vlanUri , "all");
970 assertEquals("Expecting the vlan to be found", 200, response.getStatus());
971 String vlanResourceVersion = new JSONObject(response.getEntity().toString()).getString("resource-version");
973 //Setup customer with service instance relation to vlan
974 response = httpTestUtil.doGet(custUri);
975 assertEquals("Expecting the customer to be not found", 404, response.getStatus());
976 response = httpTestUtil.doPut(custUri, custPaylaod);
977 assertEquals("Expecting the customer to be created", 201, response.getStatus());
978 response = httpTestUtil.doGet(custUri , "all");
979 assertEquals("Expecting the customer to be found", 200, response.getStatus());
980 response = httpTestUtil.doGet(siUri , "all");
981 assertEquals("Expecting the service-instance to be found", 200, response.getStatus());
982 String serviceInstanceResourceVersion = new JSONObject(response.getEntity().toString()).getString("resource-version");
984 //Verify vlan rv was updated
985 response = httpTestUtil.doGet(vlanUri , "all");
986 assertEquals("Expecting the vlan to be found", 200, response.getStatus());
987 String vlanResourceVersionAfterCustPut = new JSONObject(response.getEntity().toString()).getString("resource-version");
988 assertThat("Expecting the vlan resource version to be updated", vlanResourceVersionAfterCustPut, not(is(vlanResourceVersion)));
990 //Get linterface, replace vlans with empty json (implicit delete) and put triggering implicit delete
991 response = httpTestUtil.doGet(lintUri , "all");
992 assertEquals("Expecting the l-interface to be found", 200, response.getStatus());
993 JSONObject lintJson = new JSONObject(response.getEntity().toString());
994 lintJson.put("vlans", new JsonObject());
995 notification.clearEvents();
996 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
997 response = httpTestUtil.doPut(lintUri, lintJson.toString());
998 assertEquals("Expecting the l-interface to be updated", 200, response.getStatus());
1000 List<NotificationEvent> notificationEvents = notification.getEvents();
1001 assertThat("Expect the implied delete to generate 2", notificationEvents.size(), is(2));
1003 //Verify vlan is no longer there anf get service-instance and compare rv
1004 response = httpTestUtil.doGet(vlanUri , "all");
1005 assertEquals("Expecting the vlan not to be found", 404, response.getStatus());
1006 response = httpTestUtil.doGet(siUri , "all");
1007 assertEquals("Expecting the service-instance to be found", 200, response.getStatus());
1008 String serviceInstanceResourceVersionAfterImplicitDelete = new JSONObject(response.getEntity().toString()).getString("resource-version");
1009 assertThat("Expecting the service-instance resource version to be updated after implicit delete of vlan",
1010 serviceInstanceResourceVersionAfterImplicitDelete,
1011 not(is(serviceInstanceResourceVersion)));
1015 public void teardown() {
1017 JanusGraph janusGraph = AAIGraph.getInstance().getGraph();
1018 JanusGraphTransaction transaction = janusGraph.newTransaction();
1020 GraphTraversalSource g = transaction.traversal();
1023 .has(AAIProperties.SOURCE_OF_TRUTH, "JUNIT")
1024 .forEachRemaining(Vertex::remove);
1026 transaction.commit();