2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.impl.device;
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.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescCase;
32 * test of {@link DeviceManagerImpl} - lightweight version, using basic ways (TDD)
34 @RunWith(MockitoJUnitRunner.class)
35 public class DeviceManagerImplTest {
37 private DeviceManagerImpl deviceManager;
39 private ConnectionContext connectionContext;
41 private ConnectionAdapter connectionAdapter;
43 private FeaturesReply features;
45 private DataBroker dataBroker;
47 private RpcManager rpcManager;
49 private WriteTransaction wTx;
51 private MessageIntelligenceAgency messageIntelligenceAgency;
54 * @throws java.lang.Exception
57 public void setUp() throws Exception {
58 Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
59 Mockito.when(connectionContext.getFeatures()).thenReturn(features);
60 Mockito.when(features.getVersion()).thenReturn((short) 42);
61 Mockito.when(dataBroker.newWriteOnlyTransaction()).thenReturn(wTx);
62 deviceManager = new DeviceManagerImpl(dataBroker, messageIntelligenceAgency);
66 * @throws java.lang.Exception
69 public void tearDown() throws Exception {
73 * Test method for {@link org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl#deviceConnected(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext)}.
76 @Ignore // FIXME : fix the test ASAP
77 public void testDeviceConnected() {
78 deviceManager.deviceConnected(connectionContext);
80 final ArgumentCaptor<MultipartRequestInput> mpInputCaptor = ArgumentCaptor.forClass(MultipartRequestInput.class);
81 Mockito.verify(connectionAdapter).multipartRequest(mpInputCaptor.capture());
83 Assert.assertTrue(mpInputCaptor.getAllValues().get(0).getMultipartRequestBody() instanceof MultipartRequestDescCase);
84 //Assert.assertTrue(mpInputCaptor.getAllValues().get(1).getMultipartRequestBody() instanceof MultipartRequestGroupDescCase);
88 * Test method for {@link org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl#sendMessage(org.opendaylight.yangtools.yang.binding.DataObject, org.opendaylight.openflowplugin.api.openflow.device.RequestContext)}.
91 public void testSendMessage() {
95 * Test method for {@link org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl#sendRequest(org.opendaylight.yangtools.yang.binding.DataObject, org.opendaylight.openflowplugin.api.openflow.device.RequestContext)}.
98 public void testSendRequest() {
102 * Test method for {@link org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl#addRequestContextReadyHandler(org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextReadyHandler)}.
105 public void testAddRequestContextReadyHandler() {
109 public void testHookRequest() {