blob: 4948ec60afaaee39d97d48063ef641f2022f74da [file] [log] [blame]
chidambar babu344dc812016-05-02 19:13:10 +05301package org.onosproject.isis.controller.impl;
2
3import com.google.common.primitives.Bytes;
4import org.easymock.EasyMock;
5import org.jboss.netty.buffer.ChannelBuffer;
6import org.jboss.netty.buffer.ChannelBuffers;
7import org.jboss.netty.channel.Channel;
8import org.jboss.netty.channel.ChannelHandlerContext;
9import org.junit.After;
10import org.junit.Before;
11import org.junit.Test;
12import org.onosproject.isis.io.util.IsisUtil;
13
14import java.net.InetSocketAddress;
15import java.net.SocketAddress;
16
17import static org.hamcrest.CoreMatchers.is;
18import static org.hamcrest.CoreMatchers.nullValue;
19import static org.hamcrest.MatcherAssert.assertThat;
20
21/**
22 * Unit test class for IsisMessageDecoder.
23 */
24public class IsisMessageDecoderTest {
25
26 private final byte[] hello = {
sunish vk4b5ce002016-05-09 20:18:35 +053027 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
chidambar babu344dc812016-05-02 19:13:10 +053028 -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 vk4b5ce002016-05-09 20:18:35 +053032 private final byte[] array2 = {0, 0, 0, 0, 0, 0, 0};
chidambar babu344dc812016-05-02 19:13:10 +053033 private final String id = "127.0.0.1";
sunish vk4b5ce002016-05-09 20:18:35 +053034 private byte[] array1;
chidambar babu344dc812016-05-02 19:13:10 +053035 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 vk4b5ce002016-05-09 20:18:35 +053055 byte[] array = IsisUtil.getPaddingTlvs(hello.length - 17);
56 array1 = Bytes.concat(hello, array);
chidambar babu344dc812016-05-02 19:13:10 +053057 channelBuffer = ChannelBuffers.copiedBuffer(Bytes.concat(hello, array));
58 assertThat(isisMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue()));
59 }
60}