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.common.utils;
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;
29 import java.util.HashMap;
34 * @author Rajiv Singla . Creation Date: 3/3/2017.
36 public class MessageProcessorUtilsTest extends BaseAnalyticsCommonUnitTest {
40 public void testProcessJsonFilterMappings() throws Exception {
41 final String jsonMessage = fromStream(CEF_MESSAGE_FILE_PATH);
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"));
48 final JsonMessageFilterProcessorContext jsonMessageFilterProcessorContext =
49 MessageProcessorUtils.processJsonFilterMappings(jsonMessage, jsonFilterMappings);
50 final Boolean matched = jsonMessageFilterProcessorContext.getMatched();
51 Assert.assertNotNull(matched);
52 Assert.assertTrue(matched);
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);