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;
13 import java.net.InetSocketAddress;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.Mock;
19 import org.mockito.MockitoAnnotations;
20 import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer;
26 public class UdpConnectionMapTest {
28 @Mock MessageConsumer consumerMock;
29 @Mock ByteBuf messageBuffer;
32 public void startUp(){
33 MockitoAnnotations.initMocks(this);
37 * Test {@link UdpConnectionMap} - sender address is not null
40 public void testWithSenderAddress(){
41 InetSocketAddress recipientISA = InetSocketAddress.createUnresolved("localhost", 9876);
42 InetSocketAddress senderISA = InetSocketAddress.createUnresolved("192.168.15.2", 21021);
43 DatagramPacket datagramPacket = new DatagramPacket(messageBuffer, recipientISA, senderISA);
44 UdpConnectionMap.addConnection(datagramPacket.sender(), consumerMock);
45 Assert.assertEquals("Wrong - different object has been returned",
46 consumerMock, UdpConnectionMap.getMessageConsumer(datagramPacket.sender()));
47 UdpConnectionMap.removeConnection(datagramPacket.sender());
48 Assert.assertNull("Wrong - object has been returned after remove key-value pair",
49 UdpConnectionMap.getMessageConsumer(datagramPacket.sender()));
53 * Test {@link UdpConnectionMap} - sender address is null to add connection
55 @Test(expected = IllegalArgumentException.class)
56 public void testWithoutSenderAddressOnAdd(){
57 UdpConnectionMap.addConnection(null, consumerMock);
61 * Test {@link UdpConnectionMap} - sender address is not null to get message consumer
63 @Test(expected = IllegalArgumentException.class)
64 public void testWithoutSenderAddressOnGet(){
65 UdpConnectionMap.getMessageConsumer(null);
69 * Test {@link UdpConnectionMap} - sender address is not null to remove connection
71 @Test(expected = IllegalArgumentException.class)
72 public void testWithoutSenderAddressOnRemove(){
73 UdpConnectionMap.removeConnection(null);