blob: 0e8689c54a256eea176fa18d2002f3fc9a83896f [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
Sho SHIMIZU14ccab52014-11-06 11:11:40 -080018import com.google.common.testing.EqualsTester;
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -080019import org.junit.Before;
20import org.junit.Test;
21import org.onlab.onos.net.DefaultLink;
22import org.onlab.onos.net.DefaultPath;
23import org.onlab.onos.net.DeviceId;
24import org.onlab.onos.net.Path;
25import org.onlab.onos.net.PortNumber;
Sho SHIMIZU14ccab52014-11-06 11:11:40 -080026import org.onlab.onos.net.intent.Constraint;
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -080027import org.onlab.onos.net.provider.ProviderId;
28import org.onlab.onos.net.resource.LinkResourceService;
29
30import java.util.Arrays;
31
32import static org.easymock.EasyMock.createMock;
33import static org.hamcrest.Matchers.is;
34import static org.junit.Assert.assertThat;
35import static org.onlab.onos.net.DefaultLinkTest.cp;
36import static org.onlab.onos.net.DeviceId.deviceId;
37import static org.onlab.onos.net.Link.Type.DIRECT;
38
39/**
40 * Test for constraint of intermediate elements.
41 */
42public class WaypointConstraintTest {
43
Sho SHIMIZU1332b172014-11-06 16:03:09 -080044 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 SHIMIZU0e51fe52014-11-05 12:04:23 -080053
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 SHIMIZU14ccab52014-11-06 11:11:40 -080089
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 SHIMIZU0e51fe52014-11-05 12:04:23 -0800104}