060b436cd7cbb037a29b859162f819035acce235
[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.data.ModifiableDataTree;
25 import io.fd.honeycomb.v3po.data.ReadableDataTree;
26 import io.fd.honeycomb.v3po.impl.V3poProvider;
27 import io.fd.honeycomb.v3po.translate.read.ReaderRegistry;
28 import io.fd.honeycomb.v3po.translate.write.WriterRegistry;
29 import javax.management.ObjectName;
30 import org.junit.Test;
31 import org.opendaylight.controller.config.api.DependencyResolver;
32 import org.opendaylight.controller.config.api.JmxAttribute;
33 import org.opendaylight.controller.config.api.ModuleIdentifier;
34 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
35 import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer;
36
37 public class V3poModuleTest {
38     @Test
39     public void testCustomValidation() {
40         V3poModule module = new V3poModule(mock(ModuleIdentifier.class), mock(DependencyResolver.class));
41
42         // ensure no exceptions on validation
43         // currently this method is empty
44         module.customValidation();
45     }
46
47
48     @Test
49     public void testCreateInstance() throws Exception {
50         // configure mocks
51         DependencyResolver dependencyResolver = mock(DependencyResolver.class);
52         BindingAwareBroker broker = mock(BindingAwareBroker.class);
53         when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class)))
54             .thenReturn(broker);
55         final org.opendaylight.controller.sal.core.api.Broker domBroker = mock(org.opendaylight.controller.sal.core.api.Broker.class);
56         when(dependencyResolver.resolveInstance(eq(org.opendaylight.controller.sal.core.api.Broker.class), any(ObjectName.class), any(JmxAttribute.class)))
57             .thenReturn(domBroker);
58         when(dependencyResolver.resolveInstance(eq(ReaderRegistry.class), any(ObjectName.class), any(JmxAttribute.class)))
59                 .thenReturn(mock(ReaderRegistry.class));
60         when(dependencyResolver.resolveInstance(eq(WriterRegistry.class), any(ObjectName.class), any(JmxAttribute.class)))
61                 .thenReturn(mock(WriterRegistry.class));
62         when(dependencyResolver.resolveInstance(eq(BindingNormalizedNodeSerializer.class), any(ObjectName.class), any(JmxAttribute.class)))
63                 .thenReturn(mock(BindingNormalizedNodeSerializer.class));
64         when(dependencyResolver.resolveInstance(eq(ModifiableDataTree.class), any(ObjectName.class), any(JmxAttribute.class)))
65                 .thenReturn(mock(ModifiableDataTree.class));
66         when(dependencyResolver.resolveInstance(eq(ReadableDataTree.class), any(ObjectName.class), any(JmxAttribute.class)))
67                 .thenReturn(mock(ReadableDataTree.class));
68
69         // create instance of module with injected mocks
70         V3poModule module = new V3poModule(mock(ModuleIdentifier.class), dependencyResolver);
71
72         // getInstance calls resolveInstance to get the broker dependency and then calls createInstance
73         AutoCloseable closeable = module.getInstance();
74
75         // verify that the module registered the returned provider with the broker
76         verify(broker).registerProvider((V3poProvider)closeable);
77
78         // ensure no exceptions on close
79         closeable.close();
80     }
81 }