blob: a2fb8ce469ad3816a493aeb7a192929dcd4a9b26 [file] [log] [blame]
Ray Milkey85267002016-11-16 11:06:35 -08001/*
2 * Copyright 2016-present 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 */
chidambar babu344dc812016-05-02 19:13:10 +053016package org.onosproject.isis.controller.impl;
17
18import com.google.common.primitives.Bytes;
19import org.easymock.EasyMock;
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.jboss.netty.buffer.ChannelBuffers;
22import org.jboss.netty.channel.Channel;
23import org.jboss.netty.channel.ChannelHandlerContext;
24import org.junit.After;
25import org.junit.Before;
26import org.junit.Test;
27import org.onosproject.isis.io.util.IsisUtil;
28
29import java.net.InetSocketAddress;
30import java.net.SocketAddress;
31
32import static org.hamcrest.CoreMatchers.is;
33import static org.hamcrest.CoreMatchers.nullValue;
34import static org.hamcrest.MatcherAssert.assertThat;
35
36/**
37 * Unit test class for IsisMessageDecoder.
38 */
39public class IsisMessageDecoderTest {
40
41 private final byte[] hello = {
sunish vk4b5ce002016-05-09 20:18:35 +053042 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
chidambar babu344dc812016-05-02 19:13:10 +053043 -125, 20, 1, 0, 17, 1, 0, 0,
44 2, 51, 51, 51, 51, 51, 51, 0, 100, 5, -39, -126, 1, 4, 3,
45 73, 0, 0, -127, 1, -52, -124, 4, -64, -88, 56, 102
46 };
sunish vk4b5ce002016-05-09 20:18:35 +053047 private final byte[] array2 = {0, 0, 0, 0, 0, 0, 0};
chidambar babu344dc812016-05-02 19:13:10 +053048 private final String id = "127.0.0.1";
sunish vk4b5ce002016-05-09 20:18:35 +053049 private byte[] array1;
chidambar babu344dc812016-05-02 19:13:10 +053050 private IsisMessageDecoder isisMessageDecoder;
51 private ChannelHandlerContext ctx;
52 private Channel channel;
53 private SocketAddress socketAddress;
54 private ChannelBuffer channelBuffer;
55
56 @Before
57 public void setUp() throws Exception {
58 isisMessageDecoder = new IsisMessageDecoder();
59 }
60
61 @After
62 public void tearDown() throws Exception {
63 isisMessageDecoder = null;
64 }
65
66 @Test
67 public void testDecode() throws Exception {
68 channel = EasyMock.createMock(Channel.class);
69 socketAddress = InetSocketAddress.createUnresolved(id, 7000);
sunish vk4b5ce002016-05-09 20:18:35 +053070 byte[] array = IsisUtil.getPaddingTlvs(hello.length - 17);
71 array1 = Bytes.concat(hello, array);
chidambar babu344dc812016-05-02 19:13:10 +053072 channelBuffer = ChannelBuffers.copiedBuffer(Bytes.concat(hello, array));
73 assertThat(isisMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue()));
74 }
Ray Milkey85267002016-11-16 11:06:35 -080075}