Merge "Bug 3328: Set icmpv4-match into OF10 match."
[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 com.google.common.util.concurrent.CheckedFuture;
11 import org.junit.After;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Ignore;
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.controller.md.sal.binding.api.DataBroker;
22 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
23 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
24 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
25 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
26 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
27 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescCase;
31
32
33 /**
34  * test of {@link DeviceManagerImpl} - lightweight version, using basic ways (TDD)
35  */
36 @RunWith(MockitoJUnitRunner.class)
37 public class DeviceManagerImplTest {
38
39     private DeviceManagerImpl deviceManager;
40     @Mock
41     private ConnectionContext connectionContext;
42     @Mock
43     private ConnectionAdapter connectionAdapter;
44     @Mock
45     private FeaturesReply features;
46     @Mock
47     private DataBroker dataBroker;
48     @Mock
49     private RpcManager rpcManager;
50     @Mock
51     private WriteTransaction wTx;
52     @Mock
53     private MessageIntelligenceAgency messageIntelligenceAgency;
54     @Mock
55     private CheckedFuture<Void, TransactionCommitFailedException> checkedFuture;
56
57     /**
58      * @throws java.lang.Exception
59      */
60     @Before
61     public void setUp() throws Exception {
62         Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
63         Mockito.when(connectionContext.getFeatures()).thenReturn(features);
64         Mockito.when(features.getVersion()).thenReturn((short) 42);
65         Mockito.when(dataBroker.newWriteOnlyTransaction()).thenReturn(wTx);
66         Mockito.when(wTx.submit()).thenReturn(checkedFuture);
67         Mockito.when(checkedFuture.get()).thenReturn((Void) null);
68
69     }
70
71     /**
72      * @throws java.lang.Exception
73      */
74     @After
75     public void tearDown() throws Exception {
76     }
77
78     /**
79      * Test method for {@link org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl#deviceConnected(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext)}.
80      */
81     @Test
82     @Ignore // FIXME : fix the test ASAP
83     public void testDeviceConnected() {
84         deviceManager.deviceConnected(connectionContext);
85
86         final ArgumentCaptor<MultipartRequestInput> mpInputCaptor = ArgumentCaptor.forClass(MultipartRequestInput.class);
87         Mockito.verify(connectionAdapter).multipartRequest(mpInputCaptor.capture());
88
89         Assert.assertTrue(mpInputCaptor.getAllValues().get(0).getMultipartRequestBody() instanceof MultipartRequestDescCase);
90         //Assert.assertTrue(mpInputCaptor.getAllValues().get(1).getMultipartRequestBody() instanceof MultipartRequestGroupDescCase);
91     }
92
93
94     @Test
95     public void testHookRequest() {
96
97     }
98
99 }