chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.isis.controller.impl; |
| 17 | |
| 18 | import com.google.common.primitives.Bytes; |
| 19 | import org.easymock.EasyMock; |
| 20 | import org.jboss.netty.buffer.ChannelBuffer; |
| 21 | import org.jboss.netty.buffer.ChannelBuffers; |
| 22 | import org.jboss.netty.channel.Channel; |
| 23 | import org.jboss.netty.channel.ChannelHandlerContext; |
| 24 | import org.junit.After; |
| 25 | import org.junit.Before; |
| 26 | import org.junit.Test; |
| 27 | import org.onosproject.isis.io.util.IsisUtil; |
| 28 | |
| 29 | import java.net.InetSocketAddress; |
| 30 | import java.net.SocketAddress; |
| 31 | |
| 32 | import static org.hamcrest.CoreMatchers.is; |
| 33 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 34 | import static org.hamcrest.MatcherAssert.assertThat; |
| 35 | |
| 36 | /** |
| 37 | * Unit test class for IsisMessageEncoder. |
| 38 | */ |
| 39 | public 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 | } |