ef5aa3063f41edbf41b909fead6f7d6cbd97771a
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / connection / OutboundQueueProviderImplTest.java
1 package org.opendaylight.openflowplugin.impl.connection;
2
3 import static org.mockito.Mockito.mock;
4 import static org.mockito.Mockito.when;
5
6 import junit.framework.TestCase;
7 import org.junit.Test;
8 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
9 import org.opendaylight.openflowplugin.api.OFConstants;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
11
12 public class OutboundQueueProviderImplTest extends TestCase {
13
14     private static final Long DUMMY_ENTRY_NUMBER = 44L;
15     private static final Long DUMMY_XID = 55L;
16
17     private final OutboundQueueProviderImpl outboundQueueProvider = new OutboundQueueProviderImpl(OFConstants.OFP_VERSION_1_3);
18
19     @Test
20     public void testReserveEntry() throws Exception {
21
22         outboundQueueProvider.onConnectionQueueChanged(null);
23         Long returnValue = outboundQueueProvider.reserveEntry();
24         assertEquals(null, returnValue);
25
26         OutboundQueue mockedQueue = mock(OutboundQueue.class);
27         when(mockedQueue.reserveEntry()).thenReturn(DUMMY_ENTRY_NUMBER);
28         outboundQueueProvider.onConnectionQueueChanged(mockedQueue);
29         returnValue = outboundQueueProvider.reserveEntry();
30         assertEquals(DUMMY_ENTRY_NUMBER, returnValue);
31     }
32
33     @Test
34     public void testCreateBarrierRequest() {
35         final BarrierInput barrierRequest = outboundQueueProvider.createBarrierRequest(DUMMY_XID);
36         assertNotNull(barrierRequest);;
37         assertEquals((short)OFConstants.OFP_VERSION_1_3, (short)barrierRequest.getVersion());
38         assertEquals(DUMMY_XID, barrierRequest.getXid());
39     }
40 }