summaryrefslogtreecommitdiffstats
path: root/aai-core/src/test/java
diff options
context:
space:
mode:
authorNandkishor Patke <nandkishor-laxman.patke@t-systems.com>2024-10-09 09:24:23 +0000
committerGerrit Code Review <gerrit@onap.org>2024-10-09 09:24:23 +0000
commitcc343f0701d094de1ccc3fa3459d10e0fdc8db49 (patch)
tree15fef77e226aa9c132e0f15de825ba92510aa6c6 /aai-core/src/test/java
parentb53da76193279c6004bb27cc0db5f7bfa2d118e4 (diff)
parent180f2967c7db5cbbace67616146a66d9d9658af7 (diff)
Merge "Refactor UEBNotification class"
Diffstat (limited to 'aai-core/src/test/java')
-rw-r--r--aai-core/src/test/java/org/onap/aai/AAISetup.java6
-rw-r--r--aai-core/src/test/java/org/onap/aai/DataLinkSetup.java5
-rw-r--r--aai-core/src/test/java/org/onap/aai/HttpTestUtil.java8
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/IntrospectorSerializationTest.java35
-rw-r--r--aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventIntegrationTest.java18
-rw-r--r--aai-core/src/test/java/org/onap/aai/prevalidation/ValidationServiceTest.java50
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java6
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/ImpliedDeleteIntegrationTest.java14
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/NotificationDmaapEventTest.java145
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryNotificationIntegrationTest.java15
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/notification/NotificationServiceTest.java12
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/notification/UEBNotificationTest.java8
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java6
13 files changed, 194 insertions, 134 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/AAISetup.java b/aai-core/src/test/java/org/onap/aai/AAISetup.java
index 08a0e91b..f51b5732 100644
--- a/aai-core/src/test/java/org/onap/aai/AAISetup.java
+++ b/aai-core/src/test/java/org/onap/aai/AAISetup.java
@@ -41,6 +41,7 @@ import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
import org.onap.aai.util.AAIConstants;
import org.onap.aai.web.KafkaConfig;
+import org.onap.aai.web.KafkaNotificationEventConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
@@ -54,11 +55,12 @@ import org.springframework.test.context.web.WebAppConfiguration;
classes = {ConfigConfiguration.class, AAIConfigTranslator.class, EdgeIngestor.class, EdgeSerializer.class,
NodeIngestor.class, SpringContextAware.class, IntrospectionConfig.class, RestBeanConfig.class,
XmlFormatTransformerConfiguration.class, ValidationService.class, ValidationConfiguration.class,
- KafkaConfig.class, LoaderFactory.class, NotificationService.class})
+ KafkaConfig.class, LoaderFactory.class, NotificationService.class, KafkaNotificationEventConfig.class})
@TestPropertySource(
properties = {"schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000", "schema.translator.list=config",
"schema.nodes.location=src/test/resources/onap/oxm",
- "schema.edges.location=src/test/resources/onap/dbedgerules"})
+ "schema.edges.location=src/test/resources/onap/dbedgerules",
+ "aai.notifications.enabled=false"})
public abstract class AAISetup {
@ClassRule
diff --git a/aai-core/src/test/java/org/onap/aai/DataLinkSetup.java b/aai-core/src/test/java/org/onap/aai/DataLinkSetup.java
index b38a5c69..b0825162 100644
--- a/aai-core/src/test/java/org/onap/aai/DataLinkSetup.java
+++ b/aai-core/src/test/java/org/onap/aai/DataLinkSetup.java
@@ -38,6 +38,7 @@ import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
import org.onap.aai.testutils.TestUtilConfigTranslatorforDataLink;
import org.onap.aai.util.AAIConstants;
+import org.onap.aai.web.KafkaNotificationEventConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.annotation.DirtiesContext;
@@ -49,13 +50,13 @@ import org.springframework.test.context.junit4.rules.SpringMethodRule;
@ContextConfiguration(
classes = {ConfigConfiguration.class, TestUtilConfigTranslatorforDataLink.class, EdgeIngestor.class,
EdgeSerializer.class, NodeIngestor.class, SpringContextAware.class, IntrospectionConfig.class,
- RestBeanConfig.class, XmlFormatTransformerConfiguration.class, LoaderFactory.class, NotificationService.class})
+ RestBeanConfig.class, XmlFormatTransformerConfiguration.class, LoaderFactory.class, NotificationService.class, KafkaNotificationEventConfig.class})
@TestPropertySource(
properties = {"schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000", "schema.version.api.default = v4",
"schema.version.edge.label.start = v4", "schema.version.depth.start = v3",
"schema.version.app.root.start = v4", "schema.version.related.link.start = v4",
"schema.version.namespace.change.start = v4", "schema.version.list = v1,v2,v3,v4",
- "schema.translator.list = config"})
+ "schema.translator.list = config","aai.notifications.enabled = false"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public abstract class DataLinkSetup {
diff --git a/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java b/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java
index 49524c4e..62f63ea3 100644
--- a/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java
+++ b/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java
@@ -153,14 +153,6 @@ public class HttpTestUtil extends RESTAPI {
doReturn(null).when(queryParameters).remove(any());
when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON);
-
- try {
- if (notification != null) {
- doNothing().when(notification).triggerEvents();
- }
- } catch (AAIException e) {
- e.printStackTrace();
- }
}
public Response doPut(String uri, String payload) throws UnsupportedEncodingException, AAIException {
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/IntrospectorSerializationTest.java b/aai-core/src/test/java/org/onap/aai/introspection/IntrospectorSerializationTest.java
index 51eb0cea..60749ddd 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/IntrospectorSerializationTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/IntrospectorSerializationTest.java
@@ -27,14 +27,14 @@ import java.nio.file.Path;
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
-import org.onap.aai.exceptions.AAIException;
-import org.onap.aai.introspection.Introspector;
-import org.onap.aai.introspection.Loader;
+import org.onap.aai.domain.notificationEvent.NotificationEvent;
+import org.onap.aai.domain.notificationEvent.NotificationEvent.EventHeader;
import org.onap.aai.introspection.exceptions.AAIUnmarshallingException;
import org.onap.aai.setup.SchemaVersion;
import org.skyscreamer.jsonassert.JSONAssert;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
public class IntrospectorSerializationTest extends AAISetup {
@@ -55,4 +55,33 @@ public class IntrospectorSerializationTest extends AAISetup {
String result = mapper.writeValueAsString(introspector);
JSONAssert.assertEquals(pserver, result, false);
}
+
+ @Test
+ public void serializeNotificationEvent() throws IOException, AAIUnmarshallingException {
+ mapper = new ObjectMapper();
+ mapper.registerModule(new JaxbAnnotationModule());
+
+ String pserver = new String(Files.readAllBytes(Path.of("src/test/resources/payloads/templates/pserver.json"))).replace("${hostname}", "pserver1");
+ Introspector introspector = loader.unmarshal("pserver", pserver);
+
+ NotificationEvent notificationEvent = new NotificationEvent();
+ notificationEvent.setCambriaPartition("AAI");
+ notificationEvent.setEntity(introspector);
+ EventHeader eventHeader = new EventHeader();
+ eventHeader.setSeverity("NORMAL");
+ eventHeader.setEntityType("pserver");
+ eventHeader.setTopEntityType("pserver");
+ eventHeader.setEntityLink("/aai/v14/cloud-infrastructure/pservers/pserver/pserver1");
+ eventHeader.setEventType("AAI-EVENT");
+ eventHeader.setDomain("devINT1");
+ eventHeader.setAction("CREATE");
+ eventHeader.setSequenceNumber("0");
+ eventHeader.setId("someTransaction");
+ eventHeader.setSourceName("test");
+ eventHeader.setVersion("v14");
+ notificationEvent.setEventHeader(eventHeader);
+ String result = mapper.writeValueAsString(notificationEvent);
+ String expectedEvent = new String(Files.readAllBytes(Path.of("src/test/resources/payloads/expected/pserver-event.json")));
+ JSONAssert.assertEquals(expectedEvent, result, false);
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventIntegrationTest.java b/aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventIntegrationTest.java
index ce636a51..fa52c014 100644
--- a/aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventIntegrationTest.java
+++ b/aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventIntegrationTest.java
@@ -44,6 +44,7 @@ import org.junit.Test;
import org.mockito.Mock;
import org.onap.aai.AAISetup;
import org.onap.aai.PayloadUtil;
+import org.onap.aai.domain.notificationEvent.NotificationEvent;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
@@ -63,10 +64,11 @@ import org.springframework.kafka.test.utils.KafkaTestUtils;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
-@Ignore
@Slf4j
@ActiveProfiles("kafka")
@Import(KafkaTestConfiguration.class)
@@ -77,7 +79,8 @@ import lombok.extern.slf4j.Slf4j;
"aai.events.enabled=true",
"spring.kafka.producer.retries=0",
"spring.kafka.producer.properties.sasl.jaas.config=#{null}",
- "spring.kafka.producer.bootstrap-servers=${spring.embedded.kafka.brokers}"
+ "spring.kafka.producer.bootstrap-servers=${spring.embedded.kafka.brokers}",
+ "aai.notifications.enabled=true"
})
public class AAIKafkaEventIntegrationTest extends AAISetup {
@@ -85,7 +88,10 @@ public class AAIKafkaEventIntegrationTest extends AAISetup {
private KafkaTemplate<String, String> kafkaTemplate;
@Autowired
- MessageProducer messageProducer;
+ ObjectMapper mapper;
+
+ @Autowired
+ NotificationProducer messageProducer;
@Autowired
private ConsumerFactory<String, String> consumerFactory;
@@ -103,6 +109,7 @@ public class AAIKafkaEventIntegrationTest extends AAISetup {
}
@Test
+ @Ignore
public void onMessage_shouldSendMessageToKafkaTopic_whenAAIEventReceived()
throws Exception {
Consumer<String, String> consumer = consumerFactory.createConsumer();
@@ -110,8 +117,9 @@ public class AAIKafkaEventIntegrationTest extends AAISetup {
consumer.subscribe(Collections.singletonList("AAI-EVENT"));
String payload = PayloadUtil.getResourcePayload("aai-event.json");
+ NotificationEvent event = mapper.readValue(payload, NotificationEvent.class);
String expectedResponse = PayloadUtil.getExpectedPayload("aai-event.json");
- messageProducer.sendMessageToDefaultDestination(payload);
+ messageProducer.sendNotification(event);
ConsumerRecords<String, String> consumerRecords = KafkaTestUtils.getRecords(consumer, 10000);
assertFalse(consumerRecords.isEmpty());
@@ -121,8 +129,6 @@ public class AAIKafkaEventIntegrationTest extends AAISetup {
}
@Test
- @Ignore
- // only works when aai.jms.enable=true in aaiconfig.properties
public void thatEventsAreBeingCreated() throws AAIException, IOException {
Consumer<String, String> consumer = consumerFactory.createConsumer();
consumer.subscribe(Collections.singletonList("AAI-EVENT"));
diff --git a/aai-core/src/test/java/org/onap/aai/prevalidation/ValidationServiceTest.java b/aai-core/src/test/java/org/onap/aai/prevalidation/ValidationServiceTest.java
index 8ef1d706..db9ee961 100644
--- a/aai-core/src/test/java/org/onap/aai/prevalidation/ValidationServiceTest.java
+++ b/aai-core/src/test/java/org/onap/aai/prevalidation/ValidationServiceTest.java
@@ -24,9 +24,14 @@ import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentCaptor.forClass;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
import com.google.gson.Gson;
import java.io.IOException;
@@ -38,10 +43,13 @@ import org.apache.http.conn.ConnectTimeoutException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.onap.aai.PayloadUtil;
+import org.onap.aai.domain.notificationEvent.NotificationEvent;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.restclient.RestClient;
+import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
@@ -56,12 +64,15 @@ public class ValidationServiceTest {
public OutputCaptureRule capture = new OutputCaptureRule();
private Gson gson;
+ private ObjectMapper mapper;
@Before
public void setUp() throws Exception {
+ mapper = new ObjectMapper();
+ mapper.registerModule(new JaxbAnnotationModule());
gson = new Gson();
restClient = Mockito.mock(RestClient.class);
- validationService = Mockito.spy(new ValidationService(restClient, "JUNIT", "generic-vnf", null));
+ validationService = Mockito.spy(new ValidationService(restClient, "JUNIT", "generic-vnf", null, mapper));
}
@Test
@@ -81,14 +92,19 @@ public class ValidationServiceTest {
throws IOException, AAIException {
String pserverRequest = PayloadUtil.getResourcePayload("prevalidation/success-request-with-no-violations.json");
+ NotificationEvent notificationEvent = mapper.readValue(pserverRequest, NotificationEvent.class);
Mockito.when(restClient.execute(eq(ValidationService.VALIDATION_ENDPOINT), eq(HttpMethod.POST), any(),
- eq(pserverRequest))).thenThrow(new RuntimeException(new ConnectException("Connection refused")));
+ anyString())).thenThrow(new RuntimeException(new ConnectException("Connection refused")));
- validationService.preValidate(pserverRequest);
+ validationService.preValidate(notificationEvent);
assertThat(capture.toString(),
containsString("Connection refused to the validation microservice due to service unreachable"));
+ ArgumentCaptor<String> bodyCaptor = forClass(String.class);
+ verify(restClient).execute(eq(ValidationService.VALIDATION_ENDPOINT), eq(HttpMethod.POST), any(), bodyCaptor.capture());
+
+ JSONAssert.assertEquals(pserverRequest, bodyCaptor.getValue(), false);
}
@Test
@@ -96,15 +112,20 @@ public class ValidationServiceTest {
throws IOException, AAIException {
String pserverRequest = PayloadUtil.getResourcePayload("prevalidation/success-request-with-no-violations.json");
+ NotificationEvent notificationEvent = mapper.readValue(pserverRequest, NotificationEvent.class);
Mockito.when(restClient.execute(eq(ValidationService.VALIDATION_ENDPOINT), eq(HttpMethod.POST), any(),
- eq(pserverRequest)))
+ anyString()))
.thenThrow(new RuntimeException(new ConnectTimeoutException("Connection timed out")));
- validationService.preValidate(pserverRequest);
+ validationService.preValidate(notificationEvent);
assertThat(capture.toString(), containsString(
"Connection timeout to the validation microservice as this could indicate the server is unable to reach port"));
+ ArgumentCaptor<String> bodyCaptor = forClass(String.class);
+ verify(restClient).execute(eq(ValidationService.VALIDATION_ENDPOINT), eq(HttpMethod.POST), any(), bodyCaptor.capture());
+
+ JSONAssert.assertEquals(pserverRequest, bodyCaptor.getValue(), false);
}
@Test
@@ -112,22 +133,28 @@ public class ValidationServiceTest {
throws IOException, AAIException {
String pserverRequest = PayloadUtil.getResourcePayload("prevalidation/success-request-with-no-violations.json");
+ NotificationEvent notificationEvent = mapper.readValue(pserverRequest, NotificationEvent.class);
String validationResponse =
PayloadUtil.getResourcePayload("prevalidation/success-response-with-empty-violations.json");
ResponseEntity responseEntity = Mockito.mock(ResponseEntity.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(restClient.execute(eq(ValidationService.VALIDATION_ENDPOINT), eq(HttpMethod.POST), any(),
- eq(pserverRequest))).thenReturn(responseEntity);
+ anyString())).thenReturn(responseEntity);
Mockito.when(responseEntity.getStatusCodeValue()).thenReturn(200);
Mockito.when(responseEntity.getBody()).thenReturn(validationResponse);
Mockito.doReturn(true).when(validationService).isSuccess(responseEntity);
- List<String> errorMessages = validationService.preValidate(pserverRequest);
+ List<String> errorMessages = validationService.preValidate(notificationEvent);
assertNotNull("Expected the error messages to be not null", errorMessages);
assertThat(errorMessages.size(), is(0));
+
+ ArgumentCaptor<String> bodyCaptor = forClass(String.class);
+ verify(restClient).execute(eq(ValidationService.VALIDATION_ENDPOINT), eq(HttpMethod.POST), any(), bodyCaptor.capture());
+
+ JSONAssert.assertEquals(pserverRequest, bodyCaptor.getValue(), false);
}
@Test
@@ -135,16 +162,21 @@ public class ValidationServiceTest {
throws IOException, AAIException {
String pserverRequest = PayloadUtil.getResourcePayload("prevalidation/success-request-with-no-violations.json");
+ NotificationEvent notificationEvent = mapper.readValue(pserverRequest, NotificationEvent.class);
Mockito.when(restClient.execute(eq(ValidationService.VALIDATION_ENDPOINT), eq(HttpMethod.POST), any(),
- eq(pserverRequest)))
+ anyString()))
.thenThrow(new RuntimeException(
new SocketTimeoutException("Request timed out due to taking longer than client expected")));
- validationService.preValidate(pserverRequest);
+ validationService.preValidate(notificationEvent);
assertThat(capture.toString(),
containsString("Request to validation service took longer than the currently set timeout"));
+ ArgumentCaptor<String> bodyCaptor = forClass(String.class);
+ verify(restClient).execute(eq(ValidationService.VALIDATION_ENDPOINT), eq(HttpMethod.POST), any(), bodyCaptor.capture());
+
+ JSONAssert.assertEquals(pserverRequest, bodyCaptor.getValue(), false);
}
@Test
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java b/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java
index 8f4a209b..629243a7 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java
@@ -58,6 +58,7 @@ import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
import org.onap.aai.serialization.queryformats.QueryFormatTestHelper;
import org.onap.aai.setup.SchemaVersions;
import org.onap.aai.util.AAIConstants;
+import org.onap.aai.web.KafkaNotificationEventConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
@@ -68,11 +69,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration(
classes = {ConfigConfiguration.class, QueryTestsConfigTranslator.class, NodeIngestor.class, EdgeIngestor.class,
EdgeSerializer.class, SpringContextAware.class, IntrospectionConfig.class,
- XmlFormatTransformerConfiguration.class, LoaderFactory.class, NotificationService.class})
+ XmlFormatTransformerConfiguration.class, LoaderFactory.class, NotificationService.class, KafkaNotificationEventConfig.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@TestPropertySource(
properties = {"schema.translator.list = config", "schema.nodes.location=src/test/resources/onap/oxm",
- "schema.edges.location=src/test/resources/onap/dbedgerules"})
+ "schema.edges.location=src/test/resources/onap/dbedgerules",
+ "aai.notifications.enabled=false"})
public abstract class QueryBuilderTestAbstraction {
protected Loader loader;
diff --git a/aai-core/src/test/java/org/onap/aai/rest/ImpliedDeleteIntegrationTest.java b/aai-core/src/test/java/org/onap/aai/rest/ImpliedDeleteIntegrationTest.java
index 218c3a24..38731288 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/ImpliedDeleteIntegrationTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/ImpliedDeleteIntegrationTest.java
@@ -45,8 +45,9 @@ import org.onap.aai.HttpTestUtil;
import org.onap.aai.PayloadUtil;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.dbmap.AAIGraph;
+import org.onap.aai.domain.notificationEvent.NotificationEvent;
+import org.onap.aai.domain.notificationEvent.NotificationEvent.EventHeader;
import org.onap.aai.introspection.ModelType;
-import org.onap.aai.rest.notification.NotificationEvent;
import org.onap.aai.rest.notification.UEBNotification;
import org.onap.aai.serialization.engines.QueryStyle;
import org.skyscreamer.jsonassert.JSONAssert;
@@ -73,7 +74,7 @@ public class ImpliedDeleteIntegrationTest extends AAISetup {
String uri = "/aai/v12/cloud-infrastructure/pservers/pserver/test-pserver-implied-delete";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
String resource = PayloadUtil.getResourcePayload("pserver-implied-delete.json");
@@ -91,7 +92,7 @@ public class ImpliedDeleteIntegrationTest extends AAISetup {
JSONAssert.assertEquals(resource, response.getEntity().toString(), false);
jsonObject.getJSONObject("p-interfaces").remove("p-interface");
- notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
response = httpTestUtil.doPut(uri, jsonObject.toString());
@@ -100,10 +101,11 @@ public class ImpliedDeleteIntegrationTest extends AAISetup {
List<NotificationEvent> notificationEvents = notification.getEvents();
assertThat(notificationEvents.size(), is(5));
- List<String> notificationEventHeaders = notification.getEvents().stream()
- .map(event -> event.getEventHeader().marshal(false)).collect(Collectors.toList());
+ List<EventHeader> notificationEventHeaders = notification.getEvents().stream()
+ .map(NotificationEvent::getEventHeader)
+ .collect(Collectors.toList());
- Long deletedEventsCount = notificationEventHeaders.stream().filter(e -> e.contains("\"DELETE\"")).count();
+ Long deletedEventsCount = notificationEventHeaders.stream().filter(e -> "DELETE".equals(e.getAction())).count();
assertThat(deletedEventsCount, is(4L));
diff --git a/aai-core/src/test/java/org/onap/aai/rest/NotificationDmaapEventTest.java b/aai-core/src/test/java/org/onap/aai/rest/NotificationDmaapEventTest.java
index 4b52462e..0eafdf1c 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/NotificationDmaapEventTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/NotificationDmaapEventTest.java
@@ -26,6 +26,7 @@ import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.junit.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@@ -55,24 +56,29 @@ import org.onap.aai.HttpTestUtil;
import org.onap.aai.PayloadUtil;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.dbmap.AAIGraph;
+import org.onap.aai.domain.notificationEvent.NotificationEvent;
+import org.onap.aai.domain.notificationEvent.NotificationEvent.EventHeader;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.ModelType;
-import org.onap.aai.rest.notification.NotificationEvent;
import org.onap.aai.rest.notification.UEBNotification;
import org.onap.aai.serialization.engines.QueryStyle;
import org.skyscreamer.jsonassert.JSONAssert;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
@RunWith(value = Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class NotificationDmaapEventTest extends AAISetup {
+// ObjectMapper mapper = new ObjectMapper();
+ @Autowired private ObjectMapper mapper;
+
@Parameterized.Parameter
public QueryStyle queryStyle;
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}});
}
@Test
@@ -80,7 +86,7 @@ public class NotificationDmaapEventTest extends AAISetup {
throws IOException, AAIException {
String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -97,13 +103,8 @@ public class NotificationDmaapEventTest extends AAISetup {
// Verify all the events are create since its a new PUT
notification.getEvents().forEach((event) -> {
-
- String header = event.getEventHeader().marshal(false);
-
- assertThat(event.getEventHeader().marshal(false), containsString("\"CREATE\""));
-
- assertThat(header, containsString("\"top-entity-type\":\"pserver\""));
-
+ assertEquals("CREATE", event.getEventHeader().getAction());
+ assertEquals("pserver", event.getEventHeader().getTopEntityType());
});
response = httpTestUtil.doGet(uri);
@@ -116,7 +117,7 @@ public class NotificationDmaapEventTest extends AAISetup {
throws IOException, AAIException {
String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -147,19 +148,20 @@ public class NotificationDmaapEventTest extends AAISetup {
List<NotificationEvent> events = notification.getEvents();
assertThat(events.size(), is(2));
- String notificationEventHeader = events.get(1).getEventHeader().marshal(false);
- String notificationEventBody = events.get(1).getObj().marshal(false);
+ EventHeader notificationEventHeader = events.get(1).getEventHeader();
+ String notificationEventBody = events.get(1).getEntity().toString();
- assertThat(notificationEventHeader, containsString("\"action\":\"CREATE\""));
- assertThat(notificationEventHeader, containsString("\"entity-type\":\"p-interface\""));
- assertThat(notificationEventHeader, containsString("\"top-entity-type\":\"pserver\""));
+ assertEquals("CREATE", notificationEventHeader.getAction());
+ assertEquals("p-interface", notificationEventHeader.getEntityType());
+ assertEquals("pserver", notificationEventHeader.getTopEntityType());
String expectedNotificationHeader = PayloadUtil.getResourcePayload(
"notification-dmaap-events/depth-zero/expected-notification-header-create-child-on-existing-obj.json");
String expectedNotificationBody = PayloadUtil.getResourcePayload(
"notification-dmaap-events/depth-zero/expected-notification-body-create-child-on-existing-obj.json");
- JSONAssert.assertEquals(expectedNotificationHeader, notificationEventHeader, false);
+ String eventHeaderJson = mapper.writeValueAsString(events.get(1).getEventHeader());
+ JSONAssert.assertEquals(expectedNotificationHeader, eventHeaderJson, false);
JSONAssert.assertEquals(expectedNotificationBody, notificationEventBody, false);
}
@@ -168,7 +170,7 @@ public class NotificationDmaapEventTest extends AAISetup {
throws IOException, AAIException {
String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -200,19 +202,19 @@ public class NotificationDmaapEventTest extends AAISetup {
List<NotificationEvent> events = notification.getEvents();
assertThat(events.size(), is(1));
- String notificationEventHeader = events.get(0).getEventHeader().marshal(false);
- String notificationEventBody = events.get(0).getObj().marshal(false);
-
- assertThat(notificationEventHeader, containsString("\"action\":\"UPDATE\""));
- assertThat(notificationEventHeader, containsString("\"entity-type\":\"pserver\""));
- assertThat(notificationEventHeader, containsString("\"top-entity-type\":\"pserver\""));
+ EventHeader notificationEventHeader = events.get(0).getEventHeader();
+ String notificationEventBody = events.get(0).getEntity().toString();
+ assertEquals("UPDATE", notificationEventHeader.getAction());
+ assertEquals("pserver", notificationEventHeader.getEntityType());
+ assertEquals("pserver", notificationEventHeader.getTopEntityType());
String expectedNotificationHeader = PayloadUtil.getResourcePayload(
"notification-dmaap-events/depth-all/expected-notification-header-create-child-on-existing-obj.json");
String expectedNotificationBody = PayloadUtil.getResourcePayload(
"notification-dmaap-events/depth-all/expected-notification-body-create-child-on-existing-obj.json");
- JSONAssert.assertEquals(expectedNotificationHeader, notificationEventHeader, false);
+ String eventHeaderJson = mapper.writeValueAsString(events.get(0).getEventHeader());
+ JSONAssert.assertEquals(expectedNotificationHeader, eventHeaderJson, false);
JSONAssert.assertEquals(expectedNotificationBody, notificationEventBody, false);
response = httpTestUtil.doGet(uri, "0");
@@ -235,7 +237,7 @@ public class NotificationDmaapEventTest extends AAISetup {
String cloudRegionUri =
"/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/random-cloud-region-owner/random-cloud-region-id";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MINIMUM_DEPTH);
Map<String, String> uriPayload = new LinkedHashMap<>();
@@ -252,8 +254,7 @@ public class NotificationDmaapEventTest extends AAISetup {
assertThat("Expecting the number of dmaap events to be 2", numberOfEventsActual, is(expectedEvents));
notification.getEvents().forEach((event) -> {
- String notificationEventHeader = event.getEventHeader().marshal(false);
- assertThat(notificationEventHeader, containsString("\"CREATE\""));
+ assertEquals("CREATE", event.getEventHeader().getAction());
});
}
@@ -265,7 +266,7 @@ public class NotificationDmaapEventTest extends AAISetup {
String cloudRegionUri =
"/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/random-cloud-region-owner/random-cloud-region-id";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
Map<String, String> uriPayload = new LinkedHashMap<>();
@@ -282,8 +283,7 @@ public class NotificationDmaapEventTest extends AAISetup {
assertThat("Expecting the number of dmaap events to be 2", numberOfEventsActual, is(expectedEvents));
notification.getEvents().forEach((event) -> {
- String notificationEventHeader = event.getEventHeader().marshal(false);
- assertThat(notificationEventHeader, containsString("\"CREATE\""));
+ assertEquals("CREATE", event.getEventHeader().getAction());
});
}
@@ -291,7 +291,7 @@ public class NotificationDmaapEventTest extends AAISetup {
public void testDeleteOnExistingPserverAndCheckIfNotificationDepthIsZeroThatAllEventsHaveDeleteAndThatDepthIsZeroOnEachNotificationEvent()
throws IOException, AAIException {
String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -316,19 +316,16 @@ public class NotificationDmaapEventTest extends AAISetup {
assertThat(notificationEvents.size(), is(17));
notificationEvents.forEach((event) -> {
-
- String header = event.getEventHeader().marshal(false);
-
- assertThat(event.getEventHeader().marshal(false), containsString("\"DELETE\""));
-
- assertThat(header, containsString("\"top-entity-type\":\"pserver\""));
+ EventHeader header = event.getEventHeader();
+ assertEquals("DELETE", header.getAction());
+ assertEquals("pserver", header.getTopEntityType());
});
}
@Test
public void testDeleteOnExistingResourceVersionMismatchNoEventGenerated() throws IOException, AAIException {
String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -362,7 +359,7 @@ public class NotificationDmaapEventTest extends AAISetup {
throws IOException, AAIException {
String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -378,20 +375,16 @@ public class NotificationDmaapEventTest extends AAISetup {
NotificationEvent notificationEvent = notification.getEvents().get(0);
// Verify all the events are create since its a new PUT
- String header = notificationEvent.getEventHeader().marshal(false);
-
- assertThat(header, containsString("\"CREATE\""));
-
- assertThat(header, containsString("\"entity-type\":\"pserver\""));
-
- assertThat(header, containsString("\"top-entity-type\":\"pserver\""));
-
- assertThat(header, containsString("\"entity-link\":\"" + uri + "\""));
+ EventHeader eventHeader = notificationEvent.getEventHeader();
+ assertEquals("CREATE", eventHeader.getAction());
+ assertEquals("pserver", eventHeader.getEntityType());
+ assertEquals("pserver", eventHeader.getTopEntityType());
+ assertEquals(uri, eventHeader.getEntityLink());
response = httpTestUtil.doGet(uri);
assertEquals("Expecting the pserver to be found", 200, response.getStatus());
- JSONAssert.assertEquals(response.getEntity().toString(), notificationEvent.getObj().marshal(false), false);
+ JSONAssert.assertEquals(response.getEntity().toString(), notificationEvent.getEntity().toString(), false);
}
@Test
@@ -399,7 +392,7 @@ public class NotificationDmaapEventTest extends AAISetup {
throws IOException, AAIException {
String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -424,7 +417,7 @@ public class NotificationDmaapEventTest extends AAISetup {
assertThat(response.getEntity().toString(), containsString("new-equip-patch-type"));
assertThat(notification.getEvents().size(), is(1));
- String updateNotificationEvent = notification.getEvents().get(0).getObj().marshal(true);
+ String updateNotificationEvent = notification.getEvents().get(0).getEntity().toString();
// Check that everything in notification event is also response body
// Not comparing the other way as notification only includes parents main properties
@@ -436,7 +429,7 @@ public class NotificationDmaapEventTest extends AAISetup {
throws IOException, AAIException {
String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -461,7 +454,7 @@ public class NotificationDmaapEventTest extends AAISetup {
assertThat(response.getEntity().toString(), containsString("new-equip-patch-type"));
assertThat(notification.getEvents().size(), is(1));
- String updateNotificationEvent = notification.getEvents().get(0).getObj().marshal(true);
+ String updateNotificationEvent = notification.getEvents().get(0).getEntity().toString();
// Check that everything in notification event is also response body
// Not comparing the other way as notification only includes parents main properties
@@ -476,7 +469,7 @@ public class NotificationDmaapEventTest extends AAISetup {
throws IOException, AAIException {
String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -506,7 +499,7 @@ public class NotificationDmaapEventTest extends AAISetup {
assertThat(response.getEntity().toString(), containsString("new-equipment-identifier"));
assertThat(notification.getEvents().size(), is(1));
- String updateNotificationEvent = notification.getEvents().get(0).getObj().marshal(true);
+ String updateNotificationEvent = notification.getEvents().get(0).getEntity().toString();
// Check that everything in notification event is also response body
// Not comparing the other way as notification only includes parents main properties
@@ -520,7 +513,7 @@ public class NotificationDmaapEventTest extends AAISetup {
throws IOException, AAIException {
String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -547,7 +540,7 @@ public class NotificationDmaapEventTest extends AAISetup {
response = httpTestUtil.doGet(uri);
assertThat(notification.getEvents().size(), is(1));
- String updateNotificationEvent = notification.getEvents().get(0).getObj().marshal(true);
+ String updateNotificationEvent = notification.getEvents().get(0).getEntity().toString();
System.out.println("Update notification " + updateNotificationEvent);
// Check that everything in notification event is also response body
@@ -564,7 +557,7 @@ public class NotificationDmaapEventTest extends AAISetup {
String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/" + hostname;
String genericVnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/generic-vnf-notification";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -604,9 +597,9 @@ public class NotificationDmaapEventTest extends AAISetup {
String expectedNotificationBody = PayloadUtil.getResourcePayload(
"notification-dmaap-events/depth-zero/expected-notification-body-create-edge-between-pserver-and-generic-vnf.json");
- JSONAssert.assertEquals(expectedNotificationHeader, notificationEvents.get(0).getEventHeader().marshal(false),
+ JSONAssert.assertEquals(expectedNotificationHeader, mapper.writeValueAsString(notificationEvents.get(0).getEventHeader()),
false);
- JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getObj().marshal(false), false);
+ JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getEntity().toString(), false);
response = httpTestUtil.doGet(genericVnfUri);
@@ -623,7 +616,7 @@ public class NotificationDmaapEventTest extends AAISetup {
String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/" + hostname;
String genericVnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/generic-vnf-notification";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -663,10 +656,10 @@ public class NotificationDmaapEventTest extends AAISetup {
String expectedNotificationBody = PayloadUtil.getResourcePayload(
"notification-dmaap-events/depth-all/expected-notification-body-create-edge-between-pserver-and-generic-vnf.json");
- System.out.println("Notification Body: " + notificationEvents.get(0).getObj().marshal(false));
- JSONAssert.assertEquals(expectedNotificationHeader, notificationEvents.get(0).getEventHeader().marshal(false),
+ System.out.println("Notification Body: " + notificationEvents.get(0).getEntity().toString());
+ JSONAssert.assertEquals(expectedNotificationHeader, mapper.writeValueAsString(notificationEvents.get(0).getEventHeader()),
false);
- JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getObj().marshal(false), false);
+ JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getEntity().toString(), false);
response = httpTestUtil.doGet(genericVnfUri);
@@ -685,7 +678,7 @@ public class NotificationDmaapEventTest extends AAISetup {
String relationship = PayloadUtil.getResourcePayload("pserver-to-gvnf-relationship-notification.json");
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -741,9 +734,9 @@ public class NotificationDmaapEventTest extends AAISetup {
String expectedNotificationBody = PayloadUtil.getResourcePayload(
"notification-dmaap-events/depth-zero/expected-notification-body-delete-edge-between-pserver-and-generic-vnf.json");
- JSONAssert.assertEquals(expectedNotificationHeader, notificationEvents.get(0).getEventHeader().marshal(false),
+ JSONAssert.assertEquals(expectedNotificationHeader, mapper.writeValueAsString(notificationEvents.get(0).getEventHeader()),
false);
- JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getObj().marshal(false), false);
+ JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getEntity().toString(), false);
}
@@ -758,7 +751,7 @@ public class NotificationDmaapEventTest extends AAISetup {
String relationship = PayloadUtil.getResourcePayload("pserver-to-gvnf-relationship-notification.json");
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String resource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -813,9 +806,9 @@ public class NotificationDmaapEventTest extends AAISetup {
String expectedNotificationBody = PayloadUtil.getResourcePayload(
"notification-dmaap-events/depth-all/expected-notification-body-delete-edge-between-pserver-and-generic-vnf.json");
- JSONAssert.assertEquals(expectedNotificationHeader, notificationEvents.get(0).getEventHeader().marshal(false),
+ JSONAssert.assertEquals(expectedNotificationHeader, mapper.writeValueAsString(notificationEvents.get(0).getEventHeader()),
false);
- JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getObj().marshal(false), false);
+ JSONAssert.assertEquals(expectedNotificationBody, notificationEvents.get(0).getEntity().toString(), false);
}
@@ -823,7 +816,7 @@ public class NotificationDmaapEventTest extends AAISetup {
public void testDeleteOnExistingResourceVersionMismatchNoEventGeneratedFullDepth()
throws IOException, AAIException {
String uri = "/aai/v14/cloud-infrastructure/pservers/pserver/example-hostname-val-85598";
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String pserverResource = PayloadUtil.getResourcePayload("pserver-with-children-for-notification.json");
@@ -851,7 +844,7 @@ public class NotificationDmaapEventTest extends AAISetup {
@Test
public void testCreateVnfWithChildrenCreateCustomerWithChildrenAndCousinBetweenVlanAndServiceInstanceThenDeleteCustomerVerifyingVlanRV()
throws IOException, AAIException {
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String json = PayloadUtil.getResourcePayload(
@@ -912,7 +905,7 @@ public class NotificationDmaapEventTest extends AAISetup {
@Test
public void testBulkCreateOfComplexAndPserverWithRelationshipThenBulkDeleteBoth() throws IOException, AAIException {
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
JsonObject payloads = JsonParser
@@ -945,7 +938,7 @@ public class NotificationDmaapEventTest extends AAISetup {
Map<String, Pair<String, String>> deletes = new LinkedHashMap<>();
deletes.put(pserverUri, new Pair<>(pserverRv, null));
deletes.put(complexUri, new Pair<>(complexRV, null));
- notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH);
httpTestUtil.doDelete(deletes);
@@ -958,7 +951,7 @@ public class NotificationDmaapEventTest extends AAISetup {
@Test
public void testCreateVnfWithChildrenCreateCustomerWithChildrenAndCousinBetweenVlanAndServiceInstanceThenImplicitDeleteVlanVerifyingServiceInstanceRV()
throws IOException, AAIException {
- UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions));
+ UEBNotification notification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle);
String json = PayloadUtil.getResourcePayload(
diff --git a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryNotificationIntegrationTest.java b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryNotificationIntegrationTest.java
index e8e3d691..6b90782c 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryNotificationIntegrationTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryNotificationIntegrationTest.java
@@ -61,8 +61,6 @@ import org.onap.aai.restcore.HttpMethod;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.springframework.test.annotation.DirtiesContext;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class HttpEntryNotificationIntegrationTest extends AAISetup {
@@ -77,8 +75,6 @@ public class HttpEntryNotificationIntegrationTest extends AAISetup {
private List<String> aaiRequestContextList;
private List<MediaType> outputMediaTypes;
- ObjectMapper mapper = new ObjectMapper();
-
@Before
public void setup() {
@@ -129,7 +125,7 @@ public class HttpEntryNotificationIntegrationTest extends AAISetup {
public void notificationOnRelatedToTest() throws UnsupportedEncodingException, AAIException {
Loader ld = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
- UEBNotification uebNotification = Mockito.spy(new UEBNotification(ld, loaderFactory, schemaVersions));
+ UEBNotification uebNotification = Mockito.spy(new UEBNotification(loaderFactory, schemaVersions));
traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), uebNotification);
Loader loader = traversalHttpEntry.getLoader();
@@ -148,25 +144,24 @@ public class HttpEntryNotificationIntegrationTest extends AAISetup {
content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString()
+ "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\"}";
- doNothing().when(uebNotification).triggerEvents();
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, uri,
content);
assertEquals("Expected the pserver relationship to be deleted", 200, response.getStatus());
assertEquals("Two notifications", 2, uebNotification.getEvents().size());
assertEquals("Notification generated for PUT edge", "UPDATE",
- uebNotification.getEvents().get(0).getEventHeader().getValue("action").toString());
+ uebNotification.getEvents().get(1).getEventHeader().getAction());
assertThat("Event body for the edge create has the related to",
- uebNotification.getEvents().get(0).getObj().marshal(false),
+ uebNotification.getEvents().get(1).getEntity().toString(),
containsString("cloud-infrastructure/pservers/pserver/junit-edge-test-pserver"));
response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.DELETE_EDGE, uri, content);
assertEquals("Expected the pserver relationship to be deleted", 204, response.getStatus());
assertEquals("Two notifications", 2, uebNotification.getEvents().size());
assertEquals("Notification generated for DELETE edge", "UPDATE",
- uebNotification.getEvents().get(0).getEventHeader().getValue("action").toString());
+ uebNotification.getEvents().get(0).getEventHeader().getAction());
assertThat("Event body for the edge delete does not have the related to",
- uebNotification.getEvents().get(0).getObj().marshal(false),
+ uebNotification.getEvents().get(0).getEntity().toString(),
not(containsString("cloud-infrastructure/pservers/pserver/junit-edge-test-pserver")));
dbEngine.rollback();
diff --git a/aai-core/src/test/java/org/onap/aai/rest/notification/NotificationServiceTest.java b/aai-core/src/test/java/org/onap/aai/rest/notification/NotificationServiceTest.java
index 95301c6f..4fd21497 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/notification/NotificationServiceTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/notification/NotificationServiceTest.java
@@ -24,6 +24,7 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -50,6 +51,7 @@ import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.LoaderFactory;
+import org.onap.aai.kafka.NotificationProducerService;
import org.onap.aai.prevalidation.ValidationService;
import org.onap.aai.serialization.db.DBSerializer;
import org.onap.aai.serialization.engines.query.QueryEngine;
@@ -62,6 +64,7 @@ public class NotificationServiceTest extends AAISetup {
@Mock SchemaVersions schemaVersions;
@Mock UEBNotification uebNotification;
@Mock ValidationService validationService;
+ @Mock NotificationProducerService notificationProducerService;
@Mock DBSerializer dbSerializer;
@Mock QueryEngine queryEngine;
@Mock Introspector introspector;
@@ -77,9 +80,10 @@ public class NotificationServiceTest extends AAISetup {
when(dbSerializer.touchStandardVertexPropertiesForEdges()).thenReturn(Collections.emptySet());
when(dbSerializer.getLatestVersionView(any(),anyInt())).thenReturn(introspector);
- notificationService = new NotificationService(validationService, loaderFactory, basePath, isDeltaEventsEnabled);
+ notificationService = new NotificationService(validationService, loaderFactory, basePath, isDeltaEventsEnabled, notificationProducerService);
when(schemaVersions.getDefaultVersion()).thenReturn(new SchemaVersion("v29"));
doNothing().when(uebNotification).createNotificationEvent(any(),any(),any(),any(),any(),any(),any());
+ doNothing().when(notificationProducerService).sendUEBNotification(any());
}
@Test
@@ -101,7 +105,7 @@ public class NotificationServiceTest extends AAISetup {
verify(uebNotification, times(1)).createNotificationEvent(eq("transactionId"), eq("sourceOfTruth"), eq(Status.OK), eq(URI.create("/aai/v29/pservers/pserver/hostname")), eq(introspector), any(), eq("/aai"));
verify(validationService, times(1)).validate(anyList());
- verify(uebNotification, times(1)).triggerEvents();
+ verify(notificationProducerService, times(1)).sendUEBNotification(uebNotification);
}
@Test
@@ -119,9 +123,9 @@ public class NotificationServiceTest extends AAISetup {
SchemaVersion schemaVersion = new SchemaVersion("v29");
when(dbSerializer.getUpdatedVertexes()).thenReturn(Collections.emptyMap());
- notificationService = new NotificationService(null, loaderFactory, basePath, isDeltaEventsEnabled);
+ notificationService = new NotificationService(null, loaderFactory, basePath, isDeltaEventsEnabled, notificationProducerService);
notificationService.generateEvents(uebNotification, AAIProperties.MINIMUM_DEPTH, "sourceOfTruth", dbSerializer, "transactionId", queryEngine, mainVertexesToNotifyOn, schemaVersion);
- verify(uebNotification, times(1)).triggerEvents();
+ verify(notificationProducerService, times(1)).sendUEBNotification(uebNotification);
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/notification/UEBNotificationTest.java b/aai-core/src/test/java/org/onap/aai/rest/notification/UEBNotificationTest.java
index 229abae4..e176f1cb 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/notification/UEBNotificationTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/notification/UEBNotificationTest.java
@@ -71,14 +71,14 @@ public class UEBNotificationTest extends AAISetup {
Introspector pserver = loader.introspectorFromName("pserver");
pserver.setValue("hostname", "hn");
URI uri = new URI("/cloud-infrastructure/pservers/pserver/hn");
- UEBNotification uebNotification = new UEBNotification(loader, loaderFactory, schemaVersions);
+ UEBNotification uebNotification = new UEBNotification(loaderFactory, schemaVersions);
uebNotification.createNotificationEvent(UUID.randomUUID().toString(), "JUNIT-SOT", Response.Status.CREATED, uri,
pserver, new HashMap<>(), BASE_PATH);
assertEquals("One event created", 1, uebNotification.getEvents().size());
assertEquals("Uri is correct",
BASE_PATH + "/" + schemaVersions.getDefaultVersion() + "/cloud-infrastructure/pservers/pserver/hn",
- uebNotification.getEvents().get(0).getEventHeader().getValue("entity-link").toString());
+ uebNotification.getEvents().get(0).getEventHeader().getEntityLink());
}
@Test
@@ -87,13 +87,13 @@ public class UEBNotificationTest extends AAISetup {
Introspector pserver = loader.introspectorFromName("pserver");
pserver.setValue("hostname", "hn");
URI uri = new URI(BASE_PATH + "/v12/cloud-infrastructure/pservers/pserver/hn");
- UEBNotification uebNotification = new UEBNotification(loader, loaderFactory, schemaVersions);
+ UEBNotification uebNotification = new UEBNotification(loaderFactory, schemaVersions);
uebNotification.createNotificationEvent(UUID.randomUUID().toString(), "JUNIT-SOT", Response.Status.CREATED, uri,
pserver, new HashMap<>(), BASE_PATH);
assertEquals("One event created", 1, uebNotification.getEvents().size());
assertEquals("Uri is correct",
BASE_PATH + "/" + schemaVersions.getDefaultVersion() + "/cloud-infrastructure/pservers/pserver/hn",
- uebNotification.getEvents().get(0).getEventHeader().getValue("entity-link").toString());
+ uebNotification.getEvents().get(0).getEventHeader().getEntityLink());
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java
index 7dca441e..bec04ee8 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java
@@ -61,6 +61,7 @@ import org.onap.aai.serialization.queryformats.QueryFormatTestHelper;
import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
import org.onap.aai.util.AAIConstants;
+import org.onap.aai.web.KafkaNotificationEventConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
@@ -71,10 +72,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration(
classes = {ConfigConfiguration.class, AAICoreFakeEdgesConfigTranslator.class, NodeIngestor.class,
EdgeIngestor.class, EdgeSerializer.class, SpringContextAware.class, IntrospectionConfig.class,
- XmlFormatTransformerConfiguration.class, LoaderFactory.class, NotificationService.class})
+ XmlFormatTransformerConfiguration.class, LoaderFactory.class, NotificationService.class,
+ KafkaNotificationEventConfig.class})
@TestPropertySource(
properties = {"schema.translator.list = config", "schema.nodes.location=src/test/resources/onap/oxm",
- "schema.edges.location=src/test/resources/onap/dbedgerules"})
+ "schema.edges.location=src/test/resources/onap/dbedgerules","aai.notifications.enabled=false"})
public class DbSerializer_needsFakeRulesTest {
// to use, set thrown.expect to whatever your test needs