blob: de00bd22cd9e2b986e8b26327d8807b0fa6cff46 [file] [log] [blame]
Simon Huntc13082f2016-08-03 21:20:23 -07001/*
2 * Copyright 2016-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
17package org.onosproject.ui.model.topo;
18
19import org.junit.Test;
20import org.onosproject.net.ConnectPoint;
21import org.onosproject.net.DefaultLink;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.Link;
24import org.onosproject.net.provider.ProviderId;
25import org.onosproject.net.region.RegionId;
26import org.onosproject.ui.model.AbstractUiModelTest;
27
28import static org.junit.Assert.assertEquals;
29import static org.onosproject.net.DeviceId.deviceId;
30import static org.onosproject.net.PortNumber.P0;
31import static org.onosproject.net.region.RegionId.regionId;
32
33/**
34 * Unit tests for {@link UiRegionLink}.
35 */
36public class UiRegionLinkTest extends AbstractUiModelTest {
37
38 private static final RegionId R1 = regionId("r1");
39 private static final RegionId R2 = regionId("r2");
40
41 private static final DeviceId DEV_X = deviceId("device-X");
42 private static final DeviceId DEV_Y = deviceId("device-Y");
43
44 private static final ConnectPoint CP_X = new ConnectPoint(DEV_X, P0);
45 private static final ConnectPoint CP_Y = new ConnectPoint(DEV_Y, P0);
46
47 private static final Link LINK_X_TO_Y = DefaultLink.builder()
48 .providerId(ProviderId.NONE)
49 .src(CP_X)
50 .dst(CP_Y)
51 .type(Link.Type.DIRECT)
52 .build();
53
54
55 @Test(expected = NullPointerException.class)
56 public void nullPointerRegion() {
57 title("nullPointerRegion");
58 new UiRegionLink(null, null);
59 }
60
61 @Test
62 public void regionToRegion() {
63 title("regionToRegion");
64 UiLinkId id = UiLinkId.uiLinkId(R1, R2);
65 UiRegionLink link = new UiRegionLink(null, id);
66 print("link: %s", link);
67 assertEquals("bad first region", R1, link.regionA());
68 assertEquals("bad second region", R2, link.regionB());
69 }
70
71 @Test(expected = IllegalArgumentException.class)
72 public void wrongLinkType() {
73 title("wrongLinkType");
74 UiLinkId id = UiLinkId.uiLinkId(LINK_X_TO_Y);
75 new UiRegionLink(null, id);
76 }
77}