2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowjava.protocol.impl.core;
10 import io.netty.buffer.ByteBuf;
11 import io.netty.channel.socket.DatagramPacket;
12 import java.net.InetSocketAddress;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.mockito.Mock;
17 import org.mockito.MockitoAnnotations;
18 import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer;
21 * Unit tests for UdpConnectionMap.
25 public class UdpConnectionMapTest {
27 @Mock MessageConsumer consumerMock;
28 @Mock ByteBuf messageBuffer;
31 public void startUp() {
32 MockitoAnnotations.initMocks(this);
36 * Test {@link UdpConnectionMap} - sender address is not null.
39 public void testWithSenderAddress() {
40 InetSocketAddress recipientISA = InetSocketAddress.createUnresolved("localhost", 9876);
41 InetSocketAddress senderISA = InetSocketAddress.createUnresolved("192.168.15.2", 21021);
42 DatagramPacket datagramPacket = new DatagramPacket(messageBuffer, recipientISA, senderISA);
43 UdpConnectionMap.addConnection(datagramPacket.sender(), consumerMock);
44 Assert.assertEquals("Wrong - different object has been returned",
45 consumerMock, UdpConnectionMap.getMessageConsumer(datagramPacket.sender()));
46 UdpConnectionMap.removeConnection(datagramPacket.sender());
47 Assert.assertNull("Wrong - object has been returned after remove key-value pair",
48 UdpConnectionMap.getMessageConsumer(datagramPacket.sender()));
52 * Test {@link UdpConnectionMap} - sender address is null to add connection.
54 @Test(expected = IllegalArgumentException.class)
55 public void testWithoutSenderAddressOnAdd() {
56 UdpConnectionMap.addConnection(null, consumerMock);
60 * Test {@link UdpConnectionMap} - sender address is not null to get message consumer.
62 @Test(expected = IllegalArgumentException.class)
63 public void testWithoutSenderAddressOnGet() {
64 UdpConnectionMap.getMessageConsumer(null);
68 * Test {@link UdpConnectionMap} - sender address is not null to remove connection.
70 @Test(expected = IllegalArgumentException.class)
71 public void testWithoutSenderAddressOnRemove() {
72 UdpConnectionMap.removeConnection(null);