ONOS-4326: Focusing on add/remove cluster member. (WIP).
If reviewing this, please refer to http://tinyurl.com/onos-ui-topo-model
Change-Id: Ic6568074ac768ec828f9103e92caab5e9a06ade6
diff --git a/core/api/src/test/java/org/onosproject/ui/AbstractUiTest.java b/core/api/src/test/java/org/onosproject/ui/AbstractUiTest.java
new file mode 100644
index 0000000..077d132
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/ui/AbstractUiTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2016-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.ui;
+
+/**
+ * Abstract base class for UI tests.
+ */
+public abstract class AbstractUiTest {
+
+ /**
+ * System agnostic end-of-line character.
+ */
+ protected static final String EOL = String.format("%n");
+
+ /**
+ * Prints the given string to stdout.
+ *
+ * @param s string to print
+ */
+ protected static void print(String s) {
+ System.out.println(s);
+ }
+
+ /**
+ * Prints the toString() of the given object to stdout.
+ *
+ * @param o object to print
+ */
+ protected static void print(Object o) {
+ if (o == null) {
+ print("<null>");
+ } else {
+ print(o.toString());
+ }
+ }
+
+ /**
+ * Prints the formatted string to stdout.
+ *
+ * @param fmt format string
+ * @param params parameters
+ * @see String#format(String, Object...)
+ */
+ protected static void print(String fmt, Object... params) {
+ print(String.format(fmt, params));
+ }
+
+ /**
+ * Prints a title, to delimit individual unit test output.
+ *
+ * @param s a title for the test
+ */
+ protected static void title(String s) {
+ print(EOL + "=== %s ===", s);
+ }
+}
diff --git a/core/api/src/test/java/org/onosproject/ui/model/AbstractUiModelTest.java b/core/api/src/test/java/org/onosproject/ui/model/AbstractUiModelTest.java
new file mode 100644
index 0000000..5037832
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/ui/model/AbstractUiModelTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2016-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.ui.model;
+
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.cluster.ClusterServiceAdapter;
+import org.onosproject.cluster.ControllerNode;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.host.HostService;
+import org.onosproject.net.intent.IntentService;
+import org.onosproject.net.link.LinkService;
+import org.onosproject.net.region.RegionService;
+import org.onosproject.ui.AbstractUiTest;
+
+/**
+ * Base class for UI model unit tests.
+ */
+public class AbstractUiModelTest extends AbstractUiTest {
+
+ /**
+ * Returns canned results.
+ * At some future point, we may make this "programmable", so that
+ * it returns certain values based on element IDs etc.
+ */
+ protected static final ServiceBundle MOCK_SERVICES =
+ new ServiceBundle() {
+ @Override
+ public ClusterService cluster() {
+ return MOCK_CLUSTER;
+ }
+
+ @Override
+ public MastershipService mastership() {
+ return null;
+ }
+
+ @Override
+ public RegionService region() {
+ return null;
+ }
+
+ @Override
+ public DeviceService device() {
+ return null;
+ }
+
+ @Override
+ public LinkService link() {
+ return null;
+ }
+
+ @Override
+ public HostService host() {
+ return null;
+ }
+
+ @Override
+ public IntentService intent() {
+ return null;
+ }
+
+ @Override
+ public FlowRuleService flow() {
+ return null;
+ }
+ };
+
+ private static final ClusterService MOCK_CLUSTER = new MockClusterService();
+
+
+ private static class MockClusterService extends ClusterServiceAdapter {
+ @Override
+ public ControllerNode.State getState(NodeId nodeId) {
+ // For now, a hardcoded state of ACTIVE (but not READY)
+ // irrespective of the node ID.
+ return ControllerNode.State.ACTIVE;
+ }
+ }
+
+}
diff --git a/core/api/src/test/java/org/onosproject/ui/model/topo/UiClusterMemberTest.java b/core/api/src/test/java/org/onosproject/ui/model/topo/UiClusterMemberTest.java
new file mode 100644
index 0000000..db35b33
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/ui/model/topo/UiClusterMemberTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016-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.ui.model.topo;
+
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cluster.ControllerNode;
+import org.onosproject.cluster.DefaultControllerNode;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.ui.model.AbstractUiModelTest;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit tests for {@link UiClusterMember}.
+ */
+public class UiClusterMemberTest extends AbstractUiModelTest {
+
+ private static final NodeId NODE_ID = NodeId.nodeId("Node-1");
+ private static final IpAddress NODE_IP = IpAddress.valueOf("1.2.3.4");
+
+ private static final ControllerNode CNODE_1 =
+ new DefaultControllerNode(NODE_ID, NODE_IP);
+
+ private UiClusterMember member;
+
+ @Test
+ public void basic() {
+ title("basic");
+ member = new UiClusterMember(CNODE_1);
+ print(member);
+
+ assertEquals("wrong id", NODE_ID, member.id());
+ assertEquals("wrong IP", NODE_IP, member.ip());
+ assertEquals("unex. online", false, member.isOnline());
+ assertEquals("unex. ready", false, member.isReady());
+ assertEquals("unex. device count", 0, member.deviceCount());
+ }
+}