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