cee38b287558642a1f2bac4d7a43169fb90301c8
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.impl.rev141210;
17
18 import static org.mockito.Matchers.any;
19 import static org.mockito.Matchers.eq;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.verify;
22 import static org.mockito.Mockito.when;
23
24 import io.fd.honeycomb.v3po.impl.V3poProvider;
25 import javax.management.ObjectName;
26 import org.junit.Test;
27 import org.opendaylight.controller.config.api.DependencyResolver;
28 import org.opendaylight.controller.config.api.JmxAttribute;
29 import org.opendaylight.controller.config.api.ModuleIdentifier;
30 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
31
32 public class V3poModuleTest {
33     @Test
34     public void testCustomValidation() {
35         V3poModule module = new V3poModule(mock(ModuleIdentifier.class), mock(DependencyResolver.class));
36
37         // ensure no exceptions on validation
38         // currently this method is empty
39         module.customValidation();
40     }
41
42     @Test
43     public void testCreateInstance() throws Exception {
44         // configure mocks
45         DependencyResolver dependencyResolver = mock(DependencyResolver.class);
46         BindingAwareBroker broker = mock(BindingAwareBroker.class);
47         when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class)))
48             .thenReturn(broker);
49         final org.opendaylight.controller.sal.core.api.Broker domBroker = mock(org.opendaylight.controller.sal.core.api.Broker.class);
50         when(dependencyResolver.resolveInstance(eq(org.opendaylight.controller.sal.core.api.Broker.class), any(ObjectName.class), any(JmxAttribute.class)))
51             .thenReturn(domBroker);
52
53         // create instance of module with injected mocks
54         V3poModule module = new V3poModule(mock(ModuleIdentifier.class), dependencyResolver);
55
56         // getInstance calls resolveInstance to get the broker dependency and then calls createInstance
57         AutoCloseable closeable = module.getInstance();
58
59         // verify that the module registered the returned provider with the broker
60         verify(broker).registerProvider((V3poProvider)closeable);
61
62         // ensure no exceptions on close
63         closeable.close();
64     }
65 }