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 | */ |
| 16 | package org.onlab.onos.net.intent.constraint; |
| 17 | |
| 18 | import org.junit.Before; |
| 19 | import org.junit.Test; |
| 20 | import org.onlab.onos.net.DefaultLink; |
| 21 | import org.onlab.onos.net.DefaultPath; |
| 22 | import org.onlab.onos.net.DeviceId; |
| 23 | import org.onlab.onos.net.Path; |
| 24 | import org.onlab.onos.net.PortNumber; |
| 25 | import org.onlab.onos.net.provider.ProviderId; |
| 26 | import org.onlab.onos.net.resource.LinkResourceService; |
| 27 | |
| 28 | import java.util.Arrays; |
| 29 | |
| 30 | import static org.easymock.EasyMock.createMock; |
| 31 | import static org.hamcrest.Matchers.is; |
| 32 | import static org.junit.Assert.assertThat; |
| 33 | import static org.onlab.onos.net.DefaultLinkTest.cp; |
| 34 | import static org.onlab.onos.net.DeviceId.deviceId; |
| 35 | import static org.onlab.onos.net.Link.Type.DIRECT; |
| 36 | |
| 37 | /** |
| 38 | * Test for constraint of intermediate elements. |
| 39 | */ |
| 40 | public class WaypointConstraintTest { |
| 41 | |
| 42 | public static final DeviceId DID1 = deviceId("of:1"); |
| 43 | public static final DeviceId DID2 = deviceId("of:2"); |
| 44 | public static final DeviceId DID3 = deviceId("of:3"); |
| 45 | public static final DeviceId DID4 = deviceId("of:4"); |
| 46 | public static final PortNumber PN1 = PortNumber.portNumber(1); |
| 47 | public static final PortNumber PN2 = PortNumber.portNumber(2); |
| 48 | public static final PortNumber PN3 = PortNumber.portNumber(3); |
| 49 | public static final PortNumber PN4 = PortNumber.portNumber(4); |
| 50 | public static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); |
| 51 | |
| 52 | private WaypointConstraint sut; |
| 53 | private LinkResourceService linkResourceService; |
| 54 | |
| 55 | private Path path; |
| 56 | private DefaultLink link2; |
| 57 | private DefaultLink link1; |
| 58 | |
| 59 | @Before |
| 60 | public void setUp() { |
| 61 | linkResourceService = createMock(LinkResourceService.class); |
| 62 | |
| 63 | link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT); |
| 64 | link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT); |
| 65 | path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Tests that all of the specified waypoints are included in the specified path in order. |
| 70 | */ |
| 71 | @Test |
| 72 | public void testSatisfyWaypoints() { |
| 73 | sut = new WaypointConstraint(DID1, DID2, DID3); |
| 74 | |
| 75 | assertThat(sut.validate(path, linkResourceService), is(true)); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Tests that the specified path does not includes the specified waypoint. |
| 80 | */ |
| 81 | @Test |
| 82 | public void testNotSatisfyWaypoint() { |
| 83 | sut = new WaypointConstraint(DID4); |
| 84 | |
| 85 | assertThat(sut.validate(path, linkResourceService), is(false)); |
| 86 | } |
| 87 | } |