533315021099b6d6bc59db7ff143caaf03f87850
[dcaegen2/analytics/tca.git] / dcae-analytics-common / src / test / java / org / openecomp / dcae / apod / analytics / common / utils / MessageProcessorUtilsTest.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.common.utils;
22
23 import com.google.common.collect.ImmutableSet;
24 import org.junit.Assert;
25 import org.junit.Test;
26 import org.openecomp.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest;
27 import org.openecomp.dcae.apod.analytics.common.service.filter.JsonMessageFilterProcessorContext;
28
29 import java.util.HashMap;
30 import java.util.Map;
31 import java.util.Set;
32
33 /**
34  * @author Rajiv Singla . Creation Date: 3/3/2017.
35  */
36 public class MessageProcessorUtilsTest extends BaseAnalyticsCommonUnitTest {
37
38
39     @Test
40     public void testProcessJsonFilterMappings() throws Exception {
41         final String jsonMessage = fromStream(CEF_MESSAGE_FILE_PATH);
42
43         final Map<String, Set<String>> jsonFilterMappings = new HashMap<>();
44         jsonFilterMappings.put("$.event.commonEventHeader.domain", ImmutableSet.of("measurementsForVfScaling"));
45         jsonFilterMappings.put("$.event.commonEventHeader.eventName",
46                 ImmutableSet.of("vFirewall", "vLoadBalancer", "Mfvs_eNodeB_RANKPI"));
47
48         final JsonMessageFilterProcessorContext jsonMessageFilterProcessorContext =
49                 MessageProcessorUtils.processJsonFilterMappings(jsonMessage, jsonFilterMappings);
50         final Boolean matched = jsonMessageFilterProcessorContext.getMatched();
51         Assert.assertNotNull(matched);
52         Assert.assertTrue(matched);
53     }
54
55     @Test(expected = IllegalStateException.class)
56     public void testProcessJsonFilterMappingsWhenMappingsAreEmpty() throws Exception {
57         final String jsonMessage = fromStream(CEF_MESSAGE_FILE_PATH);
58         final Map<String, Set<String>> jsonFilterMappings = new HashMap<>();
59         MessageProcessorUtils.processJsonFilterMappings(jsonMessage, jsonFilterMappings);
60     }
61
62 }