test enhancements
Change-Id: I28ac2733e6e1ee96810a47500d59d6b54aab3157
diff --git a/core/store/dist/src/test/java/org/onosproject/store/core/impl/DistributedApplicationIdStoreTest.java b/core/store/dist/src/test/java/org/onosproject/store/core/impl/DistributedApplicationIdStoreTest.java
new file mode 100644
index 0000000..dee8048
--- /dev/null
+++ b/core/store/dist/src/test/java/org/onosproject/store/core/impl/DistributedApplicationIdStoreTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2014-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.store.core.impl;
+
+import org.junit.Test;
+import org.junit.After;
+import org.junit.Before;
+
+import org.onosproject.app.ApplicationIdStore;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.store.service.TestStorageService;
+
+import java.util.Collection;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test Class for DistributedApplicationIdStore.
+ */
+public class DistributedApplicationIdStoreTest {
+ private DistributedApplicationIdStore appIdStore;
+ private ApplicationIdStore idStore;
+
+ private final String app1 = "appID1";
+ private final String app2 = "appID2";
+
+ @Before
+ public void setUp() throws Exception {
+ appIdStore = new DistributedApplicationIdStore();
+ appIdStore.storageService = new TestStorageService();
+ appIdStore.activate();
+ idStore = appIdStore;
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ appIdStore.deactivate();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testEmpty() {
+ idStore = new DistributedApplicationIdStore();
+ idStore.getAppIds();
+ }
+
+ @Test
+ public void testIdStore() {
+ Collection<ApplicationId> appIds = idStore.getAppIds();
+ assertTrue("App ID's should be empty", appIds.isEmpty());
+
+ idStore.registerApplication(app1);
+ appIds = idStore.getAppIds();
+ assertEquals("There should be one app ID", appIds.size(), 1);
+ assertEquals(idStore.getAppId((short) 1).id(), 1);
+ assertEquals(idStore.getAppId(app1).name(), "appID1");
+ assertEquals(idStore.getAppId(app2), null);
+
+ //Register same appid
+ idStore.registerApplication("appID1");
+ assertEquals(appIds.size(), 1);
+
+ idStore.registerApplication(app2);
+ assertEquals(idStore.getAppIds().size(), 2);
+ assertEquals(idStore.getAppId((short) 2).name(), app2);
+ }
+}
\ No newline at end of file
diff --git a/core/store/dist/src/test/java/org/onosproject/store/flowobjective/impl/DistributedFlowObjectiveStoreTest.java b/core/store/dist/src/test/java/org/onosproject/store/flowobjective/impl/DistributedFlowObjectiveStoreTest.java
index 93c40ec..535a095 100644
--- a/core/store/dist/src/test/java/org/onosproject/store/flowobjective/impl/DistributedFlowObjectiveStoreTest.java
+++ b/core/store/dist/src/test/java/org/onosproject/store/flowobjective/impl/DistributedFlowObjectiveStoreTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-present Open Networking Laboratory
+ * Copyright 2017-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,8 +24,14 @@
import org.onosproject.store.service.TestStorageService;
import com.google.common.base.Charsets;
+
+import java.util.Collections;
+
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
* Unit tests for distributed flow objective store.
@@ -49,15 +55,28 @@
@Test
public void testFlowObjectiveStore() {
+ NextGroup group1 = new DefaultNextGroup("1".getBytes(Charsets.US_ASCII));
NextGroup group2 = new DefaultNextGroup("2".getBytes(Charsets.US_ASCII));
int group1Id = store.allocateNextId();
int group2Id = store.allocateNextId();
NextGroup group1add = store.getNextGroup(group1Id);
assertThat(group1add, nullValue());
+ NextGroup dif = store.getNextGroup(3);
+ assertThat(dif, is(nullValue()));
+
+ store.putNextGroup(group1Id, group1);
store.putNextGroup(group2Id, group2);
NextGroup group2Query = store.getNextGroup(group2Id);
assertThat(group2Query.data(), is(group2.data()));
+ assertTrue(store.getAllGroups().containsKey(group2Id));
+ assertTrue(store.getAllGroups().containsKey(group1Id));
+
+ store.removeNextGroup(group2Id);
+ assertTrue(store.getAllGroups().containsKey(group1Id));
+ assertFalse(store.getAllGroups().containsKey(group2Id));
+ store.removeNextGroup(group1Id);
+ assertEquals(store.getAllGroups(), Collections.emptyMap());
}
-}
+}
\ No newline at end of file