Open Kilda Java Documentation
InstallOneSwitchFlowTest.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.messaging.command.flow;
17 
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertNotNull;
30 
32 
33 import org.junit.Test;
34 
36  private InstallOneSwitchFlow flow = new InstallOneSwitchFlow(0L, flowName, 0L, switchId, inputPort, outputPort,
37  inputVlanId, outputVlanId, outputVlanType, bandwidth, meterId);
38 
39  @Test
40  public void toStringTest() throws Exception {
41  String flowString = flow.toString();
42  assertNotNull(flowString);
43  assertFalse(flowString.isEmpty());
44  }
45 
46  @Test
47  public void getOutputVlanType() throws Exception {
48  assertEquals(outputVlanType, flow.getOutputVlanType());
49  }
50 
51  @Test
52  public void getBandwidth() throws Exception {
53  assertEquals(bandwidth, flow.getBandwidth().longValue());
54  }
55 
56  @Test
57  public void getMeterId() throws Exception {
58  assertEquals(meterId, flow.getMeterId().longValue());
59  }
60 
61  @Test
62  public void getInputVlanId() throws Exception {
63  assertEquals(inputVlanId, flow.getInputVlanId().intValue());
64  }
65 
66  @Test
67  public void getOutputVlanId() throws Exception {
68  assertEquals(outputVlanId, flow.getOutputVlanId().intValue());
69  }
70 
71  @Test
72  public void setBandwidth() throws Exception {
73  flow.setBandwidth(bandwidth);
74  assertEquals(bandwidth, flow.getBandwidth().longValue());
75  }
76 
77  @Test(expected = IllegalArgumentException.class)
78  public void setNullBandwidth() throws Exception {
79  flow.setBandwidth(null);
80  }
81 
82  @Test(expected = IllegalArgumentException.class)
83  public void setNegativeBandwidth() throws Exception {
84  flow.setBandwidth(-1L);
85  }
86 
87  @Test
88  public void setMeterId() throws Exception {
89  flow.setMeterId(meterId);
90  assertEquals(meterId, flow.getMeterId().longValue());
91  }
92 
93  @Test(expected = IllegalArgumentException.class)
94  public void setNullInputMeterId() throws Exception {
95  flow.setMeterId(null);
96  }
97 
98  @Test(expected = IllegalArgumentException.class)
99  public void setNegativeInputMeterId() throws Exception {
100  flow.setInputVlanId(-1);
101  }
102 
103  @Test(expected = IllegalArgumentException.class)
104  public void setNullMeterId() throws Exception {
105  flow.setMeterId(null);
106  }
107 
108  @Test(expected = IllegalArgumentException.class)
109  public void setNegativeMeterId() throws Exception {
110  flow.setMeterId(-1L);
111  }
112 
113  @Test
114  public void setInputVlanId() throws Exception {
115  flow.setInputVlanId(inputVlanId);
116  assertEquals(inputVlanId, flow.getInputVlanId().intValue());
117  }
118 
119  @Test
120  public void setNullInputVlanId() throws Exception {
121  flow.setInputVlanId(null);
122  assertEquals(0, flow.getInputVlanId().intValue());
123  }
124 
125  @Test
126  public void setZeroInputVlanId() throws Exception {
127  flow.setInputVlanId(0);
128  assertEquals(0, flow.getInputVlanId().intValue());
129  }
130 
131  @Test(expected = IllegalArgumentException.class)
132  public void setNegativeInputVlanId() throws Exception {
133  flow.setInputVlanId(-1);
134  }
135 
136  @Test(expected = IllegalArgumentException.class)
137  public void setTooBigInputVlanId() throws Exception {
138  flow.setInputVlanId(4096);
139  }
140 
141  @Test
142  public void setOutputVlanId() throws Exception {
143  flow.setOutputVlanId(outputVlanId);
144  assertEquals(outputVlanId, flow.getOutputVlanId().intValue());
145  }
146 
147  @Test
148  public void setNullOutputVlanId() throws Exception {
149  flow.setOutputVlanId(null);
150  assertEquals(0, flow.getOutputVlanId().intValue());
151  }
152 
153  @Test
154  public void setZeroOutputVlanId() throws Exception {
155  flow.setOutputVlanId(0);
156  assertEquals(0, flow.getOutputVlanId().intValue());
157  }
158 
159  @Test(expected = IllegalArgumentException.class)
160  public void setNegativeOutputVlanId() throws Exception {
161  flow.setOutputVlanId(-1);
162  }
163 
164  @Test(expected = IllegalArgumentException.class)
165  public void setTooBigOutputVlanId() throws Exception {
166  flow.setOutputVlanId(4096);
167  }
168 
169  @Test
170  public void setOutputVlanType() throws Exception {
171  flow.setOutputVlanId(outputVlanId);
172  flow.setOutputVlanType(outputVlanType);
173  assertEquals(outputVlanType, flow.getOutputVlanType());
174  }
175 
176  @Test(expected = IllegalArgumentException.class)
177  public void setNullOutputVlanType() throws Exception {
178  flow.setOutputVlanType(null);
179  }
180 
181  @Test(expected = IllegalArgumentException.class)
182  public void setInvalidOutputVlanType() throws Exception {
183  flow.setOutputVlanType(null);
184  }
185 
186  @Test(expected = IllegalArgumentException.class)
187  public void setIncorrectNoneOutputVlanType() throws Exception {
188  flow.setOutputVlanId(outputVlanId);
190  }
191 
192  @Test(expected = IllegalArgumentException.class)
193  public void setIncorrectPopOutputVlanType() throws Exception {
194  flow.setOutputVlanId(outputVlanId);
196  }
197 
198  @Test(expected = IllegalArgumentException.class)
199  public void setIncorrectPushOutputVlanType() throws Exception {
200  flow.setOutputVlanId(0);
202  }
203 
204  @Test(expected = IllegalArgumentException.class)
205  public void setIncorrectReplaceOutputVlanType() throws Exception {
206  flow.setOutputVlanId(null);
208  }
209 }
void setOutputVlanType(final OutputVlanType outputVlanType)
static final OutputVlanType outputVlanType
Definition: Constants.java:32