2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2021 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 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 package org.o.ran.oam.nf.oam.adopter.snmp.manager;
22 import static org.junit.jupiter.api.Assertions.assertNotNull;
23 import static org.mockito.ArgumentMatchers.anyString;
24 import static org.mockito.Mockito.when;
26 import java.time.ZoneId;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29 import org.junit.jupiter.api.extension.ExtendWith;
30 import org.o.ran.oam.nf.oam.adopter.snmp.manager.api.TimeZoneOffsetService;
31 import org.o.ran.oam.nf.oam.adopter.snmp.manager.configurations.SnmpManagerConfig;
32 import org.o.ran.oam.nf.oam.adopter.snmp.manager.mapper.SnmpMapperImpl;
33 import org.o.ran.oam.nf.oam.adopter.snmp.manager.properties.SnmpManagerProperties;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.beans.factory.annotation.Qualifier;
36 import org.springframework.boot.test.context.SpringBootTest;
37 import org.springframework.boot.test.mock.mockito.MockBean;
38 import org.springframework.test.context.junit.jupiter.SpringExtension;
40 @ExtendWith(SpringExtension.class)
41 @SpringBootTest(classes = {VesEventNotifierMock.class, SnmpMappingConfigurationProvider.class,
42 SnmpMapperImpl.class, SnmpManagerProperties.class, SnmpManagerConfig.class})
43 public class SnmpManagerTest {
46 private VesEventNotifierMock listener;
48 private SnmpManagerProperties snmpManagerProperties;
50 private SnmpManagerImpl snmpManager;
52 private TimeZoneOffsetService timeZoneOffsetService;
56 when(timeZoneOffsetService.getTimeZone(anyString())).thenReturn(ZoneId.of("+02:00"));
59 private static String getVesNotification(final VesEventNotifierMock notificationProvider)
60 throws InterruptedException {
61 for (int i = 0; i < 1000; i++) {
63 if (notificationProvider.getEvent() != null) {
67 final String event = notificationProvider.getEvent();
69 notificationProvider.clear();
74 public void testDefaultTrap() throws Exception {
76 .sendDefaultTrapV2(snmpManagerProperties.getHost(), Integer.toString(snmpManagerProperties.getPort()));
77 final String expected = JsonUtils.readJson("/json/VESMessageDefaultTrap.json");
78 final String actual = getVesNotification(listener);
79 JsonUtils.compareResultSkipEpoch(expected, actual);
83 public void testBoxDown() throws Exception {
84 SnmpTestUtil.sendPortDownTrapV2(snmpManagerProperties.getHost(),
85 Integer.toString(snmpManagerProperties.getPort()));
86 final String expected = JsonUtils.readJson("/json/PortDOWN.json");
87 final String actual = getVesNotification(listener);
88 JsonUtils.compareResult(expected, actual);