blob: 34fb320da85ddd1d324fac13e10043bf27acc0bf [file] [log] [blame]
Andrea Campanella8e94b0c2016-04-12 13:58:07 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
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
17package org.onosproject.faultmanagement.impl;
18
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
22import org.onosproject.incubator.net.faultmanagement.alarm.Alarm;
23import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm;
24import org.onosproject.net.DeviceId;
25import org.onosproject.store.service.TestStorageService;
26
27import static org.junit.Assert.assertFalse;
28import static org.junit.Assert.assertTrue;
29
30/**
31 * Distributed Alarm store test suite.
32 */
33public class DistributedAlarmStoreTest {
34 private DistributedAlarmStore alarmStore;
35 private static final DeviceId DEVICE_ID = DeviceId.deviceId("foo:bar");
36 private static final DefaultAlarm ALARM_A = new DefaultAlarm.Builder(
37 DEVICE_ID, "aaa", Alarm.SeverityLevel.CRITICAL, 0).build();
38
39 /**
40 * Sets up the device key store and the storage service test harness.
41 */
42 @Before
43 public void setUp() {
44 alarmStore = new DistributedAlarmStore();
45 alarmStore.storageService = new TestStorageService();
46 alarmStore.setDelegate(event -> {
47 });
48 alarmStore.activate();
49 }
50
51 /**
52 * Tears down the device key store.
53 */
54 @After
55 public void tearDown() {
56 alarmStore.deactivate();
57 }
58
59 /**
60 * Tests adding, removing and getting.
61 */
62 @Test
63 public void basics() {
64 alarmStore.setAlarm(ALARM_A);
65 assertTrue("There should be one alarm in the set.",
66 alarmStore.getAlarms().contains(ALARM_A));
67 assertTrue("The same alarm should be returned.",
68 alarmStore.getAlarms(DEVICE_ID).contains(ALARM_A));
69 assertTrue("The alarm should be the same",
70 alarmStore.getAlarm(ALARM_A.id()).equals(ALARM_A));
71 alarmStore.removeAlarm(ALARM_A.id());
72 assertFalse("There should be no alarm in the set.",
73 alarmStore.getAlarms().contains(ALARM_A));
74 }
75
76}