TCA pom: enable unit test execution
[dcaegen2/analytics/tca.git] / dcae-analytics-tca / src / test / java / org / openecomp / dcae / apod / analytics / tca / processor / TCACEFPolicyFunctionalRoleFilterTest.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.EventListener;
27 import org.openecomp.dcae.apod.analytics.tca.BaseAnalyticsTCAUnitTest;
28
29 import static org.hamcrest.CoreMatchers.is;
30 import static org.junit.Assert.assertThat;
31
32 /**
33  * @author Rajiv Singla . Creation Date: 12/19/2016.
34  */
35 public class TCACEFPolicyFunctionalRoleFilterTest extends BaseAnalyticsTCAUnitTest {
36
37     private TCACEFPolicyFunctionalRoleFilter tcacefPolicyFunctionalRoleFilter;
38     private TCACEFProcessorContext processorContext;
39     private EventListener cefEventListener;
40
41     @Before
42     public void before() throws Exception {
43         tcacefPolicyFunctionalRoleFilter = new TCACEFPolicyFunctionalRoleFilter();
44         processorContext = new TCACEFProcessorContext("", getSampleTCAPolicy());
45         cefEventListener = getCEFEventListener();
46         processorContext.setCEFEventListener(cefEventListener);
47     }
48
49     @Test
50     public void testProcessMessageWhenMessageIsValid() throws Exception {
51         tcacefPolicyFunctionalRoleFilter.processMessage(processorContext);
52         assertThat("Processing must finish successfully",
53                 tcacefPolicyFunctionalRoleFilter.getProcessingState(),
54                 is(ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY));
55     }
56
57     @Test
58     public void testProcessMessageWhenCEFEventIsNull() throws Exception {
59         cefEventListener.setEvent(null);
60         processorContext.setCEFEventListener(cefEventListener);
61         tcacefPolicyFunctionalRoleFilter.processMessage(processorContext);
62         assertThat("Processing must terminate early",
63                 tcacefPolicyFunctionalRoleFilter.getProcessingState(), is(ProcessingState.PROCESSING_TERMINATED_EARLY));
64     }
65
66     @Test
67     public void testProcessMessageWhenPolicyFunctionalRoleDoesNotMatchMessageFunctionalRole() throws Exception {
68         cefEventListener.getEvent().getCommonEventHeader().setFunctionalRole("someNonPolicyFunctionalRole");
69         tcacefPolicyFunctionalRoleFilter.processMessage(processorContext);
70         assertThat("Processing must terminate early",
71                 tcacefPolicyFunctionalRoleFilter.getProcessingState(), is(ProcessingState.PROCESSING_TERMINATED_EARLY));
72     }
73
74
75 }