2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2018 TechMahindra
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=========================================================
20 package org.onap.universalvesadapter.service;
22 import static org.junit.Assert.*;
23 import static org.mockito.Mockito.when;
25 import java.io.FileNotFoundException;
26 import java.io.FileReader;
27 import java.io.IOException;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.MockitoAnnotations;
34 import org.onap.dcaegen2.ves.domain.AdditionalField;
35 import org.onap.universalvesadapter.Application;
36 import org.onap.universalvesadapter.exception.MapperConfigException;
37 import org.onap.universalvesadapter.service.AdapterService;
38 import org.onap.universalvesadapter.utils.MapperConfigUtils;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.beans.factory.annotation.Value;
43 import org.springframework.boot.test.context.SpringBootTest;
44 import org.springframework.test.context.junit4.SpringRunner;
45 import org.springframework.util.FileCopyUtils;
47 @RunWith(SpringRunner.class)
48 @SpringBootTest(classes=Application.class)
49 public class AdapterServiceTest {
51 // private final Logger eLOGGER = LoggerFactory.getLogger(this.getClass());
55 MockitoAnnotations.initMocks(this);
60 private AdapterService adapterService;
63 //AdapterService adapterService = new AdapterService();
65 @Value("${mapperConfig.file}")
66 private String mapperConfigFile;
69 public void identifyEventTypeFromIncomingJson() throws MapperConfigException, FileNotFoundException, IOException {
71 String inputJsonString = "{ "
72 + "\"protocol version\":\"v2c\", "
73 + "\"notify OID\":\".1.3.6.1.4.1.74.2.46.12.1.1AAA\", "
74 + "\"cambria.partition\":\"dcae-snmp.client.research.att.com\", "
75 + "\"trap category\":\"UCSNMP-HEARTBEAT\", "
76 + "\"epoch_serno\": 15161177410000, "
77 + "\"community\":\"public\", "
78 + "\"time received\": 1516117741, "
79 + "\"agent name\":\"localhost\", "
80 + "\"agent address\":\"127.0.0.1\", "
81 + "\"community len\": 6, "
82 + "\"notify OID len\": 12, "
84 + " \"varbind_type\":\"octet\", "
85 + " \"varbind_oid\":\".1.3.6.1.4.1.74.2.46.12.1.1.1\", "
86 + " \"varbind_value\":\"ucsnmp heartbeat - ignore\" "
88 + " \"varbind_type\":\"octet\", "
89 + " \"varbind_oid\":\".1.3.6.1.4.1.74.2.46.12.1.1.2\", "
90 + " \"varbind_value\":\"Tue Jan 16 10:49:01 EST 2018\" "
96 String mappingConfigFileData = FileCopyUtils.copyToString(new FileReader(mapperConfigFile));
97 MapperConfigUtils.readMapperConfigFile(mappingConfigFileData);
98 domain = adapterService.identifyEventTypeFromIncomingJson(inputJsonString);
99 adapterService.identifyEventTypeFromIncomingJson(inputJsonString);
102 assertEquals("snmp", domain);
105 public void testidentifyEventTypeFromIncomingJson() throws MapperConfigException{
106 String inputJsonString = "{ "
107 + "\"protocol version\":\"v2c\", "
108 + "\"notify OID\":\".1.3.6.1.4.1.74.2.46.12.1.1AAA\", "
109 + "\"cambria.partition\":\"dcae-snmp.client.research.att.com\", "
110 + "\"trap category\":\"UCSNMP-HEARTBEAT\", "
111 + "\"epoch_serno\": 15161177410000, "
112 + "\"community\":\"public\", "
113 + "\"time received\": 1516117741, "
114 + "\"agent name\":\"localhost\", "
115 + "\"agent address\":\"127.0.0.1\", "
116 + "\"community len\": 6, "
117 + "\"notify OID len\": 12, "
118 + "\"varbinds\": [{ "
119 + " \"varbind_type\":\"octet\", "
120 + " \"varbind_oid\":\".1.3.6.1.4.1.74.2.46.12.1.1.1\", "
121 + " \"varbind_value\":\"ucsnmp heartbeat - ignore\" "
123 + " \"varbind_type\":\"octet\", "
124 + " \"varbind_oid\":\".1.3.6.1.4.1.74.2.46.12.1.1.2\", "
125 + " \"varbind_value\":\"Tue Jan 16 10:49:01 EST 2018\" "
128 // when(MapperConfigUtils.checkIncomingJsonForMatchingDomain(inputJsonString)).thenReturn("snmp");
129 String actualDomain=adapterService.identifyEventTypeFromIncomingJson(inputJsonString);
130 assertEquals("default", actualDomain);