2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.api;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.junit.Test;
19 import org.opendaylight.protocol.concepts.IPv4Address;
20 import org.opendaylight.protocol.pcep.PCEPErrors;
21 import org.opendaylight.protocol.pcep.message.PCEPCloseMessage;
22 import org.opendaylight.protocol.pcep.message.PCEPErrorMessage;
23 import org.opendaylight.protocol.pcep.message.PCEPKeepAliveMessage;
24 import org.opendaylight.protocol.pcep.message.PCEPNotificationMessage;
25 import org.opendaylight.protocol.pcep.message.PCEPOpenMessage;
26 import org.opendaylight.protocol.pcep.message.PCEPReplyMessage;
27 import org.opendaylight.protocol.pcep.message.PCEPReportMessage;
28 import org.opendaylight.protocol.pcep.message.PCEPRequestMessage;
29 import org.opendaylight.protocol.pcep.message.PCEPUpdateRequestMessage;
30 import org.opendaylight.protocol.pcep.object.CompositeErrorObject;
31 import org.opendaylight.protocol.pcep.object.CompositeNotifyObject;
32 import org.opendaylight.protocol.pcep.object.CompositeRequestObject;
33 import org.opendaylight.protocol.pcep.object.CompositeResponseObject;
34 import org.opendaylight.protocol.pcep.object.CompositeStateReportObject;
35 import org.opendaylight.protocol.pcep.object.CompositeUpdateRequestObject;
36 import org.opendaylight.protocol.pcep.object.PCEPCloseObject;
37 import org.opendaylight.protocol.pcep.object.PCEPCloseObject.Reason;
38 import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject;
39 import org.opendaylight.protocol.pcep.object.PCEPErrorObject;
40 import org.opendaylight.protocol.pcep.object.PCEPLspObject;
41 import org.opendaylight.protocol.pcep.object.PCEPNotificationObject;
42 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
43 import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject;
45 public class MessagesTest {
48 public void errorMessageTest() {
49 final List<PCEPErrorObject> errorObjs = new ArrayList<PCEPErrorObject>() {
50 private static final long serialVersionUID = 1L;
53 this.add(new PCEPErrorObject(PCEPErrors.ATTEMPT_2ND_SESSION));
54 this.add(new PCEPErrorObject(PCEPErrors.ATTEMPT_2ND_SESSION));
57 final List<CompositeErrorObject> errors = new ArrayList<CompositeErrorObject>() {
58 private static final long serialVersionUID = 1L;
61 this.add(new CompositeErrorObject(errorObjs));
65 final List<?> objs = new ArrayList<Object>() {
66 private static final long serialVersionUID = 1L;
69 this.add(new CompositeErrorObject(errorObjs));
70 this.add(new PCEPErrorObject(PCEPErrors.BANDWIDTH_MISSING));
74 final PCEPErrorMessage m = new PCEPErrorMessage(new PCEPOpenObject(10, 10, 1), errorObjs, errors);
75 final PCEPErrorMessage m2 = new PCEPErrorMessage(new PCEPOpenObject(10, 10, 1), errorObjs, errors);
76 final PCEPErrorMessage m3 = new PCEPErrorMessage(objs);
79 assertEquals(m.toString(), m2.toString());
80 assertEquals(m.hashCode(), m2.hashCode());
81 assertEquals(m.getOpenObject(), m2.getOpenObject());
82 assertEquals(m.getErrors(), m2.getErrors());
83 assertEquals(m.getErrorObjects(), m2.getErrorObjects());
84 assertFalse(m.equals(null));
85 assertFalse(m.equals(m3));
86 assertFalse(m.equals(new PCEPCloseMessage(new PCEPCloseObject(Reason.EXP_DEADTIMER))));
87 assertTrue(m.equals(m));
90 @Test(expected = IllegalArgumentException.class)
91 public void closeMessageTest() {
92 final PCEPCloseMessage m = new PCEPCloseMessage(new PCEPCloseObject(Reason.EXP_DEADTIMER));
93 final PCEPCloseMessage m2 = new PCEPCloseMessage(new PCEPCloseObject(Reason.EXP_DEADTIMER));
94 final PCEPCloseMessage m3 = new PCEPCloseMessage(new PCEPCloseObject(Reason.MALFORMED_MSG));
97 assertEquals(m.toString(), m2.toString());
98 assertEquals(m.hashCode(), m2.hashCode());
99 assertEquals(m.getCloseObject(), m2.getCloseObject());
100 assertFalse(m.equals(null));
101 assertFalse(m.equals(m3));
102 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
103 assertTrue(m.equals(m));
105 new PCEPCloseMessage(null);
108 @Test(expected = IllegalArgumentException.class)
109 public void openMessageTest() {
110 final PCEPOpenMessage m = new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1));
111 final PCEPOpenMessage m2 = new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1));
112 final PCEPOpenMessage m3 = new PCEPOpenMessage(new PCEPOpenObject(5, 5, 1));
115 assertEquals(m.toString(), m2.toString());
116 assertEquals(m.hashCode(), m2.hashCode());
117 assertEquals(m.getOpenObject(), m2.getOpenObject());
118 assertFalse(m.equals(null));
119 assertFalse(m.equals(m3));
120 assertFalse(m.equals(new PCEPCloseMessage(new PCEPCloseObject(Reason.EXP_DEADTIMER))));
121 assertTrue(m.equals(m));
123 new PCEPOpenMessage(null);
126 @Test(expected = IllegalArgumentException.class)
127 public void keepAliveMessageTest() {
128 final PCEPKeepAliveMessage m = new PCEPKeepAliveMessage();
129 final PCEPKeepAliveMessage m2 = new PCEPKeepAliveMessage();
132 assertEquals(m.toString(), m2.toString());
133 assertEquals(m.hashCode(), m2.hashCode());
134 assertFalse(m.equals(null));
135 assertFalse(m.equals(new PCEPCloseMessage(new PCEPCloseObject(Reason.EXP_DEADTIMER))));
136 assertTrue(m.equals(m));
138 new PCEPOpenMessage(null);
141 @Test(expected = IllegalArgumentException.class)
142 public void notifyMessageTest() {
143 final List<CompositeNotifyObject> notifications = new ArrayList<CompositeNotifyObject>() {
144 private static final long serialVersionUID = 1L;
147 this.add(new CompositeNotifyObject(new ArrayList<PCEPNotificationObject>() {
148 private static final long serialVersionUID = 1L;
151 this.add(new PCEPNotificationObject((short) 2, (short) 3));
157 final PCEPNotificationMessage m = new PCEPNotificationMessage(notifications);
158 final PCEPNotificationMessage m2 = new PCEPNotificationMessage(notifications);
159 final PCEPNotificationMessage m3 = new PCEPNotificationMessage(new ArrayList<CompositeNotifyObject>() {
160 private static final long serialVersionUID = 1L;
163 this.add(new CompositeNotifyObject(new ArrayList<PCEPNotificationObject>() {
164 private static final long serialVersionUID = 1L;
167 this.add(new PCEPNotificationObject((short) 2, (short) 5));
174 assertEquals(m.toString(), m2.toString());
175 assertEquals(m.hashCode(), m2.hashCode());
176 assertEquals(m.getNotifications(), m2.getNotifications());
177 assertFalse(m.equals(null));
178 assertFalse(m.equals(m3));
179 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
180 assertTrue(m.equals(m));
182 new PCEPNotificationMessage(null);
185 @Test(expected = IllegalArgumentException.class)
186 public void replyMessageTest() {
187 final List<CompositeResponseObject> replies = new ArrayList<CompositeResponseObject>() {
188 private static final long serialVersionUID = 1L;
191 this.add(new CompositeResponseObject(new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 1, 1, true,
196 final PCEPReplyMessage m = new PCEPReplyMessage(replies);
197 final PCEPReplyMessage m2 = new PCEPReplyMessage(replies);
198 final PCEPReplyMessage m3 = new PCEPReplyMessage(new ArrayList<CompositeResponseObject>() {
199 private static final long serialVersionUID = 1L;
202 this.add(new CompositeResponseObject(new PCEPRequestParameterObject(true, true, true, false, true, false, false, false, (short) 2, 1, false,
208 assertEquals(m.toString(), m2.toString());
209 assertEquals(m.hashCode(), m2.hashCode());
210 assertEquals(m.getResponses(), m2.getResponses());
211 assertFalse(m.equals(null));
212 assertFalse(m.equals(m3));
213 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
214 assertTrue(m.equals(m));
216 new PCEPReplyMessage(null);
219 @Test(expected = IllegalArgumentException.class)
220 public void reportMessageTest() {
221 final List<CompositeStateReportObject> reports = new ArrayList<CompositeStateReportObject>() {
222 private static final long serialVersionUID = 1L;
225 this.add(new CompositeStateReportObject(new PCEPLspObject(1, true, true, true, true)));
229 final PCEPReportMessage m = new PCEPReportMessage(reports);
230 final PCEPReportMessage m2 = new PCEPReportMessage(reports);
231 final PCEPReportMessage m3 = new PCEPReportMessage(new ArrayList<CompositeStateReportObject>() {
232 private static final long serialVersionUID = 1L;
235 this.add(new CompositeStateReportObject(new PCEPLspObject(5, false, true, true, true)));
240 assertEquals(m.toString(), m2.toString());
241 assertEquals(m.hashCode(), m2.hashCode());
242 assertEquals(m.getStateReports(), m2.getStateReports());
243 assertFalse(m.equals(null));
244 assertFalse(m.equals(m3));
245 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
246 assertTrue(m.equals(m));
248 new PCEPReportMessage(null);
251 @Test(expected = IllegalArgumentException.class)
252 public void requestMessageTest() {
253 final List<CompositeRequestObject> reports = new ArrayList<CompositeRequestObject>() {
254 private static final long serialVersionUID = 1L;
257 this.add(new CompositeRequestObject(
258 new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 5, 5, true, true),
259 new PCEPEndPointsObject<IPv4Address>(
260 new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 1 }),
261 new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 1 }))));
265 final PCEPRequestMessage m = new PCEPRequestMessage(reports);
266 final PCEPRequestMessage m2 = new PCEPRequestMessage(reports);
267 final PCEPRequestMessage m3 = new PCEPRequestMessage(new ArrayList<CompositeRequestObject>() {
268 private static final long serialVersionUID = 1L;
271 this.add(new CompositeRequestObject(
272 new PCEPRequestParameterObject(true, true, true, false, true, false, false, false, (short) 5, 5, true, true),
273 new PCEPEndPointsObject<IPv4Address>(
274 new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }),
275 new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 1 }))));
280 assertEquals(m.toString(), m2.toString());
281 assertEquals(m.hashCode(), m2.hashCode());
282 assertEquals(m.getSvecObjects(), m2.getSvecObjects());
283 assertEquals(m.getRequests(), m2.getRequests());
284 assertFalse(m.equals(null));
285 assertFalse(m.equals(m3));
286 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
287 assertTrue(m.equals(m));
289 new PCEPRequestMessage(null);
292 @Test(expected = IllegalArgumentException.class)
293 public void updateRequestMessageTest() {
294 final List<CompositeUpdateRequestObject> reports = new ArrayList<CompositeUpdateRequestObject>() {
295 private static final long serialVersionUID = 1L;
298 this.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, true, true, true)));
302 final PCEPUpdateRequestMessage m = new PCEPUpdateRequestMessage(reports);
303 final PCEPUpdateRequestMessage m2 = new PCEPUpdateRequestMessage(reports);
304 final PCEPUpdateRequestMessage m3 = new PCEPUpdateRequestMessage(new ArrayList<CompositeUpdateRequestObject>() {
305 private static final long serialVersionUID = 1L;
308 this.add(new CompositeUpdateRequestObject(new PCEPLspObject(5, true, true, true, true)));
313 assertEquals(m.toString(), m2.toString());
314 assertEquals(m.hashCode(), m2.hashCode());
315 assertEquals(m.getUpdateRequests(), m2.getUpdateRequests());
316 assertFalse(m.equals(null));
317 assertFalse(m.equals(m3));
318 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
319 assertTrue(m.equals(m));
321 new PCEPUpdateRequestMessage(null);