912fe6fd154b94b83e09b63389719e7ae1656224
[dcaegen2/analytics/tca.git] / dcae-analytics-tca / src / test / java / org / openecomp / dcae / apod / analytics / tca / processor / TCACEFPolicyThresholdsProcessorTest.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.processor;\r
22 \r
23 import org.junit.Test;\r
24 import org.openecomp.dcae.apod.analytics.common.service.processor.ProcessingState;\r
25 import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;\r
26 import org.openecomp.dcae.apod.analytics.tca.BaseAnalyticsTCAUnitTest;\r
27 \r
28 import static org.hamcrest.CoreMatchers.is;\r
29 import static org.junit.Assert.assertEquals;\r
30 import static org.junit.Assert.assertFalse;\r
31 import static org.junit.Assert.assertThat;\r
32 import static org.junit.Assert.assertTrue;\r
33 \r
34 /**\r
35  *\r
36  * @author Rajiv Singla . Creation Date: 11/9/2016.\r
37  */\r
38 public class TCACEFPolicyThresholdsProcessorTest extends BaseAnalyticsTCAUnitTest {\r
39 \r
40     @Test\r
41     public void testCEFPolicyThresholdProcessorWithNoThresholdViolation() throws Exception {\r
42 \r
43         final String cefMessageString = fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);\r
44         final TCACEFProcessorContext tcacefProcessorContext = new TCACEFProcessorContext(cefMessageString,\r
45                 getSampleTCAPolicy());\r
46         tcacefProcessorContext.setCEFEventListener(getCEFEventListener());\r
47 \r
48         AbstractTCAECEFPolicyProcessor policyThresholdsProcessor = new TCACEFPolicyThresholdsProcessor();\r
49         final TCACEFProcessorContext finalProcessorContext = policyThresholdsProcessor.apply(tcacefProcessorContext);\r
50 \r
51         assertFalse("Process Context can Processing Continue flag should be false", finalProcessorContext\r
52                 .canProcessingContinue());\r
53         assertThat("Policy Threshold Processor State must be terminated early",\r
54                 policyThresholdsProcessor.getProcessingState(), is(ProcessingState.PROCESSING_TERMINATED_EARLY));\r
55         assertEquals("Policy must not change", getSampleTCAPolicy(), finalProcessorContext.getTCAPolicy());\r
56 \r
57     }\r
58 \r
59     @Test\r
60     public void testCEFPolicyThresholdProcessorWithThresholdViolation() throws Exception {\r
61 \r
62         final String cefMessageString = fromStream(CEF_MESSAGE_WITH_THRESHOLD_VIOLATION_JSON_FILE_LOCATION);\r
63         final TCACEFProcessorContext tcacefProcessorContext = new TCACEFProcessorContext(cefMessageString,\r
64                 getSampleTCAPolicy());\r
65 \r
66         final EventListener eventListener = ANALYTICS_MODEL_OBJECT_MAPPER.readValue(cefMessageString,\r
67                 EventListener.class);\r
68         tcacefProcessorContext.setCEFEventListener(eventListener);\r
69 \r
70         AbstractTCAECEFPolicyProcessor policyThresholdsProcessor = new TCACEFPolicyThresholdsProcessor();\r
71         final TCACEFProcessorContext finalProcessorContext = policyThresholdsProcessor.apply(tcacefProcessorContext);\r
72 \r
73         assertTrue("Process Context can Processing Continue flag should be true", finalProcessorContext\r
74                 .canProcessingContinue());\r
75         assertThat("Policy Threshold Processor State must be successful",\r
76                 policyThresholdsProcessor.getProcessingState(), is(ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY));\r
77         assertEquals("Policy must not change", getSampleTCAPolicy(), finalProcessorContext.getTCAPolicy());\r
78 \r
79     }\r
80 \r
81 }\r