2 * Copyright (c) 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.impl.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.ovsdb.netvirt.impl.NetvirtProvider;
17 import javax.management.ObjectName;
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Matchers.eq;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.verify;
23 import static org.mockito.Mockito.when;
25 public class NetvirtModuleTest {
27 public void testCustomValidation() {
28 NetvirtModule module = new NetvirtModule(mock(ModuleIdentifier.class), mock(DependencyResolver.class));
30 // ensure no exceptions on validation
31 // currently this method is empty
32 module.customValidation();
36 public void testCreateInstance() throws Exception {
38 DependencyResolver dependencyResolver = mock(DependencyResolver.class);
39 BindingAwareBroker broker = mock(BindingAwareBroker.class);
40 when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class))).thenReturn(broker);
42 // create instance of module with injected mocks
43 NetvirtModule module = new NetvirtModule(mock(ModuleIdentifier.class), dependencyResolver);
45 // getInstance calls resolveInstance to get the broker dependency and then calls createInstance
46 AutoCloseable closeable = module.getInstance();
48 // verify that the module registered the returned provider with the broker
49 verify(broker).registerProvider((NetvirtProvider)closeable);
51 // ensure no exceptions on close