blob: 9482f199d1cdcfeef7d7c73565a2051fef473979 [file] [log] [blame]
Dhruv Dhodyb5850122016-02-17 17:51:19 +05301/*
2 * Copyright 2016 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 */
16package org.onosproject.ospf.controller.impl;
17
18import org.easymock.EasyMock;
19import org.jboss.netty.buffer.ChannelBuffer;
20import org.jboss.netty.buffer.ChannelBuffers;
21import org.jboss.netty.channel.Channel;
22import org.jboss.netty.channel.ChannelHandlerContext;
23import org.junit.After;
24import org.junit.Before;
25import org.junit.Test;
26
27import java.net.InetSocketAddress;
28import java.net.SocketAddress;
29
30import static org.hamcrest.CoreMatchers.is;
31import static org.hamcrest.CoreMatchers.nullValue;
32import static org.hamcrest.MatcherAssert.assertThat;
33
34/**
35 * Unit test class for OspfMessageDecoder.
36 */
37public class OspfMessageDecoderTest {
38
39 private final byte[] hellopacket = {0, 0, 0, 0, 2, 1, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, 39, 59,
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 10, 2, 1, 0, 0, 0,
41 40, -64, -88, -86, 8, 0, 0, 0, 0};
42 private final byte[] ddpacket = {0, 0, 0, 0, 2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82,
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, -87, 126};
44 private final byte[] ddpacket44 = {0, 0, 0, 0, 2, 2, 0, 10, -64, -88};
45 private final byte[] lsAckpacket = {0, 0, 0, 0, 2, 5, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, -30, -12,
46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 16, 2, 1, -64, -88, -86, 2, -64,
47 -88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48};
48 private final byte[] lsUpdatePacket = {0, 0, 0, 0, 2, 4, 0, 76, -64, -88, -86, 3, 0, 0, 0, 1, 7, 111,
49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 14, 16, 2, 1, -64, -88,
sunish vkaa48da82016-03-02 23:17:06 +053050 -86, 2, -64, -88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48, 2, 0, 0, 2,
51 -64, -88, -86, 0, -1, -1, -1, 0, 3, 0, 0, 10, -64, -88, -86, 0, -1, -1, -1, 0, 3, 0, 0, 10};
Dhruv Dhodyb5850122016-02-17 17:51:19 +053052 private final byte[] lsRequestPacket = {0, 0, 0, 0, 2, 3, 0, 36, -64, -88, -86, 3, 0, 0, 0, 1, -67, -57,
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -64, -88, -86, 8, -64, -88, -86, 8};
54 private OspfMessageDecoder ospfMessageDecoder;
55 private ChannelHandlerContext ctx;
56 private Channel channel;
57 private SocketAddress socketAddress;
58 private ChannelBuffer channelBuffer;
59
60 @Before
61 public void setUp() throws Exception {
62 ospfMessageDecoder = new OspfMessageDecoder();
63 }
64
65 @After
66 public void tearDown() throws Exception {
67 ospfMessageDecoder = null;
68 channel = null;
69 socketAddress = null;
70 channelBuffer = null;
71 }
72
73 /**
74 * Tests decode() method.
75 */
76 @Test
77 public void testDecode() throws Exception {
78
79 channel = EasyMock.createMock(Channel.class);
80 socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 7000);
81 channelBuffer = ChannelBuffers.copiedBuffer(hellopacket);
82 assertThat(ospfMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue()));
Dhruv Dhodyb5850122016-02-17 17:51:19 +053083 }
84}