Support 7.2.1 VES in TCAGEN2
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-tca-web / src / test / java / org / onap / dcae / analytics / tca / web / service / TcaProcessingServiceImplTest.java
1 /*
2  * ===========LICENSE_START========================================================
3  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4  * Copyright (c) 2022 Wipro Limited Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * 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
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END=========================================================
18  *
19  */
20
21 package org.onap.dcae.analytics.tca.web.service;
22
23 import static org.onap.dcae.analytics.tca.model.util.json.TcaModelJsonConversion.TCA_POLICY_JSON_FUNCTION;
24
25 import java.util.Arrays;
26 import java.util.List;
27
28 import org.junit.jupiter.api.Test;
29 import org.mockito.Mockito;
30 import org.onap.dcae.analytics.tca.core.exception.AnalyticsParsingException;
31 import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentContext;
32 import org.onap.dcae.analytics.tca.core.service.TcaAbatementContext;
33 import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext;
34 import org.onap.dcae.analytics.tca.model.facade.TcaAlert;
35 import org.onap.dcae.analytics.tca.model.policy.TcaPolicy;
36 import org.onap.dcae.analytics.tca.web.domain.TcaPolicyWrapper;
37
38 import com.fasterxml.jackson.databind.ObjectMapper;
39
40 /**
41  * @author Rajiv Singla
42  */
43 class TcaProcessingServiceImplTest {
44
45 //  @Autowired
46 //  Environment environment;
47
48     public List<TcaPolicy> convertTcaPolicy(String tcaPolicyString) {
49       return TCA_POLICY_JSON_FUNCTION.apply(tcaPolicyString).orElseThrow(
50                 () -> new AnalyticsParsingException("Unable to parse Tca Policy String: " + tcaPolicyString,
51                         new IllegalArgumentException()));
52     }
53         
54     String policy = "[{\"domain\":\"measurementsForVfScaling\",\"metricsPerEventName\":[{\"eventName\":\"Mfvs_eNodeB_RANKPI\",\"controlLoopSchemaType\":\"VNF\",\"policyScope\":\"resource=vFirewall;type=configuration\",\"policyName\":\"configuration.dcae.microservice.tca.xml\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8\",\"closedLoopEventStatus\":\"ONSET\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\"thresholdValue\":4000,\"direction\":\"LESS_OR_EQUAL\",\"severity\":\"MAJOR\"},{\"closedLoopControlName\":\"CL-FRWL-HIGH-TRAFFIC-SIG-EA36FE84-9342-5E13-A656-EC5F21309A09\",\"closedLoopEventStatus\":\"ONSET\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\"thresholdValue\":20000,\"direction\":\"GREATER_OR_EQUAL\",\"severity\":\"CRITICAL\"},{\"closedLoopControlName\":\"CL-FRWL-HIGH-TRAFFIC-SIG-EA36FE84-9342-5E13-A656-EC5F21309A09\",\"closedLoopEventStatus\":\"ABATED\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\"thresholdValue\":0,\"direction\":\"EQUAL\",\"severity\":\"CRITICAL\"}]},{\"eventName\":\"vLoadBalancer\",\"controlLoopSchemaType\":\"VNF\",\"policyScope\":\"resource=vLoadBalancer;type=configuration\",\"policyName\":\"configuration.dcae.microservice.tca.xml\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A\",\"closedLoopEventStatus\":\"ONSET\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\"thresholdValue\":500,\"direction\":\"LESS_OR_EQUAL\",\"severity\":\"MAJOR\"},{\"closedLoopControlName\":\"CL-LBAL-LOW-TRAFFIC-SIG-0C5920A6-B564-8035-C878-0E814352BC2B\",\"closedLoopEventStatus\":\"ONSET\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\"thresholdValue\":5000,\"direction\":\"GREATER_OR_EQUAL\",\"severity\":\"CRITICAL\"}]},{\"eventName\":\"virtualVMEventName\",\"controlLoopSchemaType\":\"VM\",\"policyScope\":\"resource=virtualVM;type=configuration\",\"policyName\":\"configuration.dcae.microservice.tca.xml\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A\",\"closedLoopEventStatus\":\"ONSET\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\"thresholdValue\":500,\"direction\":\"LESS_OR_EQUAL\",\"severity\":\"MAJOR\"}]}]},{\"domain\":\"measurement\",\"metricsPerEventName\":[{\"eventName\":\"vFirewallBroadcastPackets\",\"controlLoopSchemaType\":\"VM\",\"policyScope\":\"DCAE\",\"policyName\":\"DCAE.Config_tca-hi-lo\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementFields.nicPerformanceArray[*].receivedTotalPacketsDelta\",\"thresholdValue\":300,\"direction\":\"LESS_OR_EQUAL\",\"severity\":\"MAJOR\",\"closedLoopEventStatus\":\"ABATED\"},{\"closedLoopControlName\":\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementFields.nicPerformanceArray[*].receivedTotalPacketsDelta\",\"thresholdValue\":700,\"direction\":\"GREATER_OR_EQUAL\",\"severity\":\"CRITICAL\",\"closedLoopEventStatus\":\"ONSET\"}]},{\"eventName\":\"vLoadBalancer\",\"controlLoopSchemaType\":\"VM\",\"policyScope\":\"DCAE\",\"policyName\":\"DCAE.Config_tca-hi-lo\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementFields.nicPerformanceArray[*].receivedTotalPacketsDelta\",\"thresholdValue\":300,\"direction\":\"GREATER_OR_EQUAL\",\"severity\":\"CRITICAL\",\"closedLoopEventStatus\":\"ONSET\"}]},{\"eventName\":\"Measurement_vGMUX\",\"controlLoopSchemaType\":\"VNF\",\"policyScope\":\"DCAE\",\"policyName\":\"DCAE.Config_tca-hi-lo\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementFields.additionalMeasurements[*].arrayOfFields[0].value\",\"thresholdValue\":0,\"direction\":\"EQUAL\",\"severity\":\"MAJOR\",\"closedLoopEventStatus\":\"ABATED\"},{\"closedLoopControlName\":\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementFields.additionalMeasurements[*].arrayOfFields[0].value\",\"thresholdValue\":0,\"direction\":\"GREATER\",\"severity\":\"CRITICAL\",\"closedLoopEventStatus\":\"ONSET\"}]}]}]";
55
56     String cefMessage = "{\r\n" + 
57                 "  \"event\": {\r\n" + 
58                 "    \"commonEventHeader\": {\r\n" + 
59                 "      \"domain\": \"measurementsForVfScaling\",\r\n" + 
60                 "      \"eventId\": \"UC1-SCL01081-1492639920787\",\r\n" + 
61                 "      \"eventName\": \"Mfvs_eNodeB_RANKPI\",\r\n" + 
62                 "      \"lastEpochMicrosec\": 1492639920787,\r\n" + 
63                 "      \"nfNamingCode\": \"ENBE\",\r\n" + 
64                 "      \"priority\": \"Normal\",\r\n" + 
65                 "      \"reportingEntityId\": \"\",\r\n" + 
66                 "      \"reportingEntityName\": \"vtc2e7admn2\",\r\n" + 
67                 "      \"sequence\": 0,\r\n" + 
68                 "      \"sourceId\": \"SCL01081_9B_1\",\r\n" + 
69                 "      \"sourceName\": \"SCL01081\",\r\n" + 
70                 "      \"startEpochMicrosec\": 1492639920787,\r\n" + 
71                 "      \"version\": 3.0\r\n" + 
72                 "    },\r\n" + 
73                 "    \"measurementsForVfScalingFields\": {\r\n" + 
74                 "      \"additionalFields\": [\r\n" + 
75                 "        {\r\n" + 
76                 "          \"name\": \"software_version \",\r\n" + 
77                 "          \"value\": \"version1\"\r\n" + 
78                 "        },\r\n" + 
79                 "        {\r\n" + 
80                 "          \"name\": \"vendor \",\r\n" + 
81                 "          \"value\": \"Ericsson \"\r\n" + 
82                 "        }\r\n" + 
83                 "      ],\r\n" + 
84                 "      \"additionalMeasurements\": [\r\n" + 
85                 "        {\r\n" + 
86                 "          \"name\": \"OaaS_UC1_EricssonSleepingCell\",\r\n" + 
87                 "          \"arrayOfFields\": [\r\n" + 
88                 "            {\r\n" + 
89                 "              \"name\": \"PMRAATTCBRA\",\r\n" + 
90                 "              \"value\": \"1353\"\r\n" + 
91                 "            },\r\n" + 
92                 "            {\r\n" + 
93                 "              \"name\": \"PMRASUCCCBRA\",\r\n" + 
94                 "              \"value\": \"1351\"\r\n" + 
95                 "            },\r\n" + 
96                 "            {\r\n" + 
97                 "              \"name\": \"PMCELLDOWNTIMEAUTO\",\r\n" + 
98                 "              \"value\": \"0\"\r\n" + 
99                 "            },\r\n" + 
100                 "            {\r\n" + 
101                 "              \"name\": \"PMCELLDOWNTIMEMAN\",\r\n" + 
102                 "              \"value\": \"0\"\r\n" + 
103                 "            },\r\n" + 
104                 "            {\r\n" + 
105                 "              \"name\": \"PMRRCCONNESTABATT\",\r\n" + 
106                 "              \"value\": \"297\"\r\n" + 
107                 "            },\r\n" + 
108                 "            {\r\n" + 
109                 "              \"name\": \"PMRRCCONNESTABSUCC\",\r\n" + 
110                 "              \"value\": \"297\"\r\n" + 
111                 "            }\r\n" + 
112                 "          ]\r\n" + 
113                 "        }\r\n" + 
114                 "      ],\r\n" + 
115                 "      \"vNicPerformanceArray\": [\r\n" + 
116                 "        {\r\n" + 
117                 "          \"receivedBroadcastPacketsAccumulated\": 5000,\r\n" + 
118                 "          \"receivedBroadcastPacketsDelta\": 5,\r\n" + 
119                 "          \"receivedDiscardedPacketsAccumulated\": 12,\r\n" + 
120                 "          \"receivedDiscardedPacketsDelta\": 2,\r\n" + 
121                 "          \"receivedErrorPacketsAccumulated\": 2,\r\n" + 
122                 "          \"receivedErrorPacketsDelta\": 1,\r\n" + 
123                 "          \"valuesAreSuspect\": false,\r\n" + 
124                 "          \"vNicIdentifier\": \"someVNicIdentifier\"\r\n" + 
125                 "        }\r\n" + 
126                 "      ],\r\n" + 
127                 "      \"measurementInterval\": 900,\r\n" + 
128                 "      \"measurementsForVfScalingVersion\": 2.0\r\n" + 
129                 "    }\r\n" + 
130                 "  }\r\n" + 
131                 "}\r\n" + 
132                 "";
133
134     String cefV7Message = "{\r\n" + 
135                 "  \"event\": {\r\n" + 
136                 "    \"commonEventHeader\": {\r\n" + 
137                 "      \"domain\": \"measurement\",\r\n" + 
138                 "      \"eventId\": \"UC1-SCL01081-1492639920787\",\r\n" + 
139                 "      \"eventName\": \"vFirewallBroadcastPackets\",\r\n" + 
140                 "      \"lastEpochMicrosec\": 1492639920787,\r\n" + 
141                 "      \"nfNamingCode\": \"ENBE\",\r\n" + 
142                 "      \"priority\": \"Normal\",\r\n" + 
143                 "      \"reportingEntityId\": \"\",\r\n" + 
144                 "      \"reportingEntityName\": \"vtc2e7admn2\",\r\n" + 
145                 "      \"sequence\": 0,\r\n" + 
146                 "      \"sourceId\": \"SCL01081_9B_1\",\r\n" + 
147                 "      \"sourceName\": \"SCL01081\",\r\n" + 
148                 "      \"startEpochMicrosec\": 1492639920787,\r\n" + 
149                 "      \"version\": 3.0,\r\n" + 
150                 "      \"vesEventListenerVersion\":\"7.2.1\"\r\n" +
151                 "    },\r\n" + 
152                 "    \"measurementFields\": {\r\n" + 
153                 "      \"additionalFields\": [\r\n" + 
154                 "        {\r\n" + 
155                 "          \"name\": \"software_version \",\r\n" + 
156                 "          \"value\": \"version1\"\r\n" + 
157                 "        },\r\n" + 
158                 "        {\r\n" + 
159                 "          \"name\": \"vendor \",\r\n" + 
160                 "          \"value\": \"Ericsson \"\r\n" + 
161                 "        }\r\n" + 
162                 "      ],\r\n" + 
163                 "      \"additionalMeasurements\": [\r\n" + 
164                 "        {\r\n" + 
165                 "          \"name\": \"OaaS_UC1_EricssonSleepingCell\",\r\n" + 
166                 "          \"arrayOfFields\": [\r\n" + 
167                 "            {\r\n" + 
168                 "              \"name\": \"PMRAATTCBRA\",\r\n" + 
169                 "              \"value\": \"1353\"\r\n" + 
170                 "            },\r\n" + 
171                 "            {\r\n" + 
172                 "              \"name\": \"PMRASUCCCBRA\",\r\n" + 
173                 "              \"value\": \"1351\"\r\n" + 
174                 "            },\r\n" + 
175                 "            {\r\n" + 
176                 "              \"name\": \"PMCELLDOWNTIMEAUTO\",\r\n" + 
177                 "              \"value\": \"0\"\r\n" + 
178                 "            },\r\n" + 
179                 "            {\r\n" + 
180                 "              \"name\": \"PMCELLDOWNTIMEMAN\",\r\n" + 
181                 "              \"value\": \"0\"\r\n" + 
182                 "            },\r\n" + 
183                 "            {\r\n" + 
184                 "              \"name\": \"PMRRCCONNESTABATT\",\r\n" + 
185                 "              \"value\": \"297\"\r\n" + 
186                 "            },\r\n" + 
187                 "            {\r\n" + 
188                 "              \"name\": \"PMRRCCONNESTABSUCC\",\r\n" + 
189                 "              \"value\": \"297\"\r\n" + 
190                 "            }\r\n" + 
191                 "          ]\r\n" + 
192                 "        }\r\n" + 
193                 "      ],\r\n" + 
194                 "      \"nicPerformanceArray\": [\r\n" + 
195                 "        {\r\n" + 
196                 "          \"receivedBroadcastPacketsAccumulated\": 1002,\r\n" + 
197                 "          \"receivedBroadcastPacketsDelta\": 5,\r\n" + 
198                 "          \"receivedDiscardedPacketsAccumulated\": 12,\r\n" + 
199                 "          \"receivedDiscardedPacketsDelta\": 2,\r\n" + 
200                 "          \"receivedErrorPacketsAccumulated\": 2,\r\n" + 
201                 "          \"receivedErrorPacketsDelta\": 1,\r\n" + 
202                 "          \"valuesAreSuspect\": false,\r\n" + 
203                 "          \"nicIdentifier\": \"someVNicIdentifier\"\r\n" + 
204                 "        }\r\n" + 
205                 "      ],\r\n" + 
206                 "      \"measurementInterval\": 900,\r\n" + 
207                 "      \"measurementFieldsVersion\": 2.0\r\n" + 
208                 "    }\r\n" + 
209                 "  }\r\n" + 
210                 "}\r\n" + 
211                 "";
212
213     String cefV7OnsetMessage = "{\r\n" +
214                 "  \"event\": {\r\n" +
215                 "    \"commonEventHeader\": {\r\n" +
216                 "      \"domain\": \"measurement\",\r\n" +
217                 "      \"eventId\": \"UC1-SCL01081-1492639920787\",\r\n" +
218                 "      \"eventName\": \"vFirewallBroadcastPackets\",\r\n" +
219                 "      \"lastEpochMicrosec\": 1492639920787,\r\n" +
220                 "      \"nfNamingCode\": \"ENBE\",\r\n" +
221                 "      \"priority\": \"Normal\",\r\n" +
222                 "      \"reportingEntityId\": \"\",\r\n" +
223                 "      \"reportingEntityName\": \"vtc2e7admn2\",\r\n" +
224                 "      \"sequence\": 0,\r\n" +
225                 "      \"sourceId\": \"SCL01081_9B_1\",\r\n" +
226                 "      \"sourceName\": \"SCL01081\",\r\n" +
227                 "      \"startEpochMicrosec\": 1492639920787,\r\n" +
228                 "      \"version\": 3.0,\r\n" +
229                 "      \"vesEventListenerVersion\":\"7.2.1\"\r\n" +
230                 "    },\r\n" +
231                 "    \"measurementFields\": {\r\n" +
232                 "      \"cpuUsageArray\": [\r\n" +
233                 "        {\r\n" +
234                 "          \"percentUsage\": 0,\r\n" +
235                 "          \"cpuIdentifier\": \"cpu1\",\r\n" +
236                 "          \"cpuIdle\": 100,\r\n" +
237                 "          \"cpuUsageSystem\": 0\r\n" +
238                 "        }\r\n" +
239                 "      ],\r\n" +  
240                 "      \"nicPerformanceArray\": [\r\n" +
241                 "        {\r\n" +
242                 "          \"receivedTotalPacketsDelta\": 1002,\r\n" +
243                 "          \"transmittedOctetsDelta\": 0,\r\n" +
244                 "          \"transmittedTotalPacketsDelta\": 0,\r\n" +
245                 "          \"receivedOctetsDelta\": 61200,\r\n" +
246                 "          \"valuesAreSuspect\": true,\r\n" +
247                 "          \"nicIdentifier\": \"someNicIdentifier\"\r\n" +
248                 "        }\r\n" +
249                 "      ],\r\n" +
250                 "      \"measurementInterval\": 900,\r\n" +
251                 "      \"measurementFieldsVersion\": 4.0\r\n" +
252                 "    }\r\n" +
253                 "  }\r\n" +
254                 "}\r\n" +
255                 "";    
256
257     String cefV7AbatementMessage = "{\r\n" +
258                 "  \"event\": {\r\n" +
259                 "    \"commonEventHeader\": {\r\n" +
260                 "      \"domain\": \"measurement\",\r\n" +
261                 "      \"eventId\": \"UC1-SCL01081-1492639920787\",\r\n" +
262                 "      \"eventName\": \"vFirewallBroadcastPackets\",\r\n" +
263                 "      \"lastEpochMicrosec\": 1492639920787,\r\n" +
264                 "      \"nfNamingCode\": \"ENBE\",\r\n" +
265                 "      \"priority\": \"Normal\",\r\n" +
266                 "      \"reportingEntityId\": \"\",\r\n" +
267                 "      \"reportingEntityName\": \"vtc2e7admn2\",\r\n" +
268                 "      \"sequence\": 0,\r\n" +
269                 "      \"sourceId\": \"SCL01081_9B_1\",\r\n" +
270                 "      \"sourceName\": \"SCL01081\",\r\n" +
271                 "      \"startEpochMicrosec\": 1492639920787,\r\n" +
272                 "      \"version\": 3.0,\r\n" +
273                 "      \"vesEventListenerVersion\":\"7.2.1\"\r\n" +
274                 "    },\r\n" +
275                 "    \"measurementFields\": {\r\n" +
276                 "      \"cpuUsageArray\": [\r\n" +
277                 "        {\r\n" +
278                 "          \"percentUsage\": 0,\r\n" +
279                 "          \"cpuIdentifier\": \"cpu1\",\r\n" +
280                 "          \"cpuIdle\": 100,\r\n" +
281                 "          \"cpuUsageSystem\": 0\r\n" +
282                 "        }\r\n" +
283                 "      ],\r\n" +
284                 "      \"nicPerformanceArray\": [\r\n" +
285                 "        {\r\n" +
286                 "          \"receivedTotalPacketsDelta\": 100,\r\n" +
287                 "          \"transmittedOctetsDelta\": 0,\r\n" +
288                 "          \"transmittedTotalPacketsDelta\": 0,\r\n" +
289                 "          \"receivedOctetsDelta\": 61200,\r\n" +
290                 "          \"valuesAreSuspect\": true,\r\n" +
291                 "          \"nicIdentifier\": \"someNicIdentifier\"\r\n" +
292                 "        }\r\n" +
293                 "      ],\r\n" +
294                 "      \"measurementInterval\": 900,\r\n" +
295                 "      \"measurementFieldsVersion\": 4.0\r\n" +
296                 "    }\r\n" +
297                 "  }\r\n" +
298                 "}\r\n" +
299                 "";
300
301     String cefViolationMessage = "{\r\n" + 
302                 "  \"event\": {\r\n" + 
303                 "    \"commonEventHeader\": {\r\n" + 
304                 "      \"domain\": \"measurementsForVfScaling\",\r\n" + 
305                 "      \"eventId\": \"UC1-SCL01081-1492639920787\",\r\n" + 
306                 "      \"eventName\": \"Mfvs_eNodeB_RANKPI\",\r\n" + 
307                 "      \"lastEpochMicrosec\": 1492639920787,\r\n" + 
308                 "      \"nfNamingCode\": \"ENBE\",\r\n" + 
309                 "      \"priority\": \"Normal\",\r\n" + 
310                 "      \"reportingEntityId\": \"\",\r\n" + 
311                 "      \"reportingEntityName\": \"vtc2e7admn2\",\r\n" + 
312                 "      \"sequence\": 0,\r\n" + 
313                 "      \"sourceId\": \"SCL01081_9B_1\",\r\n" + 
314                 "      \"sourceName\": \"SCL01081\",\r\n" + 
315                 "      \"startEpochMicrosec\": 1492639920787,\r\n" + 
316                 "      \"version\": 3.0\r\n" + 
317                 "    },\r\n" + 
318                 "    \"measurementsForVfScalingFields\": {\r\n" + 
319                 "      \"additionalFields\": [\r\n" + 
320                 "        {\r\n" + 
321                 "          \"name\": \"software_version \",\r\n" + 
322                 "          \"value\": \"version1\"\r\n" + 
323                 "        },\r\n" + 
324                 "        {\r\n" + 
325                 "          \"name\": \"vendor \",\r\n" + 
326                 "          \"value\": \"Ericsson \"\r\n" + 
327                 "        }\r\n" + 
328                 "      ],\r\n" + 
329                 "      \"additionalMeasurements\": [\r\n" + 
330                 "        {\r\n" + 
331                 "          \"name\": \"OaaS_UC1_EricssonSleepingCell\",\r\n" + 
332                 "          \"arrayOfFields\": [\r\n" + 
333                 "            {\r\n" + 
334                 "              \"name\": \"PMRAATTCBRA\",\r\n" + 
335                 "              \"value\": \"1353\"\r\n" + 
336                 "            },\r\n" + 
337                 "            {\r\n" + 
338                 "              \"name\": \"PMRASUCCCBRA\",\r\n" + 
339                 "              \"value\": \"1351\"\r\n" + 
340                 "            },\r\n" + 
341                 "            {\r\n" + 
342                 "              \"name\": \"PMCELLDOWNTIMEAUTO\",\r\n" + 
343                 "              \"value\": \"0\"\r\n" + 
344                 "            },\r\n" + 
345                 "            {\r\n" + 
346                 "              \"name\": \"PMCELLDOWNTIMEMAN\",\r\n" + 
347                 "              \"value\": \"0\"\r\n" + 
348                 "            },\r\n" + 
349                 "            {\r\n" + 
350                 "              \"name\": \"PMRRCCONNESTABATT\",\r\n" + 
351                 "              \"value\": \"297\"\r\n" + 
352                 "            },\r\n" + 
353                 "            {\r\n" + 
354                 "              \"name\": \"PMRRCCONNESTABSUCC\",\r\n" + 
355                 "              \"value\": \"297\"\r\n" + 
356                 "            }\r\n" + 
357                 "          ]\r\n" + 
358                 "        }\r\n" + 
359                 "      ],\r\n" + 
360                 "      \"vNicPerformanceArray\": [\r\n" + 
361                 "        {\r\n" + 
362                 "          \"receivedBroadcastPacketsAccumulated\": 21000,\r\n" + 
363                 "          \"receivedBroadcastPacketsDelta\": 5,\r\n" + 
364                 "          \"receivedDiscardedPacketsAccumulated\": 12,\r\n" + 
365                 "          \"receivedDiscardedPacketsDelta\": 2,\r\n" + 
366                 "          \"receivedErrorPacketsAccumulated\": 2,\r\n" + 
367                 "          \"receivedErrorPacketsDelta\": 1,\r\n" + 
368                 "          \"valuesAreSuspect\": false,\r\n" + 
369                 "          \"vNicIdentifier\": \"someVNicIdentifier\"\r\n" + 
370                 "        }\r\n" + 
371                 "      ],\r\n" + 
372                 "      \"measurementInterval\": 900,\r\n" + 
373                 "      \"measurementsForVfScalingVersion\": 2.0\r\n" + 
374                 "    }\r\n" + 
375                 "  }\r\n" + 
376                 "}\r\n" + 
377                 "";
378
379     String cefAbatementMessage = "{\r\n" + 
380                 "  \"event\": {\r\n" + 
381                 "    \"commonEventHeader\": {\r\n" + 
382                 "      \"domain\": \"measurementsForVfScaling\",\r\n" + 
383                 "      \"eventId\": \"UC1-SCL01081-1492639920787\",\r\n" + 
384                 "      \"eventName\": \"Mfvs_eNodeB_RANKPI\",\r\n" + 
385                 "      \"lastEpochMicrosec\": 1492639920787,\r\n" + 
386                 "      \"nfNamingCode\": \"ENBE\",\r\n" + 
387                 "      \"priority\": \"Normal\",\r\n" + 
388                 "      \"reportingEntityId\": \"\",\r\n" + 
389                 "      \"reportingEntityName\": \"vtc2e7admn2\",\r\n" + 
390                 "      \"sequence\": 0,\r\n" + 
391                 "      \"sourceId\": \"SCL01081_9B_1\",\r\n" + 
392                 "      \"sourceName\": \"SCL01081\",\r\n" + 
393                 "      \"startEpochMicrosec\": 1492639920787,\r\n" + 
394                 "      \"version\": 3.0\r\n" + 
395                 "    },\r\n" + 
396                 "    \"measurementsForVfScalingFields\": {\r\n" + 
397                 "      \"additionalFields\": [\r\n" + 
398                 "        {\r\n" + 
399                 "          \"name\": \"software_version \",\r\n" + 
400                 "          \"value\": \"version1\"\r\n" + 
401                 "        },\r\n" + 
402                 "        {\r\n" + 
403                 "          \"name\": \"vendor \",\r\n" + 
404                 "          \"value\": \"Ericsson \"\r\n" + 
405                 "        }\r\n" + 
406                 "      ],\r\n" + 
407                 "      \"additionalMeasurements\": [\r\n" + 
408                 "        {\r\n" + 
409                 "          \"name\": \"OaaS_UC1_EricssonSleepingCell\",\r\n" + 
410                 "          \"arrayOfFields\": [\r\n" + 
411                 "            {\r\n" + 
412                 "              \"name\": \"PMRAATTCBRA\",\r\n" + 
413                 "              \"value\": \"1353\"\r\n" + 
414                 "            },\r\n" + 
415                 "            {\r\n" + 
416                 "              \"name\": \"PMRASUCCCBRA\",\r\n" + 
417                 "              \"value\": \"1351\"\r\n" + 
418                 "            },\r\n" + 
419                 "            {\r\n" + 
420                 "              \"name\": \"PMCELLDOWNTIMEAUTO\",\r\n" + 
421                 "              \"value\": \"0\"\r\n" + 
422                 "            },\r\n" + 
423                 "            {\r\n" + 
424                 "              \"name\": \"PMCELLDOWNTIMEMAN\",\r\n" + 
425                 "              \"value\": \"0\"\r\n" + 
426                 "            },\r\n" + 
427                 "            {\r\n" + 
428                 "              \"name\": \"PMRRCCONNESTABATT\",\r\n" + 
429                 "              \"value\": \"297\"\r\n" + 
430                 "            },\r\n" + 
431                 "            {\r\n" + 
432                 "              \"name\": \"PMRRCCONNESTABSUCC\",\r\n" + 
433                 "              \"value\": \"297\"\r\n" + 
434                 "            }\r\n" + 
435                 "          ]\r\n" + 
436                 "        }\r\n" + 
437                 "      ],\r\n" + 
438                 "      \"vNicPerformanceArray\": [\r\n" + 
439                 "        {\r\n" + 
440                 "          \"receivedBroadcastPacketsAccumulated\": 0,\r\n" + 
441                 "          \"receivedBroadcastPacketsDelta\": 5,\r\n" + 
442                 "          \"receivedDiscardedPacketsAccumulated\": 12,\r\n" + 
443                 "          \"receivedDiscardedPacketsDelta\": 2,\r\n" + 
444                 "          \"receivedErrorPacketsAccumulated\": 2,\r\n" + 
445                 "          \"receivedErrorPacketsDelta\": 1,\r\n" + 
446                 "          \"valuesAreSuspect\": false,\r\n" + 
447                 "          \"vNicIdentifier\": \"someVNicIdentifier\"\r\n" + 
448                 "        }\r\n" + 
449                 "      ],\r\n" + 
450                 "      \"measurementInterval\": 900,\r\n" + 
451                 "      \"measurementsForVfScalingVersion\": 2.0\r\n" + 
452                 "    }\r\n" + 
453                 "  }\r\n" + 
454                 "}\r\n" + 
455                 "";
456
457     String cefInapplicableMessage = "{\r\n" + 
458                 "  \"event\": {\r\n" + 
459                 "    \"commonEventHeader\": {\r\n" + 
460                 "      \"domain\": \"measurementsForVfScaling\",\r\n" + 
461                 "      \"eventId\": \"UC1-SCL01081-1492639920787\",\r\n" + 
462                 "      \"eventName\": \"testEventName\",\r\n" + 
463                 "      \"lastEpochMicrosec\": 1492639920787,\r\n" + 
464                 "      \"nfNamingCode\": \"ENBE\",\r\n" + 
465                 "      \"priority\": \"Normal\",\r\n" + 
466                 "      \"reportingEntityId\": \"\",\r\n" + 
467                 "      \"reportingEntityName\": \"vtc2e7admn2\",\r\n" + 
468                 "      \"sequence\": 0,\r\n" + 
469                 "      \"sourceId\": \"SCL01081_9B_1\",\r\n" + 
470                 "      \"sourceName\": \"SCL01081\",\r\n" + 
471                 "      \"startEpochMicrosec\": 1492639920787,\r\n" + 
472                 "      \"version\": 3.0\r\n" + 
473                 "    },\r\n" + 
474                 "    \"measurementsForVfScalingFields\": {\r\n" + 
475                 "      \"additionalFields\": [\r\n" + 
476                 "        {\r\n" + 
477                 "          \"name\": \"software_version \",\r\n" + 
478                 "          \"value\": \"version1\"\r\n" + 
479                 "        },\r\n" + 
480                 "        {\r\n" + 
481                 "          \"name\": \"vendor \",\r\n" + 
482                 "          \"value\": \"Ericsson \"\r\n" + 
483                 "        }\r\n" + 
484                 "      ],\r\n" + 
485                 "      \"additionalMeasurements\": [\r\n" + 
486                 "        {\r\n" + 
487                 "          \"name\": \"OaaS_UC1_EricssonSleepingCell\",\r\n" + 
488                 "          \"arrayOfFields\": [\r\n" + 
489                 "            {\r\n" + 
490                 "              \"name\": \"PMRAATTCBRA\",\r\n" + 
491                 "              \"value\": \"1353\"\r\n" + 
492                 "            },\r\n" + 
493                 "            {\r\n" + 
494                 "              \"name\": \"PMRASUCCCBRA\",\r\n" + 
495                 "              \"value\": \"1351\"\r\n" + 
496                 "            },\r\n" + 
497                 "            {\r\n" + 
498                 "              \"name\": \"PMCELLDOWNTIMEAUTO\",\r\n" + 
499                 "              \"value\": \"0\"\r\n" + 
500                 "            },\r\n" + 
501                 "            {\r\n" + 
502                 "              \"name\": \"PMCELLDOWNTIMEMAN\",\r\n" + 
503                 "              \"value\": \"0\"\r\n" + 
504                 "            },\r\n" + 
505                 "            {\r\n" + 
506                 "              \"name\": \"PMRRCCONNESTABATT\",\r\n" + 
507                 "              \"value\": \"297\"\r\n" + 
508                 "            },\r\n" + 
509                 "            {\r\n" + 
510                 "              \"name\": \"PMRRCCONNESTABSUCC\",\r\n" + 
511                 "              \"value\": \"297\"\r\n" + 
512                 "            }\r\n" + 
513                 "          ]\r\n" + 
514                 "        }\r\n" + 
515                 "      ],\r\n" + 
516                 "      \"vNicPerformanceArray\": [\r\n" + 
517                 "        {\r\n" + 
518                 "          \"receivedBroadcastPacketsAccumulated\": 5000,\r\n" + 
519                 "          \"receivedBroadcastPacketsDelta\": 5,\r\n" + 
520                 "          \"receivedDiscardedPacketsAccumulated\": 12,\r\n" + 
521                 "          \"receivedDiscardedPacketsDelta\": 2,\r\n" + 
522                 "          \"receivedErrorPacketsAccumulated\": 2,\r\n" + 
523                 "          \"receivedErrorPacketsDelta\": 1,\r\n" + 
524                 "          \"valuesAreSuspect\": false,\r\n" + 
525                 "          \"vNicIdentifier\": \"someVNicIdentifier\"\r\n" + 
526                 "        }\r\n" + 
527                 "      ],\r\n" + 
528                 "      \"measurementInterval\": 900,\r\n" + 
529                 "      \"measurementsForVfScalingVersion\": 2.0\r\n" + 
530                 "    }\r\n" + 
531                 "  }\r\n" + 
532                 "}\r\n" + 
533                 "";
534
535     @Test
536     void getTcaExecutionResults() throws Exception {
537        TcaAbatementContext tcaAbatementContext = new TestTcaAbatementContext();
538        TcaAaiEnrichmentContext tcaAaiEnrichmentContext = new TestTcaAaiEnrichmentContext();
539        TcaPolicyWrapper tcaPolicyWrapper = Mockito.mock(TcaPolicyWrapper.class);
540
541        List<TcaPolicy>  tcaPolicy = convertTcaPolicy(policy);
542        Mockito.when(tcaPolicyWrapper.getTcaPolicy()).thenReturn(tcaPolicy);
543        TcaProcessingService tcaProcessingService = new TcaProcessingServiceImpl(tcaAbatementContext, tcaAaiEnrichmentContext);
544
545        ObjectMapper objectMapper = new ObjectMapper();
546        final List<TcaExecutionContext> tcaExecutionResults = tcaProcessingService.getTcaExecutionResults(
547                 "testRequestId", "testTransactionId", tcaPolicyWrapper,
548                 Arrays.asList(cefMessage, cefViolationMessage,
549                         cefAbatementMessage));
550         
551         for (TcaExecutionContext tcaExecutionResult : tcaExecutionResults) {
552             final TcaAlert tcaAlert = tcaExecutionResult.getTcaResultContext().getTcaAlert();
553             String tcaAlertString = "";
554             if (tcaAlert != null) {
555                 tcaAlertString = objectMapper.writeValueAsString(tcaAlert);
556             }
557         }
558     }
559
560     @Test
561     void getTcaExecutionResultsV7() throws Exception{
562        TcaAbatementContext tcaAbatementContext = new TestTcaAbatementContext();
563        TcaAaiEnrichmentContext tcaAaiEnrichmentContext = new TestTcaAaiEnrichmentContext();
564        TcaPolicyWrapper tcaPolicyWrapper = Mockito.mock(TcaPolicyWrapper.class);
565
566        List<TcaPolicy>  tcaPolicy = convertTcaPolicy(policy);
567        Mockito.when(tcaPolicyWrapper.getTcaPolicy()).thenReturn(tcaPolicy);
568        TcaProcessingService tcaProcessingService = new TcaProcessingServiceImpl(tcaAbatementContext, tcaAaiEnrichmentContext);
569
570        ObjectMapper objectMapper = new ObjectMapper();
571        final List<TcaExecutionContext> tcaExecutionResults = tcaProcessingService.getTcaExecutionResults(
572                  "testRequestId", "testTransactionId", tcaPolicyWrapper,
573                  Arrays.asList(cefV7Message, cefV7OnsetMessage,
574                       cefV7AbatementMessage));
575
576        for (TcaExecutionContext tcaExecutionResult : tcaExecutionResults) {
577             final TcaAlert tcaAlert = tcaExecutionResult.getTcaResultContext().getTcaAlert();
578             String tcaAlertString = "";
579             if (tcaAlert != null) {
580                  tcaAlertString = objectMapper.writeValueAsString(tcaAlert);
581             }
582        }
583     }
584 }
585
586