fix oauth code
[ccsdk/features.git] / sdnr / wt / mountpoint-registrar / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / mountpointregistrar / test / consumer / TestStrimziKafkaFaultVESMsgConsumer.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.consumer;
20
21 import java.io.IOException;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.config.GeneralConfigForTest;
26 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.fault.StrimziKafkaFaultVESMsgConsumer;
27
28 public class TestStrimziKafkaFaultVESMsgConsumer {
29
30     private static final String DEFAULT_SDNRUSER = "admin";
31     private static final String DEFAULT_SDNRPASSWD = "admin";
32     private static final String DEFAULT_SDNRBASEURL = "http://localhost:8181";
33     private static final String CONFIGURATIONFILE = "test2.properties";
34
35     // @formatter:off
36     private static final String faultVESMsg = ""
37             + "{\"event\":" + " {\"commonEventHeader\":"
38             + "         {       \"domain\":\"fault\","
39             + "                 \"eventId\":\"1e9a28bcd119_50007_2019-11-20T14:59:47.3Z\","
40             + "                 \"eventName\":\"fault_O_RAN_COMPONENT_Alarms\","
41             + "                 \"eventType\":\"O_RAN_COMPONENT_Alarms\","
42             + "                 \"sequence\":1,"
43             + "                 \"priority\":\"Low\","
44             + "                 \"reportingEntityId\":\"\","
45             + "                 \"reportingEntityName\":\"1e9a28bcd119_50007\","
46             + "                 \"sourceId\":\"\","
47             + "                 \"sourceName\":\"1e9a28bcd119_50007\","
48             + "                 \"startEpochMicrosec\":1614004128699785,"
49             + "                 \"lastEpochMicrosec\":1614004128699785,"
50             + "                 \"nfNamingCode\":\"sdn controller\","
51             + "                 \"nfVendorName\":\"sdn\","
52             + "                 \"timeZoneOffset\":\"+00:00\","
53             + "                 \"version\":\"4.0.1\","
54             + "                 \"vesEventListenerVersion\":\"7.0.1\""
55             + "         },"
56             + "         \"faultFields\":"
57             + "         {"
58             + "                 \"faultFieldsVersion\":\"4.0\","
59             + "                 \"alarmCondition\":\"8\","
60             + "                 \"alarmInterfaceA\":\"dkom32\","
61             + "                 \"eventSourceType\":\"O_RAN_COMPONENT\","
62             + "                 \"specificProblem\":\"dsonj32 don32 mdson32pk654\","
63             + "                 \"eventSeverity\":\"@eventSeverity@\","
64             + "                 \"vfStatus\":\"Active\","
65             + "                 \"alarmAdditionalInformation\":"
66             + "                 {"
67             + "                         \"eventTime\":\"2019-11-20T14:59:47.3Z\","
68             + "                         \"equipType\":\"O-RAN-sim\","
69             + "                         \"vendor\":\"Melacon\","
70             + "                         \"model\":\"Simulated Device\""
71             + "                 }"
72             + "         }"
73             + " }"
74             + "}";
75     // @formatter:on
76     // @formatter:off
77     private static final String faultVESMsg_Incomplete = ""
78             + "{\"event\":"
79             + " {\"commonEventHeader\":"
80             + "         {       \"domain\":\"fault\","
81             + "                 \"eventId\":\"1e9a28bcd119_50007_2019-11-20T14:59:47.3Z\","
82             + "                 \"eventName\":\"fault_O_RAN_COMPONENT_Alarms\","
83             + "                 \"eventType\":\"O_RAN_COMPONENT_Alarms\","
84             + "                 \"sequence\":1,"
85             + "                 \"priority\":\"Low\","
86             + "                 \"reportingEntityId\":\"\","
87             + "                 \"reportingEntityName\":\"1e9a28bcd119_50007\","
88             + "                 \"sourceId\":\"\","
89             + "                 \"sourceName\":\"1e9a28bcd119_50007\","
90             + "                 \"startEpochMicrosec\":1612349525626,"
91             + "                 \"lastEpochMicrosec\":1612349525626,"
92             + "                 \"nfNamingCode\":\"sdn controller\","
93             + "                 \"nfVendorName\":\"sdn\","
94             + "                 \"timeZoneOffset\":\"+00:00\","
95             + "                 \"version\":\"4.0.1\","
96             + "                 \"vesEventListenerVersion\":\"7.0.1\","
97             + "         },"
98             + "         \"faultFields\":"
99             + "         {"
100             + "                 \"faultFieldsVersion\":\"4.0\","
101             + "                 \"alarmCondition\":\"8\","
102             + "                 \"alarmInterfaceA\":\"dkom32\","
103             + "                 \"eventSourceType\":\"O_RAN_COMPONENT\","
104             + "                 \"specificProblem\":\"dsonj32 don32 mdson32pk654\","
105             + "                 \"eventSeverity\":\"CRITICAL\","
106             + "                 \"vfStatus\":\"Active\","
107             + "                 \"alarmAdditionalInformation\":"
108             + "                 {"
109             + "                         \"eventTime\":\"2019-11-20T14:59:47.3Z\","
110             + "                         \"equipType\":\"O-RAN-sim\","
111             + "                         \"vendor\":\"Melacon\","
112             + "                         \"model\":\"Simulated Device\""
113             + "                 }"
114             + "         }"
115             + " }"
116             + "}";
117     // @formatter:on
118
119     private GeneralConfigForTest cfgTest;
120
121     @Before
122     public void before() throws IOException {
123         cfgTest = new GeneralConfigForTest(CONFIGURATIONFILE);
124     }
125
126     @After
127     public void after() {
128         cfgTest.close();
129     }
130
131
132     @Test
133     public void test() throws IOException {
134         StrimziKafkaFaultVESMsgConsumer faultMsgConsumer = new StrimziKafkaFaultVESMsgConsumer(cfgTest.getCfg());
135         try {
136
137             faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "CRITICAL"));
138             faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "Major"));
139             faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "minor"));
140             faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "NonAlarmed"));
141             faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "warning"));
142             faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "Unknown"));
143             faultMsgConsumer.processMsg(faultVESMsg_Incomplete);
144         } catch (Exception e) {
145             e.printStackTrace();
146             System.out.println("Exception while processing Fault Message - " + e.getMessage());
147         }
148     }
149
150 }