DeviceContext proposal
[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 static org.junit.Assert.fail;
11
12 import org.junit.After;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.ArgumentCaptor;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.runners.MockitoJUnitRunner;
21 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
22 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescCase;
26 //import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCase;
27
28 /**
29  * test of {@link DeviceManagerImpl} - lightweight version, using basic ways (TDD)
30  */
31 @RunWith(MockitoJUnitRunner.class)
32 public class DeviceManagerImplTest {
33
34     private DeviceManagerImpl deviceManager;
35     @Mock
36     private ConnectionContext connectionContext;
37     @Mock
38     private ConnectionAdapter connectionAdapter;
39     @Mock
40     private FeaturesReply features;
41
42     /**
43      * @throws java.lang.Exception
44      */
45     @Before
46     public void setUp() throws Exception {
47         Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
48         Mockito.when(connectionContext.getFeatures()).thenReturn(features);
49         Mockito.when(features.getVersion()).thenReturn((short) 42);
50         deviceManager = new DeviceManagerImpl();
51     }
52
53     /**
54      * @throws java.lang.Exception
55      */
56     @After
57     public void tearDown() throws Exception {
58     }
59
60     /**
61      * Test method for {@link org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl#deviceConnected(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext)}.
62      */
63     @Test
64     public void testDeviceConnected() {
65         deviceManager.deviceConnected(connectionContext);
66
67         ArgumentCaptor<MultipartRequestInput> mpInputCaptor = ArgumentCaptor.forClass(MultipartRequestInput.class);
68         Mockito.verify(connectionAdapter).multipartRequest(mpInputCaptor.capture());
69
70         Assert.assertTrue(mpInputCaptor.getAllValues().get(0).getMultipartRequestBody() instanceof MultipartRequestDescCase);
71         //Assert.assertTrue(mpInputCaptor.getAllValues().get(1).getMultipartRequestBody() instanceof MultipartRequestGroupDescCase);
72     }
73
74     /**
75      * Test method for {@link org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl#sendMessage(org.opendaylight.yangtools.yang.binding.DataObject, org.opendaylight.openflowplugin.api.openflow.device.RequestContext)}.
76      */
77     @Test
78     public void testSendMessage() {
79     }
80
81     /**
82      * Test method for {@link org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl#sendRequest(org.opendaylight.yangtools.yang.binding.DataObject, org.opendaylight.openflowplugin.api.openflow.device.RequestContext)}.
83      */
84     @Test
85     public void testSendRequest() {
86     }
87
88     /**
89      * Test method for {@link org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl#addRequestContextReadyHandler(org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextReadyHandler)}.
90      */
91     @Test
92     public void testAddRequestContextReadyHandler() {
93     }
94
95 }