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