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.Test;
24 import org.openecomp.dcae.apod.analytics.common.exception.MessageProcessingException;
25 import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;
26 import org.openecomp.dcae.apod.analytics.tca.BaseAnalyticsTCAUnitTest;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertNotNull;
33 * @author Rajiv Singla . Creation Date: 11/9/2016.
35 public class TCACEFJsonProcessorTest extends BaseAnalyticsTCAUnitTest {
38 // A valid CEF Message
40 public void testCEFJsonProcessorWithValidCEFMessage() throws Exception {
42 final String cefMessageString = fromStream(CEF_MESSAGE_JSON_FILE_LOCATION);
43 final TCACEFProcessorContext tcacefProcessorContext =
44 new TCACEFProcessorContext(cefMessageString, getSampleTCAPolicy());
46 TCACEFJsonProcessor tcacefJsonProcessor = new TCACEFJsonProcessor();
47 final TCACEFProcessorContext finalProcessorContext = tcacefJsonProcessor.apply(tcacefProcessorContext);
49 final EventListener cefEventListener = finalProcessorContext.getCEFEventListener();
51 assertNotNull("CEF Event Listener must be present", cefEventListener);
55 // Even if message is not a valid CEF format but still a Json - Json Processor will parse it
57 public void testCEFJsonProcessorWithValidJson() throws Exception {
59 final TCACEFProcessorContext tcacefProcessorContext = new TCACEFProcessorContext(
60 " { \"key\" : \"value\" } ", getSampleTCAPolicy());
62 TCACEFJsonProcessor tcacefJsonProcessor = new TCACEFJsonProcessor();
63 final TCACEFProcessorContext finalProcessorContext = tcacefJsonProcessor.apply(tcacefProcessorContext);
64 final EventListener cefEventListener = finalProcessorContext.getCEFEventListener();
66 assertNotNull("Even if message is not a valid CEF format but a valid Json.Json Processor must be able to " +
71 @Test(expected = MessageProcessingException.class)
72 public void testCEFJsonProcessorWithCEFMessageAsNull() throws Exception {
74 final TCACEFProcessorContext tcacefProcessorContext = new TCACEFProcessorContext(null, getSampleTCAPolicy());
76 TCACEFJsonProcessor tcacefJsonProcessor = new TCACEFJsonProcessor();
77 tcacefJsonProcessor.apply(tcacefProcessorContext);
82 public void testCEFJsonProcessorWithCEFMessageIsBlank() throws Exception {
84 final TCACEFProcessorContext tcacefProcessorContext = new TCACEFProcessorContext(" ", getSampleTCAPolicy());
86 TCACEFJsonProcessor tcacefJsonProcessor = new TCACEFJsonProcessor();
87 final TCACEFProcessorContext finalProcessorContext = tcacefJsonProcessor.apply(tcacefProcessorContext);
88 assertFalse("Blank message must terminate processing of message chain", finalProcessorContext
89 .canProcessingContinue());
94 public void testCEFJsonProcessorWithCEFMessageWhichIsNotValidMessage() throws Exception {
96 final TCACEFProcessorContext tcacefProcessorContext = new TCACEFProcessorContext(" Invalid Message ",
97 getSampleTCAPolicy());
99 TCACEFJsonProcessor tcacefJsonProcessor = new TCACEFJsonProcessor();
100 final TCACEFProcessorContext finalProcessorContext = tcacefJsonProcessor.apply(tcacefProcessorContext);
101 assertFalse("Invalid message must terminate processing of message chain", finalProcessorContext
102 .canProcessingContinue());
106 @Test(expected = MessageProcessingException.class)
107 public void testCEFJsonProcessorWithCEFMessageWhichIsNotValidJson() throws Exception {
109 final TCACEFProcessorContext tcacefProcessorContext = new TCACEFProcessorContext(
110 " { \"Invalid Event Listener Json\" } ", getSampleTCAPolicy());
112 TCACEFJsonProcessor tcacefJsonProcessor = new TCACEFJsonProcessor();
113 tcacefJsonProcessor.apply(tcacefProcessorContext);