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/19/2016.
35 public class TCACEFPolicyEventNameFilterTest extends BaseAnalyticsTCAUnitTest {
37 private TCACEFPolicyEventNameFilter tcacefPolicyEventNameFilter;
38 private TCACEFProcessorContext processorContext;
39 private EventListener cefEventListener;
42 public void before() throws Exception {
43 tcacefPolicyEventNameFilter = new TCACEFPolicyEventNameFilter();
44 processorContext = new TCACEFProcessorContext("", getSampleTCAPolicy());
45 cefEventListener = getCEFEventListener();
46 processorContext.setCEFEventListener(cefEventListener);
50 public void testProcessMessageWhenMessageIsValid() throws Exception {
51 tcacefPolicyEventNameFilter.processMessage(processorContext);
52 assertThat("Processing must finish successfully",
53 tcacefPolicyEventNameFilter.getProcessingState(),
54 is(ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY));
58 public void testProcessMessageWhenCEFEventIsNull() throws Exception {
59 cefEventListener.setEvent(null);
60 processorContext.setCEFEventListener(cefEventListener);
61 tcacefPolicyEventNameFilter.processMessage(processorContext);
62 assertThat("Processing must terminate early",
63 tcacefPolicyEventNameFilter.getProcessingState(), is(ProcessingState.PROCESSING_TERMINATED_EARLY));
67 public void testProcessMessageWhenPolicyEventNameDoesNotMatchMessageEventName() throws Exception {
68 cefEventListener.getEvent().getCommonEventHeader().setEventName("someNonPolicyEventName");
69 tcacefPolicyEventNameFilter.processMessage(processorContext);
70 assertThat("Processing must terminate early",
71 tcacefPolicyEventNameFilter.getProcessingState(), is(ProcessingState.PROCESSING_TERMINATED_EARLY));