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.Domain;
27 import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;
28 import org.openecomp.dcae.apod.analytics.tca.BaseAnalyticsTCAUnitTest;
30 import static org.hamcrest.CoreMatchers.is;
31 import static org.junit.Assert.assertThat;
34 * @author Rajiv Singla . Creation Date: 12/16/2016.
36 public class TCACEFPolicyDomainFilterTest extends BaseAnalyticsTCAUnitTest {
38 private TCACEFPolicyDomainFilter tcacefPolicyDomainFilter;
39 private TCACEFProcessorContext processorContext;
40 private EventListener cefEventListener;
43 public void before() throws Exception {
44 tcacefPolicyDomainFilter = new TCACEFPolicyDomainFilter();
45 processorContext = new TCACEFProcessorContext("", getSampleTCAPolicy());
46 cefEventListener = getCEFEventListener();
47 processorContext.setCEFEventListener(cefEventListener);
51 public void testProcessMessageWhenMessageIsValid() throws Exception {
52 tcacefPolicyDomainFilter.processMessage(processorContext);
53 assertThat("Processing must finish successfully",
54 tcacefPolicyDomainFilter.getProcessingState(), is(ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY));
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));
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));