2 * ===============================LICENSE_START======================================
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
21 package org.openecomp.dcae.apod.analytics.common.utils;
\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
29 import java.util.HashMap;
\r
30 import java.util.Map;
\r
31 import java.util.Set;
\r
34 * @author Rajiv Singla . Creation Date: 3/3/2017.
\r
36 public class MessageProcessorUtilsTest extends BaseAnalyticsCommonUnitTest {
\r
40 public void testProcessJsonFilterMappings() throws Exception {
\r
41 final String jsonMessage = fromStream(CEF_MESSAGE_FILE_PATH);
\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
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
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