blob: f549682749ef3b737c3554fb3e8583dbd0bc60cc [file] [log] [blame]
Andrea Campanella8e94b0c2016-04-12 13:58:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Andrea Campanella8e94b0c2016-04-12 13:58:07 -07003 *
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
17package org.onosproject.faultmanagement.impl;
18
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
Thomas Vachuska52f2cd12018-11-08 21:20:04 -080022import org.onosproject.alarm.Alarm;
23import org.onosproject.alarm.AlarmId;
24import org.onosproject.alarm.DefaultAlarm;
Andrea Campanella8e94b0c2016-04-12 13:58:07 -070025import org.onosproject.net.DeviceId;
26import org.onosproject.store.service.TestStorageService;
27
28import static org.junit.Assert.assertFalse;
29import static org.junit.Assert.assertTrue;
30
31/**
32 * Distributed Alarm store test suite.
33 */
34public class DistributedAlarmStoreTest {
35 private DistributedAlarmStore alarmStore;
36 private static final DeviceId DEVICE_ID = DeviceId.deviceId("foo:bar");
Andrea Campanella65f9eb92017-05-02 11:36:14 -070037 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 Campanella8e94b0c2016-04-12 13:58:07 -070040 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 Campanella65f9eb92017-05-02 11:36:14 -070067 alarmStore.createOrUpdateAlarm(ALARM_A);
Andrea Campanella8e94b0c2016-04-12 13:58:07 -070068 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}