Sho SHIMIZU | 075268b | 2014-11-05 15:16:32 -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 | 075268b | 2014-11-05 15:16:32 -0800 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * Test for constraint of intermediate nodes not passed. |
| 20 | */ |
| 21 | import com.google.common.testing.EqualsTester; |
| 22 | import org.junit.Before; |
| 23 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 24 | import org.onosproject.net.DefaultLink; |
| 25 | import org.onosproject.net.DefaultPath; |
| 26 | import org.onosproject.net.DeviceId; |
| 27 | import org.onosproject.net.Path; |
| 28 | import org.onosproject.net.PortNumber; |
| 29 | import org.onosproject.net.provider.ProviderId; |
| 30 | import org.onosproject.net.resource.LinkResourceService; |
Sho SHIMIZU | 075268b | 2014-11-05 15:16:32 -0800 | [diff] [blame] | 31 | |
| 32 | import java.util.Arrays; |
| 33 | |
| 34 | import static org.easymock.EasyMock.createMock; |
| 35 | import static org.hamcrest.Matchers.is; |
| 36 | import static org.junit.Assert.*; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 37 | import static org.onosproject.net.DefaultLinkTest.cp; |
| 38 | import static org.onosproject.net.DeviceId.deviceId; |
| 39 | import static org.onosproject.net.Link.Type.DIRECT; |
Sho SHIMIZU | 075268b | 2014-11-05 15:16:32 -0800 | [diff] [blame] | 40 | |
| 41 | public class ObstacleConstraintTest { |
| 42 | |
| 43 | private static final DeviceId DID1 = deviceId("of:1"); |
| 44 | private static final DeviceId DID2 = deviceId("of:2"); |
| 45 | private static final DeviceId DID3 = deviceId("of:3"); |
| 46 | private static final DeviceId DID4 = deviceId("of:4"); |
| 47 | private static final PortNumber PN1 = PortNumber.portNumber(1); |
| 48 | private static final PortNumber PN2 = PortNumber.portNumber(2); |
| 49 | private static final PortNumber PN3 = PortNumber.portNumber(3); |
| 50 | private static final PortNumber PN4 = PortNumber.portNumber(4); |
| 51 | private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); |
| 52 | |
| 53 | private LinkResourceService linkResourceService; |
| 54 | |
| 55 | private Path path; |
| 56 | private DefaultLink link2; |
| 57 | private DefaultLink link1; |
| 58 | |
| 59 | private ObstacleConstraint sut; |
| 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 | @Test |
| 71 | public void testEquality() { |
| 72 | ObstacleConstraint o1 = new ObstacleConstraint(DID1, DID2, DID3); |
| 73 | ObstacleConstraint o2 = new ObstacleConstraint(DID3, DID2, DID1); |
| 74 | ObstacleConstraint o3 = new ObstacleConstraint(DID1, DID2); |
| 75 | ObstacleConstraint o4 = new ObstacleConstraint(DID2, DID1); |
| 76 | |
| 77 | new EqualsTester() |
| 78 | .addEqualityGroup(o1, o2) |
| 79 | .addEqualityGroup(o3, o4) |
| 80 | .testEquals(); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Tests the specified path avoids the specified obstacle. |
| 85 | */ |
| 86 | @Test |
| 87 | public void testPathNotThroughObstacles() { |
| 88 | sut = new ObstacleConstraint(DID4); |
| 89 | |
| 90 | assertThat(sut.validate(path, linkResourceService), is(true)); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Test the specified path does not avoid the specified obstacle. |
| 95 | */ |
| 96 | @Test |
| 97 | public void testPathThroughObstacle() { |
| 98 | sut = new ObstacleConstraint(DID1); |
| 99 | |
| 100 | assertThat(sut.validate(path, linkResourceService), is(false)); |
| 101 | } |
| 102 | } |