2 * Copyright (c) 2015 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.impl.rev141210;
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;
24 import io.fd.honeycomb.v3po.data.ModifiableDataTree;
25 import io.fd.honeycomb.v3po.impl.V3poProvider;
26 import io.fd.honeycomb.v3po.translate.read.ReaderRegistry;
27 import io.fd.honeycomb.v3po.translate.write.WriterRegistry;
28 import javax.management.ObjectName;
29 import org.junit.Test;
30 import org.opendaylight.controller.config.api.DependencyResolver;
31 import org.opendaylight.controller.config.api.JmxAttribute;
32 import org.opendaylight.controller.config.api.ModuleIdentifier;
33 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
34 import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer;
36 public class V3poModuleTest {
38 public void testCustomValidation() {
39 V3poModule module = new V3poModule(mock(ModuleIdentifier.class), mock(DependencyResolver.class));
41 // ensure no exceptions on validation
42 // currently this method is empty
43 module.customValidation();
48 public void testCreateInstance() throws Exception {
50 DependencyResolver dependencyResolver = mock(DependencyResolver.class);
51 BindingAwareBroker broker = mock(BindingAwareBroker.class);
52 when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class)))
54 final org.opendaylight.controller.sal.core.api.Broker domBroker = mock(org.opendaylight.controller.sal.core.api.Broker.class);
55 when(dependencyResolver.resolveInstance(eq(org.opendaylight.controller.sal.core.api.Broker.class), any(ObjectName.class), any(JmxAttribute.class)))
56 .thenReturn(domBroker);
57 when(dependencyResolver.resolveInstance(eq(ReaderRegistry.class), any(ObjectName.class), any(JmxAttribute.class)))
58 .thenReturn(mock(ReaderRegistry.class));
59 when(dependencyResolver.resolveInstance(eq(WriterRegistry.class), any(ObjectName.class), any(JmxAttribute.class)))
60 .thenReturn(mock(WriterRegistry.class));
61 when(dependencyResolver.resolveInstance(eq(BindingNormalizedNodeSerializer.class), any(ObjectName.class), any(JmxAttribute.class)))
62 .thenReturn(mock(BindingNormalizedNodeSerializer.class));
63 when(dependencyResolver.resolveInstance(eq(ModifiableDataTree.class), any(ObjectName.class), any(JmxAttribute.class)))
64 .thenReturn(mock(ModifiableDataTree.class));
66 // create instance of module with injected mocks
67 V3poModule module = new V3poModule(mock(ModuleIdentifier.class), dependencyResolver);
69 // getInstance calls resolveInstance to get the broker dependency and then calls createInstance
70 AutoCloseable closeable = module.getInstance();
72 // verify that the module registered the returned provider with the broker
73 verify(broker).registerProvider((V3poProvider)closeable);
75 // ensure no exceptions on close