Andrea Campanella | 8e94b0c | 2016-04-12 13:58:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Andrea Campanella | 8e94b0c | 2016-04-12 13:58:07 -0700 | [diff] [blame] | 3 | * |
| 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 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 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 | |
| 17 | package org.onosproject.faultmanagement.impl; |
| 18 | |
| 19 | import org.junit.After; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame^] | 22 | import org.onosproject.alarm.Alarm; |
| 23 | import org.onosproject.alarm.AlarmId; |
| 24 | import org.onosproject.alarm.DefaultAlarm; |
Andrea Campanella | 8e94b0c | 2016-04-12 13:58:07 -0700 | [diff] [blame] | 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.store.service.TestStorageService; |
| 27 | |
| 28 | import static org.junit.Assert.assertFalse; |
| 29 | import static org.junit.Assert.assertTrue; |
| 30 | |
| 31 | /** |
| 32 | * Distributed Alarm store test suite. |
| 33 | */ |
| 34 | public class DistributedAlarmStoreTest { |
| 35 | private DistributedAlarmStore alarmStore; |
| 36 | private static final DeviceId DEVICE_ID = DeviceId.deviceId("foo:bar"); |
Andrea Campanella | 65f9eb9 | 2017-05-02 11:36:14 -0700 | [diff] [blame] | 37 | private static final String UNIQUE_ID_1 = "unique_id_1"; |
| 38 | private static final AlarmId A_ID = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_1); |
| 39 | private static final DefaultAlarm ALARM_A = new DefaultAlarm.Builder(A_ID, |
Andrea Campanella | 8e94b0c | 2016-04-12 13:58:07 -0700 | [diff] [blame] | 40 | DEVICE_ID, "aaa", Alarm.SeverityLevel.CRITICAL, 0).build(); |
| 41 | |
| 42 | /** |
| 43 | * Sets up the device key store and the storage service test harness. |
| 44 | */ |
| 45 | @Before |
| 46 | public void setUp() { |
| 47 | alarmStore = new DistributedAlarmStore(); |
| 48 | alarmStore.storageService = new TestStorageService(); |
| 49 | alarmStore.setDelegate(event -> { |
| 50 | }); |
| 51 | alarmStore.activate(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Tears down the device key store. |
| 56 | */ |
| 57 | @After |
| 58 | public void tearDown() { |
| 59 | alarmStore.deactivate(); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Tests adding, removing and getting. |
| 64 | */ |
| 65 | @Test |
| 66 | public void basics() { |
Andrea Campanella | 65f9eb9 | 2017-05-02 11:36:14 -0700 | [diff] [blame] | 67 | alarmStore.createOrUpdateAlarm(ALARM_A); |
Andrea Campanella | 8e94b0c | 2016-04-12 13:58:07 -0700 | [diff] [blame] | 68 | assertTrue("There should be one alarm in the set.", |
| 69 | alarmStore.getAlarms().contains(ALARM_A)); |
| 70 | assertTrue("The same alarm should be returned.", |
| 71 | alarmStore.getAlarms(DEVICE_ID).contains(ALARM_A)); |
| 72 | assertTrue("The alarm should be the same", |
| 73 | alarmStore.getAlarm(ALARM_A.id()).equals(ALARM_A)); |
| 74 | alarmStore.removeAlarm(ALARM_A.id()); |
| 75 | assertFalse("There should be no alarm in the set.", |
| 76 | alarmStore.getAlarms().contains(ALARM_A)); |
| 77 | } |
| 78 | |
| 79 | } |