Dhruv Dhody | b585012 | 2016-02-17 17:51:19 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Dhruv Dhody | b585012 | 2016-02-17 17:51:19 +0530 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.ospf.controller.impl; |
| 17 | |
| 18 | import org.easymock.EasyMock; |
| 19 | import org.jboss.netty.buffer.ChannelBuffer; |
| 20 | import org.jboss.netty.buffer.ChannelBuffers; |
| 21 | import org.jboss.netty.channel.Channel; |
| 22 | import org.jboss.netty.channel.ChannelHandlerContext; |
| 23 | import org.junit.After; |
| 24 | import org.junit.Before; |
| 25 | import org.junit.Test; |
| 26 | |
| 27 | import java.net.InetSocketAddress; |
| 28 | import java.net.SocketAddress; |
| 29 | |
| 30 | import static org.hamcrest.CoreMatchers.is; |
| 31 | import static org.hamcrest.CoreMatchers.nullValue; |
| 32 | import static org.hamcrest.MatcherAssert.assertThat; |
| 33 | |
| 34 | /** |
| 35 | * Unit test class for OspfMessageDecoder. |
| 36 | */ |
| 37 | public 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 vk | aa48da8 | 2016-03-02 23:17:06 +0530 | [diff] [blame] | 50 | -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 Dhody | b585012 | 2016-02-17 17:51:19 +0530 | [diff] [blame] | 52 | 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 Dhody | b585012 | 2016-02-17 17:51:19 +0530 | [diff] [blame] | 83 | } |
| 84 | } |