blob: 33c00ddfa7e082a3108dae6b6422fd65d43e5251 [file] [log] [blame]
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -07001/*
2 * Copyright 2014-2015 Open Networking Laboratory
3 *
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;
21import org.onosproject.pcepio.exceptions.PcepParseException;
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070022
23import static org.hamcrest.MatcherAssert.assertThat;
Sho SHIMIZUe090a422015-09-04 17:35:49 -070024import static org.hamcrest.Matchers.instanceOf;
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070025import static org.hamcrest.core.Is.is;
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070026
27public class PcepCloseMsgTest {
28
29 /**
30 * Common header, reason to close.
31 */
32 @Test
33 public void closeMessageTest1() throws PcepParseException {
34
35 byte[] closeMsg = new byte[] {0x20, 0x07, 0x00, 0x0C, 0x0f, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02 };
36
37 byte[] testCloseMsg = {0 };
38 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
39 buffer.writeBytes(closeMsg);
40
41 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
42 PcepMessage message;
43
44 message = reader.readFrom(buffer);
Sho SHIMIZUe090a422015-09-04 17:35:49 -070045 assertThat(message, instanceOf(PcepCloseMsg.class));
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070046
47 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
48 message.writeTo(buf);
49 testCloseMsg = buf.array();
50
51 int readLen = buf.writerIndex();
52 testCloseMsg = new byte[readLen];
53 buf.readBytes(testCloseMsg, 0, readLen);
54 assertThat(testCloseMsg, is(closeMsg));
55 }
56}