2 * Copyright © 2015 Red Hat, 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.rev141210;
10 import org.junit.Test;
11 import org.opendaylight.controller.config.api.DependencyResolver;
12 import org.opendaylight.controller.config.api.JmxAttribute;
13 import org.opendaylight.controller.config.api.ModuleIdentifier;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.ovsdb.openstack.netvirt.sfc.NetvirtSfcProvider;
17 import org.osgi.framework.BundleContext;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
20 import javax.management.ObjectName;
22 import static org.mockito.Matchers.any;
23 import static org.mockito.Matchers.eq;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
28 public class NetvirtSfcModuleTest {
30 public void testCustomValidation() {
31 NetvirtSfcModule module = new NetvirtSfcModule(mock(ModuleIdentifier.class), mock(DependencyResolver.class));
32 // ensure no exceptions on validation
33 // currently this method is empty
34 module.customValidation();
38 public void testCreateInstance() throws Exception {
40 DependencyResolver dependencyResolver = mock(DependencyResolver.class);
41 BindingAwareBroker broker = mock(BindingAwareBroker.class);
42 ProviderContext session = mock(ProviderContext.class);
43 DataBroker dataBroker = mock(DataBroker.class);
44 when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class))).thenReturn(broker);
45 when(session.getSALService(eq(DataBroker.class))).thenReturn(dataBroker);
47 // create instance of module with injected mocks
48 NetvirtSfcModule module = new NetvirtSfcModule(mock(ModuleIdentifier.class), dependencyResolver);
49 // getInstance calls resolveInstance to get the broker dependency and then calls createInstance
50 AutoCloseable closeable = module.getInstance();
51 ((NetvirtSfcProvider)closeable).onSessionInitiated(session);
52 // verify that the module registered the returned provider with the broker
53 verify(broker).registerProvider((NetvirtSfcProvider)closeable);
55 // ensure no exceptions on close