Initial TCA commit into DCAEGEN2
[dcaegen2/analytics/tca.git] / dcae-analytics-tca / src / test / java / org / openecomp / dcae / apod / analytics / tca / processor / TCACEFPolicyThresholdsProcessorTest.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
4  * ================================================================================
5  *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *   You may obtain a copy of the License at
10  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  *  ============================LICENSE_END===========================================
19  */
20
21 package org.openecomp.dcae.apod.analytics.tca.processor;
22
23 import org.junit.Test;
24 import org.openecomp.dcae.apod.analytics.common.service.processor.ProcessingState;
25 import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;
26 import org.openecomp.dcae.apod.analytics.tca.BaseAnalyticsTCAUnitTest;
27
28 import static org.hamcrest.CoreMatchers.is;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertFalse;
31 import static org.junit.Assert.assertThat;
32 import static org.junit.Assert.assertTrue;
33
34 /**
35  *
36  * @author Rajiv Singla . Creation Date: 11/9/2016.
37  */
38 public class TCACEFPolicyThresholdsProcessorTest extends BaseAnalyticsTCAUnitTest {
39
40     @Test
41     public void testCEFPolicyThresholdProcessorWithNoThresholdViolation() throws Exception {
42
43         final String cefMessageString = fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);
44         final TCACEFProcessorContext tcacefProcessorContext = new TCACEFProcessorContext(cefMessageString,
45                 getSampleTCAPolicy());
46         tcacefProcessorContext.setCEFEventListener(getCEFEventListener());
47
48         AbstractTCAECEFPolicyProcessor policyThresholdsProcessor = new TCACEFPolicyThresholdsProcessor();
49         final TCACEFProcessorContext finalProcessorContext = policyThresholdsProcessor.apply(tcacefProcessorContext);
50
51         assertFalse("Process Context can Processing Continue flag should be false", finalProcessorContext
52                 .canProcessingContinue());
53         assertThat("Policy Threshold Processor State must be terminated early",
54                 policyThresholdsProcessor.getProcessingState(), is(ProcessingState.PROCESSING_TERMINATED_EARLY));
55         assertEquals("Policy must not change", getSampleTCAPolicy(), finalProcessorContext.getTCAPolicy());
56
57     }
58
59     @Test
60     public void testCEFPolicyThresholdProcessorWithThresholdViolation() throws Exception {
61
62         final String cefMessageString = fromStream(CEF_MESSAGE_WITH_THRESHOLD_VIOLATION_JSON_FILE_LOCATION);
63         final TCACEFProcessorContext tcacefProcessorContext = new TCACEFProcessorContext(cefMessageString,
64                 getSampleTCAPolicy());
65
66         final EventListener eventListener = getCEFEventListener();
67         tcacefProcessorContext.setCEFEventListener(eventListener);
68
69         AbstractTCAECEFPolicyProcessor policyThresholdsProcessor = new TCACEFPolicyThresholdsProcessor();
70         final TCACEFProcessorContext finalProcessorContext = policyThresholdsProcessor.apply(tcacefProcessorContext);
71
72         assertTrue("Process Context can Processing Continue flag should be true", finalProcessorContext
73                 .canProcessingContinue());
74         assertThat("Policy Threshold Processor State must be successful",
75                 policyThresholdsProcessor.getProcessingState(), is(ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY));
76         assertEquals("Policy must not change", getSampleTCAPolicy(), finalProcessorContext.getTCAPolicy());
77
78     }
79
80 }