Sho SHIMIZU | af1dffc | 2015-09-04 15:56:07 -0700 | [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 | |
| 18 | import org.jboss.netty.buffer.ChannelBuffer; |
| 19 | import org.jboss.netty.buffer.ChannelBuffers; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.pcepio.exceptions.PcepParseException; |
| 22 | import org.onosproject.pcepio.protocol.PcepCloseMsg; |
| 23 | import org.onosproject.pcepio.protocol.PcepFactories; |
| 24 | import org.onosproject.pcepio.protocol.PcepMessage; |
| 25 | import org.onosproject.pcepio.protocol.PcepMessageReader; |
| 26 | |
| 27 | import static org.hamcrest.MatcherAssert.assertThat; |
| 28 | import static org.hamcrest.core.Is.is; |
| 29 | import static org.hamcrest.core.IsSame.sameInstance; |
| 30 | |
| 31 | public class PcepCloseMsgTest { |
| 32 | |
| 33 | /** |
| 34 | * Common header, reason to close. |
| 35 | */ |
| 36 | @Test |
| 37 | public void closeMessageTest1() throws PcepParseException { |
| 38 | |
| 39 | byte[] closeMsg = new byte[] {0x20, 0x07, 0x00, 0x0C, 0x0f, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02 }; |
| 40 | |
| 41 | byte[] testCloseMsg = {0 }; |
| 42 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 43 | buffer.writeBytes(closeMsg); |
| 44 | |
| 45 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 46 | PcepMessage message; |
| 47 | |
| 48 | message = reader.readFrom(buffer); |
| 49 | assertThat(message, sameInstance((PcepCloseMsg) message)); |
| 50 | |
| 51 | ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); |
| 52 | message.writeTo(buf); |
| 53 | testCloseMsg = buf.array(); |
| 54 | |
| 55 | int readLen = buf.writerIndex(); |
| 56 | testCloseMsg = new byte[readLen]; |
| 57 | buf.readBytes(testCloseMsg, 0, readLen); |
| 58 | assertThat(testCloseMsg, is(closeMsg)); |
| 59 | } |
| 60 | } |