2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright 2018-2019 TechMahindra
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.onap.universalvesadapter.adapter;
\r
23 import static org.junit.Assert.assertNotEquals;
\r
24 import static org.junit.Assert.assertNotNull;
\r
26 import java.util.HashMap;
\r
27 import java.util.Map;
\r
29 import org.junit.Before;
\r
30 import org.junit.Test;
\r
31 import org.junit.runner.RunWith;
\r
32 import org.mockito.InjectMocks;
\r
33 import org.mockito.Mock;
\r
34 import org.mockito.MockitoAnnotations;
\r
35 import org.onap.universalvesadapter.Application;
\r
36 import org.onap.universalvesadapter.exception.VesException;
\r
37 import org.onap.universalvesadapter.service.VESAdapterInitializer;
\r
38 import org.onap.universalvesadapter.utils.CollectorConfigPropertyRetrival;
\r
39 import org.powermock.api.mockito.PowerMockito;
\r
40 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
41 import org.powermock.modules.junit4.PowerMockRunner;
\r
42 import org.slf4j.Logger;
\r
43 import org.slf4j.LoggerFactory;
\r
44 import org.springframework.boot.test.context.SpringBootTest;
\r
46 @RunWith(PowerMockRunner.class)
\r
47 @SpringBootTest(classes = Application.class)
\r
48 public class UniversalEventAdapterTest {
\r
50 private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger");
\r
53 private VESAdapterInitializer vesAdapterInitializer;
\r
56 private UniversalEventAdapter universalVesAdapter;
\r
59 public void init() {
\r
60 MockitoAnnotations.initMocks(this);
\r
63 @PrepareForTest({CollectorConfigPropertyRetrival.class})
\r
65 public void testtransform() {
\r
67 StringBuffer incomingJsonString = new StringBuffer("{\n" + " \"rule-id\": \"12121\",\n"
\r
68 + " \"notification\": {\n"
\r
69 + " \"event-time\": \"2018-03-15T08:15:32.000Z\",\n"
\r
70 + " \"notification-id\": \"2541256\",\n" + " \"message\": {\n"
\r
71 + " \"topic\":\"resource\",\n"
\r
72 + " \"object-type\":\"onu\", \n"
\r
73 + " \"version\": \"v1\", \n"
\r
74 + " \"operation\": \"create\", \n"
\r
75 + " \"target\": \"ont/ont=23hk1231231232\", \n"
\r
76 + " \"content\": {\n" + " \"onu\": {\n"
\r
77 + " \"sn\": \"48575443FA637D1A\",\n"
\r
78 + " \"refParentNE\": \"550e8400-e29b-41d4-a716-446655440000\",\n"
\r
79 + " \"refParentNeNativeId\": \"FDN\",\n"
\r
80 + " \"refParentLTP\": \"8c0db89e-218c-4e18-b0de-7a6788b3dda4\",\n"
\r
81 + " \"refParentLTPNativeId\": \"FDN\",\n"
\r
82 + " \"onuId\": \"213\",\n"
\r
83 + " \"accessID\": \"HG65875420001\"\n" + " }\n"
\r
84 + " }\n" + " }\n" + " }\n" + "}");
\r
85 Map<String, String> testMap = new HashMap<String, String>();
\r
86 testMap.put("defaultMappingFile-" + Thread.currentThread().getName(),
\r
87 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
\r
88 + "<smooks-resource-list xmlns=\"http://www.milyn.org/xsd/smooks-1.1.xsd\" xmlns:jb=\"http://www.milyn.org/xsd/smooks/javabean-1.4.xsd\" xmlns:json=\"http://www.milyn.org/xsd/smooks/json-1.1.xsd\">\n"
\r
89 + " <json:reader rootName=\"vesevent\" keyWhitspaceReplacement=\"-\">\n"
\r
90 + " <json:keyMap>\n"
\r
91 + " <json:key from=\"date&time\" to=\"date-and-time\" />\n"
\r
92 + " </json:keyMap>\n" + " </json:reader>\n"
\r
93 + " <jb:bean class=\"org.onap.dcaegen2.ves.domain.ves70.VesEvent\""
\r
94 + " beanId=\"vesEvent\" createOnElement=\"vesevent\">\n"
\r
95 + " <jb:wiring property=\"event\" beanIdRef=\"event\" />\n"
\r
97 + " <jb:bean class=\"org.onap.dcaegen2.ves.domain.ves70.Event\" "
\r
98 + "beanId=\"event\" createOnElement=\"vesevent\">\n"
\r
99 + " <jb:wiring property=\"commonEventHeader\" beanIdRef=\"commonEventHeader\" />\n"
\r
100 + " <jb:wiring property=\"pnfRegistrationFields\" beanIdRef=\"pnfRegistrationFields\" />\n"
\r
102 + " <jb:bean class=\"org.onap.dcaegen2.ves.domain.ves70.CommonEventHeader\""
\r
103 + " beanId=\"commonEventHeader\" createOnElement=\"vesevent\">\n"
\r
104 + "<jb:expression property=\"version\">"
\r
105 + "org.onap.dcaegen2.ves.domain.ves70.CommonEventHeader.Version._4_0_1</jb:expression> \n"
\r
106 + "<jb:expression property=\"eventType\">\"pnfRegistration\"</jb:expression>\n"
\r
107 + "<jb:expression property=\"vesEventListenerVersion\">"
\r
108 + "org.onap.dcaegen2.ves.domain.ves70.CommonEventHeader.VesEventListenerVersion._7_0_1"
\r
109 + "</jb:expression>\n"
\r
110 + " <jb:expression property=\"eventId\" execOnElement=\"vesevent\">"
\r
111 + "\"registration_\"+commonEventHeader.ts1</jb:expression>\n"
\r
112 + "<jb:expression property=\"reportingEntityName\">\"VESMapper\"</jb:expression>\n"
\r
113 + " <jb:expression property=\"domain\">"
\r
114 + "org.onap.dcaegen2.ves.domain.ves70.CommonEventHeader.Domain.PNF_REGISTRATION"
\r
115 + "</jb:expression>\n"
\r
116 + " <jb:expression property=\"eventName\" execOnElement=\"vesevent\">"
\r
117 + "commonEventHeader.domain</jb:expression>\n"
\r
118 + "<jb:value property=\"sequence\" data=\"0\" default=\"0\" decoder=\"Long\" />\n"
\r
119 + "<jb:expression property=\"lastEpochMicrosec\" execOnElement=\"vesevent\">"
\r
120 + "commonEventHeader.ts1</jb:expression>\n"
\r
121 + " <jb:expression property=\"startEpochMicrosec\" execOnElement=\"vesevent\">"
\r
122 + "commonEventHeader.ts1</jb:expression>\n"
\r
123 + " <jb:expression property=\"priority\">"
\r
124 + "org.onap.dcaegen2.ves.domain.ves70.CommonEventHeader.Priority.NORMAL</jb:expression>\n"
\r
125 + " <jb:value property=\"sourceName\" data=\"notification/message/target\" />\n"
\r
127 + " <jb:bean class=\"org.onap.dcaegen2.ves.domain.ves70.PnfRegistrationFields\""
\r
128 + " beanId=\"pnfRegistrationFields\" createOnElement=\"vesevent\">\n"
\r
130 + " <jb:expression property=\"pnfRegistrationFieldsVersion\">"
\r
131 + "org.onap.dcaegen2.ves.domain.ves70.PnfRegistrationFields.PnfRegistrationFieldsVersion._2_0"
\r
132 + "</jb:expression>\n"
\r
133 + " <jb:value property=\"serialNumber\" data=\"notification/message/content/onu/sn\" />\n"
\r
134 + " \n" + " </jb:bean>\n" + "</smooks-resource-list>");
\r
137 vesAdapterInitializer.setMappingFiles(testMap);
\r
139 String [] identifiertest =
\r
140 CollectorConfigPropertyRetrival.getProperyArray("identifier", "kvTest.json");
\r
141 PowerMockito.mockStatic(CollectorConfigPropertyRetrival.class);
\r
142 PowerMockito.when(CollectorConfigPropertyRetrival.getProperyArray("identifier", null))
\r
143 .thenReturn(identifiertest);
\r
145 String actualResult = universalVesAdapter.transform(incomingJsonString.toString());
\r
146 assertNotNull(actualResult);
\r
147 assertNotEquals("", actualResult);
\r
148 } catch (VesException exception) {
\r
149 errorLogger.error("Error occurred : {}", exception);
\r