diff options
Diffstat (limited to 'framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo')
11 files changed, 0 insertions, 1390 deletions
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/BiLinkMapTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/BiLinkMapTest.java deleted file mode 100644 index 83f4809c..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/BiLinkMapTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2015 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.topo; - -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -/** - * Unit tests for {@link BiLinkMap}. - */ -public class BiLinkMapTest extends BiLinkTestBase { - - - private ConcreteLink clink; - private ConcreteLinkMap linkMap; - - @Before - public void setUp() { - linkMap = new ConcreteLinkMap(); - } - - @Test - public void basic() { - assertEquals("wrong map size", 0, linkMap.size()); - assertTrue("unexpected links", linkMap.biLinks().isEmpty()); - } - - @Test - public void addSameLinkTwice() { - linkMap.add(LINK_AB); - assertEquals("wrong map size", 1, linkMap.size()); - clink = linkMap.biLinks().iterator().next(); - assertEquals("wrong link one", LINK_AB, clink.one()); - assertNull("unexpected link two", clink.two()); - - linkMap.add(LINK_AB); - assertEquals("wrong map size", 1, linkMap.size()); - clink = linkMap.biLinks().iterator().next(); - assertEquals("wrong link one", LINK_AB, clink.one()); - assertNull("unexpected link two", clink.two()); - } - - @Test - public void addPairOfLinks() { - linkMap.add(LINK_AB); - assertEquals("wrong map size", 1, linkMap.size()); - clink = linkMap.biLinks().iterator().next(); - assertEquals("wrong link one", LINK_AB, clink.one()); - assertNull("unexpected link two", clink.two()); - - linkMap.add(LINK_BA); - assertEquals("wrong map size", 1, linkMap.size()); - clink = linkMap.biLinks().iterator().next(); - assertEquals("wrong link one", LINK_AB, clink.one()); - assertEquals("wrong link two", LINK_BA, clink.two()); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTest.java deleted file mode 100644 index 55f31ac9..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2015 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.topo; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -/** - * Unit tests for {@link BiLink}. - */ -public class BiLinkTest extends BiLinkTestBase { - - private static final String EXP_ID_AB = "device-a/1-device-b/2"; - - private BiLink blink; - - @Test - public void basic() { - blink = new ConcreteLink(KEY_AB, LINK_AB); - assertEquals("wrong id", EXP_ID_AB, blink.linkId()); - assertEquals("wrong key", KEY_AB, blink.key()); - assertEquals("wrong link one", LINK_AB, blink.one()); - assertNull("what?", blink.two()); - - blink.setOther(LINK_BA); - assertEquals("wrong link two", LINK_BA, blink.two()); - } - - @Test(expected = NullPointerException.class) - public void nullKey() { - new ConcreteLink(null, LINK_AB); - } - - @Test(expected = NullPointerException.class) - public void nullLink() { - new ConcreteLink(KEY_AB, null); - } - - @Test(expected = NullPointerException.class) - public void nullOther() { - blink = new ConcreteLink(KEY_AB, LINK_AB); - blink.setOther(null); - } -} - diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTestBase.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTestBase.java deleted file mode 100644 index a6beec86..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/BiLinkTestBase.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2015 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.topo; - -import org.onosproject.net.Annotations; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Link; -import org.onosproject.net.LinkKey; -import org.onosproject.net.PortNumber; -import org.onosproject.net.provider.ProviderId; - -/** - * Base class for unit tests of {@link BiLink} and {@link BiLinkMap}. - */ -public abstract class BiLinkTestBase { - - protected static class FakeLink implements Link { - private final ConnectPoint src; - private final ConnectPoint dst; - - FakeLink(ConnectPoint src, ConnectPoint dst) { - this.src = src; - this.dst = dst; - } - - @Override public ConnectPoint src() { - return src; - } - @Override public ConnectPoint dst() { - return dst; - } - - @Override public Type type() { - return null; - } - @Override public State state() { - return null; - } - @Override public boolean isDurable() { - return false; - } - @Override public Annotations annotations() { - return null; - } - @Override public ProviderId providerId() { - return null; - } - } - - protected static final DeviceId DEV_A_ID = DeviceId.deviceId("device-A"); - protected static final DeviceId DEV_B_ID = DeviceId.deviceId("device-B"); - protected static final PortNumber PORT_1 = PortNumber.portNumber(1); - protected static final PortNumber PORT_2 = PortNumber.portNumber(2); - - protected static final ConnectPoint CP_A1 = new ConnectPoint(DEV_A_ID, PORT_1); - protected static final ConnectPoint CP_B2 = new ConnectPoint(DEV_B_ID, PORT_2); - - protected static final LinkKey KEY_AB = LinkKey.linkKey(CP_A1, CP_B2); - protected static final LinkKey KEY_BA = LinkKey.linkKey(CP_B2, CP_A1); - - protected static final Link LINK_AB = new FakeLink(CP_A1, CP_B2); - protected static final Link LINK_BA = new FakeLink(CP_B2, CP_A1); - - protected static class ConcreteLink extends BiLink { - public ConcreteLink(LinkKey key, Link link) { - super(key, link); - } - @Override - public LinkHighlight highlight(Enum<?> type) { - return null; - } - } - - protected static class ConcreteLinkMap extends BiLinkMap<ConcreteLink> { - @Override - public ConcreteLink create(LinkKey key, Link link) { - return new ConcreteLink(key, link); - } - } - - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/ButtonIdTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/ButtonIdTest.java deleted file mode 100644 index 01a1b975..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/ButtonIdTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2015 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.topo; - -import org.junit.Test; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * Unit tests for {@link ButtonId}. - */ -public class ButtonIdTest { - - private static final String ID1 = "id-1"; - private static final String ID2 = "id-2"; - - private ButtonId b1, b2; - - - @Test - public void basic() { - b1 = new ButtonId(ID1); - } - - @Test - public void same() { - b1 = new ButtonId(ID1); - b2 = new ButtonId(ID1); - assertFalse("same ref?", b1 == b2); - assertTrue("not equal?", b1.equals(b2)); - } - - @Test - public void notSame() { - b1 = new ButtonId(ID1); - b2 = new ButtonId(ID2); - assertFalse("same ref?", b1 == b2); - assertFalse("equal?", b1.equals(b2)); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/HighlightsTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/HighlightsTest.java deleted file mode 100644 index fe663a5b..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/HighlightsTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2015 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.topo; - -import org.junit.Before; -import org.junit.Test; -import org.onosproject.ui.topo.Highlights.Amount; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -/** - * Unit tests for {@link Highlights}. - */ -public class HighlightsTest { - - private static final String DEV_1 = "dev-1"; - private static final String DEV_2 = "dev-2"; - private static final String HOST_A = "Host...A"; - - private Highlights highlights; - private DeviceHighlight dh1; - private DeviceHighlight dh2; - private HostHighlight hha; - - @Before - public void setUp() { - highlights = new Highlights(); - } - - @Test - public void basic() { - assertEquals("devices", 0, highlights.devices().size()); - assertEquals("hosts", 0, highlights.hosts().size()); - assertEquals("links", 0, highlights.links().size()); - assertEquals("sudue", Amount.ZERO, highlights.subdueLevel()); - } - - @Test - public void coupleOfDevices() { - dh1 = new DeviceHighlight(DEV_1); - dh2 = new DeviceHighlight(DEV_2); - - highlights.add(dh1); - highlights.add(dh2); - assertTrue("missing dh1", highlights.devices().contains(dh1)); - assertTrue("missing dh2", highlights.devices().contains(dh2)); - } - - @Test - public void alternateSubdue() { - highlights.subdueAllElse(Amount.MINIMALLY); - assertEquals("wrong level", Amount.MINIMALLY, highlights.subdueLevel()); - } - - @Test - public void highlightRetrieval() { - dh1 = new DeviceHighlight(DEV_1); - hha = new HostHighlight(HOST_A); - highlights.add(dh1) - .add(hha); - - assertNull("dev as host", highlights.getHost(DEV_1)); - assertNull("host as dev", highlights.getDevice(HOST_A)); - - assertEquals("missed dev as dev", dh1, highlights.getDevice(DEV_1)); - assertEquals("missed dev as node", dh1, highlights.getNode(DEV_1)); - - assertEquals("missed host as host", hha, highlights.getHost(HOST_A)); - assertEquals("missed host as node", hha, highlights.getNode(HOST_A)); - } - - // NOTE: further unit tests involving the Highlights class are done - // in TopoJsonTest. -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/LinkHighlightTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/LinkHighlightTest.java deleted file mode 100644 index a88de33a..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/LinkHighlightTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2015 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.topo; - -import org.junit.Test; - -import java.util.Iterator; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.onosproject.ui.topo.LinkHighlight.Flavor.*; - -/** - * Unit tests for {@link LinkHighlight}. - */ -public class LinkHighlightTest { - - private static final String LINK_ID = "link-id-for-testing"; - private static final String LABEL = "some label"; - private static final String EMPTY = ""; - private static final String CUSTOM = "custom"; - private static final String ANIMATED = "animated"; - private static final String OPTICAL = "optical"; - - private LinkHighlight lh; - - @Test - public void basic() { - lh = new LinkHighlight(LINK_ID, NO_HIGHLIGHT); - - assertEquals("wrong flavor", NO_HIGHLIGHT, lh.flavor()); - assertTrue("unexpected mods", lh.mods().isEmpty()); - assertEquals("wrong css", "plain", lh.cssClasses()); - assertEquals("wrong label", EMPTY, lh.label()); - } - - @Test - public void primaryOptical() { - lh = new LinkHighlight(LINK_ID, PRIMARY_HIGHLIGHT) - .addMod(LinkHighlight.MOD_OPTICAL); - - assertEquals("wrong flavor", PRIMARY_HIGHLIGHT, lh.flavor()); - assertEquals("missing mod", 1, lh.mods().size()); - Mod m = lh.mods().iterator().next(); - assertEquals("wrong mod", LinkHighlight.MOD_OPTICAL, m); - assertEquals("wrong css", "primary optical", lh.cssClasses()); - assertEquals("wrong label", EMPTY, lh.label()); - } - - @Test - public void secondaryAnimatedWithLabel() { - lh = new LinkHighlight(LINK_ID, SECONDARY_HIGHLIGHT) - .addMod(LinkHighlight.MOD_ANIMATED) - .setLabel(LABEL); - - assertEquals("wrong flavor", SECONDARY_HIGHLIGHT, lh.flavor()); - assertEquals("missing mod", 1, lh.mods().size()); - Mod m = lh.mods().iterator().next(); - assertEquals("wrong mod", LinkHighlight.MOD_ANIMATED, m); - assertEquals("wrong css", "secondary animated", lh.cssClasses()); - assertEquals("wrong label", LABEL, lh.label()); - } - - @Test - public void customMod() { - lh = new LinkHighlight(LINK_ID, PRIMARY_HIGHLIGHT) - .addMod(new Mod(CUSTOM)); - - assertEquals("missing mod", 1, lh.mods().size()); - Mod m = lh.mods().iterator().next(); - assertEquals("wrong mod", CUSTOM, m.toString()); - assertEquals("wrong css", "primary custom", lh.cssClasses()); - } - - @Test - public void severalMods() { - lh = new LinkHighlight(LINK_ID, SECONDARY_HIGHLIGHT) - .addMod(LinkHighlight.MOD_OPTICAL) - .addMod(LinkHighlight.MOD_ANIMATED) - .addMod(new Mod(CUSTOM)); - - assertEquals("missing mods", 3, lh.mods().size()); - Iterator<Mod> iter = lh.mods().iterator(); - // NOTE: we know we are using TreeSet as backing => sorted order - assertEquals("wrong mod", ANIMATED, iter.next().toString()); - assertEquals("wrong mod", CUSTOM, iter.next().toString()); - assertEquals("wrong mod", OPTICAL, iter.next().toString()); - assertEquals("wrong css", "secondary animated custom optical", lh.cssClasses()); - } - - @Test(expected = NullPointerException.class) - public void noFlavor() { - new LinkHighlight(LINK_ID, null); - } - - @Test(expected = NullPointerException.class) - public void noIdentity() { - new LinkHighlight(null, PRIMARY_HIGHLIGHT); - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/ModTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/ModTest.java deleted file mode 100644 index 03a18f97..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/ModTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2015 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.topo; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Unit tests for {@link Mod}. - */ -public class ModTest { - - private static final String AAA = "aaa"; - private static final String BBB = "bbb"; - - private Mod mod1; - private Mod mod2; - - @Test(expected = NullPointerException.class) - public void nullId() { - new Mod(null); - } - - @Test - public void basic() { - mod1 = new Mod(AAA); - assertEquals("wrong id", AAA, mod1.toString()); - } - - @Test - public void equivalence() { - mod1 = new Mod(AAA); - mod2 = new Mod(AAA); - assertNotSame("oops", mod1, mod2); - assertEquals("not equivalent", mod1, mod2); - } - - @Test - public void comparable() { - mod1 = new Mod(AAA); - mod2 = new Mod(BBB); - assertNotEquals("what?", mod1, mod2); - assertTrue(mod1.compareTo(mod2) < 0); - assertTrue(mod2.compareTo(mod1) > 0); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/NodeBadgeTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/NodeBadgeTest.java deleted file mode 100644 index c8243695..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/NodeBadgeTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2015 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.topo; - -import org.junit.Test; -import org.onosproject.ui.topo.NodeBadge.Status; - -import static org.junit.Assert.assertEquals; - -/** - * Unit tests for {@link NodeBadge}. - */ -public class NodeBadgeTest { - - private static final String MSG = "a msg"; - private static final String TXT = "text"; - private static final String GID = "glyph-id"; - private static final int NUM = 42; - private static final String NUM_STR = Integer.toString(NUM); - - private static final String WR_S = "wrong status"; - private static final String WR_B = "wrong boolean"; - private static final String WR_T = "wrong text"; - private static final String WR_M = "wrong message"; - private static final String WR_SF = "wrong string format"; - - private NodeBadge badge; - - private void checkFields(NodeBadge b, Status s, boolean g, - String txt, String msg) { - assertEquals(WR_S, s, b.status()); - assertEquals(WR_B, g, b.isGlyph()); - assertEquals(WR_T, txt, b.text()); - assertEquals(WR_M, msg, b.message()); - } - - @Test - public void badgeTypes() { - assertEquals(WR_SF, "i", Status.INFO.code()); - assertEquals(WR_SF, "w", Status.WARN.code()); - assertEquals(WR_SF, "e", Status.ERROR.code()); - assertEquals("unexpected size", 3, Status.values().length); - } - - @Test - public void textOnly() { - badge = NodeBadge.text(TXT); - checkFields(badge, Status.INFO, false, TXT, null); - } - - @Test - public void glyphOnly() { - badge = NodeBadge.glyph(GID); - checkFields(badge, Status.INFO, true, GID, null); - } - - @Test - public void numberOnly() { - badge = NodeBadge.number(NUM); - checkFields(badge, Status.INFO, false, NUM_STR, null); - } - - @Test - public void textInfo() { - badge = NodeBadge.text(Status.INFO, TXT); - checkFields(badge, Status.INFO, false, TXT, null); - } - - @Test - public void glyphWarn() { - badge = NodeBadge.glyph(Status.WARN, GID); - checkFields(badge, Status.WARN, true, GID, null); - } - - @Test - public void numberError() { - badge = NodeBadge.number(Status.ERROR, NUM); - checkFields(badge, Status.ERROR, false, NUM_STR, null); - } - - @Test - public void textInfoMsg() { - badge = NodeBadge.text(Status.INFO, TXT, MSG); - checkFields(badge, Status.INFO, false, TXT, MSG); - } - - @Test - public void glyphWarnMsg() { - badge = NodeBadge.glyph(Status.WARN, GID, MSG); - checkFields(badge, Status.WARN, true, GID, MSG); - } - - @Test - public void numberErrorMsg() { - badge = NodeBadge.number(Status.ERROR, NUM, MSG); - checkFields(badge, Status.ERROR, false, NUM_STR, MSG); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/NodeSelectionTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/NodeSelectionTest.java deleted file mode 100644 index 06a78580..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/NodeSelectionTest.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright 2015 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.topo; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.junit.Test; -import org.onlab.packet.ChassisId; -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onlab.packet.VlanId; -import org.onosproject.net.Annotations; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Host; -import org.onosproject.net.HostId; -import org.onosproject.net.HostLocation; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.device.DeviceServiceAdapter; -import org.onosproject.net.host.HostService; -import org.onosproject.net.host.HostServiceAdapter; -import org.onosproject.net.provider.ProviderId; - -import java.util.Set; - -import static org.junit.Assert.*; - -/** - * Unit tests for {@link NodeSelection}. - */ -public class NodeSelectionTest { - - private static class FakeDevice implements Device { - - private final DeviceId id; - - FakeDevice(DeviceId id) { - this.id = id; - } - - @Override - public DeviceId id() { - return id; - } - - @Override - public Type type() { - return null; - } - - @Override - public String manufacturer() { - return null; - } - - @Override - public String hwVersion() { - return null; - } - - @Override - public String swVersion() { - return null; - } - - @Override - public String serialNumber() { - return null; - } - - @Override - public ChassisId chassisId() { - return null; - } - - @Override - public Annotations annotations() { - return null; - } - - @Override - public ProviderId providerId() { - return null; - } - } - - private static class FakeHost implements Host { - - private final HostId id; - - FakeHost(HostId id) { - this.id = id; - } - - @Override - public HostId id() { - return id; - } - - @Override - public MacAddress mac() { - return null; - } - - @Override - public VlanId vlan() { - return null; - } - - @Override - public Set<IpAddress> ipAddresses() { - return null; - } - - @Override - public HostLocation location() { - return null; - } - - @Override - public Annotations annotations() { - return null; - } - - @Override - public ProviderId providerId() { - return null; - } - } - - - - private final ObjectMapper mapper = new ObjectMapper(); - - private static final String IDS = "ids"; - private static final String HOVER = "hover"; - - private static final DeviceId DEVICE_1_ID = DeviceId.deviceId("Device-1"); - private static final DeviceId DEVICE_2_ID = DeviceId.deviceId("Device-2"); - private static final HostId HOST_A_ID = HostId.hostId("aa:aa:aa:aa:aa:aa/1"); - private static final HostId HOST_B_ID = HostId.hostId("bb:bb:bb:bb:bb:bb/2"); - - private static final Device DEVICE_1 = new FakeDevice(DEVICE_1_ID); - private static final Device DEVICE_2 = new FakeDevice(DEVICE_2_ID); - private static final Host HOST_A = new FakeHost(HOST_A_ID); - private static final Host HOST_B = new FakeHost(HOST_B_ID); - - // ================== - // == FAKE SERVICES - private static class FakeDevices extends DeviceServiceAdapter { - @Override - public Device getDevice(DeviceId deviceId) { - if (DEVICE_1_ID.equals(deviceId)) { - return DEVICE_1; - } - if (DEVICE_2_ID.equals(deviceId)) { - return DEVICE_2; - } - return null; - } - } - - private static class FakeHosts extends HostServiceAdapter { - @Override - public Host getHost(HostId hostId) { - if (HOST_A_ID.equals(hostId)) { - return HOST_A; - } - if (HOST_B_ID.equals(hostId)) { - return HOST_B; - } - return null; - } - } - - private DeviceService deviceService = new FakeDevices(); - private HostService hostService = new FakeHosts(); - - private NodeSelection ns; - - private ObjectNode objectNode() { - return mapper.createObjectNode(); - } - - private ArrayNode arrayNode() { - return mapper.createArrayNode(); - } - - private NodeSelection createNodeSelection(ObjectNode payload) { - return new NodeSelection(payload, deviceService, hostService); - } - - // selection JSON payload creation methods - private ObjectNode emptySelection() { - ObjectNode payload = objectNode(); - ArrayNode ids = arrayNode(); - payload.set(IDS, ids); - return payload; - } - - private ObjectNode oneDeviceSelected() { - ObjectNode payload = objectNode(); - ArrayNode ids = arrayNode(); - payload.set(IDS, ids); - ids.add(DEVICE_1_ID.toString()); - return payload; - } - - private ObjectNode oneHostSelected() { - ObjectNode payload = objectNode(); - ArrayNode ids = arrayNode(); - payload.set(IDS, ids); - ids.add(HOST_A_ID.toString()); - return payload; - } - - private ObjectNode twoHostsOneDeviceSelected() { - ObjectNode payload = objectNode(); - ArrayNode ids = arrayNode(); - payload.set(IDS, ids); - ids.add(HOST_A_ID.toString()); - ids.add(DEVICE_1_ID.toString()); - ids.add(HOST_B_ID.toString()); - return payload; - } - - private ObjectNode oneHostAndHoveringDeviceSelected() { - ObjectNode payload = objectNode(); - ArrayNode ids = arrayNode(); - payload.set(IDS, ids); - ids.add(HOST_A_ID.toString()); - payload.put(HOVER, DEVICE_2_ID.toString()); - return payload; - } - - private ObjectNode twoDevicesOneHostAndHoveringHostSelected() { - ObjectNode payload = objectNode(); - ArrayNode ids = arrayNode(); - payload.set(IDS, ids); - ids.add(HOST_A_ID.toString()); - ids.add(DEVICE_1_ID.toString()); - ids.add(DEVICE_2_ID.toString()); - payload.put(HOVER, HOST_B_ID.toString()); - return payload; - } - - - @Test - public void basic() { - ns = createNodeSelection(emptySelection()); - assertEquals("unexpected devices", 0, ns.devices().size()); - assertEquals("unexpected devices w/hover", 0, ns.devicesWithHover().size()); - assertEquals("unexpected hosts", 0, ns.hosts().size()); - assertEquals("unexpected hosts w/hover", 0, ns.hostsWithHover().size()); - assertTrue("unexpected selection", ns.none()); - assertNull("hover?", ns.hovered()); - } - - @Test - public void oneDevice() { - ns = createNodeSelection(oneDeviceSelected()); - assertEquals("missing device", 1, ns.devices().size()); - assertTrue("missing device 1", ns.devices().contains(DEVICE_1)); - assertEquals("missing device w/hover", 1, ns.devicesWithHover().size()); - assertTrue("missing device 1 w/hover", ns.devicesWithHover().contains(DEVICE_1)); - assertEquals("unexpected hosts", 0, ns.hosts().size()); - assertEquals("unexpected hosts w/hover", 0, ns.hostsWithHover().size()); - assertFalse("unexpected selection", ns.none()); - assertNull("hover?", ns.hovered()); - } - - @Test - public void oneHost() { - ns = createNodeSelection(oneHostSelected()); - assertEquals("unexpected devices", 0, ns.devices().size()); - assertEquals("unexpected devices w/hover", 0, ns.devicesWithHover().size()); - assertEquals("missing host", 1, ns.hosts().size()); - assertTrue("missing host A", ns.hosts().contains(HOST_A)); - assertEquals("missing host w/hover", 1, ns.hostsWithHover().size()); - assertTrue("missing host A w/hover", ns.hostsWithHover().contains(HOST_A)); - assertFalse("unexpected selection", ns.none()); - assertNull("hover?", ns.hovered()); - } - - @Test - public void twoHostsOneDevice() { - ns = createNodeSelection(twoHostsOneDeviceSelected()); - assertEquals("missing device", 1, ns.devices().size()); - assertTrue("missing device 1", ns.devices().contains(DEVICE_1)); - assertEquals("missing device w/hover", 1, ns.devicesWithHover().size()); - assertTrue("missing device 1 w/hover", ns.devicesWithHover().contains(DEVICE_1)); - assertEquals("unexpected hosts", 2, ns.hosts().size()); - assertTrue("missing host A", ns.hosts().contains(HOST_A)); - assertTrue("missing host B", ns.hosts().contains(HOST_B)); - assertEquals("unexpected hosts w/hover", 2, ns.hostsWithHover().size()); - assertTrue("missing host A w/hover", ns.hostsWithHover().contains(HOST_A)); - assertTrue("missing host B w/hover", ns.hostsWithHover().contains(HOST_B)); - assertFalse("unexpected selection", ns.none()); - assertNull("hover?", ns.hovered()); - } - - @Test - public void oneHostAndHoveringDevice() { - ns = createNodeSelection(oneHostAndHoveringDeviceSelected()); - assertEquals("unexpected devices", 0, ns.devices().size()); - assertEquals("unexpected devices w/hover", 1, ns.devicesWithHover().size()); - assertTrue("missing device 2 w/hover", ns.devicesWithHover().contains(DEVICE_2)); - assertEquals("missing host", 1, ns.hosts().size()); - assertTrue("missing host A", ns.hosts().contains(HOST_A)); - assertEquals("missing host w/hover", 1, ns.hostsWithHover().size()); - assertTrue("missing host A w/hover", ns.hostsWithHover().contains(HOST_A)); - assertFalse("unexpected selection", ns.none()); - assertEquals("missing hover device 2", DEVICE_2, ns.hovered()); - } - - @Test - public void twoDevicesOneHostAndHoveringHost() { - ns = createNodeSelection(twoDevicesOneHostAndHoveringHostSelected()); - assertEquals("missing devices", 2, ns.devices().size()); - assertTrue("missing device 1", ns.devices().contains(DEVICE_1)); - assertTrue("missing device 2", ns.devices().contains(DEVICE_2)); - assertEquals("missing devices w/hover", 2, ns.devicesWithHover().size()); - assertTrue("missing device 1 w/hover", ns.devicesWithHover().contains(DEVICE_1)); - assertTrue("missing device 2 w/hover", ns.devicesWithHover().contains(DEVICE_2)); - assertEquals("missing host", 1, ns.hosts().size()); - assertTrue("missing host A", ns.hosts().contains(HOST_A)); - assertEquals("missing host w/hover", 2, ns.hostsWithHover().size()); - assertTrue("missing host A w/hover", ns.hostsWithHover().contains(HOST_A)); - assertTrue("missing host B w/hover", ns.hostsWithHover().contains(HOST_B)); - assertFalse("unexpected selection", ns.none()); - assertEquals("missing hover host B", HOST_B, ns.hovered()); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java deleted file mode 100644 index b6d32bed..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright 2015 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.topo; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.onosproject.ui.topo.PropertyPanel.Prop; - -import java.text.NumberFormat; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Locale; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - -/** - * Unit tests for {@link PropertyPanel}. - */ -public class PropertyPanelTest { - - // Modified property panel subclass to use ENGLISH locale formatter so - // we know formatted numbers will use comma for the thousand separator. - private static final class EnglishPropertyPanel extends PropertyPanel { - private static final NumberFormat ENGLISH_FORMATTER = - NumberFormat.getInstance(Locale.ENGLISH); - - public EnglishPropertyPanel(String title, String typeId) { - super(title, typeId); - } - - @Override - protected NumberFormat formatter() { - return ENGLISH_FORMATTER; - } - } - - private static final String TITLE_ORIG = "Original Title"; - private static final String TYPE_ORIG = "Original type ID"; - private static final String TITLE_NEW = "New Title"; - private static final String TYPE_NEW = "New type"; - private static final String SOME_IDENTIFICATION = "It's Me!"; - - private static final String KEY_A = "A"; - private static final String KEY_B = "B"; - private static final String KEY_C = "C"; - private static final String SEP = "-"; - private static final String KEY_Z = "Z"; - - private static final String VALUE_A = "Hay"; - private static final String VALUE_B = "Bee"; - private static final String VALUE_C = "Sea"; - private static final String VALUE_Z = "Zed"; - - private static final Map<String, Prop> PROP_MAP = new HashMap<>(); - - private static class FooClass { - private final String s; - FooClass(String s) { - this.s = s; - } - - @Override - public String toString() { - return ">" + s + "<"; - } - } - - private PropertyPanel pp; - - - - @BeforeClass - public static void setUpClass() { - PROP_MAP.put(KEY_A, new Prop(KEY_A, VALUE_A)); - PROP_MAP.put(KEY_B, new Prop(KEY_B, VALUE_B)); - PROP_MAP.put(KEY_C, new Prop(KEY_C, VALUE_C)); - PROP_MAP.put(KEY_Z, new Prop(KEY_Z, VALUE_Z)); - PROP_MAP.put(SEP, new PropertyPanel.Separator()); - } - - @Test - public void basic() { - pp = new EnglishPropertyPanel(TITLE_ORIG, TYPE_ORIG); - assertEquals("wrong title", TITLE_ORIG, pp.title()); - assertEquals("wrong type", TYPE_ORIG, pp.typeId()); - assertNull("id?", pp.id()); - assertEquals("unexpected props", 0, pp.properties().size()); - assertEquals("unexpected buttons", 0, pp.buttons().size()); - } - - @Test - public void changeTitle() { - basic(); - pp.title(TITLE_NEW); - assertEquals("wrong title", TITLE_NEW, pp.title()); - } - - @Test - public void changeType() { - basic(); - pp.typeId(TYPE_NEW); - assertEquals("wrong type", TYPE_NEW, pp.typeId()); - } - - @Test - public void setId() { - basic(); - pp.id(SOME_IDENTIFICATION); - assertEquals("wrong id", SOME_IDENTIFICATION, pp.id()); - } - - private void validateProps(String... keys) { - Iterator<Prop> iter = pp.properties().iterator(); - for (String k: keys) { - Prop exp = PROP_MAP.get(k); - Prop act = iter.next(); - assertEquals("Bad prop sequence", exp, act); - } - } - - private void validateProp(String key, String expValue) { - Iterator<Prop> iter = pp.properties().iterator(); - Prop prop = null; - while (iter.hasNext()) { - Prop p = iter.next(); - if (p.key().equals(key)) { - prop = p; - break; - } - } - if (prop == null) { - fail("no prop found with key: " + key); - } - assertEquals("Wrong prop value", expValue, prop.value()); - } - - @Test - public void props() { - basic(); - pp.addProp(KEY_A, VALUE_A) - .addProp(KEY_B, VALUE_B) - .addProp(KEY_C, VALUE_C); - assertEquals("bad props", 3, pp.properties().size()); - validateProps(KEY_A, KEY_B, KEY_C); - } - - @Test - public void separator() { - props(); - pp.addSeparator() - .addProp(KEY_Z, VALUE_Z); - - assertEquals("bad props", 5, pp.properties().size()); - validateProps(KEY_A, KEY_B, KEY_C, SEP, KEY_Z); - } - - @Test - public void removeAllProps() { - props(); - assertEquals("wrong props", 3, pp.properties().size()); - pp.removeAllProps(); - assertEquals("unexpected props", 0, pp.properties().size()); - } - - @Test - public void adjustProps() { - props(); - pp.removeProps(KEY_B, KEY_A); - pp.addProp(KEY_Z, VALUE_Z); - validateProps(KEY_C, KEY_Z); - } - - @Test - public void intValues() { - basic(); - pp.addProp(KEY_A, 200) - .addProp(KEY_B, 2000) - .addProp(KEY_C, 1234567); - - validateProp(KEY_A, "200"); - validateProp(KEY_B, "2,000"); - validateProp(KEY_C, "1,234,567"); - } - - @Test - public void longValues() { - basic(); - pp.addProp(KEY_A, 200L) - .addProp(KEY_B, 2000L) - .addProp(KEY_C, 1234567L) - .addProp(KEY_Z, Long.MAX_VALUE); - - validateProp(KEY_A, "200"); - validateProp(KEY_B, "2,000"); - validateProp(KEY_C, "1,234,567"); - validateProp(KEY_Z, "9,223,372,036,854,775,807"); - } - - @Test - public void objectValue() { - basic(); - pp.addProp(KEY_A, new FooClass("a")) - .addProp(KEY_B, new FooClass("bxyyzy"), "[xz]"); - - validateProp(KEY_A, ">a<"); - validateProp(KEY_B, ">byyy<"); - } - - private static final ButtonId BD_A = new ButtonId(KEY_A); - private static final ButtonId BD_B = new ButtonId(KEY_B); - private static final ButtonId BD_C = new ButtonId(KEY_C); - private static final ButtonId BD_Z = new ButtonId(KEY_Z); - - private void verifyButtons(String... keys) { - Iterator<ButtonId> iter = pp.buttons().iterator(); - for (String k: keys) { - assertEquals("wrong button", k, iter.next().id()); - } - assertFalse("too many buttons", iter.hasNext()); - } - - @Test - public void buttons() { - basic(); - pp.addButton(BD_A) - .addButton(BD_B); - assertEquals("wrong buttons", 2, pp.buttons().size()); - verifyButtons(KEY_A, KEY_B); - - pp.removeButtons(BD_B) - .addButton(BD_C) - .addButton(BD_Z); - assertEquals("wrong buttons", 3, pp.buttons().size()); - verifyButtons(KEY_A, KEY_C, KEY_Z); - - pp.removeAllButtons() - .addButton(BD_B); - assertEquals("wrong buttons", 1, pp.buttons().size()); - verifyButtons(KEY_B); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/TopoJsonTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/TopoJsonTest.java deleted file mode 100644 index 50aabf8e..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/TopoJsonTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2015 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.topo; - -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.junit.Test; -import org.onosproject.ui.JsonUtils; -import org.onosproject.ui.topo.Highlights.Amount; -import org.onosproject.ui.topo.NodeBadge.Status; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -/** - * Unit tests for {@link TopoJson}. - */ -public class TopoJsonTest { - - private static final String DEV1 = "device-1"; - private static final String DEV2 = "device-2"; - private static final String SOME_MSG = "Hello there"; - private static final String GID = "glyph-ID"; - - private ObjectNode payload; - - private void checkArrayLength(String key, int expLen) { - ArrayNode a = (ArrayNode) payload.get(key); - assertEquals("wrong size: " + key, expLen, a.size()); - } - - private void checkEmptyArrays() { - checkArrayLength(TopoJson.DEVICES, 0); - checkArrayLength(TopoJson.HOSTS, 0); - checkArrayLength(TopoJson.LINKS, 0); - } - - @Test - public void basicHighlights() { - Highlights h = new Highlights(); - payload = TopoJson.json(h); - checkEmptyArrays(); - String subdue = JsonUtils.string(payload, TopoJson.SUBDUE); - assertEquals("subdue", "", subdue); - } - - @Test - public void subdueMinimalHighlights() { - Highlights h = new Highlights().subdueAllElse(Amount.MINIMALLY); - payload = TopoJson.json(h); - checkEmptyArrays(); - String subdue = JsonUtils.string(payload, TopoJson.SUBDUE); - assertEquals("not min", "min", subdue); - } - - @Test - public void subdueMaximalHighlights() { - Highlights h = new Highlights().subdueAllElse(Amount.MAXIMALLY); - payload = TopoJson.json(h); - checkEmptyArrays(); - String subdue = JsonUtils.string(payload, TopoJson.SUBDUE); - assertEquals("not max", "max", subdue); - } - - @Test - public void badgedDevice() { - Highlights h = new Highlights(); - DeviceHighlight dh = new DeviceHighlight(DEV1); - dh.setBadge(NodeBadge.number(7)); - h.add(dh); - - dh = new DeviceHighlight(DEV2); - dh.setBadge(NodeBadge.glyph(Status.WARN, GID, SOME_MSG)); - h.add(dh); - - payload = TopoJson.json(h); -// System.out.println(payload); - - // dig into the payload, and verify the badges are set on the devices - ArrayNode a = (ArrayNode) payload.get(TopoJson.DEVICES); - - ObjectNode d = (ObjectNode) a.get(0); - assertEquals("wrong device id", DEV1, d.get(TopoJson.ID).asText()); - - ObjectNode b = (ObjectNode) d.get(TopoJson.BADGE); - assertNotNull("missing badge", b); - assertEquals("wrong status code", "i", b.get(TopoJson.STATUS).asText()); - assertEquals("wrong text", "7", b.get(TopoJson.TXT).asText()); - assertNull("glyph?", b.get(TopoJson.GID)); - assertNull("msg?", b.get(TopoJson.MSG)); - - d = (ObjectNode) a.get(1); - assertEquals("wrong device id", DEV2, d.get(TopoJson.ID).asText()); - - b = (ObjectNode) d.get(TopoJson.BADGE); - assertNotNull("missing badge", b); - assertEquals("wrong status code", "w", b.get(TopoJson.STATUS).asText()); - assertNull("text?", b.get(TopoJson.TXT)); - assertEquals("wrong text", GID, b.get(TopoJson.GID).asText()); - assertEquals("wrong message", SOME_MSG, b.get(TopoJson.MSG).asText()); - } -} |