blob: fb59ee914fcf9d663027053ff9f96d63775ba700 [file] [log] [blame]
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Sho SHIMIZUaf1dffc2015-09-04 15:56: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 */
Sho SHIMIZU3559c312015-11-04 14:59:31 -080016package org.onosproject.pcepio.protocol;
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070017
18import org.jboss.netty.buffer.ChannelBuffer;
19import org.jboss.netty.buffer.ChannelBuffers;
20import org.junit.Test;
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053021import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070022import org.onosproject.pcepio.exceptions.PcepParseException;
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070023
24import static org.hamcrest.MatcherAssert.assertThat;
Sho SHIMIZUe090a422015-09-04 17:35:49 -070025import static org.hamcrest.Matchers.instanceOf;
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070026import static org.hamcrest.core.Is.is;
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070027
28public class PcepCloseMsgTest {
29
30 /**
31 * Common header, reason to close.
32 */
33 @Test
Mahesh Poojary Sf1bbd362016-02-25 18:19:59 +053034 public void closeMessageTest1() throws PcepParseException, PcepOutOfBoundMessageException {
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070035
36 byte[] closeMsg = new byte[] {0x20, 0x07, 0x00, 0x0C, 0x0f, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02 };
37
38 byte[] testCloseMsg = {0 };
39 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
40 buffer.writeBytes(closeMsg);
41
42 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
43 PcepMessage message;
44
45 message = reader.readFrom(buffer);
Sho SHIMIZUe090a422015-09-04 17:35:49 -070046 assertThat(message, instanceOf(PcepCloseMsg.class));
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070047
48 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
49 message.writeTo(buf);
50 testCloseMsg = buf.array();
51
52 int readLen = buf.writerIndex();
53 testCloseMsg = new byte[readLen];
54 buf.readBytes(testCloseMsg, 0, readLen);
55 assertThat(testCloseMsg, is(closeMsg));
56 }
57}