2 * ===============================LICENSE_START======================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===========================================
21 package org.openecomp.dcae.apod.analytics.tca.processor;
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;
29 import static org.hamcrest.CoreMatchers.is;
30 import static org.junit.Assert.assertThat;
33 * @author Rajiv Singla . Creation Date: 12/16/2016.
35 public class TCACEFPolicyDomainFilterTest extends BaseAnalyticsTCAUnitTest {
37 private TCACEFPolicyDomainFilter tcacefPolicyDomainFilter;
38 private TCACEFProcessorContext processorContext;
39 private EventListener cefEventListener;
42 public void before() throws Exception {
43 tcacefPolicyDomainFilter = new TCACEFPolicyDomainFilter();
44 processorContext = new TCACEFProcessorContext("", getSampleTCAPolicy());
45 cefEventListener = getCEFEventListener();
46 processorContext.setCEFEventListener(cefEventListener);
50 public void testProcessMessageWhenMessageIsValid() throws Exception {
51 tcacefPolicyDomainFilter.processMessage(processorContext);
52 assertThat("Processing must finish successfully",
53 tcacefPolicyDomainFilter.getProcessingState(), is(ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY));
57 public void testProcessMessageWhenCEFEventIsNull() throws Exception {
58 cefEventListener.setEvent(null);
59 processorContext.setCEFEventListener(cefEventListener);
60 tcacefPolicyDomainFilter.processMessage(processorContext);
61 assertThat("Processing must terminate early",
62 tcacefPolicyDomainFilter.getProcessingState(), is(ProcessingState.PROCESSING_TERMINATED_EARLY));
66 public void testProcessMessageWhenPolicyDomainDoesNotMatchMessageDomain() throws Exception {
67 cefEventListener.getEvent().getCommonEventHeader().setDomain("notPolicyDomain");
68 tcacefPolicyDomainFilter.processMessage(processorContext);
69 assertThat("Processing must terminate early",
70 tcacefPolicyDomainFilter.getProcessingState(), is(ProcessingState.PROCESSING_TERMINATED_EARLY));