853ac54719142f9b2fea36178275fa55920e7e66
[dcaegen2/analytics/tca.git] / dcae-analytics-tca / src / test / java / org / openecomp / dcae / apod / analytics / tca / utils / TCAUtilsTest.java
1 /*\r
2  * ===============================LICENSE_START======================================\r
3  *  dcae-analytics\r
4  * ================================================================================\r
5  *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.\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
10  *\r
11  *          http://www.apache.org/licenses/LICENSE-2.0\r
12  *\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
19  */\r
20 \r
21 package org.openecomp.dcae.apod.analytics.tca.utils;\r
22 \r
23 import com.fasterxml.jackson.databind.JsonNode;\r
24 import com.google.common.base.Supplier;\r
25 import com.google.common.collect.ImmutableSet;\r
26 import com.google.common.collect.Table;\r
27 import org.apache.commons.lang3.tuple.Pair;\r
28 import org.junit.Rule;\r
29 import org.junit.Test;\r
30 import org.junit.rules.ExpectedException;\r
31 import org.mockito.Mockito;\r
32 import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants;\r
33 import org.openecomp.dcae.apod.analytics.common.exception.MessageProcessingException;\r
34 import org.openecomp.dcae.apod.analytics.model.domain.cef.CommonEventHeader;\r
35 import org.openecomp.dcae.apod.analytics.model.domain.cef.Domain;\r
36 import org.openecomp.dcae.apod.analytics.model.domain.cef.Event;\r
37 import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;\r
38 import org.openecomp.dcae.apod.analytics.model.domain.cef.EventSeverity;\r
39 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.ClosedLoopEventStatus;\r
40 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.ControlLoopSchemaType;\r
41 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Direction;\r
42 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName;\r
43 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.TCAPolicy;\r
44 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold;\r
45 import org.openecomp.dcae.apod.analytics.model.facade.tca.AAI;\r
46 import org.openecomp.dcae.apod.analytics.model.facade.tca.TCAVESResponse;\r
47 import org.openecomp.dcae.apod.analytics.tca.BaseAnalyticsTCAUnitTest;\r
48 import org.openecomp.dcae.apod.analytics.tca.processor.TCACEFProcessorContext;\r
49 import org.quartz.Job;\r
50 import org.quartz.JobDataMap;\r
51 import org.quartz.JobDetail;\r
52 import org.quartz.Scheduler;\r
53 import org.quartz.SimpleTrigger;\r
54 import org.quartz.impl.StdSchedulerFactory;\r
55 \r
56 import java.util.Arrays;\r
57 import java.util.HashMap;\r
58 import java.util.List;\r
59 import java.util.Map;\r
60 import java.util.Set;\r
61 \r
62 import static org.hamcrest.CoreMatchers.is;\r
63 import static org.hamcrest.CoreMatchers.isA;\r
64 import static org.hamcrest.Matchers.containsInAnyOrder;\r
65 import static org.junit.Assert.assertEquals;\r
66 import static org.junit.Assert.assertFalse;\r
67 import static org.junit.Assert.assertNotNull;\r
68 import static org.junit.Assert.assertNull;\r
69 import static org.junit.Assert.assertThat;\r
70 import static org.junit.Assert.assertTrue;\r
71 import static org.mockito.Mockito.mock;\r
72 import static org.mockito.Mockito.times;\r
73 import static org.mockito.Mockito.verify;\r
74 import static org.mockito.Mockito.when;\r
75 \r
76 /**\r
77  * @author Rajiv Singla . Creation Date: 11/9/2016.\r
78  */\r
79 public class TCAUtilsTest extends BaseAnalyticsTCAUnitTest {\r
80 \r
81     @Test\r
82     public void testGetPolicyEventNames() throws Exception {\r
83 \r
84         final TCAPolicy sampleTCAPolicy = getSampleTCAPolicy();\r
85         final List<String> eventNames = TCAUtils.getPolicyEventNames(sampleTCAPolicy);\r
86 \r
87         assertThat("Policy event names must contain vFirewall, vLoadBalancer, virtualVMEventName", eventNames,\r
88                 containsInAnyOrder("Mfvs_eNodeB_RANKPI", "vLoadBalancer", "virtualVMEventName"));\r
89     }\r
90 \r
91     @Test\r
92     public void testGetPolicyEventNamesSupplier() throws Exception {\r
93         final TCAPolicy sampleTCAPolicy = getSampleTCAPolicy();\r
94         final Supplier<List<String>> policyEventNamesSupplier = TCAUtils.getPolicyEventNamesSupplier\r
95                 (sampleTCAPolicy);\r
96         final List<String> eventNames = policyEventNamesSupplier.get();\r
97         assertThat("Policy event names must contain vFirewall and vLoadBalancer", eventNames,\r
98                 containsInAnyOrder("Mfvs_eNodeB_RANKPI", "vLoadBalancer", "virtualVMEventName"));\r
99     }\r
100 \r
101     @Test\r
102     public void testProcessCEFMessage() throws Exception {\r
103         final String cefMessageString = fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);\r
104         final TCACEFProcessorContext tcacefProcessorContext = TCAUtils.filterCEFMessage(cefMessageString,\r
105                 getSampleTCAPolicy());\r
106         assertThat("TCAECEFProcessor Processor Context can continue flag is true", tcacefProcessorContext\r
107                 .canProcessingContinue(), is(true));\r
108     }\r
109 \r
110     @Test\r
111     public void testGetPolicyFRThresholdsTableSupplier() throws Exception {\r
112         final Table<String, String, List<Threshold>> policyFRThresholdPathTable = TCAUtils\r
113                 .getPolicyEventNameThresholdsTableSupplier(getSampleTCAPolicy()).get();\r
114 \r
115         final Map<String, List<Threshold>> eNodeBRankpi = policyFRThresholdPathTable.row("Mfvs_eNodeB_RANKPI");\r
116         final Map<String, List<Threshold>> vLoadBalancer = policyFRThresholdPathTable.row("vLoadBalancer");\r
117 \r
118         final Set<String> eNodeBRankpiFieldPaths = eNodeBRankpi.keySet();\r
119         final Set<String> vLoadBalancerPaths = vLoadBalancer.keySet();\r
120 \r
121         final String receivedBroadcastPacketsFieldPath =\r
122                 "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated";\r
123         assertThat("eNodeBRankpi threshold field path size must be " +\r
124                         "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*]" +\r
125                         ".receivedBroadcastPacketsAccumulated",\r
126                 eNodeBRankpiFieldPaths.iterator().next(),\r
127                 is(receivedBroadcastPacketsFieldPath));\r
128 \r
129         assertThat("vLoadBalancer threshold field path size must be " +\r
130                         "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*]" +\r
131                         ".receivedBroadcastPacketsAccumulated",\r
132                 vLoadBalancerPaths.iterator().next(),\r
133                 is(receivedBroadcastPacketsFieldPath));\r
134 \r
135         final List<Threshold> eNodeBRankpiThresholds = policyFRThresholdPathTable.get("Mfvs_eNodeB_RANKPI",\r
136                 receivedBroadcastPacketsFieldPath);\r
137         final List<Threshold> vLoadBalancerThresholds = policyFRThresholdPathTable.get("vLoadBalancer",\r
138                 receivedBroadcastPacketsFieldPath);\r
139 \r
140         assertThat("eNodeBRankpi Threshold size must be 3", eNodeBRankpiThresholds.size(), is(3));\r
141         assertThat("vLoadBalancer Threshold size must be 2", vLoadBalancerThresholds.size(), is(2));\r
142     }\r
143 \r
144     @Test\r
145     public void testGetJsonPathValueWithValidMessageAndPolicy() throws Exception {\r
146         final String cefMessageString = fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);\r
147         final String jsonPath =\r
148                 "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated";\r
149         final ImmutableSet<String> fieldPaths = ImmutableSet.of(jsonPath);\r
150         final Map<String, List<Long>> jsonPathValueMap = TCAUtils.getJsonPathValue(cefMessageString, fieldPaths);\r
151         assertThat("Json Path value must match", jsonPathValueMap.get(jsonPath).get(0), is(5000L));\r
152 \r
153     }\r
154 \r
155     @Test\r
156     public void testGetJsonPathValueWithValidPath() throws Exception {\r
157         final String cefMessageString = fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);\r
158         final String jsonPath = "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].invalid";\r
159         final ImmutableSet<String> fieldPaths = ImmutableSet.of(jsonPath);\r
160         final Map<String, List<Long>> jsonPathValueMap = TCAUtils.getJsonPathValue(cefMessageString, fieldPaths);\r
161         assertThat("Json path value must be empty", jsonPathValueMap.size(), is(0));\r
162 \r
163     }\r
164 \r
165 \r
166     @Test\r
167     public void testCreateNewTCAVESResponseWithVFControlLoopSchemaType() throws Exception {\r
168         TCACEFProcessorContext tcacefProcessorContext = mock(TCACEFProcessorContext.class);\r
169 \r
170         MetricsPerEventName metricsPerEventName = mock(MetricsPerEventName.class);\r
171         when(metricsPerEventName.getThresholds()).thenReturn(getThresholds());\r
172         when(metricsPerEventName.getPolicyScope()).thenReturn("Test Policy scope");\r
173         when(tcacefProcessorContext.getMetricsPerEventName()).thenReturn(metricsPerEventName);\r
174         when(metricsPerEventName.getEventName()).thenReturn("testEventName");\r
175         when(metricsPerEventName.getControlLoopSchemaType()).thenReturn(ControlLoopSchemaType.VM);\r
176 \r
177         when(tcacefProcessorContext.getCEFEventListener()).thenReturn(getCEFEventListener());\r
178         TCAVESResponse tcaVESResponse = TCAUtils.createNewTCAVESResponse(tcacefProcessorContext, "TCA_APP_NAME");\r
179 \r
180         //TODO :  Add proper assertions, as the usage is not clearly understood\r
181         assertThat(tcaVESResponse.getClosedLoopControlName(),\r
182                 is("CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A"));\r
183         assertThat(tcaVESResponse.getVersion(), is("Test Version"));\r
184         assertThat(tcaVESResponse.getPolicyScope(), is("Test Policy scope"));\r
185         assertNull(tcaVESResponse.getAai().getGenericVNFId());\r
186         assertNotNull(tcaVESResponse.getAai().getGenericServerId());\r
187     }\r
188 \r
189     @Test\r
190     public void testCreateNewTCAVESResponseWithFunctionalRolevFirewall() throws Exception {\r
191         TCACEFProcessorContext tcacefProcessorContext = mock(TCACEFProcessorContext.class);\r
192 \r
193         MetricsPerEventName metricsPerEventName = mock(MetricsPerEventName.class);\r
194         when(metricsPerEventName.getThresholds()).thenReturn(getThresholds());\r
195         when(metricsPerEventName.getPolicyScope()).thenReturn("Test Policy scope");\r
196         when(tcacefProcessorContext.getMetricsPerEventName()).thenReturn(metricsPerEventName);\r
197         when(metricsPerEventName.getEventName()).thenReturn("vFirewall");\r
198 \r
199         when(tcacefProcessorContext.getCEFEventListener()).thenReturn(getCEFEventListener());\r
200         TCAVESResponse tcaVESResponse = TCAUtils.createNewTCAVESResponse(tcacefProcessorContext, "TCA_APP_NAME");\r
201 \r
202         //TODO :  Add proper assertions, as the usage is not clearly understood\r
203         assertThat(tcaVESResponse.getClosedLoopControlName(),\r
204                 is("CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A"));\r
205         assertThat(tcaVESResponse.getVersion(), is("Test Version"));\r
206         assertThat(tcaVESResponse.getPolicyScope(), is("Test Policy scope"));\r
207         assertNotNull(tcaVESResponse.getAai().getGenericVNFId());\r
208         assertNull(tcaVESResponse.getAai().getGenericServerId());\r
209     }\r
210 \r
211     @Rule\r
212     public ExpectedException expectedIllegalArgumentException = ExpectedException.none();\r
213 \r
214     @Test\r
215     public void testCreateNewTCAVESResponseNullFunctionalRole() throws Exception {\r
216         expectedIllegalArgumentException.expect(MessageProcessingException.class);\r
217         expectedIllegalArgumentException.expectCause(isA(IllegalArgumentException.class));\r
218         expectedIllegalArgumentException.expectMessage("No violations metrics. Unable to create VES Response");\r
219 \r
220         TCACEFProcessorContext tcacefProcessorContext = mock(TCACEFProcessorContext.class);\r
221         TCAVESResponse tcaVESResponse = TCAUtils.createNewTCAVESResponse(tcacefProcessorContext, "TCA_APP_NAME");\r
222         assertNotNull(tcaVESResponse.getClosedLoopControlName());\r
223     }\r
224 \r
225     @Test\r
226     public void testPrioritizeThresholdViolations() throws Exception {\r
227 \r
228         Map<String, Threshold> thresholdMap = new HashMap<>();\r
229         Threshold majorThreshold = mock(Threshold.class);\r
230         when(majorThreshold.getSeverity()).thenReturn(EventSeverity.MAJOR);\r
231         thresholdMap.put("MAJOR", majorThreshold);\r
232 \r
233         Threshold result1 = TCAUtils.prioritizeThresholdViolations(thresholdMap);\r
234         assertEquals(result1.getSeverity(), EventSeverity.MAJOR);\r
235 \r
236         Threshold criticalThreshold = mock(Threshold.class);\r
237         when(criticalThreshold.getSeverity()).thenReturn(EventSeverity.CRITICAL);\r
238         thresholdMap.put("CRITICAL", criticalThreshold);\r
239 \r
240         Threshold result2 = TCAUtils.prioritizeThresholdViolations(thresholdMap);\r
241         assertEquals(result2.getSeverity(), EventSeverity.CRITICAL);\r
242     }\r
243 \r
244     @Test\r
245     public void testCreateViolatedMetrics() throws Exception {\r
246         TCAPolicy tcaPolicy = getSampleTCAPolicy();\r
247         Threshold violatedThreshold = getCriticalThreshold();\r
248         String functionalRole = "Mfvs_eNodeB_RANKPI";\r
249         MetricsPerEventName result = TCAUtils.createViolatedMetrics(tcaPolicy, violatedThreshold, functionalRole);\r
250         assertThat(result.getPolicyScope(), is("resource=vFirewall;type=configuration"));\r
251         assertThat(result.getPolicyName(), is("configuration.dcae.microservice.tca.xml"));\r
252     }\r
253 \r
254     @Test\r
255     public void testCreateViolatedMetricsWrongEventName() throws Exception {\r
256         expectedIllegalArgumentException.expect(MessageProcessingException.class);\r
257         expectedIllegalArgumentException.expectCause(isA(IllegalStateException.class));\r
258         String eventName = "badEventName";\r
259         expectedIllegalArgumentException.expectMessage("TCA Policy must contain eventName: " + eventName);\r
260         TCAPolicy tcaPolicy = getSampleTCAPolicy();\r
261         Threshold violatedThreshold = getCriticalThreshold();\r
262         TCAUtils.createViolatedMetrics(tcaPolicy, violatedThreshold, eventName);\r
263     }\r
264 \r
265     @Test\r
266     public void testGetDomainAndEventName() {\r
267         TCACEFProcessorContext tcacefProcessorContext = mock(TCACEFProcessorContext.class);\r
268         EventListener eventListener = mock(EventListener.class);\r
269         Event event = mock(Event.class);\r
270         CommonEventHeader commonEventHeader = mock(CommonEventHeader.class);\r
271 \r
272         Pair<String, String> result = TCAUtils.getDomainAndEventName(tcacefProcessorContext);\r
273         assertNull(result.getLeft());\r
274         assertNull(result.getRight());\r
275 \r
276         when(tcacefProcessorContext.getCEFEventListener()).thenReturn(eventListener);\r
277         result = TCAUtils.getDomainAndEventName(tcacefProcessorContext);\r
278         assertNull(result.getLeft());\r
279         assertNull(result.getRight());\r
280 \r
281         when(eventListener.getEvent()).thenReturn(event);\r
282         result = TCAUtils.getDomainAndEventName(tcacefProcessorContext);\r
283         assertNull(result.getLeft());\r
284         assertNull(result.getRight());\r
285 \r
286         when(event.getCommonEventHeader()).thenReturn(commonEventHeader);\r
287         result = TCAUtils.getDomainAndEventName(tcacefProcessorContext);\r
288         assertNull(result.getLeft());\r
289         assertNull(result.getRight());\r
290 \r
291         when(commonEventHeader.getDomain()).thenReturn(Domain.other);\r
292         when(commonEventHeader.getEventName()).thenReturn("eventName");\r
293 \r
294         result = TCAUtils.getDomainAndEventName(tcacefProcessorContext);\r
295         assertEquals(result.getLeft(), "other");\r
296         assertEquals(result.getRight(), "eventName");\r
297 \r
298     }\r
299 \r
300     @Test\r
301     public void testComputeThresholdViolationsNotPresent() throws Exception {\r
302         TCACEFProcessorContext tcacefProcessorContext = mock(TCACEFProcessorContext.class);\r
303         when(tcacefProcessorContext.canProcessingContinue()).thenReturn(true);\r
304         when(tcacefProcessorContext.getMessage()).thenReturn(getValidCEFMessage());\r
305 \r
306         when(tcacefProcessorContext.getTCAPolicy()).thenReturn(getSampleTCAPolicy());\r
307         when(tcacefProcessorContext.getCEFEventListener()).thenReturn(getCEFEventListener());\r
308 \r
309         TCACEFProcessorContext result = TCAUtils.computeThresholdViolations(tcacefProcessorContext);\r
310         assertNotNull(result);\r
311         verify(result, times(0)).setMetricsPerEventName(Mockito.any(MetricsPerEventName.class));\r
312         assertEquals("Policy must not change", getSampleTCAPolicy(), result.getTCAPolicy());\r
313     }\r
314 \r
315     @Test\r
316     public void testComputeThresholdViolationsPresent() throws Exception {\r
317         TCACEFProcessorContext tcacefProcessorContext = mock(TCACEFProcessorContext.class);\r
318         when(tcacefProcessorContext.canProcessingContinue()).thenReturn(true);\r
319         final String cefMessageString = fromStream(CEF_MESSAGE_WITH_THRESHOLD_VIOLATION_JSON_FILE_LOCATION);\r
320         when(tcacefProcessorContext.getMessage()).thenReturn(cefMessageString);\r
321 \r
322         when(tcacefProcessorContext.getTCAPolicy()).thenReturn(getSampleTCAPolicy());\r
323         when(tcacefProcessorContext.getCEFEventListener()).thenReturn(getCEFEventListener());\r
324 \r
325         TCACEFProcessorContext result = TCAUtils.computeThresholdViolations(tcacefProcessorContext);\r
326         verify(result, times(1)).setMetricsPerEventName(Mockito.any(MetricsPerEventName.class));\r
327 \r
328         assertEquals("Policy must not change", getSampleTCAPolicy(), result.getTCAPolicy());\r
329     }\r
330 \r
331 \r
332     @Test\r
333     public void testCreateTCAPolicyMetricsPerKeyName() throws Exception {\r
334 \r
335         final Map<String, String> tcaPolicyMap = TCAUtils.filterMapByKeyNamePrefix(getControllerRuntimeArguments(),\r
336                 AnalyticsConstants.TCA_POLICY_METRICS_PER_FUNCTIONAL_ROLE_PATH);\r
337 \r
338         // determine functional Roles\r
339         final Map<String, Map<String, String>> functionalRolesMap =\r
340                 TCAUtils.extractSubTree(tcaPolicyMap, 2, 3, AnalyticsConstants.TCA_POLICY_DELIMITER);\r
341 \r
342         final List<MetricsPerEventName> tcaPolicyMetricsPerEventNameList =\r
343                 TCAUtils.createTCAPolicyMetricsPerEventNameList(functionalRolesMap);\r
344 \r
345         assertThat("There are two Metrics per function role", 2,\r
346                 is(tcaPolicyMetricsPerEventNameList.size()));\r
347     }\r
348 \r
349 \r
350     @Test\r
351     public void testCreateQuartzScheduler() throws Exception {\r
352         final Scheduler scheduler = Mockito.mock(Scheduler.class);\r
353         final StdSchedulerFactory stdSchedulerFactory = Mockito.mock(StdSchedulerFactory.class);\r
354         when(stdSchedulerFactory.getScheduler()).thenReturn(scheduler);\r
355         final JobDataMap jobDataMap = Mockito.mock(JobDataMap.class);\r
356         TCAUtils.createQuartzScheduler(1000, stdSchedulerFactory,\r
357                 "data/properties/quartz-test.properties", jobDataMap, Job.class,\r
358                 "testJob", "testTigger");\r
359         verify(scheduler, times(1))\r
360                 .scheduleJob(Mockito.any(JobDetail.class), Mockito.any(SimpleTrigger.class));\r
361     }\r
362 \r
363 \r
364     @Test\r
365     public void testCreateTCAAlertStringWhenCEFIsEnabled() throws Exception {\r
366         final MetricsPerEventName violatedMetrics = createViolatedMetricsPerEventName(EventSeverity.CRITICAL);\r
367         TCACEFProcessorContext processorContext = mock(TCACEFProcessorContext.class);\r
368         when(processorContext.getMetricsPerEventName()).thenReturn(violatedMetrics);\r
369         when(processorContext.getCEFEventListener()).thenReturn(getCEFEventListener());\r
370         final String alertString = TCAUtils.createTCAAlertString(processorContext, "testApp", true);\r
371         assertTrue(alertString.contains("thresholdCrossingAlertFields"));\r
372     }\r
373 \r
374     @Test(expected = MessageProcessingException.class)\r
375     public void testCreateTCAAlertStringWhenViolatedMetricsNotPresentAndCEFIsEnabled() throws Exception {\r
376         TCACEFProcessorContext processorContext = mock(TCACEFProcessorContext.class);\r
377         when(processorContext.getMetricsPerEventName()).thenReturn(null);\r
378         TCAUtils.createTCAAlertString(processorContext, "testApp", true);\r
379     }\r
380 \r
381     @Test\r
382     public void testCreateTCAAlertStringWhenCEFIsDisabled() throws Exception {\r
383         final MetricsPerEventName violatedMetrics = createViolatedMetricsPerEventName(EventSeverity.MAJOR);\r
384         TCACEFProcessorContext processorContext = mock(TCACEFProcessorContext.class);\r
385         when(processorContext.getMetricsPerEventName()).thenReturn(violatedMetrics);\r
386         when(processorContext.getCEFEventListener()).thenReturn(getCEFEventListener());\r
387         final String alertString = TCAUtils.createTCAAlertString(processorContext, "testApp", false);\r
388         assertFalse(alertString.contains("thresholdCrossingAlertFields"));\r
389     }\r
390 \r
391     @Test(expected = MessageProcessingException.class)\r
392     public void testCreateTCAAlertStringWhenViolatedMetricsNotPresentAndCEFIsDisabled() throws Exception {\r
393         TCACEFProcessorContext processorContext = mock(TCACEFProcessorContext.class);\r
394         when(processorContext.getMetricsPerEventName()).thenReturn(null);\r
395         TCAUtils.createTCAAlertString(processorContext, "testApp", false);\r
396     }\r
397 \r
398     private static MetricsPerEventName createViolatedMetricsPerEventName(EventSeverity severity) {\r
399         final Threshold violatedThreshold = new Threshold();\r
400         violatedThreshold.setSeverity(severity);\r
401         violatedThreshold.setDirection(Direction.GREATER);\r
402         violatedThreshold.setClosedLoopControlName("violatedThresholdClosedLoopName");\r
403         violatedThreshold.setActualFieldValue(100L);\r
404         violatedThreshold.setFieldPath("violatedThresholdFieldPath");\r
405         violatedThreshold.setVersion("violatedThresholdVersion");\r
406         violatedThreshold.setClosedLoopEventStatus(ClosedLoopEventStatus.ONSET);\r
407         violatedThreshold.setThresholdValue(50L);\r
408 \r
409         final MetricsPerEventName violatedMetrics = new MetricsPerEventName();\r
410         violatedMetrics.setPolicyName("violatePolicyName");\r
411         violatedMetrics.setPolicyVersion("violatedPolicyVersion");\r
412         violatedMetrics.setPolicyScope("violatedPolicyScope");\r
413         violatedMetrics.setEventName("violatedEventName");\r
414         violatedMetrics.setThresholds(Arrays.asList(violatedThreshold));\r
415         return violatedMetrics;\r
416     }\r
417 }\r