Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.ui.model.topo; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.DefaultLink; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.Link; |
| 24 | import org.onosproject.net.PortNumber; |
| 25 | import org.onosproject.net.provider.ProviderId; |
| 26 | import org.onosproject.ui.model.AbstractUiModelTest; |
| 27 | |
| 28 | import static org.junit.Assert.assertEquals; |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 29 | import static org.junit.Assert.assertNotEquals; |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 30 | import static org.onosproject.net.DeviceId.deviceId; |
| 31 | import static org.onosproject.net.PortNumber.portNumber; |
| 32 | |
| 33 | /** |
| 34 | * Unit tests for {@link UiLinkId}. |
| 35 | */ |
| 36 | public class UiLinkIdTest extends AbstractUiModelTest { |
| 37 | |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 38 | 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 Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 42 | private static final PortNumber P3 = portNumber(3); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 43 | |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 44 | 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 Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 47 | |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 48 | private static final Link LINK_X1_TO_Y2 = DefaultLink.builder() |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 49 | .providerId(ProviderId.NONE) |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 50 | .src(CP_X1) |
| 51 | .dst(CP_Y2) |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 52 | .type(Link.Type.DIRECT) |
| 53 | .build(); |
| 54 | |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 55 | private static final Link LINK_Y2_TO_X1 = DefaultLink.builder() |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 56 | .providerId(ProviderId.NONE) |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 57 | .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 Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 66 | .type(Link.Type.DIRECT) |
| 67 | .build(); |
| 68 | |
| 69 | |
| 70 | @Test |
| 71 | public void canonical() { |
| 72 | title("canonical"); |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 73 | UiLinkId one = UiLinkId.uiLinkId(LINK_X1_TO_Y2); |
| 74 | UiLinkId two = UiLinkId.uiLinkId(LINK_Y2_TO_X1); |
Simon Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 75 | print("link one: %s", one); |
| 76 | print("link two: %s", two); |
| 77 | assertEquals("not equiv", one, two); |
| 78 | } |
Simon Hunt | 58a0dd0 | 2016-05-17 11:54:23 -0700 | [diff] [blame] | 79 | |
| 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 Hunt | c0f20c1 | 2016-05-09 09:30:20 -0700 | [diff] [blame] | 89 | } |