blob: 64908fd058eea1ff395baa9ce82b6679abd9a6b3 [file] [log] [blame]
Simon Huntc4ca7102017-04-08 22:28:04 -07001/*
2 * Copyright 2017-present 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
18package org.onosproject.ui.topo;
19
20import org.junit.Test;
21import org.onosproject.ui.AbstractUiTest;
22
23import static org.junit.Assert.*;
24import static org.onosproject.ui.topo.LayoutLocation.Type;
25import static org.onosproject.ui.topo.LayoutLocation.layoutLocation;
26
27/**
28 * Unit tests for {@link LayoutLocation}.
29 */
30public class LayoutLocationTest extends AbstractUiTest {
31
32 private static final String SOME_ID = "foo";
33 private static final double SQRT2 = 1.414;
34 private static final double PI = 3.142;
35 private static final double ZERO = 0.0;
36
37 private LayoutLocation ll;
38
39 @Test
40 public void basic() {
41 ll = layoutLocation(SOME_ID, Type.GRID, SQRT2, PI);
42 print(ll);
43 assertEquals("bad id", SOME_ID, ll.id());
44 assertEquals("bad type", Type.GRID, ll.locType());
45 assertEquals("bad Y", SQRT2, ll.latOrY(), TOLERANCE);
46 assertEquals("bad X", PI, ll.longOrX(), TOLERANCE);
47 assertFalse("bad origin check", ll.isOrigin());
48 }
49
50 @Test
51 public void createGeoLocFromStringType() {
52 ll = layoutLocation(SOME_ID, "geo", SQRT2, PI);
53 assertEquals("bad type - not geo", Type.GEO, ll.locType());
54 }
55
56 @Test
57 public void createGridLocFromStringType() {
58 ll = layoutLocation(SOME_ID, "grid", SQRT2, PI);
59 assertEquals("bad type - not grid", Type.GRID, ll.locType());
60 }
61
62 @Test
63 public void zeroLatitude() {
64 ll = layoutLocation(SOME_ID, Type.GEO, ZERO, PI);
65 assertFalse("shouldn't be origin for zero latitude", ll.isOrigin());
66 }
67
68 @Test
69 public void zeroLongitude() {
70 ll = layoutLocation(SOME_ID, Type.GEO, PI, ZERO);
71 assertFalse("shouldn't be origin for zero longitude", ll.isOrigin());
72 }
73
74 @Test
75 public void origin() {
76 ll = layoutLocation(SOME_ID, Type.GRID, ZERO, ZERO);
77 assertTrue("should be origin", ll.isOrigin());
78 }
79
80 @Test(expected = IllegalArgumentException.class)
81 public void badType() {
82 layoutLocation(SOME_ID, "foo", ZERO, PI);
83 }
84
85 @Test(expected = NullPointerException.class)
86 public void nullId() {
87 layoutLocation(null, Type.GRID, PI, PI);
88 }
89}