Migrate to odlparent 2.0.0
[alto.git] / alto-core / standard-northbound-routes / example / src / test / java / org / opendaylight / yang / gen / v1 / urn / alto / northbound / route / example / impl / rev151021 / AltoNorthboundRouteExampleModuleTest.java
1 /*
2  * Copyright © 2015 Yale University 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.yang.gen.v1.urn.alto.northbound.route.example.impl.rev151021;
9
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.alto.core.northbound.api.AltoNorthboundRouter;
16
17 import javax.management.ObjectName;
18
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;
24
25 public class AltoNorthboundRouteExampleModuleTest {
26     @Test
27     public void testCustomValidation() {
28         AltoNorthboundRouteExampleModule module = new AltoNorthboundRouteExampleModule(mock(ModuleIdentifier.class), mock(DependencyResolver.class));
29
30         // ensure no exceptions on validation
31         // currently this method is empty
32         module.customValidation();
33     }
34
35     @Test
36     public void testCreateInstance() throws Exception {
37         // configure mocks
38         DependencyResolver dependencyResolver = mock(DependencyResolver.class);
39         BindingAwareBroker broker = mock(BindingAwareBroker.class);
40         AltoNorthboundRouter router = mock(AltoNorthboundRouter.class);
41         when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class))).thenReturn(broker);
42         when(dependencyResolver.resolveInstance(eq(AltoNorthboundRouter.class), any(ObjectName.class), any(JmxAttribute.class))).thenReturn(router);
43
44         // create instance of module with injected mocks
45         AltoNorthboundRouteExampleModule module = new AltoNorthboundRouteExampleModule(mock(ModuleIdentifier.class), dependencyResolver);
46
47         // getInstance calls resolveInstance to get the broker dependency and then calls createInstance
48         AutoCloseable closeable = module.getInstance();
49
50         // ensure no exceptions on close
51         closeable.close();
52
53         // verify that the route is released after closed
54         verify(router).removeRoute("example");
55     }
56 }