X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ves-nf-oam-adopter%2Fves-nf-oam-adopter-snmp-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fo%2Fran%2Foam%2Fnf%2Foam%2Fadopter%2Fsnmp%2Fmanager%2FSnmpManagerTest.java;fp=ves-nf-oam-adopter%2Fves-nf-oam-adopter-snmp-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fo%2Fran%2Foam%2Fnf%2Foam%2Fadopter%2Fsnmp%2Fmanager%2FSnmpManagerTest.java;h=67cdfab61680e39f892480665d2c5d45463026cf;hb=ac6434712cc8c877ec2cb61aa306e33dd89f482e;hp=0000000000000000000000000000000000000000;hpb=204d666f85db71b0cff4f8508350524dde492f08;p=oam%2Fnf-oam-adopter.git diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-snmp-manager/src/test/java/org/o/ran/oam/nf/oam/adopter/snmp/manager/SnmpManagerTest.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-snmp-manager/src/test/java/org/o/ran/oam/nf/oam/adopter/snmp/manager/SnmpManagerTest.java new file mode 100644 index 0000000..67cdfab --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-snmp-manager/src/test/java/org/o/ran/oam/nf/oam/adopter/snmp/manager/SnmpManagerTest.java @@ -0,0 +1,90 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.o.ran.oam.nf.oam.adopter.snmp.manager; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + +import java.time.ZoneId; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.o.ran.oam.nf.oam.adopter.snmp.manager.api.TimeZoneOffsetService; +import org.o.ran.oam.nf.oam.adopter.snmp.manager.configurations.SnmpManagerConfig; +import org.o.ran.oam.nf.oam.adopter.snmp.manager.mapper.SnmpMapperImpl; +import org.o.ran.oam.nf.oam.adopter.snmp.manager.properties.SnmpManagerProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(classes = {VesEventNotifierMock.class, SnmpMappingConfigurationProvider.class, + SnmpMapperImpl.class, SnmpManagerProperties.class, SnmpManagerConfig.class}) +public class SnmpManagerTest { + @Autowired + @Qualifier("test") + private VesEventNotifierMock listener; + @Autowired + private SnmpManagerProperties snmpManagerProperties; + @Autowired + private SnmpManagerImpl snmpManager; + @MockBean + private TimeZoneOffsetService timeZoneOffsetService; + + @BeforeEach + public void init() { + when(timeZoneOffsetService.getTimeZone(anyString())).thenReturn(ZoneId.of("+02:00")); + } + + private static String getVesNotification(final VesEventNotifierMock notificationProvider) + throws InterruptedException { + for (int i = 0; i < 1000; i++) { + Thread.sleep(100); + if (notificationProvider.getEvent() != null) { + break; + } + } + final String event = notificationProvider.getEvent(); + assertNotNull(event); + notificationProvider.clear(); + return event; + } + + @Test + public void testDefaultTrap() throws Exception { + SnmpTestUtil + .sendDefaultTrapV2(snmpManagerProperties.getHost(), Integer.toString(snmpManagerProperties.getPort())); + final String expected = JsonUtils.readJson("/json/VESMessageDefaultTrap.json"); + final String actual = getVesNotification(listener); + JsonUtils.compareResultSkipEpoch(expected, actual); + } + + @Test + public void testBoxDown() throws Exception { + SnmpTestUtil.sendPortDownTrapV2(snmpManagerProperties.getHost(), + Integer.toString(snmpManagerProperties.getPort())); + final String expected = JsonUtils.readJson("/json/PortDOWN.json"); + final String actual = getVesNotification(listener); + JsonUtils.compareResult(expected, actual); + } +}