kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 1 | /* |
Brian O'Connor | 7cbbbb7 | 2016-04-09 02:13:23 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Laboratory |
| 3 | * |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
Brian O'Connor | 7cbbbb7 | 2016-04-09 02:13:23 -0700 | [diff] [blame^] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.provider.snmp.alarm.impl; |
| 17 | |
| 18 | import com.btisystems.pronx.ems.core.snmp.ISnmpConfiguration; |
| 19 | import com.btisystems.pronx.ems.core.snmp.ISnmpSession; |
| 20 | import com.btisystems.pronx.ems.core.snmp.ISnmpSessionFactory; |
| 21 | import java.io.IOException; |
| 22 | import java.util.HashSet; |
| 23 | import org.easymock.EasyMock; |
| 24 | import static org.easymock.EasyMock.expect; |
| 25 | import static org.easymock.EasyMock.replay; |
| 26 | import static org.easymock.EasyMock.verify; |
| 27 | import org.junit.Assert; |
| 28 | import org.junit.Before; |
| 29 | import org.junit.Test; |
| 30 | import org.onosproject.incubator.net.faultmanagement.alarm.AlarmEvent; |
| 31 | import org.onosproject.net.DeviceId; |
| 32 | |
| 33 | public class SnmpDeviceAlarmProviderTest { |
| 34 | private SnmpAlarmProviderService alarmProvider; |
| 35 | private ISnmpSessionFactory mockSessionFactory; |
| 36 | private ISnmpSession mockSession; |
| 37 | private SnmpDeviceAlarmProvider mockProvider; |
| 38 | private AlarmEvent alarmEvent; |
| 39 | |
| 40 | public SnmpDeviceAlarmProviderTest() {} |
| 41 | |
| 42 | @Before |
| 43 | public void setUp() { |
| 44 | mockSessionFactory = EasyMock.createMock(ISnmpSessionFactory.class); |
| 45 | mockSession = EasyMock.createMock(ISnmpSession.class); |
| 46 | mockProvider = EasyMock.createMock(SnmpDeviceAlarmProvider.class); |
| 47 | |
| 48 | alarmProvider = new SnmpAlarmProviderService() { |
| 49 | @Override |
| 50 | protected ISnmpSessionFactory getSessionFactory() { |
| 51 | return mockSessionFactory; |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | alarmProvider.addAlarmListener((AlarmEvent event) -> { |
| 56 | alarmEvent = event; |
| 57 | }); |
| 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void shouldPopulateAlarmsForNetSnmp() throws IOException { |
| 62 | alarmProvider.providers.put("1.2.3.4", mockProvider); |
| 63 | expect(mockSessionFactory.createSession(EasyMock.isA(ISnmpConfiguration.class), |
| 64 | EasyMock.eq("1.1.1.1"))).andReturn(mockSession); |
| 65 | expect(mockSession.identifyDevice()).andReturn("1.2.3.4"); |
| 66 | expect(mockProvider.getAlarms(mockSession, DeviceId.deviceId("snmp:1.1.1.1:161"))) |
| 67 | .andReturn(new HashSet<>()); |
| 68 | |
| 69 | mockSession.close(); |
| 70 | EasyMock.expectLastCall().once(); |
| 71 | |
| 72 | replay(mockSessionFactory, mockSession, mockProvider); |
| 73 | |
| 74 | alarmProvider.triggerProbe(DeviceId.deviceId("snmp:1.1.1.1:161")); |
| 75 | |
| 76 | verify(mockSessionFactory, mockSession, mockProvider); |
| 77 | Assert.assertNotNull(alarmEvent); |
| 78 | } |
| 79 | |
| 80 | } |