Michele Santuari | 38dd82e | 2017-01-04 09:23:49 +0100 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Michele Santuari | 38dd82e | 2017-01-04 09:23:49 +0100 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.net.domain; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableList; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.net.DefaultLink; |
| 22 | import org.onosproject.net.Link; |
| 23 | import org.onosproject.net.intent.ConnectivityIntentTest; |
| 24 | import org.onosproject.net.provider.ProviderId; |
| 25 | |
| 26 | import java.util.Arrays; |
| 27 | import java.util.LinkedList; |
| 28 | import java.util.List; |
| 29 | |
| 30 | import static org.junit.Assert.assertEquals; |
| 31 | import static org.onosproject.net.Link.State.ACTIVE; |
| 32 | import static org.onosproject.net.Link.Type.DIRECT; |
| 33 | import static org.onosproject.net.domain.DomainPointToPointIntent.resources; |
| 34 | |
| 35 | /** |
| 36 | * Suite of tests of the point-to-point domain intent descriptor. |
| 37 | */ |
| 38 | public class DomainPointToPointIntentTest extends ConnectivityIntentTest { |
| 39 | |
| 40 | private static final ProviderId PID = new ProviderId("of", "foo"); |
| 41 | private static final Link L1 = DefaultLink.builder().providerId(PID).src(FP1.connectPoint()) |
| 42 | .dst(FP2.connectPoint()).type(DIRECT).state(ACTIVE).build(); |
| 43 | private static final List<Link> LINKS_SET = new LinkedList(Arrays.asList(L1)); |
| 44 | |
| 45 | @Test |
| 46 | public void basics() { |
| 47 | DomainPointToPointIntent intent = createOne(); |
| 48 | assertEquals("incorrect id", APPID, intent.appId()); |
| 49 | assertEquals("incorrect ingress", |
| 50 | intent.filteredIngressPoints().size(), 1); |
| 51 | assertEquals("incorrect ingress", |
| 52 | intent.filteredIngressPoints().iterator().next(), FP1); |
| 53 | assertEquals("incorrect ingress", |
| 54 | intent.filteredEgressPoints().size(), 1); |
| 55 | assertEquals("incorrect ingress", |
| 56 | intent.filteredEgressPoints().iterator().next(), FP2); |
| 57 | assertEquals(intent.links().size(), 0); |
| 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void links() { |
| 62 | DomainPointToPointIntent intent = createAnother(); |
| 63 | assertEquals("incorrect id", APPID, intent.appId()); |
| 64 | assertEquals("incorrect ingress", |
| 65 | intent.filteredIngressPoints().size(), 1); |
| 66 | assertEquals("incorrect ingress", |
| 67 | intent.filteredIngressPoints().iterator().next(), FP2); |
| 68 | assertEquals("incorrect ingress", |
| 69 | intent.filteredEgressPoints().size(), 1); |
| 70 | assertEquals("incorrect ingress", |
| 71 | intent.filteredEgressPoints().iterator().next(), FP1); |
| 72 | assertEquals("links are not correctly assigned", |
| 73 | intent.links(), LINKS_SET); |
| 74 | assertEquals("resources are not correctly assigned", |
| 75 | intent.resources(), resources(LINKS_SET)); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | protected DomainPointToPointIntent createOne() { |
| 80 | return DomainPointToPointIntent.builder() |
| 81 | .appId(APPID) |
| 82 | .filteredIngressPoint(FP1) |
| 83 | .filteredEgressPoint(FP2) |
| 84 | .links(ImmutableList.of()).build(); |
| 85 | |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | protected DomainPointToPointIntent createAnother() { |
| 90 | return DomainPointToPointIntent.builder() |
| 91 | .appId(APPID) |
| 92 | .filteredIngressPoint(FP2) |
| 93 | .filteredEgressPoint(FP1) |
| 94 | .links(LINKS_SET).build(); |
| 95 | } |
| 96 | |
| 97 | } |