blob: e129e26241805f4e20260da2cbf53ae58ba26ae8 [file] [log] [blame]
Simon Huntc0f20c12016-05-09 09:30:20 -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.PortNumber;
25import org.onosproject.net.provider.ProviderId;
26import org.onosproject.ui.model.AbstractUiModelTest;
27
28import static org.junit.Assert.assertEquals;
Simon Hunt58a0dd02016-05-17 11:54:23 -070029import static org.junit.Assert.assertNotEquals;
Simon Huntc0f20c12016-05-09 09:30:20 -070030import static org.onosproject.net.DeviceId.deviceId;
31import static org.onosproject.net.PortNumber.portNumber;
32
33/**
34 * Unit tests for {@link UiLinkId}.
35 */
36public class UiLinkIdTest extends AbstractUiModelTest {
37
Simon Huntc0f20c12016-05-09 09:30:20 -070038 private static final DeviceId DEV_X = deviceId("device-X");
39 private static final DeviceId DEV_Y = deviceId("device-Y");
40 private static final PortNumber P1 = portNumber(1);
41 private static final PortNumber P2 = portNumber(2);
Simon Hunt58a0dd02016-05-17 11:54:23 -070042 private static final PortNumber P3 = portNumber(3);
Simon Huntc0f20c12016-05-09 09:30:20 -070043
Simon Hunt58a0dd02016-05-17 11:54:23 -070044 private static final ConnectPoint CP_X1 = new ConnectPoint(DEV_X, P1);
45 private static final ConnectPoint CP_Y2 = new ConnectPoint(DEV_Y, P2);
46 private static final ConnectPoint CP_Y3 = new ConnectPoint(DEV_Y, P3);
Simon Huntc0f20c12016-05-09 09:30:20 -070047
Simon Hunt58a0dd02016-05-17 11:54:23 -070048 private static final Link LINK_X1_TO_Y2 = DefaultLink.builder()
Simon Huntc0f20c12016-05-09 09:30:20 -070049 .providerId(ProviderId.NONE)
Simon Hunt58a0dd02016-05-17 11:54:23 -070050 .src(CP_X1)
51 .dst(CP_Y2)
Simon Huntc0f20c12016-05-09 09:30:20 -070052 .type(Link.Type.DIRECT)
53 .build();
54
Simon Hunt58a0dd02016-05-17 11:54:23 -070055 private static final Link LINK_Y2_TO_X1 = DefaultLink.builder()
Simon Huntc0f20c12016-05-09 09:30:20 -070056 .providerId(ProviderId.NONE)
Simon Hunt58a0dd02016-05-17 11:54:23 -070057 .src(CP_Y2)
58 .dst(CP_X1)
59 .type(Link.Type.DIRECT)
60 .build();
61
62 private static final Link LINK_X1_TO_Y3 = DefaultLink.builder()
63 .providerId(ProviderId.NONE)
64 .src(CP_X1)
65 .dst(CP_Y3)
Simon Huntc0f20c12016-05-09 09:30:20 -070066 .type(Link.Type.DIRECT)
67 .build();
68
69
70 @Test
71 public void canonical() {
72 title("canonical");
Simon Hunt58a0dd02016-05-17 11:54:23 -070073 UiLinkId one = UiLinkId.uiLinkId(LINK_X1_TO_Y2);
74 UiLinkId two = UiLinkId.uiLinkId(LINK_Y2_TO_X1);
Simon Huntc0f20c12016-05-09 09:30:20 -070075 print("link one: %s", one);
76 print("link two: %s", two);
77 assertEquals("not equiv", one, two);
78 }
Simon Hunt58a0dd02016-05-17 11:54:23 -070079
80 @Test
81 public void sameDevsDiffPorts() {
82 title("sameDevsDiffPorts");
83 UiLinkId one = UiLinkId.uiLinkId(LINK_X1_TO_Y2);
84 UiLinkId other = UiLinkId.uiLinkId(LINK_X1_TO_Y3);
85 print("link one: %s", one);
86 print("link other: %s", other);
87 assertNotEquals("equiv?", one, other);
88 }
Simon Huntc0f20c12016-05-09 09:30:20 -070089}