Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 17 | |
| 18 | import org.junit.Test; |
Ray Milkey | a2cf3a1 | 2018-02-15 16:13:56 -0800 | [diff] [blame] | 19 | import org.onosproject.net.FilteredConnectPoint; |
Daniele Moro | 3a6e151 | 2017-12-22 12:14:44 +0100 | [diff] [blame] | 20 | import org.onosproject.net.Link; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 21 | |
Daniele Moro | 3a6e151 | 2017-12-22 12:14:44 +0100 | [diff] [blame] | 22 | import java.util.LinkedList; |
| 23 | import java.util.List; |
| 24 | |
| 25 | import static org.hamcrest.MatcherAssert.assertThat; |
| 26 | import static org.hamcrest.Matchers.containsString; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 27 | import static org.junit.Assert.assertEquals; |
Daniele Moro | 3a6e151 | 2017-12-22 12:14:44 +0100 | [diff] [blame] | 28 | import static org.junit.Assert.fail; |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 29 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Suite of tests of the point-to-point intent descriptor. |
| 33 | */ |
| 34 | public class PointToPointIntentTest extends ConnectivityIntentTest { |
| 35 | |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 36 | /** |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 37 | * Checks that the PointToPointIntent class is immutable. |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 38 | */ |
| 39 | @Test |
| 40 | public void checkImmutability() { |
| 41 | assertThatClassIsImmutableBaseClass(PointToPointIntent.class); |
| 42 | } |
| 43 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 44 | @Test |
| 45 | public void basics() { |
| 46 | PointToPointIntent intent = createOne(); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 47 | assertEquals("incorrect id", APPID, intent.appId()); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 48 | assertEquals("incorrect match", MATCH, intent.selector()); |
Ray Milkey | a2cf3a1 | 2018-02-15 16:13:56 -0800 | [diff] [blame] | 49 | assertEquals("incorrect ingress", P1, intent.filteredIngressPoint().connectPoint()); |
| 50 | assertEquals("incorrect egress", P2, intent.filteredEgressPoint().connectPoint()); |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 51 | |
| 52 | intent = createWithResourceGroup(); |
| 53 | assertEquals("incorrect id", APPID, intent.appId()); |
| 54 | assertEquals("incorrect match", MATCH, intent.selector()); |
Ray Milkey | a2cf3a1 | 2018-02-15 16:13:56 -0800 | [diff] [blame] | 55 | assertEquals("incorrect ingress", P1, intent.filteredIngressPoint().connectPoint()); |
| 56 | assertEquals("incorrect egress", P2, intent.filteredEgressPoint().connectPoint()); |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 57 | assertEquals("incorrect resource group", RESOURCE_GROUP, intent.resourceGroup()); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 60 | @Test |
| 61 | public void filtered() { |
| 62 | PointToPointIntent intent = createOneFiltered(); |
| 63 | assertEquals("incorrect id", APPID, intent.appId()); |
| 64 | assertEquals("incorrect match", MATCH, intent.selector()); |
| 65 | assertEquals("incorrect ingress", FP1, intent.filteredIngressPoint()); |
| 66 | assertEquals("incorrect egress", FP2, intent.filteredEgressPoint()); |
| 67 | } |
| 68 | |
Daniele Moro | 3a6e151 | 2017-12-22 12:14:44 +0100 | [diff] [blame] | 69 | @Test |
| 70 | public void suggestedPath() { |
| 71 | List<Link> suggestedPath = new LinkedList<>(); |
| 72 | suggestedPath.add(new IntentTestsMocks.FakeLink(FP1.connectPoint(), FP2.connectPoint())); |
| 73 | |
| 74 | PointToPointIntent intent = createWithSuggestedPath(suggestedPath); |
| 75 | assertEquals("incorrect id", APPID, intent.appId()); |
| 76 | assertEquals("incorrect match", MATCH, intent.selector()); |
| 77 | assertEquals("incorrect ingress", FP1, intent.filteredIngressPoint()); |
| 78 | assertEquals("incorrect egress", FP2, intent.filteredEgressPoint()); |
| 79 | assertEquals("incorrect suggested path", suggestedPath, intent.suggestedPath()); |
| 80 | |
| 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void failSuggestedPath() { |
| 85 | List<Link> suggestedPath = new LinkedList<>(); |
| 86 | try { |
| 87 | suggestedPath.add(new IntentTestsMocks.FakeLink(FP3.connectPoint(), FP2.connectPoint())); |
| 88 | |
| 89 | createWithSuggestedPath(suggestedPath); |
| 90 | fail("Point to Point intent building with incompatible suggested path " |
| 91 | + "not throw exception."); |
| 92 | } catch (IllegalArgumentException exception) { |
| 93 | assertThat(exception.getMessage(), containsString("Suggested path not compatible")); |
| 94 | } |
| 95 | } |
| 96 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 97 | @Override |
| 98 | protected PointToPointIntent createOne() { |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 99 | return PointToPointIntent.builder() |
| 100 | .appId(APPID) |
| 101 | .selector(MATCH) |
| 102 | .treatment(NOP) |
Ray Milkey | a2cf3a1 | 2018-02-15 16:13:56 -0800 | [diff] [blame] | 103 | .filteredIngressPoint(new FilteredConnectPoint(P1)) |
| 104 | .filteredEgressPoint(new FilteredConnectPoint(P2)) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 105 | .build(); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 108 | protected PointToPointIntent createWithResourceGroup() { |
| 109 | return PointToPointIntent.builder() |
| 110 | .appId(APPID) |
| 111 | .selector(MATCH) |
| 112 | .treatment(NOP) |
Ray Milkey | a2cf3a1 | 2018-02-15 16:13:56 -0800 | [diff] [blame] | 113 | .filteredIngressPoint(new FilteredConnectPoint(P1)) |
| 114 | .filteredEgressPoint(new FilteredConnectPoint(P2)) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 115 | .resourceGroup(RESOURCE_GROUP) |
| 116 | .build(); |
| 117 | } |
| 118 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 119 | @Override |
| 120 | protected PointToPointIntent createAnother() { |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 121 | return PointToPointIntent.builder() |
| 122 | .appId(APPID) |
| 123 | .selector(MATCH) |
| 124 | .treatment(NOP) |
Ray Milkey | a2cf3a1 | 2018-02-15 16:13:56 -0800 | [diff] [blame] | 125 | .filteredIngressPoint(new FilteredConnectPoint(P2)) |
| 126 | .filteredEgressPoint(new FilteredConnectPoint(P1)) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 127 | .build(); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 128 | } |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 129 | |
| 130 | protected PointToPointIntent createOneFiltered() { |
| 131 | return PointToPointIntent.builder() |
| 132 | .appId(APPID) |
| 133 | .selector(MATCH) |
| 134 | .treatment(NOP) |
| 135 | .filteredIngressPoint(FP1) |
| 136 | .filteredEgressPoint(FP2) |
| 137 | .build(); |
| 138 | } |
Daniele Moro | 3a6e151 | 2017-12-22 12:14:44 +0100 | [diff] [blame] | 139 | |
| 140 | protected PointToPointIntent createWithSuggestedPath(List<Link> suggestedPath) { |
| 141 | return PointToPointIntent.builder() |
| 142 | .appId(APPID) |
| 143 | .selector(MATCH) |
| 144 | .treatment(NOP) |
| 145 | .filteredIngressPoint(FP1) |
| 146 | .filteredEgressPoint(FP2) |
| 147 | .suggestedPath(suggestedPath) |
| 148 | .build(); |
| 149 | } |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 150 | } |