2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright 2018 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
28 import org.junit.Before;
\r
29 import org.junit.Test;
\r
30 import org.junit.runner.RunWith;
\r
31 import org.mockito.InjectMocks;
\r
32 import org.mockito.Mock;
\r
33 import org.mockito.MockitoAnnotations;
\r
34 import org.onap.universalvesadapter.Application;
\r
35 import org.onap.universalvesadapter.exception.VesException;
\r
36 import org.onap.universalvesadapter.service.VESAdapterInitializer;
\r
37 import org.onap.universalvesadapter.utils.CollectorConfigPropertyRetrival;
\r
38 import org.powermock.api.mockito.PowerMockito;
\r
39 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
40 import org.powermock.modules.junit4.PowerMockRunner;
\r
41 import org.slf4j.Logger;
\r
42 import org.slf4j.LoggerFactory;
\r
43 import org.springframework.boot.test.context.SpringBootTest;
\r
45 @RunWith(PowerMockRunner.class)
\r
46 @SpringBootTest(classes = Application.class)
\r
47 public class UniversalEventAdapterTest {
\r
49 private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger");
\r
52 private VESAdapterInitializer vesAdapterInitializer;
\r
55 private UniversalEventAdapter universalVesAdapter;
\r
58 public void init() {
\r
59 MockitoAnnotations.initMocks(this);
\r
62 @PrepareForTest({ CollectorConfigPropertyRetrival.class })
\r
64 public void testtransform() {
\r
66 StringBuffer incomingJsonString = new StringBuffer("{\n" + " \"rule-id\": \"12121\",\n"
\r
67 + " \"notification\": {\n" + " \"event-time\": \"2018-03-15T08:15:32.000Z\",\n"
\r
68 + " \"notification-id\": \"2541256\",\n" + " \"message\": {\n"
\r
69 + " \"topic\":\"resource\",\n" + " \"object-type\":\"onu\", \n"
\r
70 + " \"version\": \"v1\", \n" + " \"operation\": \"create\", \n"
\r
71 + " \"target\": \"ont/ont=23hk1231231232\", \n" + " \"content\": {\n"
\r
72 + " \"onu\": {\n" + " \"sn\": \"48575443FA637D1A\",\n"
\r
73 + " \"refParentNE\": \"550e8400-e29b-41d4-a716-446655440000\",\n"
\r
74 + " \"refParentNeNativeId\": \"FDN\",\n"
\r
75 + " \"refParentLTP\": \"8c0db89e-218c-4e18-b0de-7a6788b3dda4\",\n"
\r
76 + " \"refParentLTPNativeId\": \"FDN\",\n"
\r
77 + " \"onuId\": \"213\",\n" + " \"accessID\": \"HG65875420001\"\n"
\r
78 + " }\n" + " }\n" + " }\n" + " }\n" + "}");
\r
79 Map<String, String> testMap = new HashMap<String, String>();
\r
80 testMap.put("defaultMappingFile-" + Thread.currentThread().getName(),
\r
81 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
\r
82 + "<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
83 + " <json:reader rootName=\"vesevent\" keyWhitspaceReplacement=\"-\">\n"
\r
84 + " <json:keyMap>\n"
\r
85 + " <json:key from=\"date&time\" to=\"date-and-time\" />\n"
\r
86 + " </json:keyMap>\n" + " </json:reader>\n"
\r
87 + " <jb:bean class=\"org.onap.dcaegen2.ves.domain.ves7_0.VesEvent\""
\r
88 + " beanId=\"vesEvent\" createOnElement=\"vesevent\">\n"
\r
89 + " <jb:wiring property=\"event\" beanIdRef=\"event\" />\n" + " </jb:bean>\n"
\r
90 + " <jb:bean class=\"org.onap.dcaegen2.ves.domain.ves7_0.Event\" "
\r
91 + "beanId=\"event\" createOnElement=\"vesevent\">\n"
\r
92 + " <jb:wiring property=\"commonEventHeader\" beanIdRef=\"commonEventHeader\" />\n"
\r
93 + " <jb:wiring property=\"pnfRegistrationFields\" beanIdRef=\"pnfRegistrationFields\" />\n"
\r
95 + " <jb:bean class=\"org.onap.dcaegen2.ves.domain.ves7_0.CommonEventHeader\""
\r
96 + " beanId=\"commonEventHeader\" createOnElement=\"vesevent\">\n"
\r
97 + "<jb:expression property=\"version\">"
\r
98 + "org.onap.dcaegen2.ves.domain.ves7_0.CommonEventHeader.Version._4_0_1</jb:expression> \n"
\r
99 + "<jb:expression property=\"eventType\">\"pnfRegistration\"</jb:expression>\n"
\r
100 + "<jb:expression property=\"vesEventListenerVersion\">"
\r
101 + "org.onap.dcaegen2.ves.domain.ves7_0.CommonEventHeader.VesEventListenerVersion._7_0_1</jb:expression>\n"
\r
102 + " <jb:expression property=\"eventId\" execOnElement=\"vesevent\">"
\r
103 + "\"registration_\"+commonEventHeader.ts1</jb:expression>\n"
\r
104 + "<jb:expression property=\"reportingEntityName\">\"VESMapper\"</jb:expression>\n"
\r
105 + " <jb:expression property=\"domain\">"
\r
106 + "org.onap.dcaegen2.ves.domain.ves7_0.CommonEventHeader.Domain.PNF_REGISTRATION</jb:expression>\n"
\r
107 + " <jb:expression property=\"eventName\" execOnElement=\"vesevent\">"
\r
108 + "commonEventHeader.domain</jb:expression>\n"
\r
109 + "<jb:value property=\"sequence\" data=\"0\" default=\"0\" decoder=\"Long\" />\n"
\r
110 + "<jb:expression property=\"lastEpochMicrosec\" execOnElement=\"vesevent\">"
\r
111 + "commonEventHeader.ts1</jb:expression>\n"
\r
112 + " <jb:expression property=\"startEpochMicrosec\" execOnElement=\"vesevent\">"
\r
113 + "commonEventHeader.ts1</jb:expression>\n" + " <jb:expression property=\"priority\">"
\r
114 + "org.onap.dcaegen2.ves.domain.ves7_0.CommonEventHeader.Priority.NORMAL</jb:expression>\n"
\r
115 + " <jb:value property=\"sourceName\" data=\"notification/message/target\" />\n"
\r
117 + " <jb:bean class=\"org.onap.dcaegen2.ves.domain.ves7_0.PnfRegistrationFields\""
\r
118 + " beanId=\"pnfRegistrationFields\" createOnElement=\"vesevent\">\n" + " \n"
\r
119 + " <jb:expression property=\"pnfRegistrationFieldsVersion\">"
\r
120 + "org.onap.dcaegen2.ves.domain.ves7_0.PnfRegistrationFields.PnfRegistrationFieldsVersion._2_0"
\r
121 + "</jb:expression>\n"
\r
122 + " <jb:value property=\"serialNumber\" data=\"notification/message/content/onu/sn\" />\n"
\r
123 + " \n" + " </jb:bean>\n" + "</smooks-resource-list>");
\r
126 vesAdapterInitializer.setMappingFiles(testMap);
\r
128 String identifiertest[] = CollectorConfigPropertyRetrival.getProperyArray("identifier", "kvTest.json");
\r
129 PowerMockito.mockStatic(CollectorConfigPropertyRetrival.class);
\r
130 PowerMockito.when(CollectorConfigPropertyRetrival.getProperyArray("identifier", null))
\r
131 .thenReturn(identifiertest);
\r
133 String actualResult = universalVesAdapter.transform(incomingJsonString.toString());
\r
134 assertNotNull(actualResult);
\r
135 assertNotEquals("", actualResult);
\r
136 } catch (VesException exception) {
\r
137 errorLogger.error("Error occurred : {}", exception);
\r