Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Simon Hunt | c13082f | 2016-08-03 21:20:23 -0700 | [diff] [blame] | 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.provider.ProviderId; |
| 25 | import org.onosproject.net.region.RegionId; |
| 26 | import org.onosproject.ui.model.AbstractUiModelTest; |
| 27 | |
| 28 | import static org.junit.Assert.assertEquals; |
| 29 | import static org.onosproject.net.DeviceId.deviceId; |
| 30 | import static org.onosproject.net.PortNumber.P0; |
| 31 | import static org.onosproject.net.region.RegionId.regionId; |
| 32 | |
| 33 | /** |
| 34 | * Unit tests for {@link UiRegionLink}. |
| 35 | */ |
| 36 | public 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 | } |