Add support for ABATED alerts within CDAP TCA
[dcaegen2/analytics/tca.git] / dcae-analytics-tca / src / test / java / org / openecomp / dcae / apod / analytics / tca / processor / TCACEFPolicyDomainFilterTest.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.Before;
24 import org.junit.Test;
25 import org.openecomp.dcae.apod.analytics.common.service.processor.ProcessingState;
26 import org.openecomp.dcae.apod.analytics.model.domain.cef.Domain;
27 import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;
28 import org.openecomp.dcae.apod.analytics.tca.BaseAnalyticsTCAUnitTest;
29
30 import static org.hamcrest.CoreMatchers.is;
31 import static org.junit.Assert.assertThat;
32
33 /**
34  * @author Rajiv Singla . Creation Date: 12/16/2016.
35  */
36 public class TCACEFPolicyDomainFilterTest extends BaseAnalyticsTCAUnitTest {
37
38     private TCACEFPolicyDomainFilter tcacefPolicyDomainFilter;
39     private TCACEFProcessorContext processorContext;
40     private EventListener cefEventListener;
41
42     @Before
43     public void before() throws Exception {
44         tcacefPolicyDomainFilter = new TCACEFPolicyDomainFilter();
45         processorContext = new TCACEFProcessorContext("", getSampleTCAPolicy());
46         cefEventListener = getCEFEventListener();
47         processorContext.setCEFEventListener(cefEventListener);
48     }
49
50     @Test
51     public void testProcessMessageWhenMessageIsValid() throws Exception {
52         tcacefPolicyDomainFilter.processMessage(processorContext);
53         assertThat("Processing must finish successfully",
54                 tcacefPolicyDomainFilter.getProcessingState(), is(ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY));
55     }
56
57     @Test
58     public void testProcessMessageWhenCEFEventIsNull() throws Exception {
59         cefEventListener.setEvent(null);
60         processorContext.setCEFEventListener(cefEventListener);
61         tcacefPolicyDomainFilter.processMessage(processorContext);
62         assertThat("Processing must terminate early",
63                 tcacefPolicyDomainFilter.getProcessingState(), is(ProcessingState.PROCESSING_TERMINATED_EARLY));
64     }
65
66     @Test
67     public void testProcessMessageWhenPolicyDomainDoesNotMatchMessageDomain() throws Exception {
68         cefEventListener.getEvent().getCommonEventHeader().setDomain(Domain.other);
69         tcacefPolicyDomainFilter.processMessage(processorContext);
70         assertThat("Processing must terminate early",
71                 tcacefPolicyDomainFilter.getProcessingState(), is(ProcessingState.PROCESSING_TERMINATED_EARLY));
72     }
73
74 }