Sho SHIMIZU | af1dffc | 2015-09-04 15:56:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Sho SHIMIZU | af1dffc | 2015-09-04 15:56:07 -0700 | [diff] [blame] | 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; |
Sho SHIMIZU | af1dffc | 2015-09-04 15:56:07 -0700 | [diff] [blame] | 17 | |
| 18 | import org.jboss.netty.buffer.ChannelBuffer; |
| 19 | import org.jboss.netty.buffer.ChannelBuffers; |
| 20 | import org.junit.Test; |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 21 | import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException; |
Sho SHIMIZU | af1dffc | 2015-09-04 15:56:07 -0700 | [diff] [blame] | 22 | import org.onosproject.pcepio.exceptions.PcepParseException; |
Sho SHIMIZU | af1dffc | 2015-09-04 15:56:07 -0700 | [diff] [blame] | 23 | |
| 24 | import static org.hamcrest.MatcherAssert.assertThat; |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 25 | import static org.hamcrest.Matchers.instanceOf; |
Sho SHIMIZU | af1dffc | 2015-09-04 15:56:07 -0700 | [diff] [blame] | 26 | import static org.hamcrest.core.Is.is; |
Sho SHIMIZU | af1dffc | 2015-09-04 15:56:07 -0700 | [diff] [blame] | 27 | |
| 28 | public class PcepCloseMsgTest { |
| 29 | |
| 30 | /** |
| 31 | * Common header, reason to close. |
| 32 | */ |
| 33 | @Test |
Mahesh Poojary S | f1bbd36 | 2016-02-25 18:19:59 +0530 | [diff] [blame] | 34 | public void closeMessageTest1() throws PcepParseException, PcepOutOfBoundMessageException { |
Sho SHIMIZU | af1dffc | 2015-09-04 15:56:07 -0700 | [diff] [blame] | 35 | |
| 36 | byte[] closeMsg = new byte[] {0x20, 0x07, 0x00, 0x0C, 0x0f, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02 }; |
| 37 | |
| 38 | byte[] testCloseMsg = {0 }; |
| 39 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 40 | buffer.writeBytes(closeMsg); |
| 41 | |
| 42 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 43 | PcepMessage message; |
| 44 | |
| 45 | message = reader.readFrom(buffer); |
Sho SHIMIZU | e090a42 | 2015-09-04 17:35:49 -0700 | [diff] [blame] | 46 | assertThat(message, instanceOf(PcepCloseMsg.class)); |
Sho SHIMIZU | af1dffc | 2015-09-04 15:56:07 -0700 | [diff] [blame] | 47 | |
| 48 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 49 | message.writeTo(buf); |
| 50 | testCloseMsg = buf.array(); |
| 51 | |
| 52 | int readLen = buf.writerIndex(); |
| 53 | testCloseMsg = new byte[readLen]; |
| 54 | buf.readBytes(testCloseMsg, 0, readLen); |
| 55 | assertThat(testCloseMsg, is(closeMsg)); |
| 56 | } |
| 57 | } |