Migrate openflow-protocol-impl tests to Uint types
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / core / UdpConnectionMapTest.java
1 /*
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowjava.protocol.impl.core;
9
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;
19
20 /**
21  * Unit tests for UdpConnectionMap.
22  *
23  * @author madamjak
24  */
25 public class UdpConnectionMapTest {
26
27     @Mock MessageConsumer consumerMock;
28     @Mock ByteBuf messageBuffer;
29
30     @Before
31     public void startUp() {
32         MockitoAnnotations.initMocks(this);
33     }
34
35     /**
36      * Test {@link UdpConnectionMap} - sender address is not null.
37      */
38     @Test
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()));
49     }
50
51     /**
52      * Test {@link UdpConnectionMap} - sender address is null to add connection.
53      */
54     @Test(expected = IllegalArgumentException.class)
55     public void testWithoutSenderAddressOnAdd() {
56         UdpConnectionMap.addConnection(null, consumerMock);
57     }
58
59     /**
60      * Test {@link UdpConnectionMap} - sender address is not null to get message consumer.
61      */
62     @Test(expected = IllegalArgumentException.class)
63     public void testWithoutSenderAddressOnGet() {
64         UdpConnectionMap.getMessageConsumer(null);
65     }
66
67     /**
68      * Test {@link UdpConnectionMap} - sender address is not null to remove connection.
69      */
70     @Test(expected = IllegalArgumentException.class)
71     public void testWithoutSenderAddressOnRemove() {
72         UdpConnectionMap.removeConnection(null);
73     }
74 }