diff options
Diffstat (limited to 'framework/src/onos/core/api/src/test/java/org/onosproject/ui')
25 files changed, 0 insertions, 2583 deletions
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/UiExtensionServiceAdapter.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/UiExtensionServiceAdapter.java deleted file mode 100644 index 68d9264c..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/UiExtensionServiceAdapter.java +++ /dev/null @@ -1,41 +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; - -import java.util.List; - -/** - * Adapter for testing against UI extension service. - */ -public class UiExtensionServiceAdapter implements UiExtensionService { - @Override - public void register(UiExtension extension) { - } - - @Override - public void unregister(UiExtension extension) { - } - - @Override - public List<UiExtension> getExtensions() { - return null; - } - - @Override - public UiExtension getViewExtension(String viewId) { - return null; - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/UiExtensionTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/UiExtensionTest.java deleted file mode 100644 index bd3d15f6..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/UiExtensionTest.java +++ /dev/null @@ -1,140 +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; - -import com.google.common.collect.ImmutableList; -import org.junit.Test; - -import java.io.IOException; -import java.util.List; - -import static com.google.common.io.ByteStreams.toByteArray; -import static org.junit.Assert.*; -import static org.onosproject.ui.UiView.Category.OTHER; - -/** - * Tests the default user interface extension descriptor. - */ -public class UiExtensionTest { - - private static final String FOO_ID = "foo"; - private static final String FOO_LABEL = "Foo View"; - private static final String BAR_ID = "bar"; - private static final String BAR_LABEL = "Bar View"; - private static final String CUSTOM = "custom"; - - - private static final UiView FOO_VIEW = new UiView(OTHER, FOO_ID, FOO_LABEL); - private static final UiView BAR_VIEW = new UiView(OTHER, BAR_ID, BAR_LABEL); - private static final UiView HIDDEN_VIEW = new UiViewHidden(FOO_ID); - - private static final UiMessageHandlerFactory MH_FACTORY = () -> null; - private static final UiTopoOverlayFactory TO_FACTORY = () -> null; - - private final ClassLoader cl = getClass().getClassLoader(); - - private List<UiView> viewList; - private UiExtension ext; - private String css; - private String js; - private UiView view; - - - - @Test - public void basics() throws IOException { - viewList = ImmutableList.of(FOO_VIEW); - ext = new UiExtension.Builder(cl, viewList).build(); - - css = new String(toByteArray(ext.css())); - assertTrue("incorrect css stream", css.contains("foo-css")); - js = new String(toByteArray(ext.js())); - assertTrue("incorrect js stream", js.contains("foo-js")); - - assertEquals("expected 1 view", 1, ext.views().size()); - view = ext.views().get(0); - assertEquals("wrong view category", OTHER, view.category()); - assertEquals("wrong view id", FOO_ID, view.id()); - assertEquals("wrong view label", FOO_LABEL, view.label()); - - assertNull("unexpected message handler factory", ext.messageHandlerFactory()); - assertNull("unexpected topo overlay factory", ext.topoOverlayFactory()); - } - - @Test - public void withPath() throws IOException { - viewList = ImmutableList.of(FOO_VIEW); - ext = new UiExtension.Builder(cl, viewList) - .resourcePath(CUSTOM) - .build(); - - css = new String(toByteArray(ext.css())); - assertTrue("incorrect css stream", css.contains("custom-css")); - js = new String(toByteArray(ext.js())); - assertTrue("incorrect js stream", js.contains("custom-js")); - - assertEquals("expected 1 view", 1, ext.views().size()); - view = ext.views().get(0); - assertEquals("wrong view category", OTHER, view.category()); - assertEquals("wrong view id", FOO_ID, view.id()); - assertEquals("wrong view label", FOO_LABEL, view.label()); - - assertNull("unexpected message handler factory", ext.messageHandlerFactory()); - assertNull("unexpected topo overlay factory", ext.topoOverlayFactory()); - } - - @Test - public void messageHandlerFactory() { - viewList = ImmutableList.of(FOO_VIEW); - ext = new UiExtension.Builder(cl, viewList) - .messageHandlerFactory(MH_FACTORY) - .build(); - - assertEquals("wrong message handler factory", MH_FACTORY, - ext.messageHandlerFactory()); - assertNull("unexpected topo overlay factory", ext.topoOverlayFactory()); - } - - @Test - public void topoOverlayFactory() { - viewList = ImmutableList.of(HIDDEN_VIEW); - ext = new UiExtension.Builder(cl, viewList) - .topoOverlayFactory(TO_FACTORY) - .build(); - - assertNull("unexpected message handler factory", ext.messageHandlerFactory()); - assertEquals("wrong topo overlay factory", TO_FACTORY, - ext.topoOverlayFactory()); - } - - @Test - public void twoViews() { - viewList = ImmutableList.of(FOO_VIEW, BAR_VIEW); - ext = new UiExtension.Builder(cl, viewList).build(); - - assertEquals("expected 2 views", 2, ext.views().size()); - - view = ext.views().get(0); - assertEquals("wrong view category", OTHER, view.category()); - assertEquals("wrong view id", FOO_ID, view.id()); - assertEquals("wrong view label", FOO_LABEL, view.label()); - - view = ext.views().get(1); - assertEquals("wrong view category", OTHER, view.category()); - assertEquals("wrong view id", BAR_ID, view.id()); - assertEquals("wrong view label", BAR_LABEL, view.label()); - } -}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/TableModelTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/TableModelTest.java deleted file mode 100644 index 7524bcb3..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/TableModelTest.java +++ /dev/null @@ -1,338 +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.table; - -import org.junit.Test; -import org.onosproject.ui.table.TableModel.SortDir; -import org.onosproject.ui.table.cell.DefaultCellFormatter; -import org.onosproject.ui.table.cell.HexFormatter; - -import static org.junit.Assert.*; - -/** - * Unit tests for {@link TableModel}. - */ -public class TableModelTest { - - private static final String UNEX_SORT = "unexpected sort: index "; - - private static final String FOO = "foo"; - private static final String BAR = "bar"; - private static final String ZOO = "zoo"; - - private enum StarWars { - LUKE_SKYWALKER, LEIA_ORGANA, HAN_SOLO, C3PO, R2D2, JABBA_THE_HUTT - } - - private static class ParenFormatter implements CellFormatter { - @Override - public String format(Object value) { - return "(" + value + ")"; - } - } - - private TableModel tm; - private TableModel.Row[] rows; - private TableModel.Row row; - private CellFormatter fmt; - - @Test(expected = NullPointerException.class) - public void guardAgainstNull() { - tm = new TableModel(null); - } - - @Test(expected = IllegalArgumentException.class) - public void guardAgainstEmpty() { - tm = new TableModel(); - } - - @Test(expected = IllegalArgumentException.class) - public void guardAgainstDuplicateCols() { - tm = new TableModel(FOO, BAR, FOO); - } - - @Test - public void basic() { - tm = new TableModel(FOO, BAR); - assertEquals("column count", 2, tm.columnCount()); - assertEquals("row count", 0, tm.rowCount()); - } - - @Test - public void defaultFormatter() { - tm = new TableModel(FOO); - fmt = tm.getFormatter(FOO); - assertTrue("Wrong formatter", fmt instanceof DefaultCellFormatter); - } - - @Test(expected = IllegalArgumentException.class) - public void formatterBadColumn() { - tm = new TableModel(FOO); - fmt = tm.getFormatter(BAR); - } - - @Test - public void altFormatter() { - tm = new TableModel(FOO, BAR); - tm.setFormatter(BAR, new ParenFormatter()); - - fmt = tm.getFormatter(FOO); - assertTrue("Wrong formatter", fmt instanceof DefaultCellFormatter); - assertEquals("Wrong result", "2", fmt.format(2)); - - fmt = tm.getFormatter(BAR); - assertTrue("Wrong formatter", fmt instanceof ParenFormatter); - assertEquals("Wrong result", "(2)", fmt.format(2)); - } - - @Test - public void emptyRow() { - tm = new TableModel(FOO, BAR); - tm.addRow(); - assertEquals("bad row count", 1, tm.rowCount()); - } - - @Test(expected = IllegalArgumentException.class) - public void rowBadColumn() { - tm = new TableModel(FOO, BAR); - tm.addRow().cell(ZOO, 2); - } - - @Test - public void simpleRow() { - tm = new TableModel(FOO, BAR); - tm.addRow().cell(FOO, 3).cell(BAR, true); - assertEquals("bad row count", 1, tm.rowCount()); - row = tm.getRows()[0]; - assertEquals("bad cell", 3, row.get(FOO)); - assertEquals("bad cell", true, row.get(BAR)); - } - - - private static final String ONE = "one"; - private static final String TWO = "two"; - private static final String THREE = "three"; - private static final String FOUR = "four"; - private static final String ELEVEN = "eleven"; - private static final String TWELVE = "twelve"; - private static final String TWENTY = "twenty"; - private static final String THIRTY = "thirty"; - - private static final String[] NAMES = { - FOUR, - THREE, - TWO, - ONE, - ELEVEN, - TWELVE, - THIRTY, - TWENTY, - }; - private static final String[] SORTED_NAMES = { - ELEVEN, - FOUR, - ONE, - THIRTY, - THREE, - TWELVE, - TWENTY, - TWO, - }; - - private static final int[] NUMBERS = { - 4, 3, 2, 1, 11, 12, 30, 20 - }; - - private static final int[] SORTED_NUMBERS = { - 1, 2, 3, 4, 11, 12, 20, 30 - }; - - private static final String[] SORTED_HEX = { - "0x1", "0x2", "0x3", "0x4", "0xb", "0xc", "0x14", "0x1e" - }; - - @Test - public void verifyTestData() { - // not a unit test per se, but will fail if we don't keep - // the three test arrays in sync - int nalen = NAMES.length; - int snlen = SORTED_NAMES.length; - int nulen = NUMBERS.length; - - if (nalen != snlen || nalen != nulen) { - fail("test data array size discrepancy"); - } - } - - private void initUnsortedTable() { - tm = new TableModel(FOO, BAR); - for (int i = 0; i < NAMES.length; i++) { - tm.addRow().cell(FOO, NAMES[i]).cell(BAR, NUMBERS[i]); - } - } - - @Test - public void tableStringSort() { - initUnsortedTable(); - - // sort by name - tm.sort(FOO, SortDir.ASC); - - // verify results - rows = tm.getRows(); - int nr = rows.length; - assertEquals("row count", NAMES.length, nr); - for (int i = 0; i < nr; i++) { - assertEquals(UNEX_SORT + i, SORTED_NAMES[i], rows[i].get(FOO)); - } - - // now the other way - tm.sort(FOO, SortDir.DESC); - - // verify results - rows = tm.getRows(); - nr = rows.length; - assertEquals("row count", NAMES.length, nr); - for (int i = 0; i < nr; i++) { - assertEquals(UNEX_SORT + i, - SORTED_NAMES[nr - 1 - i], rows[i].get(FOO)); - } - } - - @Test - public void tableNumberSort() { - initUnsortedTable(); - - // sort by number - tm.sort(BAR, SortDir.ASC); - - // verify results - rows = tm.getRows(); - int nr = rows.length; - assertEquals("row count", NUMBERS.length, nr); - for (int i = 0; i < nr; i++) { - assertEquals(UNEX_SORT + i, SORTED_NUMBERS[i], rows[i].get(BAR)); - } - - // now the other way - tm.sort(BAR, SortDir.DESC); - - // verify results - rows = tm.getRows(); - nr = rows.length; - assertEquals("row count", NUMBERS.length, nr); - for (int i = 0; i < nr; i++) { - assertEquals(UNEX_SORT + i, - SORTED_NUMBERS[nr - 1 - i], rows[i].get(BAR)); - } - } - - @Test - public void sortAndFormat() { - initUnsortedTable(); - - // set hex formatter - tm.setFormatter(BAR, HexFormatter.INSTANCE); - - // sort by number - tm.sort(BAR, SortDir.ASC); - - // verify results - rows = tm.getRows(); - int nr = rows.length; - assertEquals("row count", SORTED_HEX.length, nr); - for (int i = 0; i < nr; i++) { - assertEquals(UNEX_SORT + i, SORTED_HEX[i], rows[i].getAsString(BAR)); - } - } - - private static final String[][] SORTED_NAMES_AND_HEX = { - {ELEVEN, "0xb"}, - {FOUR, "0x4"}, - {ONE, "0x1"}, - {THIRTY, "0x1e"}, - {THREE, "0x3"}, - {TWELVE, "0xc"}, - {TWENTY, "0x14"}, - {TWO, "0x2"}, - }; - - @Test - public void sortAndFormatTwo() { - initUnsortedTable(); - tm.setFormatter(BAR, HexFormatter.INSTANCE); - tm.sort(FOO, SortDir.ASC); - rows = tm.getRows(); - int nr = rows.length; - for (int i = 0; i < nr; i++) { - String[] exp = SORTED_NAMES_AND_HEX[i]; - String[] act = rows[i].getAsFormattedStrings(); - assertArrayEquals(UNEX_SORT + i, exp, act); - } - } - - private static final String[] FBZ = {FOO, BAR, ZOO}; - - @Test - public void getColumnIds() { - tm = new TableModel(FOO, BAR, ZOO); - assertArrayEquals("col IDs", FBZ, tm.getColumnIds()); - } - - @Test - public void sortDirAsc() { - assertEquals("asc sort dir", SortDir.ASC, TableModel.sortDir("asc")); - } - - @Test - public void sortDirDesc() { - assertEquals("desc sort dir", SortDir.DESC, TableModel.sortDir("desc")); - } - - @Test - public void sortDirOther() { - assertEquals("other sort dir", SortDir.ASC, TableModel.sortDir("other")); - } - - @Test - public void sortDirNull() { - assertEquals("null sort dir", SortDir.ASC, TableModel.sortDir(null)); - } - - - @Test - public void enumSort() { - tm = new TableModel(FOO); - tm.addRow().cell(FOO, StarWars.HAN_SOLO); - tm.addRow().cell(FOO, StarWars.C3PO); - tm.addRow().cell(FOO, StarWars.JABBA_THE_HUTT); - tm.addRow().cell(FOO, StarWars.LEIA_ORGANA); - tm.addRow().cell(FOO, StarWars.R2D2); - tm.addRow().cell(FOO, StarWars.LUKE_SKYWALKER); - - tm.sort(FOO, SortDir.ASC); - - // verify expected results - StarWars[] ordered = StarWars.values(); - TableModel.Row[] rows = tm.getRows(); - assertEquals("wrong length?", ordered.length, rows.length); - int nr = rows.length; - for (int i = 0; i < nr; i++) { - assertEquals(UNEX_SORT + i, ordered[i], rows[i].get(FOO)); - } - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/TableUtilsTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/TableUtilsTest.java deleted file mode 100644 index 4456dd3d..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/TableUtilsTest.java +++ /dev/null @@ -1,44 +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.table; - -import com.fasterxml.jackson.databind.node.ArrayNode; -import org.junit.Assert; -import org.junit.Test; - -/** - * Unit tests for {@link TableUtils}. - */ -public class TableUtilsTest { - - private static final String FOO = "foo"; - private static final String BAR = "bar"; - - private static final String ARRAY_AS_STRING = - "[{\"foo\":\"1\",\"bar\":\"2\"},{\"foo\":\"3\",\"bar\":\"4\"}]"; - - @Test - public void basic() { - TableModel tm = new TableModel(FOO, BAR); - tm.addRow().cell(FOO, 1).cell(BAR, 2); - tm.addRow().cell(FOO, 3).cell(BAR, 4); - - ArrayNode array = TableUtils.generateArrayNode(tm); - Assert.assertEquals("wrong results", ARRAY_AS_STRING, array.toString()); - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/AbstractCellComparatorTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/AbstractCellComparatorTest.java deleted file mode 100644 index 30125afb..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/AbstractCellComparatorTest.java +++ /dev/null @@ -1,58 +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.table.cell; - -import org.junit.Test; -import org.onosproject.ui.table.CellComparator; - -import static org.junit.Assert.assertTrue; - -/** - * Unit tests for {@link AbstractCellComparator}. - */ -public class AbstractCellComparatorTest { - - private static class Concrete extends AbstractCellComparator { - @Override - protected int nonNullCompare(Object o1, Object o2) { - return 42; - } - } - - private CellComparator cmp = new Concrete(); - - @Test - public void twoNullArgs() { - assertTrue("two nulls", cmp.compare(null, null) == 0); - } - - @Test - public void nullArgOne() { - assertTrue("null one", cmp.compare(null, 1) < 0); - } - - @Test - public void nullArgTwo() { - assertTrue("null two", cmp.compare(1, null) > 0); - } - - // mock output, but check that our method was invoked... - @Test - public void noNulls() { - assertTrue("no Nulls", cmp.compare(1, 2) == 42); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/AbstractCellFormatterTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/AbstractCellFormatterTest.java deleted file mode 100644 index 41fefd65..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/AbstractCellFormatterTest.java +++ /dev/null @@ -1,51 +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.table.cell; - -import org.junit.Test; -import org.onosproject.ui.table.CellFormatter; - -import static org.junit.Assert.assertEquals; - -/** - * Unit tests for {@link AbstractCellFormatter}. - */ -public class AbstractCellFormatterTest { - - private static final String MOCK_OUTPUT = "Mock!!"; - - private static class Concrete extends AbstractCellFormatter { - @Override - protected String nonNullFormat(Object value) { - return MOCK_OUTPUT; - } - } - - private CellFormatter frm = new Concrete(); - - @Test - public void nullInput() { - assertEquals("wrong result", "", frm.format(null)); - } - - // mock output, but check that our method was invoked... - @Test - public void nonNullInput() { - assertEquals("what?", MOCK_OUTPUT, frm.format(1)); - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/AppIdFormatterTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/AppIdFormatterTest.java deleted file mode 100644 index a7befbdb..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/AppIdFormatterTest.java +++ /dev/null @@ -1,49 +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.table.cell; - -import org.junit.Test; -import org.onosproject.core.ApplicationId; -import org.onosproject.ui.table.CellFormatter; - -import static org.junit.Assert.assertEquals; - -/** - * Unit tests for {@link AppIdFormatter}. - */ -public class AppIdFormatterTest { - - private static final ApplicationId APP_ID = new ApplicationId() { - @Override - public short id() { - return 25; - } - - @Override - public String name() { - return "some app"; - } - }; - - private CellFormatter fmt = AppIdFormatter.INSTANCE; - - @Test - public void basic() { - assertEquals("wrong format", "25 : some app", fmt.format(APP_ID)); - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/ConnectPointFormatterTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/ConnectPointFormatterTest.java deleted file mode 100644 index f7ad2751..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/ConnectPointFormatterTest.java +++ /dev/null @@ -1,44 +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.table.cell; - -import org.junit.Test; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.onosproject.net.PortNumber; -import org.onosproject.ui.table.CellFormatter; - -import static org.junit.Assert.assertEquals; - -/** - * Unit tests for {@link ConnectPointFormatter}. - */ -public class ConnectPointFormatterTest { - - private static final DeviceId DEVID = DeviceId.deviceId("foobar"); - private static final PortNumber PORT = PortNumber.portNumber(42); - - private static final ConnectPoint CP = new ConnectPoint(DEVID, PORT); - - private CellFormatter fmt = ConnectPointFormatter.INSTANCE; - - @Test - public void basic() { - assertEquals("wrong format", "foobar/42", fmt.format(CP)); - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java deleted file mode 100644 index b870d483..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java +++ /dev/null @@ -1,146 +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.table.cell; - -import org.junit.Test; -import org.onosproject.ui.table.CellComparator; - -import static org.junit.Assert.assertTrue; - -/** - * Unit tests for {@link DefaultCellComparator}. - */ -public class DefaultCellComparatorTest { - - private static final String SOME = "SoMeStRiNg"; - private static final String OTHER = "OtherSTRING"; - - private CellComparator cmp = DefaultCellComparator.INSTANCE; - - // default comparator should detect Comparable<T> impls and use that - - @Test - public void sameString() { - assertTrue("same string", cmp.compare(SOME, SOME) == 0); - } - - @Test - public void someVsOther() { - assertTrue("some vs other", cmp.compare(SOME, OTHER) > 0); - } - - @Test - public void otherVsSome() { - assertTrue("other vs some", cmp.compare(OTHER, SOME) < 0); - } - - @Test - public void someVsNull() { - assertTrue("some vs null", cmp.compare(SOME, null) > 0); - } - - @Test - public void nullVsSome() { - assertTrue("null vs some", cmp.compare(null, SOME) < 0); - } - - @Test(expected = ClassCastException.class) - public void mismatch() { - cmp.compare(42, SOME); - } - - - @Test - public void strElevenTwo() { - assertTrue("str 11 vs 2", cmp.compare("11", "2") < 0); - } - - @Test - public void intElevenTwo() { - assertTrue("int 11 vs 2", cmp.compare(11, 2) > 0); - } - - - @Test - public void intSmallBig() { - assertTrue("int 2 vs 4", cmp.compare(2, 4) < 0); - } - - @Test - public void intBigSmall() { - assertTrue("int 4 vs 2", cmp.compare(4, 2) > 0); - } - - @Test - public void intEqual() { - assertTrue("int 4 vs 4", cmp.compare(4, 4) == 0); - } - - @Test - public void longSmallBig() { - assertTrue("long 2 vs 4", cmp.compare(2L, 4L) < 0); - } - - @Test - public void longBigSmall() { - assertTrue("long 4 vs 2", cmp.compare(4L, 2L) > 0); - } - - @Test - public void longEqual() { - assertTrue("long 4 vs 4", cmp.compare(4L, 4L) == 0); - } - - - private enum SmallStarWars { C3PO, R2D2, LUKE } - - @Test - public void swEpisodeI() { - assertTrue("c3po r2d2", - cmp.compare(SmallStarWars.C3PO, SmallStarWars.R2D2) < 0); - } - - @Test - public void swEpisodeIi() { - assertTrue("r2d2 c3po", - cmp.compare(SmallStarWars.R2D2, SmallStarWars.C3PO) > 0); - } - - @Test - public void swEpisodeIii() { - assertTrue("luke c3po", - cmp.compare(SmallStarWars.LUKE, SmallStarWars.C3PO) > 0); - } - - @Test - public void swEpisodeIv() { - assertTrue("c3po luke", - cmp.compare(SmallStarWars.C3PO, SmallStarWars.LUKE) < 0); - } - - @Test - public void swEpisodeV() { - assertTrue("luke r2d2", - cmp.compare(SmallStarWars.LUKE, SmallStarWars.R2D2) > 0); - } - - @Test - public void swEpisodeVi() { - assertTrue("r2d2 luke", - cmp.compare(SmallStarWars.R2D2, SmallStarWars.LUKE) < 0); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellFormatterTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellFormatterTest.java deleted file mode 100644 index b63793b9..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellFormatterTest.java +++ /dev/null @@ -1,70 +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.table.cell; - -import org.junit.Test; -import org.onosproject.ui.table.CellFormatter; - -import static org.junit.Assert.assertEquals; - -/** - * Unit tests for {@link DefaultCellFormatter}. - */ -public class DefaultCellFormatterTest { - - private static final String UNEX = "Unexpected result"; - private static final String SOME_STRING = "SoMeStRiNg"; - - private static class TestClass { - @Override - public String toString() { - return SOME_STRING; - } - } - - private CellFormatter fmt = DefaultCellFormatter.INSTANCE; - - @Test - public void formatNull() { - assertEquals(UNEX, "", fmt.format(null)); - } - - @Test - public void formatInteger() { - assertEquals(UNEX, "3", fmt.format(3)); - } - - @Test - public void formatTrue() { - assertEquals(UNEX, "true", fmt.format(true)); - } - - @Test - public void formatFalse() { - assertEquals(UNEX, "false", fmt.format(false)); - } - - @Test - public void formatString() { - assertEquals(UNEX, "FOO", fmt.format("FOO")); - } - - @Test - public void formatObject() { - assertEquals(UNEX, SOME_STRING, fmt.format(new TestClass())); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/EnumFormatterTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/EnumFormatterTest.java deleted file mode 100644 index 68833c90..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/EnumFormatterTest.java +++ /dev/null @@ -1,60 +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.table.cell; - -import org.junit.Test; -import org.onosproject.ui.table.CellFormatter; - -import static org.junit.Assert.assertEquals; - -/** - * Unit tests for {@link EnumFormatter}. - */ -public class EnumFormatterTest { - - enum TestEnum { - ADDED, - PENDING_ADD, - WAITING_AUDIT_COMPLETE - } - - private CellFormatter fmt = EnumFormatter.INSTANCE; - - @Test - public void nullValue() { - assertEquals("null value", "", fmt.format(null)); - } - - @Test - public void noUnderscores() { - assertEquals("All caps", "Added", fmt.format(TestEnum.ADDED)); - } - - @Test - public void underscores() { - assertEquals("All caps with underscores", - "Pending Add", fmt.format(TestEnum.PENDING_ADD)); - } - - @Test - public void multiUnderscores() { - assertEquals("All caps with underscores", - "Waiting Audit Complete", - fmt.format(TestEnum.WAITING_AUDIT_COMPLETE)); - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/HexFormatterTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/HexFormatterTest.java deleted file mode 100644 index 2f70d43c..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/HexFormatterTest.java +++ /dev/null @@ -1,56 +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.table.cell; - -import org.junit.Test; -import org.onosproject.ui.table.CellFormatter; - -import static org.junit.Assert.assertEquals; - -/** - * Unit tests for {@link HexFormatter}. - */ -public class HexFormatterTest { - - private CellFormatter fmt = HexFormatter.INSTANCE; - - @Test - public void nullValue() { - assertEquals("null value", "", fmt.format(null)); - } - - @Test - public void zero() { - assertEquals("zero", "0x0", fmt.format(0)); - } - - @Test - public void one() { - assertEquals("one", "0x1", fmt.format(1)); - } - - @Test - public void ten() { - assertEquals("ten", "0xa", fmt.format(10)); - } - - @Test - public void twenty() { - assertEquals("twenty", "0x14", fmt.format(20)); - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/HostLocationFormatterTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/HostLocationFormatterTest.java deleted file mode 100644 index 25ec89cd..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/HostLocationFormatterTest.java +++ /dev/null @@ -1,45 +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.table.cell; - -import org.junit.Test; -import org.onosproject.net.DeviceId; -import org.onosproject.net.HostLocation; -import org.onosproject.net.PortNumber; -import org.onosproject.ui.table.CellFormatter; - -import static org.junit.Assert.assertEquals; - -/** - * Unit tests for {@link HostLocationFormatter}. - */ -public class HostLocationFormatterTest { - - private static final DeviceId DEVID = DeviceId.deviceId("foobar"); - private static final PortNumber PORT = PortNumber.portNumber(42); - private static final long TIME = 12345; - - private static final HostLocation LOC = new HostLocation(DEVID, PORT, TIME); - - private CellFormatter fmt = HostLocationFormatter.INSTANCE; - - @Test - public void basic() { - assertEquals("wrong format", "foobar/42", fmt.format(LOC)); - } - -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/TimeFormatterTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/TimeFormatterTest.java deleted file mode 100644 index 1e05ded1..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/TimeFormatterTest.java +++ /dev/null @@ -1,51 +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.table.cell; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.junit.Test; -import org.onosproject.ui.table.CellFormatter; - -import java.util.Locale; - -import static org.junit.Assert.assertTrue; - -/** - * Unit tests for {@link TimeFormatter}. - */ -public class TimeFormatterTest { - - private static final Locale LOCALE = Locale.ENGLISH; - private static final DateTimeZone ZONE = DateTimeZone.UTC; - - private static final DateTime TIME = new DateTime(2015, 5, 4, 15, 30, ZONE); - private static final String EXP_ZONE_NAME = "3:30:00 PM UTC"; - private static final String EXP_ZONE_OFFSET = "3:30:00 PM +00:00"; - - // Have to use explicit Locale and TimeZone for the unit test, so that - // irrespective of which locale and time zone the test is run in, it - // always produces the same result... - private CellFormatter fmt = - new TimeFormatter().withLocale(LOCALE).withZone(ZONE); - - @Test - public void basic() { - assertTrue("wrong format", (EXP_ZONE_NAME.equals(fmt.format(TIME)) || - EXP_ZONE_OFFSET.equals(fmt.format(TIME)))); - } -} 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()); - } -} |