56cf06b45cefeec53c2215f154157805c183e388
[onosfw.git] /
1 /*
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  */
16 package org.onosproject.pcepio.protocol;
17
18 import org.jboss.netty.buffer.ChannelBuffer;
19 import org.jboss.netty.buffer.ChannelBuffers;
20 import org.junit.Assert;
21 import org.junit.Test;
22 import org.onosproject.pcepio.exceptions.PcepParseException;
23
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.hamcrest.Matchers.instanceOf;
26 import static org.hamcrest.core.Is.is;
27
28 public class PcepKeepaliveMsgTest {
29
30     /**
31      * Common header for keep alive message.
32      */
33     @Test
34     public void keepaliveMessageTest1() throws PcepParseException {
35
36         byte[] keepaliveMsg = new byte[] {0x20, 0x02, 0x00, 0x04 };
37
38         byte[] testKeepaliveMsg = {0 };
39         ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
40         buffer.writeBytes(keepaliveMsg);
41
42         PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
43         PcepMessage message = null;
44
45         message = reader.readFrom(buffer);
46         assertThat(message, instanceOf(PcepKeepaliveMsg.class));
47         ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
48
49         message.writeTo(buf);
50
51         testKeepaliveMsg = buf.array();
52
53         int iReadLen = buf.writerIndex();
54         testKeepaliveMsg = new byte[iReadLen];
55         buf.readBytes(testKeepaliveMsg, 0, iReadLen);
56
57         Assert.assertThat(testKeepaliveMsg, is(keepaliveMsg));
58     }
59 }