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=========================================================
21 package org.onap.aai.rest;
23 import static org.hamcrest.CoreMatchers.*;
24 import static org.hamcrest.junit.MatcherAssert.assertThat;
25 import static org.junit.Assert.assertEquals;
27 import com.google.gson.JsonObject;
28 import com.google.gson.JsonParser;
30 import java.io.IOException;
31 import java.io.UnsupportedEncodingException;
34 import javax.ws.rs.core.Response;
36 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
37 import org.apache.tinkerpop.gremlin.structure.Vertex;
38 import org.janusgraph.core.JanusGraph;
39 import org.janusgraph.core.JanusGraphTransaction;
40 import org.javatuples.Pair;
41 import org.json.JSONObject;
42 import org.junit.After;
43 import org.junit.Test;
44 import org.junit.runner.RunWith;
45 import org.junit.runners.Parameterized;
46 import org.mockito.Mockito;
47 import org.onap.aai.AAISetup;
48 import org.onap.aai.HttpTestUtil;
49 import org.onap.aai.PayloadUtil;
50 import org.onap.aai.db.props.AAIProperties;
51 import org.onap.aai.dbmap.AAIGraph;
52 import org.onap.aai.exceptions.AAIException;
53 import org.onap.aai.introspection.ModelType;
54 import org.onap.aai.rest.ueb.NotificationEvent;
55 import org.onap.aai.rest.ueb.UEBNotification;
56 import org.onap.aai.serialization.engines.QueryStyle;
57 import org.skyscreamer.jsonassert.JSONAssert;
58 import org.springframework.test.annotation.DirtiesContext;
60 @RunWith(value = Parameterized.class)
61 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
62 public class NotificationDmaapEventTest extends AAISetup {
64 @Parameterized.Parameter
65 public QueryStyle queryStyle;
67 @Parameterized.Parameters(name = "QueryStyle.{0}")
68 public static Collection<Object[]> data() {
69 return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
73 public void testCreateWithPserverWithAllChildrenAndVerifyMultipleNotificationsWhenNotificationDepthIsZero()
74 throws IOException, AAIException {
76 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
77 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
78 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
80 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
82 Response response = httpTestUtil.doGet(uri);
83 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
85 response = httpTestUtil.doPut(uri, resource);
86 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
88 int expectedCreateEvents = 17;
90 assertThat(notification.getEvents().size(), is(expectedCreateEvents));
92 // Verify all the events are create since its a new PUT
93 notification.getEvents().forEach((event) -> {
95 String header = event.getEventHeader().marshal(false);
97 assertThat(event.getEventHeader().marshal(false), containsString("\"CREATE\""));
99 assertThat(header, containsString("\"top-entity-type\":\"pserver\""));
103 response = httpTestUtil.doGet(uri);
104 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
107 // Test existing pserver create new pinterface check dmaap event for pinterface is CREATE
109 public void testExistingPserverCreateNewChildPInterfaceAndCheckDmaapEventForPInterfaceIsCreateWhenNotificationDepthIsZero()
110 throws IOException, AAIException {
112 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
113 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
114 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
116 String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
118 Response response = httpTestUtil.doGet(uri);
119 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
121 response = httpTestUtil.doPut(uri, pserverResource);
122 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
123 notification.clearEvents();
125 response = httpTestUtil.doGet(uri, "all");
126 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
128 JSONObject pserverJson = new JSONObject(response.getEntity().toString());
129 JSONObject pInterfaceObject = new JSONObject();
130 pInterfaceObject.put("interface-name", "p-interface-1");
132 pserverJson.getJSONObject("p-interfaces").getJSONArray("p-interface").put(pInterfaceObject);
134 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
135 response = httpTestUtil.doPut(uri, pserverJson.toString());
136 assertEquals("Expecting the pserver to be updated with a new p-interface", 200, response.getStatus());
138 response = httpTestUtil.doGet(uri + "/p-interfaces/p-interface/p-interface-1", "0");
139 assertEquals("Expecting the p-interface to be found", 200, response.getStatus());
141 List<NotificationEvent> events = notification.getEvents();
142 assertThat(events.size(), is(2));
144 String notificationEventHeader = events.get(1).getEventHeader().marshal(false);
145 String notificationEventBody = events.get(1).getObj().marshal(false);
147 assertThat(notificationEventHeader, containsString("\"action\":\"CREATE\""));
148 assertThat(notificationEventHeader, containsString("\"entity-type\":\"p-interface\""));
149 assertThat(notificationEventHeader, containsString("\"top-entity-type\":\"pserver\""));
151 String expectedNotificationHeader = PayloadUtil.getResourcePayload(
152 "notification-dmaap-events/depth-zero/expected-notification-header-create-child-on-existing-obj.json");
153 String expectedNotificationBody = PayloadUtil.getResourcePayload(
154 "notification-dmaap-events/depth-zero/expected-notification-body-create-child-on-existing-obj.json");
156 JSONAssert.assertEquals(expectedNotificationHeader, notificationEventHeader, false);
157 JSONAssert.assertEquals(expectedNotificationBody, notificationEventBody, false);
161 public void testExistingPserverCreateNewChildPInterfaceAndCheckDmaapEventForPserverIsSentWithNewPInterfaceWhenNotificationDepthIsAll()
162 throws IOException, AAIException {
164 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
165 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
166 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
168 String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
170 Response response = httpTestUtil.doGet(uri);
171 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
173 response = httpTestUtil.doPut(uri, pserverResource);
174 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
176 response = httpTestUtil.doGet(uri, "all");
177 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
179 JSONObject pserverJson = new JSONObject(response.getEntity().toString());
180 String pserverResourceVersion = pserverJson.getString("resource-version");
182 JSONObject pInterfaceObject = new JSONObject();
183 pInterfaceObject.put("interface-name", "p-interface-1");
185 pserverJson.getJSONObject("p-interfaces").getJSONArray("p-interface").put(pInterfaceObject);
187 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
188 response = httpTestUtil.doPut(uri, pserverJson.toString());
189 assertEquals("Expecting the pserver to be updated with a new p-interface", 200, response.getStatus());
191 response = httpTestUtil.doGet(uri + "/p-interfaces/p-interface/p-interface-1", "0");
192 assertEquals("Expecting the p-interface to be found", 200, response.getStatus());
194 List<NotificationEvent> events = notification.getEvents();
195 assertThat(events.size(), is(1));
197 String notificationEventHeader = events.get(0).getEventHeader().marshal(false);
198 String notificationEventBody = events.get(0).getObj().marshal(false);
200 assertThat(notificationEventHeader, containsString("\"action\":\"UPDATE\""));
201 assertThat(notificationEventHeader, containsString("\"entity-type\":\"pserver\""));
202 assertThat(notificationEventHeader, containsString("\"top-entity-type\":\"pserver\""));
204 String expectedNotificationHeader = PayloadUtil.getResourcePayload(
205 "notification-dmaap-events/depth-all/expected-notification-header-create-child-on-existing-obj.json");
206 String expectedNotificationBody = PayloadUtil.getResourcePayload(
207 "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
218 assertThat("Expecting the new pserver resource version and old resource version to be not same",
219 newPserverResourceVersion, is(not(pserverResourceVersion)));
220 assertEquals("Expecting the p-interface to be found", 200, response.getStatus());
223 // Test Bulk Scenario
225 public void testBulkScenarioWhereMultipleCreatesAndEnsureNoDuplicationInDmaapEventsWhenNotificationDepthIsZero()
226 throws UnsupportedEncodingException, AAIException {
228 String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/random-pserver";
229 String cloudRegionUri =
230 "/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/random-cloud-region-owner/random-cloud-region-id";
232 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
233 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
235 Map<String, String> uriPayload = new LinkedHashMap<>();
237 uriPayload.put(pserverUri, "{}");
238 uriPayload.put(cloudRegionUri, "{}");
240 Response response = httpTestUtil.doPut(uriPayload);
241 assertThat(response.getStatus(), is(201));
243 int numberOfEventsActual = notification.getEvents().size();
244 int expectedEvents = 2;
246 assertThat("Expecting the number of dmaap events to be 2", numberOfEventsActual, is(expectedEvents));
248 notification.getEvents().forEach((event) -> {
249 String notificationEventHeader = event.getEventHeader().marshal(false);
250 assertThat(notificationEventHeader, containsString("\"CREATE\""));
255 public void testBulkScenarioWhereMultipleCreatesAndEnsureNoDuplicationInDmaapEventsWhenNotificationDepthIsAll()
256 throws UnsupportedEncodingException, AAIException {
258 String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/random-pserver";
259 String cloudRegionUri =
260 "/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()
286 throws IOException, AAIException {
287 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
288 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
289 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
291 String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
293 Response response = httpTestUtil.doGet(uri);
294 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
296 response = httpTestUtil.doPut(uri, pserverResource);
297 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
299 response = httpTestUtil.doGet(uri, "all");
300 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
302 JSONObject pserverObject = new JSONObject(response.getEntity().toString());
303 String resourceVersion = pserverObject.getString("resource-version");
305 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
306 response = httpTestUtil.doDelete(uri, resourceVersion);
307 assertEquals("Expecting the pserver to be deleted", 204, response.getStatus());
309 List<NotificationEvent> notificationEvents = notification.getEvents();
310 assertThat(notificationEvents.size(), is(17));
312 notificationEvents.forEach((event) -> {
314 String header = event.getEventHeader().marshal(false);
316 assertThat(event.getEventHeader().marshal(false), containsString("\"DELETE\""));
318 assertThat(header, containsString("\"top-entity-type\":\"pserver\""));
323 public void testDeleteOnExistingResourceVersionMismatchNoEventGenerated() throws IOException, AAIException {
324 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
325 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
326 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
328 String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
330 Response response = httpTestUtil.doGet(uri);
331 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
333 response = httpTestUtil.doPut(uri, pserverResource);
334 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
336 response = httpTestUtil.doGet(uri, "all");
337 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
339 JSONObject pserverObject = new JSONObject(response.getEntity().toString());
340 String resourceVersion = pserverObject.getString("resource-version");
342 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
343 response = httpTestUtil.doDelete(uri, resourceVersion + "123");
344 assertEquals("Resource version mismatch exception", 412, response.getStatus());
346 List<NotificationEvent> notificationEvents = notification.getEvents();
347 assertThat(notificationEvents.size(), is(0));
350 // Test notification depth set to all
351 // Scenario for testing the creation of pserver with children, grandchildren
352 // Default behaviour is for one event to be sent out
353 // which includes all the children and grandchildren, etc
355 public void testCreateWithPserverWithAllChildrenAndVerifyOneNotificationWhenNotificationDepthIsAll()
356 throws IOException, AAIException {
358 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
359 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
360 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
362 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
364 Response response = httpTestUtil.doGet(uri);
365 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
367 response = httpTestUtil.doPut(uri, resource);
368 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
370 assertThat(notification.getEvents().size(), is(1));
372 NotificationEvent notificationEvent = notification.getEvents().get(0);
374 // Verify all the events are create since its a new PUT
375 String header = notificationEvent.getEventHeader().marshal(false);
377 assertThat(header, containsString("\"CREATE\""));
379 assertThat(header, containsString("\"entity-type\":\"pserver\""));
381 assertThat(header, containsString("\"top-entity-type\":\"pserver\""));
383 assertThat(header, containsString("\"entity-link\":\"" + uri + "\""));
385 response = httpTestUtil.doGet(uri);
386 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
388 JSONAssert.assertEquals(response.getEntity().toString(), notificationEvent.getObj().marshal(false), false);
392 public void testPatchExistingPserverWithChildrenAndModifyOnlyOneObjectAndVerifyThatOnlyOneNotificationEventNoChildrenWhenNotificationDepthIsZero()
393 throws IOException, AAIException {
395 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
396 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
397 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
399 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
401 Response response = httpTestUtil.doGet(uri);
402 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
404 response = httpTestUtil.doPut(uri, resource);
405 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
407 response = httpTestUtil.doGet(uri);
408 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
410 JSONObject pserverObject = new JSONObject();
411 pserverObject.put("equip-type", "new-equip-patch-type");
413 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
414 response = httpTestUtil.doPatch(uri, pserverObject.toString());
415 assertThat(response.getStatus(), is(200));
417 response = httpTestUtil.doGet(uri, "0");
418 assertThat(response.getEntity().toString(), containsString("new-equip-patch-type"));
420 assertThat(notification.getEvents().size(), is(1));
421 String updateNotificationEvent = notification.getEvents().get(0).getObj().marshal(true);
423 // Check that everything in notification event is also response body
424 // Not comparing the other way as notification only includes parents main properties
425 JSONAssert.assertEquals(updateNotificationEvent, response.getEntity().toString(), false);
429 public void testPatchExistingPserverWithChildrenAndModifyOnlyOneObjectAndVerifyThatOnlyOneNotificationEventIncludeChildrenWhenNotificationDepthIsAll()
430 throws IOException, AAIException {
432 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
433 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
434 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
436 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
438 Response response = httpTestUtil.doGet(uri);
439 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
441 response = httpTestUtil.doPut(uri, resource);
442 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
444 response = httpTestUtil.doGet(uri);
445 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
447 JSONObject pserverObject = new JSONObject();
448 pserverObject.put("equip-type", "new-equip-patch-type");
450 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
451 response = httpTestUtil.doPatch(uri, pserverObject.toString());
452 assertThat(response.getStatus(), is(200));
454 response = httpTestUtil.doGet(uri, "all");
455 assertThat(response.getEntity().toString(), containsString("new-equip-patch-type"));
457 assertThat(notification.getEvents().size(), is(1));
458 String updateNotificationEvent = notification.getEvents().get(0).getObj().marshal(true);
460 // Check that everything in notification event is also response body
461 // Not comparing the other way as notification only includes parents main properties
462 JSONAssert.assertEquals(updateNotificationEvent, response.getEntity().toString(), false);
465 // Test notification depth set to all
466 // Scenario where we are only updating one field in p-interface
467 // Make sure the parent and children are included
469 public void testUpdateExistingPserverWithChildrenAndModifyOnlyOneObjectAndVerifyThatOnlyOneNotificationEventIncludingChildrenWhenNotificationDepthIsAll()
470 throws IOException, AAIException {
472 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
473 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
474 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
476 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
478 Response response = httpTestUtil.doGet(uri);
479 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
481 response = httpTestUtil.doPut(uri, resource);
482 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
484 response = httpTestUtil.doGet(uri);
485 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
487 response = httpTestUtil.doGet(uri + "/p-interfaces/p-interface/example-interface-name-val-46147", "0");
488 assertEquals("Expecting the p-interface to be found", 200, response.getStatus());
490 JSONObject pInterfaceObject = new JSONObject(response.getEntity().toString());
491 pInterfaceObject.put("equipment-identifier", "new-equipment-identifier");
493 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
494 response = httpTestUtil.doPut(uri + "/p-interfaces/p-interface/example-interface-name-val-46147",
495 pInterfaceObject.toString());
496 assertThat(response.getStatus(), is(200));
498 // Get the parent uri as the notification event json has parent structure it makes it easy to compare
499 response = httpTestUtil.doGet(uri);
500 assertThat(response.getEntity().toString(), containsString("new-equipment-identifier"));
502 assertThat(notification.getEvents().size(), is(1));
503 String updateNotificationEvent = notification.getEvents().get(0).getObj().marshal(true);
505 // Check that everything in notification event is also response body
506 // Not comparing the other way as notification only includes parents main properties
507 JSONAssert.assertEquals(updateNotificationEvent, response.getEntity().toString(), false);
510 // Test notification depth set to 0
511 // Scenario where we are only updating one field in p-interface
513 public void testUpdateExistingPserverWithChildrenAndModifyOnlyPInterfaceAndVerifyThatOnlyOneNotificationForPInterfaceIsCreatedWhenNotificationDepthIsZero()
514 throws IOException, AAIException {
516 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
517 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
518 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
520 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
522 Response response = httpTestUtil.doGet(uri);
523 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
525 response = httpTestUtil.doPut(uri, resource);
526 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
528 response = httpTestUtil.doGet(uri);
529 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
531 response = httpTestUtil.doGet(uri + "/p-interfaces/p-interface/example-interface-name-val-46147", "0");
532 assertEquals("Expecting the p-interface to be found", 200, response.getStatus());
534 JSONObject pInterfaceObject = new JSONObject(response.getEntity().toString());
535 pInterfaceObject.put("equipment-identifier", "new-equipment-identifier");
537 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
538 response = httpTestUtil.doPut(uri + "/p-interfaces/p-interface/example-interface-name-val-46147",
539 pInterfaceObject.toString());
540 assertThat(response.getStatus(), is(200));
542 response = httpTestUtil.doGet(uri);
543 assertThat(notification.getEvents().size(), is(1));
544 String updateNotificationEvent = notification.getEvents().get(0).getObj().marshal(true);
545 System.out.println("Update notification " + updateNotificationEvent);
547 // Check that everything in notification event is also response body
548 // Not comparing the other way as notification only includes parents main properties
549 JSONAssert.assertEquals(updateNotificationEvent, response.getEntity().toString(), false);
553 public void testExistingPserverWithChildAndGenericVnfAndCreateEdgeBetweenThemAndCheckNoChildWhenNotificationDepthIsZero()
554 throws IOException, AAIException {
556 String hostname = "example-hostname-val-85598";
558 String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/" + hostname;
559 String genericVnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/generic-vnf-notification";
561 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
562 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
564 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
565 String genericVnfResource = PayloadUtil.getResourcePayload("generic-vnf-notification.json");
567 Response response = httpTestUtil.doGet(pserverUri);
568 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
570 response = httpTestUtil.doPut(pserverUri, resource);
571 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
573 response = httpTestUtil.doGet(pserverUri);
574 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
576 response = httpTestUtil.doGet(genericVnfUri);
577 assertEquals("Expecting the generic-vnf to be not found", 404, response.getStatus());
579 response = httpTestUtil.doPut(genericVnfUri, genericVnfResource);
580 assertEquals("Expecting the generic-vnf to be created", 201, response.getStatus());
582 response = httpTestUtil.doGet(genericVnfUri);
583 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
584 assertThat(response.getEntity().toString(), not(containsString(hostname)));
586 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
588 String relationship = PayloadUtil.getResourcePayload("pserver-to-gvnf-relationship-notification.json");
590 response = httpTestUtil.doPut(pserverUri + "/relationship-list/relationship", relationship);
591 assertEquals("Expecting the pserver to generic-vnf relationship to be created", 200, response.getStatus());
593 List<NotificationEvent> notificationEvents = notification.getEvents();
594 assertThat(notificationEvents.size(), is(2));
596 String expectedNotificationHeader = PayloadUtil.getResourcePayload(
597 "notification-dmaap-events/depth-zero/expected-notification-header-create-edge-between-pserver-and-generic-vnf.json");
598 String expectedNotificationBody = PayloadUtil.getResourcePayload(
599 "notification-dmaap-events/depth-zero/expected-notification-body-create-edge-between-pserver-and-generic-vnf.json");
601 JSONAssert.assertEquals(expectedNotificationHeader, notificationEvents.get(0).getEventHeader().marshal(false),
603 JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getObj().marshal(false), false);
605 response = httpTestUtil.doGet(genericVnfUri);
607 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
608 assertThat(response.getEntity().toString(), containsString(hostname));
612 public void testExistingPserverWithChildAndGenericVnfAndCreateEdgeBetweenThemAndCheckChildrenIncludedWhenNotificationDepthIsAll()
613 throws IOException, AAIException {
615 String hostname = "example-hostname-val-85598";
617 String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/" + hostname;
618 String genericVnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/generic-vnf-notification";
620 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
621 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
623 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
624 String genericVnfResource = PayloadUtil.getResourcePayload("generic-vnf-notification.json");
626 Response response = httpTestUtil.doGet(pserverUri);
627 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
629 response = httpTestUtil.doPut(pserverUri, resource);
630 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
632 response = httpTestUtil.doGet(pserverUri);
633 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
635 response = httpTestUtil.doGet(genericVnfUri);
636 assertEquals("Expecting the generic-vnf to be not found", 404, response.getStatus());
638 response = httpTestUtil.doPut(genericVnfUri, genericVnfResource);
639 assertEquals("Expecting the generic-vnf to be created", 201, response.getStatus());
641 response = httpTestUtil.doGet(genericVnfUri);
642 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
643 assertThat(response.getEntity().toString(), not(containsString(hostname)));
645 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
647 String relationship = PayloadUtil.getResourcePayload("pserver-to-gvnf-relationship-notification.json");
649 response = httpTestUtil.doPut(pserverUri + "/relationship-list/relationship", relationship);
650 assertEquals("Expecting the pserver to generic-vnf relationship to be created", 200, response.getStatus());
652 List<NotificationEvent> notificationEvents = notification.getEvents();
653 assertThat(notificationEvents.size(), is(2));
655 String expectedNotificationHeader = PayloadUtil.getResourcePayload(
656 "notification-dmaap-events/depth-all/expected-notification-header-create-edge-between-pserver-and-generic-vnf.json");
657 String expectedNotificationBody = PayloadUtil.getResourcePayload(
658 "notification-dmaap-events/depth-all/expected-notification-body-create-edge-between-pserver-and-generic-vnf.json");
660 System.out.println("Notification Body: " + notificationEvents.get(0).getObj().marshal(false));
661 JSONAssert.assertEquals(expectedNotificationHeader, notificationEvents.get(0).getEventHeader().marshal(false),
663 JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getObj().marshal(false), false);
665 response = httpTestUtil.doGet(genericVnfUri);
667 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
668 assertThat(response.getEntity().toString(), containsString(hostname));
672 public void testExistingPserverWithChildAndGenericVnfAndExistingEdgeBetweenThemAndDeleteEdgeAndCheckNoChildWhenNotificationDepthIsZero()
673 throws IOException, AAIException {
675 String hostname = "example-hostname-val-85598";
677 String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/" + hostname;
678 String genericVnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/generic-vnf-notification";
680 String relationship = PayloadUtil.getResourcePayload("pserver-to-gvnf-relationship-notification.json");
682 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
683 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
685 String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
686 String genericVnfResource = PayloadUtil.getResourcePayload("generic-vnf-notification.json");
688 Response response = httpTestUtil.doGet(pserverUri);
689 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
691 response = httpTestUtil.doPut(pserverUri, resource);
692 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
694 response = httpTestUtil.doGet(pserverUri);
695 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
697 response = httpTestUtil.doGet(genericVnfUri);
698 assertEquals("Expecting the generic-vnf to be not found", 404, response.getStatus());
700 response = httpTestUtil.doPut(genericVnfUri, genericVnfResource);
701 assertEquals("Expecting the generic-vnf to be created", 201, response.getStatus());
703 response = httpTestUtil.doGet(genericVnfUri);
704 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
705 assertThat(response.getEntity().toString(), not(containsString(hostname)));
707 response = httpTestUtil.doPut(pserverUri + "/relationship-list/relationship", relationship);
708 assertEquals("Expecting the pserver to generic-vnf relationship to be created", 200, response.getStatus());
710 response = httpTestUtil.doGet(genericVnfUri);
712 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
713 assertThat(response.getEntity().toString(), containsString(hostname));
715 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
716 assertThat(response.getEntity().toString(), containsString(hostname));
718 response = httpTestUtil.doGet(pserverUri);
719 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
721 JSONObject pserverJson = new JSONObject(response.getEntity().toString());
722 String resourceVersion = pserverJson.getString("resource-version");
724 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
726 response = httpTestUtil.doDelete(pserverUri + "/relationship-list/relationship", resourceVersion, relationship);
727 assertThat("Expected the pserver relationship to generic-vnf to be deleted", response.getStatus(), is(204));
729 List<NotificationEvent> notificationEvents = notification.getEvents();
731 assertThat(notificationEvents.size(), is(2));
733 String expectedNotificationHeader = PayloadUtil.getResourcePayload(
734 "notification-dmaap-events/depth-zero/expected-notification-header-delete-edge-between-pserver-and-generic-vnf.json");
735 String expectedNotificationBody = PayloadUtil.getResourcePayload(
736 "notification-dmaap-events/depth-zero/expected-notification-body-delete-edge-between-pserver-and-generic-vnf.json");
738 JSONAssert.assertEquals(expectedNotificationHeader, notificationEvents.get(0).getEventHeader().marshal(false),
740 JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getObj().marshal(false), false);
745 public void testExistingPserverWithChildAndGenericVnfAndExistingEdgeBetweenThemAndDeleteEdgeAndCheckChildrenWhenNotificationDepthIsAll()
746 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)));
780 response = httpTestUtil.doPut(pserverUri + "/relationship-list/relationship", relationship);
781 assertEquals("Expecting the pserver to generic-vnf relationship to be created", 200, response.getStatus());
783 response = httpTestUtil.doGet(genericVnfUri);
785 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
786 assertThat(response.getEntity().toString(), containsString(hostname));
788 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
789 assertThat(response.getEntity().toString(), containsString(hostname));
791 response = httpTestUtil.doGet(pserverUri);
792 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
794 JSONObject pserverJson = new JSONObject(response.getEntity().toString());
795 String resourceVersion = pserverJson.getString("resource-version");
797 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
799 response = httpTestUtil.doDelete(pserverUri + "/relationship-list/relationship", resourceVersion, relationship);
800 assertThat("Expected the pserver relationship to generic-vnf to be deleted", response.getStatus(), is(204));
802 List<NotificationEvent> notificationEvents = notification.getEvents();
803 assertThat(notificationEvents.size(), is(2));
805 String expectedNotificationHeader = PayloadUtil.getResourcePayload(
806 "notification-dmaap-events/depth-all/expected-notification-header-delete-edge-between-pserver-and-generic-vnf.json");
807 String expectedNotificationBody = PayloadUtil.getResourcePayload(
808 "notification-dmaap-events/depth-all/expected-notification-body-delete-edge-between-pserver-and-generic-vnf.json");
810 JSONAssert.assertEquals(expectedNotificationHeader, notificationEvents.get(0).getEventHeader().marshal(false),
812 JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getObj().marshal(false), false);
817 public void testDeleteOnExistingResourceVersionMismatchNoEventGeneratedFullDepth()
818 throws IOException, AAIException {
819 String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
820 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
821 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
823 String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
825 Response response = httpTestUtil.doGet(uri);
826 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
828 response = httpTestUtil.doPut(uri, pserverResource);
829 assertEquals("Expecting the pserver to be created", 201, response.getStatus());
831 response = httpTestUtil.doGet(uri, "all");
832 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
834 JSONObject pserverObject = new JSONObject(response.getEntity().toString());
835 String resourceVersion = pserverObject.getString("resource-version");
837 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
838 response = httpTestUtil.doDelete(uri, resourceVersion + "123");
839 assertEquals("Resource version mismatch exception", 412, response.getStatus());
841 List<NotificationEvent> notificationEvents = notification.getEvents();
842 assertThat(notificationEvents.size(), is(0));
846 public void testCreateVnfWithChildrenCreateCustomerWithChildrenAndCousinBetweenVlanAndServiceInstanceThenDeleteCustomerVerifyingVlanRV()
847 throws IOException, AAIException {
848 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
849 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
851 JsonObject paylaods = new JsonParser().parse(PayloadUtil.getResourcePayload(
852 "customer_with_children_and_generic-vnf_with_children_and_edge_between_service-instance_vlan.json"))
854 String gvnfPaylaod = paylaods.get("generic-vnf").toString();
855 String custPaylaod = paylaods.get("customer").toString();
856 String gvnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/gvnf";
857 String custUri = "/aai/v14/business/customers/customer/cust";
858 String vlanUri = "/aai/v14/network/generic-vnfs/generic-vnf/gvnf/l-interfaces/l-interface/lint/vlans/vlan/vlan";
861 Response response = httpTestUtil.doGet(gvnfUri);
862 assertEquals("Expecting the generic-vnf to be not found", 404, response.getStatus());
863 response = httpTestUtil.doPut(gvnfUri, gvnfPaylaod);
864 assertEquals("Expecting the generic-vnf to be created", 201, response.getStatus());
865 response = httpTestUtil.doGet(gvnfUri, "all");
866 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
867 response = httpTestUtil.doGet(vlanUri, "all");
868 assertEquals("Expecting the vlan to be found", 200, response.getStatus());
869 String vlanResourceVersion = new JSONObject(response.getEntity().toString()).getString("resource-version");
871 // Setup customer with service instance relation to vlan
872 response = httpTestUtil.doGet(custUri);
873 assertEquals("Expecting the customer to be not found", 404, response.getStatus());
874 response = httpTestUtil.doPut(custUri, custPaylaod);
875 assertEquals("Expecting the customer to be created", 201, response.getStatus());
876 response = httpTestUtil.doGet(custUri, "all");
877 assertEquals("Expecting the customer to be found", 200, response.getStatus());
878 String custResourceVersion = new JSONObject(response.getEntity().toString()).getString("resource-version");
880 // Verify vlan rv was updated
881 response = httpTestUtil.doGet(vlanUri, "all");
882 assertEquals("Expecting the vlan to be found", 200, response.getStatus());
883 String vlanResourceVersionAfterCustPut =
884 new JSONObject(response.getEntity().toString()).getString("resource-version");
885 assertThat("Expecting the vlan resource version to be updated", vlanResourceVersionAfterCustPut,
886 not(is(vlanResourceVersion)));
889 notification.clearEvents();
890 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
891 response = httpTestUtil.doDelete(custUri, custResourceVersion);
892 assertEquals("Expecting customer to be deleted", 204, response.getStatus());
894 // Verify vlan rv was updated
895 response = httpTestUtil.doGet(vlanUri, "all");
896 assertEquals("Expecting the vlan to be found", 200, response.getStatus());
897 String vlanResourceVersionAfterDelete =
898 new JSONObject(response.getEntity().toString()).getString("resource-version");
899 assertThat("Expecting the vlan resource version to be updated", vlanResourceVersionAfterDelete,
900 not(is(vlanResourceVersionAfterCustPut)));
902 List<NotificationEvent> notificationEvents = notification.getEvents();
903 assertThat("Expect the delete to generate 4 events customer, its children and vlan", notificationEvents.size(),
908 public void testBulkCreateOfComplexAndPserverWithRelationshipThenBulkDeleteBoth() throws IOException, AAIException {
909 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
910 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
912 JsonObject paylaods = new JsonParser()
913 .parse(PayloadUtil.getResourcePayload("complex_pserver_with_relation.json")).getAsJsonObject();
914 String complexPaylaod = paylaods.get("complex").toString();
915 String pserverPaylaod = paylaods.get("pserver").toString();
916 String complexUri = "/aai/v14/cloud-infrastructure/complexes/complex/complex-1";
917 String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/pserver-1";
919 Response response = httpTestUtil.doGet(complexUri);
920 assertEquals("Expecting the complex to be not found", 404, response.getStatus());
921 response = httpTestUtil.doGet(pserverUri);
922 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
924 Map<String, String> puts = new LinkedHashMap<>();
925 puts.put(complexUri, complexPaylaod);
926 puts.put(pserverUri, pserverPaylaod);
928 response = httpTestUtil.doPut(puts);
929 assertEquals("Expecting the puts request to succeed", 201, response.getStatus());
930 assertEquals("Expect 2 messages to be created", 2, notification.getEvents().size());
931 response = httpTestUtil.doGet(complexUri, "all");
932 assertEquals("Expecting the complex to be found", 200, response.getStatus());
933 String complexRV = new JSONObject(response.getEntity().toString()).getString("resource-version");
934 response = httpTestUtil.doGet(pserverUri, "all");
935 assertEquals("Expecting the pserver to be found", 200, response.getStatus());
936 String pserverRv = new JSONObject(response.getEntity().toString()).getString("resource-version");
937 assertThat("Resource versions match", complexRV, is(pserverRv));
939 Map<String, Pair<String, String>> deletes = new LinkedHashMap<>();
940 deletes.put(pserverUri, new Pair<>(pserverRv, null));
941 deletes.put(complexUri, new Pair<>(complexRV, null));
942 notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
943 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
944 httpTestUtil.doDelete(deletes);
946 response = httpTestUtil.doGet(complexUri);
947 assertEquals("Expecting the complex to be not found", 404, response.getStatus());
948 response = httpTestUtil.doGet(pserverUri);
949 assertEquals("Expecting the pserver to be not found", 404, response.getStatus());
953 public void testCreateVnfWithChildrenCreateCustomerWithChildrenAndCousinBetweenVlanAndServiceInstanceThenImplicitDeleteVlanVerifyingServiceInstanceRV()
954 throws IOException, AAIException {
955 UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
956 HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
958 JsonObject paylaods = new JsonParser().parse(PayloadUtil.getResourcePayload(
959 "customer_with_children_and_generic-vnf_with_children_and_edge_between_service-instance_vlan.json"))
961 String gvnfPaylaod = paylaods.get("generic-vnf").toString();
962 String custPaylaod = paylaods.get("customer").toString();
963 String custUri = "/aai/v14/business/customers/customer/cust";
964 String ssUri = custUri + "/service-subscriptions/service-subscription/ss";
965 String siUri = ssUri + "/service-instances/service-instance/si";
966 String gvnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/gvnf";
967 String lintUri = gvnfUri + "/l-interfaces/l-interface/lint";
968 String vlanUri = lintUri + "/vlans/vlan/vlan";
971 Response response = httpTestUtil.doGet(gvnfUri);
972 assertEquals("Expecting the generic-vnf to be not found", 404, response.getStatus());
973 response = httpTestUtil.doPut(gvnfUri, gvnfPaylaod);
974 assertEquals("Expecting the generic-vnf to be created", 201, response.getStatus());
975 response = httpTestUtil.doGet(gvnfUri, "all");
976 assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus());
977 response = httpTestUtil.doGet(vlanUri, "all");
978 assertEquals("Expecting the vlan to be found", 200, response.getStatus());
979 String vlanResourceVersion = new JSONObject(response.getEntity().toString()).getString("resource-version");
981 // Setup customer with service instance relation to vlan
982 response = httpTestUtil.doGet(custUri);
983 assertEquals("Expecting the customer to be not found", 404, response.getStatus());
984 response = httpTestUtil.doPut(custUri, custPaylaod);
985 assertEquals("Expecting the customer to be created", 201, response.getStatus());
986 response = httpTestUtil.doGet(custUri, "all");
987 assertEquals("Expecting the customer to be found", 200, response.getStatus());
988 response = httpTestUtil.doGet(siUri, "all");
989 assertEquals("Expecting the service-instance to be found", 200, response.getStatus());
990 String serviceInstanceResourceVersion =
991 new JSONObject(response.getEntity().toString()).getString("resource-version");
993 // Verify vlan rv was updated
994 response = httpTestUtil.doGet(vlanUri, "all");
995 assertEquals("Expecting the vlan to be found", 200, response.getStatus());
996 String vlanResourceVersionAfterCustPut =
997 new JSONObject(response.getEntity().toString()).getString("resource-version");
998 assertThat("Expecting the vlan resource version to be updated", vlanResourceVersionAfterCustPut,
999 not(is(vlanResourceVersion)));
1001 // Get linterface, replace vlans with empty json (implicit delete) and put triggering implicit delete
1002 response = httpTestUtil.doGet(lintUri, "all");
1003 assertEquals("Expecting the l-interface to be found", 200, response.getStatus());
1004 JSONObject lintJson = new JSONObject(response.getEntity().toString());
1005 lintJson.put("vlans", new JsonObject());
1006 notification.clearEvents();
1007 httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
1008 response = httpTestUtil.doPut(lintUri, lintJson.toString());
1009 assertEquals("Expecting the l-interface to be updated", 200, response.getStatus());
1011 List<NotificationEvent> notificationEvents = notification.getEvents();
1012 assertThat("Expect the implied delete to generate 2", notificationEvents.size(), is(2));
1014 // Verify vlan is no longer there anf get service-instance and compare rv
1015 response = httpTestUtil.doGet(vlanUri, "all");
1016 assertEquals("Expecting the vlan not to be found", 404, response.getStatus());
1017 response = httpTestUtil.doGet(siUri, "all");
1018 assertEquals("Expecting the service-instance to be found", 200, response.getStatus());
1019 String serviceInstanceResourceVersionAfterImplicitDelete =
1020 new JSONObject(response.getEntity().toString()).getString("resource-version");
1021 assertThat("Expecting the service-instance resource version to be updated after implicit delete of vlan",
1022 serviceInstanceResourceVersionAfterImplicitDelete, not(is(serviceInstanceResourceVersion)));
1026 public void teardown() {
1028 JanusGraph janusGraph = AAIGraph.getInstance().getGraph();
1029 JanusGraphTransaction transaction = janusGraph.newTransaction();
1031 GraphTraversalSource g = transaction.traversal();
1033 g.V().has(AAIProperties.SOURCE_OF_TRUTH, "JUNIT").forEachRemaining(Vertex::remove);
1035 transaction.commit();