chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 1 | package org.onosproject.isis.controller.impl; |
| 2 | |
| 3 | import com.google.common.primitives.Bytes; |
| 4 | import org.easymock.EasyMock; |
| 5 | import org.jboss.netty.buffer.ChannelBuffer; |
| 6 | import org.jboss.netty.buffer.ChannelBuffers; |
| 7 | import org.jboss.netty.channel.Channel; |
| 8 | import org.jboss.netty.channel.ChannelHandlerContext; |
| 9 | import org.junit.After; |
| 10 | import org.junit.Before; |
| 11 | import org.junit.Test; |
| 12 | import org.onosproject.isis.io.util.IsisUtil; |
| 13 | |
| 14 | import java.net.InetSocketAddress; |
| 15 | import java.net.SocketAddress; |
| 16 | |
| 17 | import static org.hamcrest.CoreMatchers.is; |
| 18 | import static org.hamcrest.CoreMatchers.nullValue; |
| 19 | import static org.hamcrest.MatcherAssert.assertThat; |
| 20 | |
| 21 | /** |
| 22 | * Unit test class for IsisMessageDecoder. |
| 23 | */ |
| 24 | public class IsisMessageDecoderTest { |
| 25 | |
| 26 | private final byte[] hello = { |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 27 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 28 | -125, 20, 1, 0, 17, 1, 0, 0, |
| 29 | 2, 51, 51, 51, 51, 51, 51, 0, 100, 5, -39, -126, 1, 4, 3, |
| 30 | 73, 0, 0, -127, 1, -52, -124, 4, -64, -88, 56, 102 |
| 31 | }; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 32 | private final byte[] array2 = {0, 0, 0, 0, 0, 0, 0}; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 33 | private final String id = "127.0.0.1"; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 34 | private byte[] array1; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 35 | private IsisMessageDecoder isisMessageDecoder; |
| 36 | private ChannelHandlerContext ctx; |
| 37 | private Channel channel; |
| 38 | private SocketAddress socketAddress; |
| 39 | private ChannelBuffer channelBuffer; |
| 40 | |
| 41 | @Before |
| 42 | public void setUp() throws Exception { |
| 43 | isisMessageDecoder = new IsisMessageDecoder(); |
| 44 | } |
| 45 | |
| 46 | @After |
| 47 | public void tearDown() throws Exception { |
| 48 | isisMessageDecoder = null; |
| 49 | } |
| 50 | |
| 51 | @Test |
| 52 | public void testDecode() throws Exception { |
| 53 | channel = EasyMock.createMock(Channel.class); |
| 54 | socketAddress = InetSocketAddress.createUnresolved(id, 7000); |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 55 | byte[] array = IsisUtil.getPaddingTlvs(hello.length - 17); |
| 56 | array1 = Bytes.concat(hello, array); |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 57 | channelBuffer = ChannelBuffers.copiedBuffer(Bytes.concat(hello, array)); |
| 58 | assertThat(isisMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue())); |
| 59 | } |
| 60 | } |