blob: b976b1157d68d201c6c31347159fc18b422bc05a [file] [log] [blame]
chidambar babu344dc812016-05-02 19:13:10 +05301/*
Brian O'Connorce2a03d2017-08-03 19:21:03 -07002 * Copyright 2016-present Open Networking Foundation
chidambar babu344dc812016-05-02 19:13:10 +05303 *
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 */
16package 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.notNullValue;
34import static org.hamcrest.MatcherAssert.assertThat;
35
36/**
37 * Unit test class for IsisMessageEncoder.
38 */
39public class IsisMessageEncoderTest {
40
41 private final String id = "127.0.0.1";
42 private final byte[] hello = {
43 -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 };
47 private IsisMessageEncoder isisMessageEncoder;
48 private ChannelHandlerContext ctx;
49 private Channel channel;
50 private SocketAddress socketAddress;
51 private ChannelBuffer channelBuffer;
52
53 @Before
54 public void setUp() throws Exception {
55 channel = EasyMock.createMock(Channel.class);
56 isisMessageEncoder = new IsisMessageEncoder();
57 }
58
59 @After
60 public void tearDown() throws Exception {
61 channel = null;
62 isisMessageEncoder = null;
63 }
64
65 /**
66 * Tests encode() method.
67 */
68 @Test
69 public void testEncode() throws Exception {
70 socketAddress = InetSocketAddress.createUnresolved(id, 7000);
71 byte[] array = IsisUtil.getPaddingTlvs(hello.length);
72 channelBuffer = ChannelBuffers.copiedBuffer(Bytes.concat(hello, array));
73 assertThat(isisMessageEncoder.encode(ctx, channel, channelBuffer.array()),
74 is(notNullValue()));
75 }
76}