blob: 7b8089141a381ab96d9d429f13bbb766992af4f6 [file] [log] [blame]
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -08001/*
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 */
16package org.onlab.onos.net.intent.constraint;
17
18import org.junit.Before;
19import org.junit.Test;
20import org.onlab.onos.net.DefaultLink;
21import org.onlab.onos.net.DefaultPath;
22import org.onlab.onos.net.DeviceId;
23import org.onlab.onos.net.Path;
24import org.onlab.onos.net.PortNumber;
25import org.onlab.onos.net.provider.ProviderId;
26import org.onlab.onos.net.resource.LinkResourceService;
27
28import java.util.Arrays;
29
30import static org.easymock.EasyMock.createMock;
31import static org.hamcrest.Matchers.is;
32import static org.junit.Assert.assertThat;
33import static org.onlab.onos.net.DefaultLinkTest.cp;
34import static org.onlab.onos.net.DeviceId.deviceId;
35import static org.onlab.onos.net.Link.Type.DIRECT;
36
37/**
38 * Test for constraint of intermediate elements.
39 */
40public 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}