Merge "added API for OFP internal flow registry"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / device / DeviceManagerImplTest.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.openflowplugin.impl.device;
9
10 import org.junit.After;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Ignore;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.ArgumentCaptor;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
21 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
22 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
23 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
24 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescCase;
28
29
30 /**
31  * test of {@link DeviceManagerImpl} - lightweight version, using basic ways (TDD)
32  */
33 @RunWith(MockitoJUnitRunner.class)
34 public class DeviceManagerImplTest {
35
36     private DeviceManagerImpl deviceManager;
37     @Mock
38     private ConnectionContext connectionContext;
39     @Mock
40     private ConnectionAdapter connectionAdapter;
41     @Mock
42     private FeaturesReply features;
43     @Mock
44     private DataBroker dataBroker;
45     @Mock
46     private RpcManager rpcManager;
47     @Mock
48     private WriteTransaction wTx;
49
50     /**
51      * @throws java.lang.Exception
52      */
53     @Before
54     public void setUp() throws Exception {
55         Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
56         Mockito.when(connectionContext.getFeatures()).thenReturn(features);
57         Mockito.when(features.getVersion()).thenReturn((short) 42);
58         Mockito.when(dataBroker.newWriteOnlyTransaction()).thenReturn(wTx);
59         deviceManager = new DeviceManagerImpl(dataBroker);
60     }
61
62     /**
63      * @throws java.lang.Exception
64      */
65     @After
66     public void tearDown() throws Exception {
67     }
68
69     /**
70      * Test method for {@link org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl#deviceConnected(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext)}.
71      */
72     @Test
73     @Ignore // FIXME : fix the test ASAP
74     public void testDeviceConnected() {
75         deviceManager.deviceConnected(connectionContext);
76
77         final ArgumentCaptor<MultipartRequestInput> mpInputCaptor = ArgumentCaptor.forClass(MultipartRequestInput.class);
78         Mockito.verify(connectionAdapter).multipartRequest(mpInputCaptor.capture());
79
80         Assert.assertTrue(mpInputCaptor.getAllValues().get(0).getMultipartRequestBody() instanceof MultipartRequestDescCase);
81         //Assert.assertTrue(mpInputCaptor.getAllValues().get(1).getMultipartRequestBody() instanceof MultipartRequestGroupDescCase);
82     }
83
84     /**
85      * Test method for {@link org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl#sendMessage(org.opendaylight.yangtools.yang.binding.DataObject, org.opendaylight.openflowplugin.api.openflow.device.RequestContext)}.
86      */
87     @Test
88     public void testSendMessage() {
89     }
90
91     /**
92      * Test method for {@link org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl#sendRequest(org.opendaylight.yangtools.yang.binding.DataObject, org.opendaylight.openflowplugin.api.openflow.device.RequestContext)}.
93      */
94     @Test
95     public void testSendRequest() {
96     }
97
98     /**
99      * Test method for {@link org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl#addRequestContextReadyHandler(org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextReadyHandler)}.
100      */
101     @Test
102     public void testAddRequestContextReadyHandler() {
103     }
104
105     @Test
106     public void testHookRequest() {
107
108     }
109
110 }