blob: ddefb024e6ce3c90616b8572d673c7997850ed9a [file] [log] [blame]
Thomas Vachuskab809b382018-02-12 15:53:01 -08001/*
2 * Copyright 2018-present Open Networking Foundation
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.store.cfg;
18
19import com.google.common.collect.ImmutableSet;
20import org.junit.After;
21import org.junit.Before;
22import org.junit.Test;
23import org.onosproject.cfg.ComponentConfigEvent;
24import org.onosproject.store.service.TestStorageService;
25
26import static org.junit.Assert.*;
27
28public class DistributedComponentConfigStoreTest {
29
30 private static final String C1 = "c1";
31 private static final String C2 = "c2";
32
33 private TestStore store;
34 private ComponentConfigEvent event;
35
36 /**
37 * Sets up the device key store and the storage service test harness.
38 */
39 @Before
40 public void setUp() {
41 store = new TestStore();
42 store.storageService = new TestStorageService();
43 store.setDelegate(e -> this.event = e);
44 store.activate();
45 }
46
47 /**
48 * Tears down the device key store.
49 */
50 @After
51 public void tearDown() {
52 store.deactivate();
53 }
54
55 @Test
56 public void basics() {
57 assertNull("property should not be found", store.getProperty(C1, "bar"));
58 store.setProperty(C1, "foo", "yo");
59 store.setProperty(C1, "bar", "true");
60 store.setProperty(C2, "goo", "6.28");
61 assertEquals("incorrect event", ComponentConfigEvent.Type.PROPERTY_SET, event.type());
62 assertEquals("incorrect event key", "goo", event.name());
63 assertEquals("incorrect event value", "6.28", event.value());
64
65 assertEquals("incorrect property value", "true", store.getProperty(C1, "bar"));
66 assertEquals("incorrect property count", ImmutableSet.of("foo", "bar"),
67 store.getProperties(C1));
68
69 store.unsetProperty(C1, "bar");
70 assertEquals("incorrect event", ComponentConfigEvent.Type.PROPERTY_UNSET, event.type());
71 assertEquals("incorrect event key", "bar", event.name());
72 assertNull("incorrect event value", event.value());
73
74 assertNull("property should not be found", store.getProperty(C1, "bar"));
75 assertEquals("incorrect property count", ImmutableSet.of("foo"),
76 store.getProperties(C1));
77 }
78
79 class TestStore extends DistributedComponentConfigStore {
80 }
81}