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