blob: 8faab5593d95cb49a9f671fdd79c2141bb77e917 [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 */
16package org.onosproject.pcepio;
17
18import org.jboss.netty.buffer.ChannelBuffer;
19import org.jboss.netty.buffer.ChannelBuffers;
20import org.junit.Test;
21import org.onosproject.pcepio.exceptions.PcepParseException;
22import org.onosproject.pcepio.protocol.PcepCloseMsg;
23import org.onosproject.pcepio.protocol.PcepFactories;
24import org.onosproject.pcepio.protocol.PcepMessage;
25import org.onosproject.pcepio.protocol.PcepMessageReader;
26
27import static org.hamcrest.MatcherAssert.assertThat;
Sho SHIMIZUe090a422015-09-04 17:35:49 -070028import static org.hamcrest.Matchers.instanceOf;
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070029import static org.hamcrest.core.Is.is;
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070030
31public class PcepCloseMsgTest {
32
33 /**
34 * Common header, reason to close.
35 */
36 @Test
37 public void closeMessageTest1() throws PcepParseException {
38
39 byte[] closeMsg = new byte[] {0x20, 0x07, 0x00, 0x0C, 0x0f, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02 };
40
41 byte[] testCloseMsg = {0 };
42 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
43 buffer.writeBytes(closeMsg);
44
45 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
46 PcepMessage message;
47
48 message = reader.readFrom(buffer);
Sho SHIMIZUe090a422015-09-04 17:35:49 -070049 assertThat(message, instanceOf(PcepCloseMsg.class));
Sho SHIMIZUaf1dffc2015-09-04 15:56:07 -070050
51 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
52 message.writeTo(buf);
53 testCloseMsg = buf.array();
54
55 int readLen = buf.writerIndex();
56 testCloseMsg = new byte[readLen];
57 buf.readBytes(testCloseMsg, 0, readLen);
58 assertThat(testCloseMsg, is(closeMsg));
59 }
60}