Add method to register listener for unknown msg
[openflowjava.git] / 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
13 import java.net.InetSocketAddress;
14
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;
21
22 /**
23  * @author madamjak
24  *
25  */
26 public class UdpConnectionMapTest {
27
28     @Mock MessageConsumer consumerMock;
29     @Mock  ByteBuf messageBuffer;
30
31     @Before
32     public void startUp(){
33         MockitoAnnotations.initMocks(this);
34     }
35
36     /**
37      * Test {@link UdpConnectionMap} - sender address is not null
38      */
39     @Test
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()));
50     }
51
52     /**
53      * Test {@link UdpConnectionMap} - sender address is null to add connection
54      */
55     @Test(expected = IllegalArgumentException.class)
56     public void testWithoutSenderAddressOnAdd(){
57         UdpConnectionMap.addConnection(null, consumerMock);
58     }
59
60     /**
61      * Test {@link UdpConnectionMap} - sender address is not null to get message consumer
62      */
63     @Test(expected = IllegalArgumentException.class)
64     public void testWithoutSenderAddressOnGet(){
65         UdpConnectionMap.getMessageConsumer(null);
66     }
67
68     /**
69      * Test {@link UdpConnectionMap} - sender address is not null to remove connection
70      */
71     @Test(expected = IllegalArgumentException.class)
72     public void testWithoutSenderAddressOnRemove(){
73         UdpConnectionMap.removeConnection(null);
74     }
75 }