GUI -- Table Model et al -- added missing unit tests.
Change-Id: Icc77457cab5b79724fcb5b354c2d74f2b2690d89
Showing
9 changed files
with
441 additions
and
0 deletions
... | @@ -267,6 +267,38 @@ public class TableModelTest { | ... | @@ -267,6 +267,38 @@ public class TableModelTest { |
267 | } | 267 | } |
268 | } | 268 | } |
269 | 269 | ||
270 | + private static final String[][] SORTED_NAMES_AND_HEX = { | ||
271 | + {ELEVEN, "0xb"}, | ||
272 | + {FOUR, "0x4"}, | ||
273 | + {ONE, "0x1"}, | ||
274 | + {THIRTY, "0x1e"}, | ||
275 | + {THREE, "0x3"}, | ||
276 | + {TWELVE, "0xc"}, | ||
277 | + {TWENTY, "0x14"}, | ||
278 | + {TWO, "0x2"}, | ||
279 | + }; | ||
280 | + | ||
281 | + @Test | ||
282 | + public void sortAndFormatTwo() { | ||
283 | + initUnsortedTable(); | ||
284 | + tm.setFormatter(BAR, HexFormatter.INSTANCE); | ||
285 | + tm.sort(FOO, SortDir.ASC); | ||
286 | + rows = tm.getRows(); | ||
287 | + int nr = rows.length; | ||
288 | + for (int i = 0; i < nr; i++) { | ||
289 | + String[] exp = SORTED_NAMES_AND_HEX[i]; | ||
290 | + String[] act = rows[i].getAsFormattedStrings(); | ||
291 | + assertArrayEquals(UNEX_SORT + i, exp, act); | ||
292 | + } | ||
293 | + } | ||
294 | + | ||
295 | + private static final String[] FBZ = {FOO, BAR, ZOO}; | ||
296 | + | ||
297 | + @Test | ||
298 | + public void getColumnIds() { | ||
299 | + tm = new TableModel(FOO, BAR, ZOO); | ||
300 | + assertArrayEquals("col IDs", FBZ, tm.getColumnIds()); | ||
301 | + } | ||
270 | 302 | ||
271 | @Test | 303 | @Test |
272 | public void sortDirAsc() { | 304 | public void sortDirAsc() { | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + * | ||
16 | + */ | ||
17 | + | ||
18 | +package org.onosproject.ui.table; | ||
19 | + | ||
20 | +import com.fasterxml.jackson.databind.node.ArrayNode; | ||
21 | +import org.junit.Assert; | ||
22 | +import org.junit.Test; | ||
23 | + | ||
24 | +/** | ||
25 | + * Unit tests for {@link TableUtils}. | ||
26 | + */ | ||
27 | +public class TableUtilsTest { | ||
28 | + | ||
29 | + private static final String FOO = "foo"; | ||
30 | + private static final String BAR = "bar"; | ||
31 | + | ||
32 | + private static final String ARRAY_AS_STRING = | ||
33 | + "[{\"foo\":\"1\",\"bar\":\"2\"},{\"foo\":\"3\",\"bar\":\"4\"}]"; | ||
34 | + | ||
35 | + @Test | ||
36 | + public void basic() { | ||
37 | + TableModel tm = new TableModel(FOO, BAR); | ||
38 | + tm.addRow().cell(FOO, 1).cell(BAR, 2); | ||
39 | + tm.addRow().cell(FOO, 3).cell(BAR, 4); | ||
40 | + | ||
41 | + ArrayNode array = TableUtils.generateArrayNode(tm); | ||
42 | + Assert.assertEquals("wrong results", ARRAY_AS_STRING, array.toString()); | ||
43 | + } | ||
44 | + | ||
45 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + * | ||
16 | + */ | ||
17 | + | ||
18 | +package org.onosproject.ui.table.cell; | ||
19 | + | ||
20 | +import org.junit.Test; | ||
21 | +import org.onosproject.ui.table.CellComparator; | ||
22 | + | ||
23 | +import static org.junit.Assert.assertTrue; | ||
24 | + | ||
25 | +/** | ||
26 | + * Unit tests for {@link AbstractCellComparator}. | ||
27 | + */ | ||
28 | +public class AbstractCellComparatorTest { | ||
29 | + | ||
30 | + private static class Concrete extends AbstractCellComparator { | ||
31 | + @Override | ||
32 | + protected int nonNullCompare(Object o1, Object o2) { | ||
33 | + return 42; | ||
34 | + } | ||
35 | + } | ||
36 | + | ||
37 | + private CellComparator cmp = new Concrete(); | ||
38 | + | ||
39 | + @Test | ||
40 | + public void twoNullArgs() { | ||
41 | + assertTrue("two nulls", cmp.compare(null, null) == 0); | ||
42 | + } | ||
43 | + | ||
44 | + @Test | ||
45 | + public void nullArgOne() { | ||
46 | + assertTrue("null one", cmp.compare(null, 1) < 0); | ||
47 | + } | ||
48 | + | ||
49 | + @Test | ||
50 | + public void nullArgTwo() { | ||
51 | + assertTrue("null two", cmp.compare(1, null) > 0); | ||
52 | + } | ||
53 | + | ||
54 | + // mock output, but check that our method was invoked... | ||
55 | + @Test | ||
56 | + public void noNulls() { | ||
57 | + assertTrue("no Nulls", cmp.compare(1, 2) == 42); | ||
58 | + } | ||
59 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + * | ||
16 | + */ | ||
17 | + | ||
18 | +package org.onosproject.ui.table.cell; | ||
19 | + | ||
20 | +import org.junit.Test; | ||
21 | +import org.onosproject.ui.table.CellFormatter; | ||
22 | + | ||
23 | +import static org.junit.Assert.assertEquals; | ||
24 | + | ||
25 | +/** | ||
26 | + * Unit tests for {@link AbstractCellFormatter}. | ||
27 | + */ | ||
28 | +public class AbstractCellFormatterTest { | ||
29 | + | ||
30 | + private static final String MOCK_OUTPUT = "Mock!!"; | ||
31 | + | ||
32 | + private static class Concrete extends AbstractCellFormatter { | ||
33 | + @Override | ||
34 | + protected String nonNullFormat(Object value) { | ||
35 | + return MOCK_OUTPUT; | ||
36 | + } | ||
37 | + } | ||
38 | + | ||
39 | + private CellFormatter frm = new Concrete(); | ||
40 | + | ||
41 | + @Test | ||
42 | + public void nullInput() { | ||
43 | + assertEquals("wrong result", "", frm.format(null)); | ||
44 | + } | ||
45 | + | ||
46 | + // mock output, but check that our method was invoked... | ||
47 | + @Test | ||
48 | + public void nonNullInput() { | ||
49 | + assertEquals("what?", MOCK_OUTPUT, frm.format(1)); | ||
50 | + } | ||
51 | + | ||
52 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + * | ||
16 | + */ | ||
17 | + | ||
18 | +package org.onosproject.ui.table.cell; | ||
19 | + | ||
20 | +import org.junit.Test; | ||
21 | +import org.onosproject.core.ApplicationId; | ||
22 | +import org.onosproject.ui.table.CellFormatter; | ||
23 | + | ||
24 | +import static org.junit.Assert.assertEquals; | ||
25 | + | ||
26 | +/** | ||
27 | + * Unit tests for {@link AppIdFormatter}. | ||
28 | + */ | ||
29 | +public class AppIdFormatterTest { | ||
30 | + | ||
31 | + private static final ApplicationId APP_ID = new ApplicationId() { | ||
32 | + @Override | ||
33 | + public short id() { | ||
34 | + return 25; | ||
35 | + } | ||
36 | + | ||
37 | + @Override | ||
38 | + public String name() { | ||
39 | + return "some app"; | ||
40 | + } | ||
41 | + }; | ||
42 | + | ||
43 | + private CellFormatter fmt = AppIdFormatter.INSTANCE; | ||
44 | + | ||
45 | + @Test | ||
46 | + public void basic() { | ||
47 | + assertEquals("wrong format", "25 : some app", fmt.format(APP_ID)); | ||
48 | + } | ||
49 | + | ||
50 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + * | ||
16 | + */ | ||
17 | + | ||
18 | +package org.onosproject.ui.table.cell; | ||
19 | + | ||
20 | +import org.junit.Test; | ||
21 | +import org.onosproject.net.ConnectPoint; | ||
22 | +import org.onosproject.net.DeviceId; | ||
23 | +import org.onosproject.net.PortNumber; | ||
24 | +import org.onosproject.ui.table.CellFormatter; | ||
25 | + | ||
26 | +import static org.junit.Assert.assertEquals; | ||
27 | + | ||
28 | +/** | ||
29 | + * Unit tests for {@link ConnectPointFormatter}. | ||
30 | + */ | ||
31 | +public class ConnectPointFormatterTest { | ||
32 | + | ||
33 | + private static final DeviceId DEVID = DeviceId.deviceId("foobar"); | ||
34 | + private static final PortNumber PORT = PortNumber.portNumber(42); | ||
35 | + | ||
36 | + private static final ConnectPoint CP = new ConnectPoint(DEVID, PORT); | ||
37 | + | ||
38 | + private CellFormatter fmt = ConnectPointFormatter.INSTANCE; | ||
39 | + | ||
40 | + @Test | ||
41 | + public void basic() { | ||
42 | + assertEquals("wrong format", "foobar/42", fmt.format(CP)); | ||
43 | + } | ||
44 | + | ||
45 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + * | ||
16 | + */ | ||
17 | + | ||
18 | +package org.onosproject.ui.table.cell; | ||
19 | + | ||
20 | +import org.junit.Test; | ||
21 | +import org.onosproject.net.DeviceId; | ||
22 | +import org.onosproject.net.HostLocation; | ||
23 | +import org.onosproject.net.PortNumber; | ||
24 | +import org.onosproject.ui.table.CellFormatter; | ||
25 | + | ||
26 | +import static org.junit.Assert.assertEquals; | ||
27 | + | ||
28 | +/** | ||
29 | + * Unit tests for {@link HostLocationFormatter}. | ||
30 | + */ | ||
31 | +public class HostLocationFormatterTest { | ||
32 | + | ||
33 | + private static final DeviceId DEVID = DeviceId.deviceId("foobar"); | ||
34 | + private static final PortNumber PORT = PortNumber.portNumber(42); | ||
35 | + private static final long TIME = 12345; | ||
36 | + | ||
37 | + private static final HostLocation LOC = new HostLocation(DEVID, PORT, TIME); | ||
38 | + | ||
39 | + private CellFormatter fmt = HostLocationFormatter.INSTANCE; | ||
40 | + | ||
41 | + @Test | ||
42 | + public void basic() { | ||
43 | + assertEquals("wrong format", "foobar/42", fmt.format(LOC)); | ||
44 | + } | ||
45 | + | ||
46 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + * | ||
16 | + */ | ||
17 | + | ||
18 | +package org.onosproject.ui.table.cell; | ||
19 | + | ||
20 | +import org.junit.Test; | ||
21 | +import org.onosproject.ui.table.CellComparator; | ||
22 | + | ||
23 | +import static org.junit.Assert.assertTrue; | ||
24 | + | ||
25 | +/** | ||
26 | + * Unit tests for {@link LongComparator}. | ||
27 | + */ | ||
28 | +public class LongComparatorTest { | ||
29 | + | ||
30 | + private CellComparator cmp = LongComparator.INSTANCE; | ||
31 | + | ||
32 | + @Test | ||
33 | + public void twoNulls() { | ||
34 | + assertTrue("two nulls", cmp.compare(null, null) == 0); | ||
35 | + } | ||
36 | + | ||
37 | + @Test | ||
38 | + public void nullVsNegValue() { | ||
39 | + assertTrue("null vs neg value", cmp.compare(null, -5L) < 0); | ||
40 | + } | ||
41 | + | ||
42 | + @Test | ||
43 | + public void nullVsPosValue() { | ||
44 | + assertTrue("null vs pos value", cmp.compare(null, 5L) < 0); | ||
45 | + } | ||
46 | + | ||
47 | + @Test | ||
48 | + public void negValueVsNull() { | ||
49 | + assertTrue("neg value vs null", cmp.compare(-5L, null) > 0); | ||
50 | + } | ||
51 | + | ||
52 | + @Test | ||
53 | + public void posValueVsNull() { | ||
54 | + assertTrue("pos value vs null", cmp.compare(5L, null) > 0); | ||
55 | + } | ||
56 | + | ||
57 | + | ||
58 | + @Test | ||
59 | + public void smallVsBig() { | ||
60 | + assertTrue("small vs big", cmp.compare(25L, 75L) < 0); | ||
61 | + } | ||
62 | + | ||
63 | + @Test | ||
64 | + public void bigVsSmall() { | ||
65 | + assertTrue("big vs small", cmp.compare(75L, 25L) > 0); | ||
66 | + } | ||
67 | + | ||
68 | + @Test | ||
69 | + public void sameValue() { | ||
70 | + assertTrue("same value", cmp.compare(50L, 50L) == 0); | ||
71 | + } | ||
72 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + * | ||
16 | + */ | ||
17 | + | ||
18 | +package org.onosproject.ui.table.cell; | ||
19 | + | ||
20 | +import org.joda.time.DateTime; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onosproject.ui.table.CellFormatter; | ||
23 | + | ||
24 | +import static org.junit.Assert.assertEquals; | ||
25 | + | ||
26 | +/** | ||
27 | + * Unit tests for {@link TimeFormatter}. | ||
28 | + */ | ||
29 | +public class TimeFormatterTest { | ||
30 | + | ||
31 | + private static final DateTime TIME = DateTime.parse("2010-06-30T01:20"); | ||
32 | + private static final String EXP_OUTPUT = "1:20:00 AM PDT"; | ||
33 | + | ||
34 | + private CellFormatter fmt = TimeFormatter.INSTANCE; | ||
35 | + | ||
36 | + @Test | ||
37 | + public void basic() { | ||
38 | + assertEquals("wrong format", EXP_OUTPUT, fmt.format(TIME)); | ||
39 | + } | ||
40 | +} |
-
Please register or login to post a comment