blob: f3db2fb25ca1a1461fa582f3f2713bac420f80e1 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connorf3d06162014-10-02 15:54:12 -070017
Pier Ventre27d42572016-08-29 17:37:08 -070018import org.junit.Rule;
Brian O'Connorf3d06162014-10-02 15:54:12 -070019import org.junit.Test;
Pier Ventre27d42572016-08-29 17:37:08 -070020import org.junit.rules.ExpectedException;
Brian O'Connorf3d06162014-10-02 15:54:12 -070021
22import static org.junit.Assert.assertEquals;
Ray Milkeybd4f0112015-03-02 17:07:09 -080023import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Brian O'Connorf3d06162014-10-02 15:54:12 -070024
25/**
26 * Suite of tests of the single-to-multi point intent descriptor.
27 */
28public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest {
29
Ray Milkeybd4f0112015-03-02 17:07:09 -080030 /**
31 * Checks that the SinglePointToMultiPointIntent class is immutable.
32 */
33 @Test
34 public void testImmutability() {
35 assertThatClassIsImmutable(SinglePointToMultiPointIntent.class);
36 }
37
Brian O'Connorf3d06162014-10-02 15:54:12 -070038 @Test
39 public void basics() {
40 SinglePointToMultiPointIntent intent = createOne();
Thomas Vachuskac96058a2014-10-20 23:00:16 -070041 assertEquals("incorrect id", APPID, intent.appId());
tom85258ee2014-10-07 00:10:02 -070042 assertEquals("incorrect match", MATCH, intent.selector());
43 assertEquals("incorrect ingress", P1, intent.ingressPoint());
44 assertEquals("incorrect egress", PS2, intent.egressPoints());
Brian O'Connorf3d06162014-10-02 15:54:12 -070045 }
46
Pier Ventre27d42572016-08-29 17:37:08 -070047 @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'Connorf3d06162014-10-02 15:54:12 -070082 @Override
83 protected SinglePointToMultiPointIntent createOne() {
Ray Milkeyebc5d222015-03-18 15:45:36 -070084 return SinglePointToMultiPointIntent.builder()
85 .appId(APPID)
86 .selector(MATCH)
87 .treatment(NOP)
88 .ingressPoint(P1)
89 .egressPoints(PS2)
90 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -070091 }
92
93 @Override
94 protected SinglePointToMultiPointIntent createAnother() {
Ray Milkeyebc5d222015-03-18 15:45:36 -070095 return SinglePointToMultiPointIntent.builder()
96 .appId(APPID)
97 .selector(MATCH)
98 .treatment(NOP)
99 .ingressPoint(P2)
100 .egressPoints(PS1)
101 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -0700102 }
Pier Ventre27d42572016-08-29 17:37:08 -0700103
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'Connorf3d06162014-10-02 15:54:12 -0700149}