Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
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 | */ |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 16 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 17 | package org.onosproject.net.intent; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 18 | |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 19 | import org.junit.Rule; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 20 | import org.junit.Test; |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 21 | import org.junit.rules.ExpectedException; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 22 | |
| 23 | import static org.junit.Assert.assertEquals; |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 24 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Suite of tests of the multi-to-single point intent descriptor. |
| 28 | */ |
| 29 | public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest { |
| 30 | |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 31 | /** |
| 32 | * Checks that the MultiPointToSinglePointIntent class is immutable. |
| 33 | */ |
| 34 | @Test |
| 35 | public void checkImmutability() { |
| 36 | assertThatClassIsImmutable(MultiPointToSinglePointIntent.class); |
| 37 | } |
| 38 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 39 | @Test |
| 40 | public void basics() { |
| 41 | MultiPointToSinglePointIntent intent = createOne(); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 42 | assertEquals("incorrect id", APPID, intent.appId()); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 43 | assertEquals("incorrect match", MATCH, intent.selector()); |
| 44 | assertEquals("incorrect ingress", PS1, intent.ingressPoints()); |
| 45 | assertEquals("incorrect egress", P2, intent.egressPoint()); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 48 | @Rule |
| 49 | public ExpectedException wrongMultiple = ExpectedException.none(); |
| 50 | |
| 51 | @Test |
| 52 | public void multipleSelectors() { |
| 53 | |
| 54 | MultiPointToSinglePointIntent intent = createFirstMultiple(); |
| 55 | assertEquals("incorrect id", APPID, intent.appId()); |
| 56 | assertEquals("incorrect match", MATCH, intent.selector()); |
| 57 | assertEquals("incorrect ingress", PS1, intent.ingressPoints()); |
| 58 | assertEquals("incorrect egress", P2, intent.egressPoint()); |
| 59 | assertEquals("incorrect selectors", MATCHES, intent.ingressSelectors()); |
| 60 | |
| 61 | intent = createSecondMultiple(); |
| 62 | assertEquals("incorrect id", APPID, intent.appId()); |
| 63 | assertEquals("incorrect match", VLANMATCH1, intent.selector()); |
| 64 | assertEquals("incorrect ingress", PS1, intent.ingressPoints()); |
| 65 | assertEquals("incorrect egress", P2, intent.egressPoint()); |
| 66 | assertEquals("incorrect selectors", MATCHES, intent.ingressSelectors()); |
| 67 | |
| 68 | intent = createThirdMultiple(); |
| 69 | assertEquals("incorrect id", APPID, intent.appId()); |
| 70 | assertEquals("incorrect match", MATCH, intent.selector()); |
| 71 | assertEquals("incorrect ingress", PS1, intent.ingressPoints()); |
| 72 | assertEquals("incorrect egress", P2, intent.egressPoint()); |
| 73 | assertEquals("incorrect selectors", VLANMATCHES, intent.ingressSelectors()); |
| 74 | |
| 75 | wrongMultiple.expect(IllegalArgumentException.class); |
| 76 | wrongMultiple.expectMessage("Selector and Multiple Selectors are both set"); |
| 77 | intent = createWrongMultiple(); |
| 78 | } |
| 79 | |
| 80 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 81 | @Override |
| 82 | protected MultiPointToSinglePointIntent createOne() { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 83 | return MultiPointToSinglePointIntent.builder() |
| 84 | .appId(APPID) |
| 85 | .selector(MATCH) |
| 86 | .treatment(NOP) |
| 87 | .ingressPoints(PS1) |
| 88 | .egressPoint(P2) |
| 89 | .build(); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
| 93 | protected MultiPointToSinglePointIntent createAnother() { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 94 | return MultiPointToSinglePointIntent.builder() |
| 95 | .appId(APPID) |
| 96 | .selector(MATCH) |
| 97 | .treatment(NOP) |
| 98 | .ingressPoints(PS2) |
| 99 | .egressPoint(P1) |
| 100 | .build(); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 101 | } |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 102 | |
| 103 | protected MultiPointToSinglePointIntent createFirstMultiple() { |
| 104 | return MultiPointToSinglePointIntent.builder() |
| 105 | .appId(APPID) |
| 106 | .selector(MATCH) |
| 107 | .treatment(NOP) |
| 108 | .ingressPoints(PS1) |
| 109 | .egressPoint(P2) |
| 110 | .selectors(MATCHES) |
| 111 | .build(); |
| 112 | } |
| 113 | |
| 114 | protected MultiPointToSinglePointIntent createSecondMultiple() { |
| 115 | return MultiPointToSinglePointIntent.builder() |
| 116 | .appId(APPID) |
| 117 | .selector(VLANMATCH1) |
| 118 | .treatment(NOP) |
| 119 | .ingressPoints(PS1) |
| 120 | .egressPoint(P2) |
| 121 | .selectors(MATCHES) |
| 122 | .build(); |
| 123 | } |
| 124 | |
| 125 | protected MultiPointToSinglePointIntent createThirdMultiple() { |
| 126 | return MultiPointToSinglePointIntent.builder() |
| 127 | .appId(APPID) |
| 128 | .selector(MATCH) |
| 129 | .treatment(NOP) |
| 130 | .ingressPoints(PS1) |
| 131 | .egressPoint(P2) |
| 132 | .selectors(VLANMATCHES) |
| 133 | .build(); |
| 134 | } |
| 135 | |
| 136 | protected MultiPointToSinglePointIntent createWrongMultiple() { |
| 137 | return MultiPointToSinglePointIntent.builder() |
| 138 | .appId(APPID) |
| 139 | .selector(VLANMATCH1) |
| 140 | .treatment(NOP) |
| 141 | .ingressPoints(PS1) |
| 142 | .egressPoint(P2) |
| 143 | .selectors(VLANMATCHES) |
| 144 | .build(); |
| 145 | } |
| 146 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 147 | } |