1a445716260c3fd399cbcb5c3032fa10d5871697
[dcaegen2/analytics/tca.git] / dcae-analytics-common / src / test / java / org / openecomp / dcae / apod / analytics / common / utils / MessageProcessorUtilsTest.java
1 /*\r
2  * ===============================LICENSE_START======================================\r
3  *  dcae-analytics\r
4  * ================================================================================\r
5  *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  *  Licensed under the Apache License, Version 2.0 (the "License");\r
8  *  you may not use this file except in compliance with the License.\r
9  *   You may obtain a copy of the License at\r
10  *\r
11  *          http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  *  Unless required by applicable law or agreed to in writing, software\r
14  *  distributed under the License is distributed on an "AS IS" BASIS,\r
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  *  See the License for the specific language governing permissions and\r
17  *  limitations under the License.\r
18  *  ============================LICENSE_END===========================================\r
19  */\r
20 \r
21 package org.openecomp.dcae.apod.analytics.common.utils;\r
22 \r
23 import com.google.common.collect.ImmutableSet;\r
24 import org.junit.Assert;\r
25 import org.junit.Test;\r
26 import org.openecomp.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest;\r
27 import org.openecomp.dcae.apod.analytics.common.service.filter.JsonMessageFilterProcessorContext;\r
28 \r
29 import java.util.HashMap;\r
30 import java.util.Map;\r
31 import java.util.Set;\r
32 \r
33 /**\r
34  * @author Rajiv Singla . Creation Date: 3/3/2017.\r
35  */\r
36 public class MessageProcessorUtilsTest extends BaseAnalyticsCommonUnitTest {\r
37 \r
38 \r
39     @Test\r
40     public void testProcessJsonFilterMappings() throws Exception {\r
41         final String jsonMessage = fromStream(CEF_MESSAGE_FILE_PATH);\r
42 \r
43         final Map<String, Set<String>> jsonFilterMappings = new HashMap<>();\r
44         jsonFilterMappings.put("$.event.commonEventHeader.domain", ImmutableSet.of("measurementsForVfScaling"));\r
45         jsonFilterMappings.put("$.event.commonEventHeader.eventName",\r
46                 ImmutableSet.of("vFirewall", "vLoadBalancer", "Mfvs_eNodeB_RANKPI"));\r
47 \r
48         final JsonMessageFilterProcessorContext jsonMessageFilterProcessorContext =\r
49                 MessageProcessorUtils.processJsonFilterMappings(jsonMessage, jsonFilterMappings);\r
50         final Boolean matched = jsonMessageFilterProcessorContext.getMatched();\r
51         Assert.assertNotNull(matched);\r
52         Assert.assertTrue(matched);\r
53     }\r
54 \r
55     @Test(expected = IllegalStateException.class)\r
56     public void testProcessJsonFilterMappingsWhenMappingsAreEmpty() throws Exception {\r
57         final String jsonMessage = fromStream(CEF_MESSAGE_FILE_PATH);\r
58         final Map<String, Set<String>> jsonFilterMappings = new HashMap<>();\r
59         MessageProcessorUtils.processJsonFilterMappings(jsonMessage, jsonFilterMappings);\r
60     }\r
61 \r
62 }\r