2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.util;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
26 import com.fasterxml.jackson.core.JsonGenerationException;
27 import com.fasterxml.jackson.databind.JsonMappingException;
29 import java.io.IOException;
31 import javax.json.Json;
32 import javax.json.JsonObject;
34 import org.eclipse.persistence.dynamic.DynamicEntity;
35 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
36 import org.junit.Before;
37 import org.junit.BeforeClass;
38 import org.junit.Ignore;
39 import org.junit.Test;
40 import org.mockito.Mockito;
41 import org.onap.aai.AAISetup;
42 import org.onap.aai.domain.notificationEvent.NotificationEvent.EventHeader;
43 import org.onap.aai.exceptions.AAIException;
44 import org.onap.aai.introspection.Introspector;
45 import org.onap.aai.introspection.Loader;
46 import org.onap.aai.introspection.ModelType;
47 import org.onap.aai.kafka.AAIKafkaEventJMSProducer;
49 public class StoreNotificationEventTest extends AAISetup {
51 private static AAIKafkaEventJMSProducer producer;
52 private static StoreNotificationEvent sne;
55 public static void setUp() {
56 producer = Mockito.mock(AAIKafkaEventJMSProducer.class);
57 // sne = new StoreNotificationEvent(producer, "transiationId", "sourceOfTruth");
61 public void setUpBefore() {
62 producer = Mockito.mock(AAIKafkaEventJMSProducer.class);
63 sne = new StoreNotificationEvent(producer, "transiationId", "sourceOfTruth");
67 @Test(expected = AAIException.class)
68 public void testStoreEventNullObj() throws AAIException {
69 sne.storeEventAndSendToJms(new EventHeader(), null);
72 @Test(expected = AAIException.class)
73 public void testStoreEventInvalidObjForPojoUtils() throws AAIException {
74 sne.storeEventAndSendToJms(new EventHeader(), new Object());
78 public void testStoreEventEmptyEventHeader()
79 throws AAIException, JsonGenerationException, JsonMappingException, IOException {
80 JsonObject object = Json.createObjectBuilder().add("hello", "world").build();
81 String res = sne.storeEventAndSendToJms(new EventHeader(), object);
84 assertTrue(res.contains("\"cambria.partition\" : \"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
85 assertTrue(res.contains("\"event-header\""));
86 assertTrue(res.contains("\"id\""));
87 assertTrue(res.contains("\"timestamp\""));
89 .contains("\"source-name\" : \"" + AAIConfig.get("aai.notificationEvent.default.sourceName") + "\""));
90 assertTrue(res.contains("\"domain\" : \"" + AAIConfig.get("aai.notificationEvent.default.domain") + "\""));
91 assertTrue(res.contains(
92 "\"sequence-number\" : \"" + AAIConfig.get("aai.notificationEvent.default.sequenceNumber") + "\""));
93 assertTrue(res.contains("\"severity\" : \"" + AAIConfig.get("aai.notificationEvent.default.severity") + "\""));
95 res.contains("\"event-type\" : \"" + AAIConfig.get("aai.notificationEvent.default.eventType") + "\""));
96 assertTrue(res.contains("\"version\" : \"" + AAIConfig.get("aai.notificationEvent.default.version") + "\""));
97 assertTrue(res.contains("\"action\" : \"UNK\""));
98 assertTrue(res.contains("\"entity-link\" : \"UNK\""));
99 assertTrue(res.contains("\"entity\""));
100 assertTrue(res.contains("\"hello\""));
101 assertTrue(res.contains("\"chars\" : \"world\""));
102 assertTrue(res.contains("\"string\" : \"world\""));
103 assertTrue(res.contains("\"valueType\" : \"STRING\""));
107 public void testStoreEvent() throws AAIException, JsonGenerationException, JsonMappingException, IOException {
108 JsonObject object = Json.createObjectBuilder().add("hello", "world").build();
109 EventHeader eh = new EventHeader();
111 eh.setTimestamp("current-time");
112 eh.setEntityLink("entity-link");
113 eh.setAction("action!");
114 eh.setEventType("surprise");
115 eh.setDomain("PROD");
116 eh.setSourceName("source");
117 eh.setSequenceNumber("23");
118 eh.setSeverity("ALERT");
119 eh.setVersion("v12");
121 String res = sne.storeEventAndSendToJms(eh, object);
124 assertTrue(res.contains("\"cambria.partition\" : \"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
125 assertTrue(res.contains("\"event-header\""));
126 assertTrue(res.contains("\"id\" : \"123\""));
127 assertTrue(res.contains("\"timestamp\" : \"current-time\""));
128 assertTrue(res.contains("\"source-name\" : \"source\""));
129 assertTrue(res.contains("\"domain\" : \"PROD\""));
130 assertTrue(res.contains("\"sequence-number\" : \"23\""));
131 assertTrue(res.contains("\"severity\" : \"ALERT\""));
132 assertTrue(res.contains("\"event-type\" : \"surprise\""));
133 assertTrue(res.contains("\"version\" : \"v12\""));
134 assertTrue(res.contains("\"action\" : \"action!\""));
135 assertTrue(res.contains("\"entity-link\" : \"entity-link\""));
136 assertTrue(res.contains("\"entity\""));
137 assertTrue(res.contains("\"hello\""));
138 assertTrue(res.contains("\"chars\" : \"world\""));
139 assertTrue(res.contains("\"string\" : \"world\""));
140 assertTrue(res.contains("\"valueType\" : \"STRING\""));
143 @Test(expected = AAIException.class)
144 public void testStoreDynamicEventNullObj() throws AAIException {
145 DynamicEntity eventHeader = Mockito.mock(DynamicEntity.class);
146 DynamicJAXBContext notificationJaxbContext =
147 nodeIngestor.getContextForVersion(schemaVersions.getEdgeLabelVersion());
148 sne.storeDynamicEvent(notificationJaxbContext, "v12", eventHeader, null);
151 @Test(expected = Exception.class)
152 public void testStoreDynamicEventAAIException() throws Exception {
154 DynamicJAXBContext notificationJaxbContext =
155 nodeIngestor.getContextForVersion(schemaVersions.getEdgeLabelVersion());
156 DynamicEntity obj = Mockito.mock(DynamicEntity.class);
157 DynamicEntity eventHeader = Mockito.mock(DynamicEntity.class);
158 sne.storeDynamicEvent(notificationJaxbContext, "v12", eventHeader, obj);
161 @Test(expected = AAIException.class)
162 public void testStoreEventIntrospectorNullObj() throws Exception {
163 Loader loader = Mockito.mock(Loader.class);
164 sne.storeEventAndSendToJms(loader, null, null);
167 @Ignore("Stopped working since the model driven story")
169 public void testStoreEvent1Introspector() throws Exception {
170 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getEdgeLabelVersion());
171 Introspector eventHeader = loader.introspectorFromName("notification-event-header");
172 eventHeader.setValue("id", "123");
173 eventHeader.setValue("timestamp", "current-time");
174 eventHeader.setValue("entity-link", "entity-link");
175 eventHeader.setValue("action", "action!");
176 eventHeader.setValue("event-type", "surprise");
177 eventHeader.setValue("domain", "PROD");
178 eventHeader.setValue("source-name", "source");
179 eventHeader.setValue("sequence-number", "23");
180 eventHeader.setValue("severity", "ALERT");
181 eventHeader.setValue("version", "v12");
182 Introspector obj = loader.introspectorFromName("notification-event");
183 String res = sne.storeEventAndSendToJms(loader, eventHeader, obj);
186 assertTrue(res.contains("\"cambria.partition\":\"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
187 assertTrue(res.contains("\"event-header\""));
188 assertTrue(res.contains("\"id\":\"123\""));
189 assertTrue(res.contains("\"timestamp\":\"current-time\""));
190 assertTrue(res.contains("\"source-name\":\"source\""));
191 assertTrue(res.contains("\"domain\":\"PROD\""));
192 assertTrue(res.contains("\"sequence-number\":\"23\""));
193 assertTrue(res.contains("\"severity\":\"ALERT\""));
194 assertTrue(res.contains("\"event-type\":\"surprise\""));
195 assertTrue(res.contains("\"version\":\"v12\""));
196 assertTrue(res.contains("\"action\":\"action!\""));
197 assertTrue(res.contains("\"entity-link\":\"entity-link\""));
198 assertTrue(res.contains("\"notification-event\""));
201 @Ignore("Stopped working since the model driven story")
203 public void testStoreEventIntrospectorEmptyEventHeader() throws Exception {
204 Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getEdgeLabelVersion());
205 Introspector eventHeader = loader.introspectorFromName("notification-event-header");
206 Introspector obj = loader.introspectorFromName("notification-event");
208 String res = sne.storeEventAndSendToJms(loader, eventHeader, obj);
211 assertTrue(res.contains("\"cambria.partition\":\"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
212 assertTrue(res.contains("\"event-header\""));
213 assertTrue(res.contains("\"id\""));
214 assertTrue(res.contains("\"timestamp\""));
216 res.contains("\"source-name\":\"" + AAIConfig.get("aai.notificationEvent.default.sourceName") + "\""));
217 assertTrue(res.contains("\"domain\":\"" + AAIConfig.get("aai.notificationEvent.default.domain") + "\""));
218 assertTrue(res.contains(
219 "\"sequence-number\":\"" + AAIConfig.get("aai.notificationEvent.default.sequenceNumber") + "\""));
220 assertTrue(res.contains("\"severity\":\"" + AAIConfig.get("aai.notificationEvent.default.severity") + "\""));
221 assertTrue(res.contains("\"event-type\":\"" + AAIConfig.get("aai.notificationEvent.default.eventType") + "\""));
222 assertTrue(res.contains("\"version\":\"" + AAIConfig.get("aai.notificationEvent.default.version") + "\""));
223 assertTrue(res.contains("\"action\":\"UNK\""));
224 assertTrue(res.contains("\"entity-link\":\"UNK\""));
225 assertTrue(res.contains("\"notification-event\""));