blob: 115af4a40d8af758d64f0d03d7eea711a716961f [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 */
Pier Ventre647138f2016-08-26 17:32:44 -070016
Brian O'Connorabafb502014-12-02 22:26:20 -080017package org.onosproject.net.intent;
Brian O'Connorf3d06162014-10-02 15:54:12 -070018
Pier Ventre647138f2016-08-26 17:32:44 -070019import org.junit.Rule;
Brian O'Connorf3d06162014-10-02 15:54:12 -070020import org.junit.Test;
Pier Ventre647138f2016-08-26 17:32:44 -070021import org.junit.rules.ExpectedException;
Brian O'Connorf3d06162014-10-02 15:54:12 -070022
23import static org.junit.Assert.assertEquals;
Ray Milkey37f6a382014-11-25 14:54:42 -080024import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Brian O'Connorf3d06162014-10-02 15:54:12 -070025
26/**
27 * Suite of tests of the multi-to-single point intent descriptor.
28 */
29public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest {
30
Ray Milkey37f6a382014-11-25 14:54:42 -080031 /**
32 * Checks that the MultiPointToSinglePointIntent class is immutable.
33 */
34 @Test
35 public void checkImmutability() {
36 assertThatClassIsImmutable(MultiPointToSinglePointIntent.class);
37 }
38
Brian O'Connorf3d06162014-10-02 15:54:12 -070039 @Test
40 public void basics() {
41 MultiPointToSinglePointIntent intent = createOne();
Thomas Vachuskac96058a2014-10-20 23:00:16 -070042 assertEquals("incorrect id", APPID, intent.appId());
tom85258ee2014-10-07 00:10:02 -070043 assertEquals("incorrect match", MATCH, intent.selector());
44 assertEquals("incorrect ingress", PS1, intent.ingressPoints());
45 assertEquals("incorrect egress", P2, intent.egressPoint());
Brian O'Connorf3d06162014-10-02 15:54:12 -070046 }
47
Pier Ventre647138f2016-08-26 17:32:44 -070048 @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'Connorf3d06162014-10-02 15:54:12 -070081 @Override
82 protected MultiPointToSinglePointIntent createOne() {
Ray Milkeyebc5d222015-03-18 15:45:36 -070083 return MultiPointToSinglePointIntent.builder()
84 .appId(APPID)
85 .selector(MATCH)
86 .treatment(NOP)
87 .ingressPoints(PS1)
88 .egressPoint(P2)
89 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -070090 }
91
92 @Override
93 protected MultiPointToSinglePointIntent createAnother() {
Ray Milkeyebc5d222015-03-18 15:45:36 -070094 return MultiPointToSinglePointIntent.builder()
95 .appId(APPID)
96 .selector(MATCH)
97 .treatment(NOP)
98 .ingressPoints(PS2)
99 .egressPoint(P1)
100 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -0700101 }
Pier Ventre647138f2016-08-26 17:32:44 -0700102
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'Connorf3d06162014-10-02 15:54:12 -0700147}