Sho SHIMIZU | 0e51fe5 | 2014-11-05 12:04:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent.constraint; |
Sho SHIMIZU | 0e51fe5 | 2014-11-05 12:04:23 -0800 | [diff] [blame] | 17 | |
Sho SHIMIZU | 14ccab5 | 2014-11-06 11:11:40 -0800 | [diff] [blame] | 18 | import com.google.common.testing.EqualsTester; |
Sho SHIMIZU | 0e51fe5 | 2014-11-05 12:04:23 -0800 | [diff] [blame] | 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.DefaultLink; |
| 22 | import org.onosproject.net.DefaultPath; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.Path; |
| 25 | import org.onosproject.net.PortNumber; |
| 26 | import org.onosproject.net.intent.Constraint; |
| 27 | import org.onosproject.net.provider.ProviderId; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame] | 28 | import org.onosproject.net.resource.link.LinkResourceService; |
Sho SHIMIZU | 0e51fe5 | 2014-11-05 12:04:23 -0800 | [diff] [blame] | 29 | |
| 30 | import java.util.Arrays; |
| 31 | |
| 32 | import static org.easymock.EasyMock.createMock; |
| 33 | import static org.hamcrest.Matchers.is; |
| 34 | import static org.junit.Assert.assertThat; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 35 | import static org.onosproject.net.DefaultLinkTest.cp; |
| 36 | import static org.onosproject.net.DeviceId.deviceId; |
| 37 | import static org.onosproject.net.Link.Type.DIRECT; |
Sho SHIMIZU | 0e51fe5 | 2014-11-05 12:04:23 -0800 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Test for constraint of intermediate elements. |
| 41 | */ |
| 42 | public class WaypointConstraintTest { |
| 43 | |
Sho SHIMIZU | 1332b17 | 2014-11-06 16:03:09 -0800 | [diff] [blame] | 44 | private static final DeviceId DID1 = deviceId("of:1"); |
| 45 | private static final DeviceId DID2 = deviceId("of:2"); |
| 46 | private static final DeviceId DID3 = deviceId("of:3"); |
| 47 | private static final DeviceId DID4 = deviceId("of:4"); |
| 48 | private static final PortNumber PN1 = PortNumber.portNumber(1); |
| 49 | private static final PortNumber PN2 = PortNumber.portNumber(2); |
| 50 | private static final PortNumber PN3 = PortNumber.portNumber(3); |
| 51 | private static final PortNumber PN4 = PortNumber.portNumber(4); |
| 52 | private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); |
Sho SHIMIZU | 0e51fe5 | 2014-11-05 12:04:23 -0800 | [diff] [blame] | 53 | |
| 54 | private WaypointConstraint sut; |
| 55 | private LinkResourceService linkResourceService; |
| 56 | |
| 57 | private Path path; |
| 58 | private DefaultLink link2; |
| 59 | private DefaultLink link1; |
| 60 | |
| 61 | @Before |
| 62 | public void setUp() { |
| 63 | linkResourceService = createMock(LinkResourceService.class); |
| 64 | |
| 65 | link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT); |
| 66 | link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT); |
| 67 | path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Tests that all of the specified waypoints are included in the specified path in order. |
| 72 | */ |
| 73 | @Test |
| 74 | public void testSatisfyWaypoints() { |
| 75 | sut = new WaypointConstraint(DID1, DID2, DID3); |
| 76 | |
| 77 | assertThat(sut.validate(path, linkResourceService), is(true)); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Tests that the specified path does not includes the specified waypoint. |
| 82 | */ |
| 83 | @Test |
| 84 | public void testNotSatisfyWaypoint() { |
| 85 | sut = new WaypointConstraint(DID4); |
| 86 | |
| 87 | assertThat(sut.validate(path, linkResourceService), is(false)); |
| 88 | } |
Sho SHIMIZU | 14ccab5 | 2014-11-06 11:11:40 -0800 | [diff] [blame] | 89 | |
| 90 | @Test |
| 91 | public void testEquality() { |
| 92 | Constraint c1 = new WaypointConstraint(DID1, DID2); |
| 93 | Constraint c2 = new WaypointConstraint(DID1, DID2); |
| 94 | |
| 95 | Constraint c3 = new WaypointConstraint(DID2); |
| 96 | Constraint c4 = new WaypointConstraint(DID3); |
| 97 | |
| 98 | new EqualsTester() |
| 99 | .addEqualityGroup(c1, c2) |
| 100 | .addEqualityGroup(c3) |
| 101 | .addEqualityGroup(c4) |
| 102 | .testEquals(); |
| 103 | } |
Sho SHIMIZU | 0e51fe5 | 2014-11-05 12:04:23 -0800 | [diff] [blame] | 104 | } |