blob: a35c8af595a2ea0674094880b6cd601f8093ca18 [file] [log] [blame]
bharat saraswalf7364db2015-08-11 13:39:31 +05301/*
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
bharat saraswalf7364db2015-08-11 13:39:31 +053018import org.jboss.netty.buffer.ChannelBuffer;
19import org.jboss.netty.buffer.ChannelBuffers;
bharat saraswalf7364db2015-08-11 13:39:31 +053020import org.junit.Assert;
bharat saraswalf7364db2015-08-11 13:39:31 +053021import org.junit.Test;
22import org.onosproject.pcepio.exceptions.PcepParseException;
23import org.onosproject.pcepio.protocol.PcepFactories;
24import org.onosproject.pcepio.protocol.PcepKeepaliveMsg;
25import org.onosproject.pcepio.protocol.PcepMessage;
26import org.onosproject.pcepio.protocol.PcepMessageReader;
bharat saraswalf7364db2015-08-11 13:39:31 +053027
Mahesh Poojary S99748322015-08-27 18:49:45 +053028import static org.hamcrest.MatcherAssert.assertThat;
29import static org.hamcrest.Matchers.instanceOf;
30import static org.hamcrest.core.Is.is;
31
bharat saraswalf7364db2015-08-11 13:39:31 +053032public class PcepKeepaliveMsgTest {
33
bharat saraswale2e7a002015-08-21 22:47:30 +053034 /**
35 * Common header for keep alive message.
bharat saraswale2e7a002015-08-21 22:47:30 +053036 */
bharat saraswalf7364db2015-08-11 13:39:31 +053037 @Test
38 public void keepaliveMessageTest1() throws PcepParseException {
39
40 byte[] keepaliveMsg = new byte[] {0x20, 0x02, 0x00, 0x04 };
41
bharat saraswale2e7a002015-08-21 22:47:30 +053042 byte[] testKeepaliveMsg = {0 };
bharat saraswalf7364db2015-08-11 13:39:31 +053043 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
44 buffer.writeBytes(keepaliveMsg);
45
46 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
47 PcepMessage message = null;
bharat saraswalf7364db2015-08-11 13:39:31 +053048
bharat saraswale2e7a002015-08-21 22:47:30 +053049 message = reader.readFrom(buffer);
Mahesh Poojary S99748322015-08-27 18:49:45 +053050 assertThat(message, instanceOf(PcepKeepaliveMsg.class));
bharat saraswale2e7a002015-08-21 22:47:30 +053051 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
Mahesh Poojary S99748322015-08-27 18:49:45 +053052
bharat saraswale2e7a002015-08-21 22:47:30 +053053 message.writeTo(buf);
Mahesh Poojary S99748322015-08-27 18:49:45 +053054
bharat saraswale2e7a002015-08-21 22:47:30 +053055 testKeepaliveMsg = buf.array();
bharat saraswalf7364db2015-08-11 13:39:31 +053056
Mahesh Poojary S99748322015-08-27 18:49:45 +053057 int iReadLen = buf.writerIndex();
bharat saraswale2e7a002015-08-21 22:47:30 +053058 testKeepaliveMsg = new byte[iReadLen];
59 buf.readBytes(testKeepaliveMsg, 0, iReadLen);
60
Mahesh Poojary S99748322015-08-27 18:49:45 +053061 Assert.assertThat(testKeepaliveMsg, is(keepaliveMsg));
bharat saraswalf7364db2015-08-11 13:39:31 +053062 }
63}