summaryrefslogtreecommitdiffstats
path: root/aai-core
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-10-08 11:52:14 +0200
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-10-09 11:12:06 +0200
commit180f2967c7db5cbbace67616146a66d9d9658af7 (patch)
tree106a9019968b489ca717ddeb7a3e93f5328ac509 /aai-core
parent6cc66cadc9db495883ce1211c1a0f712e77f8bc7 (diff)
Refactor UEBNotification class
- refactor UEBNotification class that it does not use ActiveMQ anymore and directly publishes to Kafka - use .domain.NotificationEvent class - serialize as late as possible Issue-ID: AAI-3931 Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de> Change-Id: I3836519752f810f905a9aed96678d497783a2e5d
Diffstat (limited to 'aai-core')
-rw-r--r--aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java11
-rw-r--r--aai-core/src/main/java/org/onap/aai/domain/notificationEvent/NotificationEvent.java490
-rw-r--r--aai-core/src/main/java/org/onap/aai/kafka/MessageProducer.java6
-rw-r--r--aai-core/src/main/java/org/onap/aai/kafka/NotificationProducer.java31
-rw-r--r--aai-core/src/main/java/org/onap/aai/kafka/NotificationProducerService.java48
-rw-r--r--aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java47
-rw-r--r--aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java2
-rw-r--r--aai-core/src/main/java/org/onap/aai/rest/notification/NotificationService.java8
-rw-r--r--aai-core/src/main/java/org/onap/aai/rest/notification/UEBNotification.java116
-rw-r--r--aai-core/src/main/java/org/onap/aai/web/KafkaConfig.java9
-rw-r--r--aai-core/src/main/java/org/onap/aai/web/KafkaNotificationEventConfig.java111
-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
-rw-r--r--aai-core/src/test/resources/payloads/resource/aai-event.json119
25 files changed, 549 insertions, 777 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java b/aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java
index c04e4e3c..3cc1719c 100644
--- a/aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java
+++ b/aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java
@@ -32,8 +32,19 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.web.context.annotation.RequestScope;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
+
@Configuration
public class RestBeanConfig {
+
+ @Bean
+ public ObjectMapper objectMapper() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.registerModule(new JaxbAnnotationModule());
+ return objectMapper;
+ }
+
@Bean(name = "traversalUriHttpEntry")
@Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public HttpEntry traversalUriHttpEntry() {
diff --git a/aai-core/src/main/java/org/onap/aai/domain/notificationEvent/NotificationEvent.java b/aai-core/src/main/java/org/onap/aai/domain/notificationEvent/NotificationEvent.java
index dad35669..9117e998 100644
--- a/aai-core/src/main/java/org/onap/aai/domain/notificationEvent/NotificationEvent.java
+++ b/aai-core/src/main/java/org/onap/aai/domain/notificationEvent/NotificationEvent.java
@@ -17,188 +17,35 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-//
-// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
-// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
-// Any modifications to this file will be lost upon recompilation of the source schema.
-// Generated on: 2016.01.06 at 05:38:00 PM EST
-//
-
package org.onap.aai.domain.notificationEvent;
import javax.xml.bind.annotation.*;
-import org.w3c.dom.Element;
+import com.fasterxml.jackson.annotation.JsonProperty;
-/**
- * <p>
- * Java class for anonymous complex type.
- *
- * <p>
- * The following schema fragment specifies the expected content contained within this class.
- *
- * <pre>
- * &lt;complexType>
- * &lt;complexContent>
- * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * &lt;sequence>
- * &lt;element name="cambria.partition" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="event-header" minOccurs="0">
- * &lt;complexType>
- * &lt;complexContent>
- * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * &lt;sequence>
- * &lt;element name="id" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="timestamp" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="source-name" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="domain" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="sequence-number" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="severity" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="event-type" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="version" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="action" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="entity-type" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="top-entity-type" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="entity-link" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="status" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;/sequence>
- * &lt;/restriction>
- * &lt;/complexContent>
- * &lt;/complexType>
- * &lt;/element>
- * &lt;any processContents='lax' namespace='##other' minOccurs="0"/>
- * &lt;/sequence>
- * &lt;/restriction>
- * &lt;/complexContent>
- * &lt;/complexType>
- * </pre>
- *
- *
- */
+import lombok.Data;
+
+@Data
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {"cambriaPartition", "eventHeader", "entity"})
@XmlRootElement(name = "NotificationEvent")
public class NotificationEvent {
@XmlElement(name = "cambria.partition")
+ @JsonProperty("cambria.partition")
protected String cambriaPartition;
@XmlElement(name = "event-header")
+ @JsonProperty("event-header")
protected EventHeader eventHeader;
@XmlAnyElement(lax = true)
protected Object entity;
- /**
- * Gets the value of the eventHeader property.
- *
- * @return
- * possible object is
- * {@link EventHeader }
- *
- */
- public EventHeader getEventHeader() {
- return eventHeader;
- }
-
- /**
- * Sets the value of the eventHeader property.
- *
- * @param value
- * allowed object is
- * {@link EventHeader }
- *
- */
- public void setEventHeader(EventHeader value) {
- this.eventHeader = value;
- }
-
- /**
- * Gets the value of the any property.
- *
- * @return
- * possible object is
- * {@link Object }
- * {@link Element }
- *
- */
- public Object getEntity() {
- return entity;
- }
-
- /**
- * Sets the value of the any property.
- *
- * @param value
- * allowed object is
- * {@link Object }
- * {@link Element }
- *
- */
- public void setEntity(Object value) {
- this.entity = value;
- }
-
- /**
- * Gets the value of the cambriaPartition property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getCambriaPartition() {
- return cambriaPartition;
- }
-
- /**
- * Sets the value of the cambriaPartition property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setCambriaPartition(String value) {
- this.cambriaPartition = value;
- }
-
- /**
- * <p>
- * Java class for anonymous complex type.
- *
- * <p>
- * The following schema fragment specifies the expected content contained within this class.
- *
- * <pre>
- * &lt;complexType>
- * &lt;complexContent>
- * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * &lt;sequence>
- * &lt;element name="id" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="timestamp" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="source-name" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="domain" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="sequence-number" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="severity" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="event-type" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="version" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="action" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="entity-type" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="top-entity-type" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="entity-link" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;element name="status" type="{http://www.w3.org/2001/XMLSchema}string"/>
- * &lt;/sequence>
- * &lt;/restriction>
- * &lt;/complexContent>
- * &lt;/complexType>
- * </pre>
- *
- *
- */
+ @Data
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
name = "",
propOrder = {"id", "timestamp", "sourceName", "domain", "sequenceNumber", "severity", "eventType",
- "version", "action", "entityType", "topEntityType", "entityLink", "status"})
+ "version", "action", "entityType", "topEntityType", "entityLink"})
public static class EventHeader {
@XmlElement(required = true)
@@ -206,340 +53,31 @@ public class NotificationEvent {
@XmlElement(required = true)
protected String timestamp;
@XmlElement(name = "source-name", required = true)
+ @JsonProperty("source-name")
protected String sourceName;
@XmlElement(required = true)
protected String domain;
@XmlElement(name = "sequence-number", required = true)
+ @JsonProperty("sequence-number")
protected String sequenceNumber;
@XmlElement(required = true)
protected String severity;
@XmlElement(name = "event-type", required = true)
+ @JsonProperty("event-type")
protected String eventType;
@XmlElement(required = true)
protected String version;
@XmlElement(required = true)
protected String action;
@XmlElement(name = "entity-type", required = true)
+ @JsonProperty("entity-type")
protected String entityType;
@XmlElement(name = "top-entity-type", required = true)
+ @JsonProperty("top-entity-type")
protected String topEntityType;
@XmlElement(name = "entity-link", required = true)
+ @JsonProperty("entity-link")
protected String entityLink;
- @XmlElement(required = true)
- protected String status;
-
- /**
- * Gets the value of the id property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getId() {
- return id;
- }
-
- /**
- * Sets the value of the id property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setId(String value) {
- this.id = value;
- }
-
- /**
- * Gets the value of the timestamp property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getTimestamp() {
- return timestamp;
- }
-
- /**
- * Sets the value of the timestamp property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setTimestamp(String value) {
- this.timestamp = value;
- }
-
- /**
- * Gets the value of the sourceName property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getSourceName() {
- return sourceName;
- }
-
- /**
- * Sets the value of the sourceName property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setSourceName(String value) {
- this.sourceName = value;
- }
-
- /**
- * Gets the value of the domain property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getDomain() {
- return domain;
- }
-
- /**
- * Sets the value of the domain property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setDomain(String value) {
- this.domain = value;
- }
-
- /**
- * Gets the value of the sequenceNumber property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getSequenceNumber() {
- return sequenceNumber;
- }
-
- /**
- * Sets the value of the sequenceNumber property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setSequenceNumber(String value) {
- this.sequenceNumber = value;
- }
-
- /**
- * Gets the value of the severity property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getSeverity() {
- return severity;
- }
-
- /**
- * Sets the value of the severity property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setSeverity(String value) {
- this.severity = value;
- }
-
- /**
- * Gets the value of the eventType property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getEventType() {
- return eventType;
- }
-
- /**
- * Sets the value of the eventType property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setEventType(String value) {
- this.eventType = value;
- }
-
- /**
- * Gets the value of the version property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getVersion() {
- return version;
- }
-
- /**
- * Sets the value of the version property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setVersion(String value) {
- this.version = value;
- }
-
- /**
- * Gets the value of the action property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getAction() {
- return action;
- }
-
- /**
- * Sets the value of the action property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setAction(String value) {
- this.action = value;
- }
-
- /**
- * Gets the value of the entityType property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getEntityType() {
- return entityType;
- }
-
- /**
- * Sets the value of the entityType property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setEntityType(String value) {
- this.entityType = value;
- }
-
- /**
- * Gets the value of the topEntityType property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getTopEntityType() {
- return topEntityType;
- }
-
- /**
- * Sets the value of the topEntityType property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setTopEntityType(String value) {
- this.topEntityType = value;
- }
-
- /**
- * Gets the value of the entityLink property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getEntityLink() {
- return entityLink;
- }
-
- /**
- * Sets the value of the entityLink property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setEntityLink(String value) {
- this.entityLink = value;
- }
-
- /**
- * Gets the value of the status property.
- *
- * @return
- * possible object is
- * {@link String }
- *
- */
- public String getStatus() {
- return status;
- }
-
- /**
- * Sets the value of the status property.
- *
- * @param value
- * allowed object is
- * {@link String }
- *
- */
- public void setStatus(String value) {
- this.status = value;
- }
-
}
}
diff --git a/aai-core/src/main/java/org/onap/aai/kafka/MessageProducer.java b/aai-core/src/main/java/org/onap/aai/kafka/MessageProducer.java
index d6a491ef..09fc68a2 100644
--- a/aai-core/src/main/java/org/onap/aai/kafka/MessageProducer.java
+++ b/aai-core/src/main/java/org/onap/aai/kafka/MessageProducer.java
@@ -22,6 +22,12 @@ package org.onap.aai.kafka;
import org.json.JSONObject;
+/**
+ * MessageProducer interface based on untyped messages
+ *
+ * @deprecated use {@link org.onap.aai.kafka.NotificationProducer} instead
+ */
+@Deprecated
public interface MessageProducer {
void sendMessageToDefaultDestination(JSONObject finalJson);
diff --git a/aai-core/src/main/java/org/onap/aai/kafka/NotificationProducer.java b/aai-core/src/main/java/org/onap/aai/kafka/NotificationProducer.java
new file mode 100644
index 00000000..3c739174
--- /dev/null
+++ b/aai-core/src/main/java/org/onap/aai/kafka/NotificationProducer.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2024 Deutsche Telekom. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.kafka;
+
+import org.onap.aai.domain.notificationEvent.NotificationEvent;
+import org.onap.aai.rest.notification.UEBNotification;
+import org.springframework.stereotype.Service;
+
+@Service
+public interface NotificationProducer {
+ public void sendNotification(NotificationEvent notificationEvent);
+ public void sendUEBNotification(UEBNotification uebNotification);
+}
diff --git a/aai-core/src/main/java/org/onap/aai/kafka/NotificationProducerService.java b/aai-core/src/main/java/org/onap/aai/kafka/NotificationProducerService.java
new file mode 100644
index 00000000..44a03ba1
--- /dev/null
+++ b/aai-core/src/main/java/org/onap/aai/kafka/NotificationProducerService.java
@@ -0,0 +1,48 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2024 Deutsche Telekom. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.kafka;
+
+import org.onap.aai.domain.notificationEvent.NotificationEvent;
+import org.onap.aai.rest.notification.UEBNotification;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.kafka.core.KafkaTemplate;
+import org.springframework.stereotype.Service;
+
+import lombok.RequiredArgsConstructor;
+
+@Service
+@RequiredArgsConstructor
+public class NotificationProducerService implements NotificationProducer {
+
+ private final KafkaTemplate<String,NotificationEvent> kafkaTemplate;
+ @Value("${aai.notifications.enabled:true}") boolean notificationsEnabled;
+
+ public void sendNotification(NotificationEvent notificationEvent) {
+ if(notificationsEnabled) {
+ kafkaTemplate.send("AAI-EVENT", notificationEvent);
+ }
+ }
+
+ public void sendUEBNotification(UEBNotification uebNotification) {
+ uebNotification.getEvents().stream()
+ .forEach(this::sendNotification);
+ }
+}
diff --git a/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java b/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java
index 093062a9..9d8f5fdb 100644
--- a/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java
+++ b/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java
@@ -22,8 +22,8 @@
package org.onap.aai.prevalidation;
-import com.google.gson.Gson;
-import com.google.gson.JsonSyntaxException;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
@@ -41,9 +41,10 @@ import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import org.apache.http.conn.ConnectTimeoutException;
+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.Introspector;
-import org.onap.aai.rest.notification.NotificationEvent;
+
import org.onap.aai.restclient.RestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -74,22 +75,19 @@ public class ValidationService {
static final String VALIDATION_HEALTH_ENDPOINT = "/v1/info";
private static final Logger LOGGER = LoggerFactory.getLogger(ValidationService.class);
- private static final String ENTITY_TYPE = "entity-type";
- private static final String ACTION = "action";
- private static final String SOURCE_NAME = "source-name";
private static final String DELETE = "DELETE";
private final RestClient validationRestClient;
private final String appName;
private final Set<String> validationNodeTypes;
- private final Gson gson;
-
- private List<Pattern> exclusionList;
+ private final ObjectMapper mapper;
+ private final List<Pattern> exclusionList;
public ValidationService(@Qualifier("validationRestClient") RestClient validationRestClient,
@Value("${spring.application.name}") String appName,
@Value("${validation.service.node-types}") String validationNodes,
- @Value("${validation.service.exclusion-regexes:#{null}}") String exclusionRegexes) {
+ @Value("${validation.service.exclusion-regexes:#{null}}") String exclusionRegexes,
+ ObjectMapper mapper) {
this.validationRestClient = validationRestClient;
this.appName = appName;
@@ -101,7 +99,7 @@ public class ValidationService {
this.exclusionList =
Arrays.stream(exclusionRegexes.split(",")).map(Pattern::compile).collect(Collectors.toList());
}
- this.gson = new Gson();
+ this.mapper = mapper;
LOGGER.info("Successfully initialized the pre validation service");
}
@@ -119,7 +117,7 @@ public class ValidationService {
ResponseEntity<String> healthCheckResponse = null;
try {
healthCheckResponse =
- validationRestClient.execute(VALIDATION_HEALTH_ENDPOINT, HttpMethod.GET, httpHeaders, null);
+ validationRestClient.execute(VALIDATION_HEALTH_ENDPOINT, HttpMethod.GET, httpHeaders);
} catch (Exception ex) {
AAIException validationException = new AAIException("AAI_4021", ex);
throw validationException;
@@ -142,7 +140,7 @@ public class ValidationService {
}
for (NotificationEvent event : notificationEvents) {
- Introspector eventHeader = event.getEventHeader();
+ EventHeader eventHeader = event.getEventHeader();
if (eventHeader == null) {
// Should I skip processing the request and let it continue
// or fail the request and cause client impact
@@ -156,10 +154,10 @@ public class ValidationService {
if (isDelete(eventHeader)) {
continue;
}
- String entityType = eventHeader.getValue(ENTITY_TYPE);
+ String entityType = eventHeader.getEntityType();
if (this.shouldValidate(entityType)) {
- List<String> violations = preValidate(event.getNotificationEvent());
+ List<String> violations = preValidate(event);
if (!violations.isEmpty()) {
AAIException aaiException = new AAIException("AAI_4019");
aaiException.getTemplateVars().addAll(violations);
@@ -172,8 +170,8 @@ public class ValidationService {
/**
* Determine if event is of type delete
*/
- private boolean isDelete(Introspector eventHeader) {
- String action = eventHeader.getValue(ACTION);
+ private boolean isDelete(EventHeader eventHeader) {
+ String action = eventHeader.getAction();
return DELETE.equalsIgnoreCase(action);
}
@@ -186,15 +184,15 @@ public class ValidationService {
// Get the first notification and if the source of that notification
// is in one of the regexes then we skip sending it to validation
NotificationEvent notification = notificationEvents.get(0);
- Introspector eventHeader = notification.getEventHeader();
+ EventHeader eventHeader = notification.getEventHeader();
if (eventHeader != null) {
- String source = eventHeader.getValue(SOURCE_NAME);
+ String source = eventHeader.getSourceName();
return exclusionList.stream().anyMatch(pattern -> pattern.matcher(source).matches());
}
return false;
}
- public List<String> preValidate(String body) throws AAIException {
+ public List<String> preValidate(NotificationEvent notificationEvent) throws AAIException {
Map<String, String> httpHeaders = new HashMap<>();
httpHeaders.put("X-FromAppId", appName);
httpHeaders.put("X-TransactionID", UUID.randomUUID().toString());
@@ -203,7 +201,8 @@ public class ValidationService {
List<String> violations = new ArrayList<>();
ResponseEntity<String> responseEntity;
try {
- responseEntity = validationRestClient.execute(VALIDATION_ENDPOINT, HttpMethod.POST, httpHeaders, body);
+ String requestBody = mapper.writeValueAsString(notificationEvent);
+ responseEntity = validationRestClient.execute(VALIDATION_ENDPOINT, HttpMethod.POST, httpHeaders, requestBody);
Object responseBody = responseEntity.getBody();
if (isSuccess(responseEntity)) {
LOGGER.debug("Validation Service returned following response status code {} and body {}",
@@ -242,8 +241,8 @@ public class ValidationService {
private Validation getValidation(Object responseBody) {
Validation validation = null;
try {
- validation = gson.fromJson(responseBody.toString(), Validation.class);
- } catch (JsonSyntaxException jsonException) {
+ validation = mapper.readValue(responseBody.toString(), Validation.class);
+ } catch (JsonProcessingException jsonException) {
LOGGER.warn("Unable to convert the response body {}", jsonException.getMessage());
}
return validation;
diff --git a/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java b/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
index c4f84396..dfebd6e7 100644
--- a/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
+++ b/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
@@ -130,7 +130,7 @@ public class HttpEntry {
this.dbEngine = new JanusGraphDBEngine(queryStyle, loader);
getDbEngine().startTransaction();
- this.notification = new UEBNotification(loader, loaderFactory, schemaVersions);
+ this.notification = new UEBNotification(loaderFactory, schemaVersions);
if ("true".equals(AAIConfig.get("aai.notification.depth.all.enabled", "true"))) {
this.notificationDepth = AAIProperties.MAXIMUM_DEPTH;
} else {
diff --git a/aai-core/src/main/java/org/onap/aai/rest/notification/NotificationService.java b/aai-core/src/main/java/org/onap/aai/rest/notification/NotificationService.java
index 9c3dde15..c2770692 100644
--- a/aai-core/src/main/java/org/onap/aai/rest/notification/NotificationService.java
+++ b/aai-core/src/main/java/org/onap/aai/rest/notification/NotificationService.java
@@ -34,6 +34,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.NotificationProducer;
import org.onap.aai.prevalidation.ValidationService;
import org.onap.aai.serialization.db.DBSerializer;
import org.onap.aai.serialization.engines.query.QueryEngine;
@@ -52,6 +53,7 @@ public class NotificationService {
public static final Logger LOGGER = LoggerFactory.getLogger(NotificationService.class);
private final ValidationService validationService;
+ private final NotificationProducer notificationProducer;
private final LoaderFactory loaderFactory;
private final boolean isDeltaEventsEnabled;
private final String basePath;
@@ -60,11 +62,13 @@ public class NotificationService {
@Nullable ValidationService validationService,
LoaderFactory loaderFactory,
@Value("${schema.uri.base.path}") String basePath,
- @Value("${delta.events.enabled:false}") boolean isDeltaEventsEnabled) {
+ @Value("${delta.events.enabled:false}") boolean isDeltaEventsEnabled,
+ NotificationProducer notificationProducer) {
this.validationService = validationService;
this.loaderFactory = loaderFactory;
this.basePath = basePath;
this.isDeltaEventsEnabled = isDeltaEventsEnabled;
+ this.notificationProducer = notificationProducer;
}
/**
@@ -99,7 +103,7 @@ public class NotificationService {
validationService.validate(notification.getEvents());
}
- notification.triggerEvents();
+ notificationProducer.sendUEBNotification(notification);
if (isDeltaEventsEnabled) {
try {
DeltaEvents deltaEvents = new DeltaEvents(transactionId, sourceOfTruth, schemaVersion.toString(),
diff --git a/aai-core/src/main/java/org/onap/aai/rest/notification/UEBNotification.java b/aai-core/src/main/java/org/onap/aai/rest/notification/UEBNotification.java
index a113cf14..d5803f9c 100644
--- a/aai-core/src/main/java/org/onap/aai/rest/notification/UEBNotification.java
+++ b/aai-core/src/main/java/org/onap/aai/rest/notification/UEBNotification.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2024 Deutsche Telekom.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -30,6 +32,7 @@ import java.util.Map;
import javax.ws.rs.core.Response.Status;
+import org.onap.aai.domain.notificationEvent.NotificationEvent.EventHeader;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
@@ -41,59 +44,31 @@ import org.onap.aai.logging.LogFormatTools;
import org.onap.aai.parsers.uri.URIToObject;
import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
+import org.onap.aai.util.AAIConfig;
+import org.onap.aai.util.AAIConstants;
+import org.onap.aai.util.FormatDate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * The Class UEBNotification.
- */
public class UEBNotification {
private static final Logger LOGGER = LoggerFactory.getLogger(UEBNotification.class);
+ private static final FormatDate FORMAT_DATE = new FormatDate("YYYYMMdd-HH:mm:ss:SSS");
+ private static final String EVENT_TYPE = "AAI-EVENT";
- private Loader currentVersionLoader = null;
- protected Map<String, NotificationEvent> events = null;
- private SchemaVersion notificationVersion = null;
-
- /**
- * Instantiates a new UEB notification.
- *
- * @param loader the loader
- */
- public UEBNotification(Loader loader, LoaderFactory loaderFactory, SchemaVersions schemaVersions) {
- events = new LinkedHashMap<>();
- SchemaVersion defaultVersion = schemaVersions.getDefaultVersion();
- currentVersionLoader = loaderFactory.createLoaderForVersion(loader.getModelType(), defaultVersion);
- notificationVersion = defaultVersion;
- }
+ private final String domain = AAIConfig.get("aai.notificationEvent.default.domain", "UNK");
+ private final String sequenceNumber = AAIConfig.get("aai.notificationEvent.default.sequenceNumber", "UNK");
+ private final String severity = AAIConfig.get("aai.notificationEvent.default.severity", "UNK");
+ private final Map<String, org.onap.aai.domain.notificationEvent.NotificationEvent> events;
+ private final Loader currentVersionLoader;
+ private final SchemaVersion notificationVersion;
- /**
- * Instantiates a new UEB notification.
- *
- * @param modelType - Model type
- * @param loaderFactory - the loader factory
- * @param schemaVersions the schema versions bean
- */
- public UEBNotification(ModelType modelType, LoaderFactory loaderFactory, SchemaVersions schemaVersions) {
+ public UEBNotification(LoaderFactory loaderFactory, SchemaVersions schemaVersions) {
events = new LinkedHashMap<>();
- SchemaVersion defaultVersion = schemaVersions.getDefaultVersion();
- currentVersionLoader = loaderFactory.createLoaderForVersion(modelType, defaultVersion);
- notificationVersion = defaultVersion;
+ notificationVersion = schemaVersions.getDefaultVersion();
+ currentVersionLoader = loaderFactory.createLoaderForVersion(ModelType.MOXY, notificationVersion);
}
- /**
- * Creates the notification event.
- *
- * @param transactionId the X-TransactionId
- * @param sourceOfTruth
- * @param status the status
- * @param uri the uri
- * @param obj the obj
- * @param basePath base URI path
- * @throws AAIException the AAI exception
- * @throws IllegalArgumentException the illegal argument exception
- * @throws UnsupportedEncodingException the unsupported encoding exception
- */
public void createNotificationEvent(String transactionId, String sourceOfTruth, Status status, URI uri,
Introspector obj, HashMap<String, Introspector> relatedObjects, String basePath)
throws AAIException, UnsupportedEncodingException {
@@ -102,25 +77,32 @@ public class UEBNotification {
try {
EntityConverter entityConverter = new EntityConverter(new URIToObject(currentVersionLoader, uri, relatedObjects));
- Introspector eventHeader = currentVersionLoader.introspectorFromName("notification-event-header");
+ EventHeader eventHeader = new EventHeader();
basePath = formatBasePath(basePath);
-
String entityLink = formatEntityLink(uri, basePath);
-
- eventHeader.setValue("entity-link", entityLink);
- eventHeader.setValue("action", action);
- eventHeader.setValue("entity-type", obj.getDbName());
- eventHeader.setValue("top-entity-type", entityConverter.getTopEntityName());
- eventHeader.setValue("source-name", sourceOfTruth);
- eventHeader.setValue("version", notificationVersion.toString());
- eventHeader.setValue("id", transactionId);
-
-
- Introspector eventObject = entityConverter.convert(obj);
-
- final NotificationEvent event =
- new NotificationEvent(currentVersionLoader, eventHeader, eventObject, transactionId, sourceOfTruth);
+ eventHeader.setEntityLink(entityLink);
+ eventHeader.setAction(action);
+ eventHeader.setEntityType(obj.getDbName());
+ eventHeader.setTopEntityType(entityConverter.getTopEntityName());
+ eventHeader.setSourceName(sourceOfTruth);
+ eventHeader.setVersion(notificationVersion.toString());
+ eventHeader.setId(transactionId);
+
+ // default values
+ eventHeader.setTimestamp(FORMAT_DATE.getDateTime());
+ eventHeader.setEventType(EVENT_TYPE);
+ eventHeader.setDomain(domain);
+ eventHeader.setSequenceNumber(sequenceNumber);
+ eventHeader.setSeverity(severity);
+
+ Introspector entity = entityConverter.convert(obj);
+
+ final org.onap.aai.domain.notificationEvent.NotificationEvent event =
+ new org.onap.aai.domain.notificationEvent.NotificationEvent();
+ event.setEventHeader(eventHeader);
+ event.setCambriaPartition(AAIConstants.UEB_PUB_PARTITION_AAI);
+ event.setEntity(entity);
events.put(uri.toString(), event);
} catch (AAIUnknownObjectException e) {
throw new RuntimeException("Fatal error - notification-event-header object not found!");
@@ -172,26 +154,10 @@ public class UEBNotification {
return action;
}
- /**
- * Trigger events.
- *
- * @throws AAIException the AAI exception
- */
- public void triggerEvents() throws AAIException {
- for (NotificationEvent event : events.values()) {
- event.trigger();
- }
- clearEvents();
- }
-
- public List<NotificationEvent> getEvents() {
+ public List<org.onap.aai.domain.notificationEvent.NotificationEvent> getEvents() {
return new ArrayList<>(this.events.values());
}
- public Map<String, NotificationEvent> getEventsMap() {
- return this.events;
- }
-
private String getUri(String uri, String basePath) {
if (uri == null || uri.isEmpty()) {
return "";
diff --git a/aai-core/src/main/java/org/onap/aai/web/KafkaConfig.java b/aai-core/src/main/java/org/onap/aai/web/KafkaConfig.java
index c1e8357d..d201134f 100644
--- a/aai-core/src/main/java/org/onap/aai/web/KafkaConfig.java
+++ b/aai-core/src/main/java/org/onap/aai/web/KafkaConfig.java
@@ -36,6 +36,7 @@ import org.onap.aai.introspection.LoaderFactory;
import org.onap.aai.kafka.AAIKafkaEventJMSConsumer;
import org.onap.aai.kafka.AAIKafkaEventJMSProducer;
import org.onap.aai.kafka.MessageProducer;
+import org.onap.aai.kafka.NotificationProducer;
import org.onap.aai.rest.notification.NotificationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -147,8 +148,8 @@ public class KafkaConfig {
} else {
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
}
- props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
- props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
+ props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
+ props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
props.put(ProducerConfig.RETRIES_CONFIG, retries);
props.put(ProducerConfig.MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION, "5");
@@ -179,7 +180,7 @@ public class KafkaConfig {
@ConditionalOnMissingBean
public NotificationService notificationService(LoaderFactory loaderFactory,
@Value("${schema.uri.base.path}") String basePath,
- @Value("${delta.events.enabled:false}") boolean isDeltaEventsEnabled) {
- return new NotificationService(null, loaderFactory, basePath, isDeltaEventsEnabled);
+ @Value("${delta.events.enabled:false}") boolean isDeltaEventsEnabled, NotificationProducer notificationProducer) {
+ return new NotificationService(null, loaderFactory, basePath, isDeltaEventsEnabled, notificationProducer);
}
}
diff --git a/aai-core/src/main/java/org/onap/aai/web/KafkaNotificationEventConfig.java b/aai-core/src/main/java/org/onap/aai/web/KafkaNotificationEventConfig.java
new file mode 100644
index 00000000..09d8b26c
--- /dev/null
+++ b/aai-core/src/main/java/org/onap/aai/web/KafkaNotificationEventConfig.java
@@ -0,0 +1,111 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2024 Deutsche Telekom. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.web;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.onap.aai.domain.notificationEvent.NotificationEvent;
+import org.onap.aai.kafka.NotificationProducer;
+import org.onap.aai.kafka.NotificationProducerService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.kafka.core.DefaultKafkaProducerFactory;
+import org.springframework.kafka.core.KafkaTemplate;
+import org.springframework.kafka.core.ProducerFactory;
+import org.springframework.kafka.support.serializer.JsonSerializer;
+
+@Configuration
+public class KafkaNotificationEventConfig {
+
+ private static final Logger logger = LoggerFactory.getLogger(KafkaNotificationEventConfig.class);
+
+ @Value("${jms.bind.address}")
+ private String bindAddress;
+
+ @Value("${spring.kafka.producer.bootstrap-servers}")
+ private String bootstrapServers;
+
+ @Value("${spring.kafka.producer.properties.security.protocol}")
+ private String securityProtocol;
+
+ @Value("${spring.kafka.producer.properties.sasl.mechanism}")
+ private String saslMechanism;
+
+ @Value("${spring.kafka.producer.properties.sasl.jaas.config:#{null}}")
+ private String saslJaasConfig;
+
+ @Value("${spring.kafka.producer.retries:3}")
+ private String retries;
+
+ private Map<String, Object> buildKafkaProperties() throws Exception {
+ Map<String, Object> props = new HashMap<>();
+ if (bootstrapServers == null) {
+ logger.error("Environment Variable " + bootstrapServers + " is missing");
+ throw new Exception("Environment Variable " + bootstrapServers + " is missing");
+ } else {
+ props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
+ }
+ props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
+ props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
+ props.put(ProducerConfig.RETRIES_CONFIG, retries);
+ props.put(ProducerConfig.MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION, "5");
+
+ if (saslJaasConfig == null) {
+ logger.info("Not using any authentication for kafka interaction");
+ } else {
+ logger.info("Using authentication provided by kafka interaction");
+ // Strimzi Kafka security properties
+ props.put("security.protocol", securityProtocol);
+ props.put("sasl.mechanism", saslMechanism);
+ props.put("sasl.jaas.config", saslJaasConfig);
+ }
+ return props;
+ }
+
+ @Bean
+ public ProducerFactory<String, NotificationEvent> notificationEventProducerFactory() throws Exception {
+ Map<String, Object> props = buildKafkaProperties();
+
+ return new DefaultKafkaProducerFactory<>(props);
+ }
+
+ @Bean
+ public KafkaTemplate<String, NotificationEvent> kafkaNotificationEventTemplate(ProducerFactory<String, NotificationEvent> producerFactory) throws Exception {
+ try {
+
+ return new KafkaTemplate<>(producerFactory);
+ } catch (Exception e) {
+ String smth = "";
+ return null;
+ }
+ }
+
+ @Bean
+ public NotificationProducer notificationProducer(KafkaTemplate<String,NotificationEvent> kafkaTemplate) {
+ return new NotificationProducerService(kafkaTemplate);
+ }
+}
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
diff --git a/aai-core/src/test/resources/payloads/resource/aai-event.json b/aai-core/src/test/resources/payloads/resource/aai-event.json
index 0fab96da..86c67992 100644
--- a/aai-core/src/test/resources/payloads/resource/aai-event.json
+++ b/aai-core/src/test/resources/payloads/resource/aai-event.json
@@ -1,64 +1,61 @@
{
- "event-topic": "AAI-EVENT",
- "aaiEventPayload": {
- "cambria.partition": "AAI",
- "event-header": {
- "severity": "NORMAL",
- "entity-type": "object-group",
- "top-entity-type": "object-group",
- "entity-link": "/aai/v28/common/object-groups/object-group/ric_cluster",
- "event-type": "AAI-EVENT",
- "domain": "dev",
- "action": "UPDATE",
- "sequence-number": "0",
- "id": "23f12123-c326-48a7-b57e-e48746c295ea",
- "source-name": "postman-api",
- "version": "v28",
- "timestamp": "20231207-12:14:44:757"
+ "cambria.partition": "AAI",
+ "event-header": {
+ "severity": "NORMAL",
+ "entity-type": "object-group",
+ "top-entity-type": "object-group",
+ "entity-link": "/aai/v28/common/object-groups/object-group/ric_cluster",
+ "event-type": "AAI-EVENT",
+ "domain": "dev",
+ "action": "UPDATE",
+ "sequence-number": "0",
+ "id": "23f12123-c326-48a7-b57e-e48746c295ea",
+ "source-name": "postman-api",
+ "version": "v28",
+ "timestamp": "20231207-12:14:44:757"
+ },
+ "entity": {
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "cell",
+ "relationship-data": [
+ {
+ "relationship-value": "445611193273958916",
+ "relationship-key": "cell.cell-id"
+ }
+ ],
+ "related-link": "/aai/v28/network/cells/cell/445611193273958916",
+ "relationship-label": "org.onap.relationships.inventory.MemberOf",
+ "related-to-property": [
+ {
+ "property-key": "cell.cell-name",
+ "property-value": "MY6885_M-Schwere-Reiter-Str-440460_GU2_84079913"
+ }
+ ]
+ },
+ {
+ "related-to": "cell",
+ "relationship-data": [
+ {
+ "relationship-value": "445611193272330241",
+ "relationship-key": "cell.cell-id"
+ }
+ ],
+ "related-link": "/aai/v28/network/cells/cell/445611193272330241",
+ "relationship-label": "org.onap.relationships.inventory.MemberOf",
+ "related-to-property": [
+ {
+ "property-key": "cell.cell-name",
+ "property-value": "MY6885_M-Schwere-Reiter-Str-440460_GTC2_84003803"
+ }
+ ]
+ }
+ ]
},
- "entity": {
- "relationship-list": {
- "relationship": [
- {
- "related-to": "cell",
- "relationship-data": [
- {
- "relationship-value": "445611193273958916",
- "relationship-key": "cell.cell-id"
- }
- ],
- "related-link": "/aai/v28/network/cells/cell/445611193273958916",
- "relationship-label": "org.onap.relationships.inventory.MemberOf",
- "related-to-property": [
- {
- "property-key": "cell.cell-name",
- "property-value": "MY6885_M-Schwere-Reiter-Str-440460_GU2_84079913"
- }
- ]
- },
- {
- "related-to": "cell",
- "relationship-data": [
- {
- "relationship-value": "445611193272330241",
- "relationship-key": "cell.cell-id"
- }
- ],
- "related-link": "/aai/v28/network/cells/cell/445611193272330241",
- "relationship-label": "org.onap.relationships.inventory.MemberOf",
- "related-to-property": [
- {
- "property-key": "cell.cell-name",
- "property-value": "MY6885_M-Schwere-Reiter-Str-440460_GTC2_84003803"
- }
- ]
- }
- ]
- },
- "group-name": "Urban",
- "resource-version": "1701951284582",
- "group-type": "cell",
- "object-group-id": "ric_cluster"
- }
+ "group-name": "Urban",
+ "resource-version": "1701951284582",
+ "group-type": "cell",
+ "object-group-id": "ric_cluster"
}
-} \ No newline at end of file
+}