99872549a899025abcd650e7574a66095a8838ed
[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 org.junit.Test;
19 import org.opendaylight.controller.config.api.DependencyResolver;
20 import org.opendaylight.controller.config.api.JmxAttribute;
21 import org.opendaylight.controller.config.api.ModuleIdentifier;
22 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
23 import io.fd.honeycomb.v3po.impl.V3poProvider;
24
25 import javax.management.ObjectName;
26
27 import static org.mockito.Matchers.any;
28 import static org.mockito.Matchers.eq;
29 import static org.mockito.Mockito.mock;
30 import static org.mockito.Mockito.verify;
31 import static org.mockito.Mockito.when;
32
33 public class V3poModuleTest {
34     @Test
35     public void testCustomValidation() {
36         V3poModule module = new V3poModule(mock(ModuleIdentifier.class), mock(DependencyResolver.class));
37
38         // ensure no exceptions on validation
39         // currently this method is empty
40         module.customValidation();
41     }
42
43     @Test
44     public void testCreateInstance() throws Exception {
45         // configure mocks
46         DependencyResolver dependencyResolver = mock(DependencyResolver.class);
47         BindingAwareBroker broker = mock(BindingAwareBroker.class);
48         when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class))).thenReturn(broker);
49
50         // create instance of module with injected mocks
51         V3poModule module = new V3poModule(mock(ModuleIdentifier.class), dependencyResolver);
52
53         // getInstance calls resolveInstance to get the broker dependency and then calls createInstance
54         AutoCloseable closeable = module.getInstance();
55
56         // verify that the module registered the returned provider with the broker
57         verify(broker).registerProvider((V3poProvider)closeable);
58
59         // ensure no exceptions on close
60         closeable.close();
61     }
62 }