Merge "Startup archetype: remove 'Impl' from config subsystem Module name."
[controller.git] / opendaylight / archetypes / opendaylight-startup / src / main / resources / archetype-resources / impl / src / test / java / org / opendaylight / yang / gen / v1 / urn / opendaylight / params / xml / ns / yang / __artifactId__ / impl / rev141210 / __classPrefix__ModuleTest.java
1 #set( $symbol_pound = '#' )
2 #set( $symbol_dollar = '$' )
3 #set( $symbol_escape = '\' )
4 #set( $module = "${classPrefix}Module" )
5 /*
6  * ${copyright} and others.  All rights reserved.
7  *
8  * This program and the accompanying materials are made available under the
9  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
10  * and is available at http://www.eclipse.org/legal/epl-v10.html
11  */
12 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.${artifactId}.impl.rev141210;
13
14 import org.junit.Test;
15 import org.opendaylight.controller.config.api.DependencyResolver;
16 import org.opendaylight.controller.config.api.JmxAttribute;
17 import org.opendaylight.controller.config.api.ModuleIdentifier;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
19 import ${package}.${classPrefix}Provider;
20
21 import javax.management.ObjectName;
22
23 import static org.mockito.Matchers.any;
24 import static org.mockito.Matchers.eq;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.when;
28
29 public class ${classPrefix}ModuleTest {
30     @Test
31     public void testCustomValidation() {
32         ${module} module = new ${module}(mock(ModuleIdentifier.class), mock(DependencyResolver.class));
33
34         // ensure no exceptions on validation
35         // currently this method is empty
36         module.customValidation();
37     }
38
39     @Test
40     public void testCreateInstance() throws Exception {
41         // configure mocks
42         DependencyResolver dependencyResolver = mock(DependencyResolver.class);
43         BindingAwareBroker broker = mock(BindingAwareBroker.class);
44         when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class))).thenReturn(broker);
45
46         // create instance of module with injected mocks
47         ${module} module = new ${module}(mock(ModuleIdentifier.class), dependencyResolver);
48
49         // getInstance calls resolveInstance to get the broker dependency and then calls createInstance
50         AutoCloseable closeable = module.getInstance();
51
52         // verify that the module registered the returned provider with the broker
53         verify(broker).registerProvider((${classPrefix}Provider)closeable);
54
55         // ensure no exceptions on close
56         closeable.close();
57     }
58 }