2 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
16 import static org.mockito.Mockito.when;
18 import java.lang.reflect.Field;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mockito;
22 import org.opendaylight.controller.config.yang.md.sal.rest.connector.RestConnectorRuntimeRegistration;
23 import org.opendaylight.controller.config.yang.md.sal.rest.connector.RestConnectorRuntimeRegistrator;
24 import org.opendaylight.controller.sal.core.api.Broker;
25 import org.opendaylight.controller.sal.core.api.Provider;
26 import org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl;
27 import org.opendaylight.restconf.RestConnectorProvider;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
30 public class RestconfWrapperProvidersTest {
32 private static final PortNumber PORT = new PortNumber(8181);
34 private RestconfWrapperProviders rwp;
37 public void setUp() throws Exception {
38 rwp = new RestconfWrapperProviders(PORT);
43 public void registerTest() {
44 final Broker broker = mock(Broker.class);
45 rwp.registerProviders(broker);
47 Mockito.verify(broker, times(2)).registerProvider(Mockito.any(Provider.class));
51 public void runtimeRegistrationTest() {
52 final RestConnectorRuntimeRegistrator runtimeRegistrator = mock(RestConnectorRuntimeRegistrator.class);
53 final RestConnectorRuntimeRegistration value = mock(RestConnectorRuntimeRegistration.class);
54 when(runtimeRegistrator.register(any())).thenReturn(value);
55 final RestConnectorRuntimeRegistration runtimeRegistration = rwp.runtimeRegistration(runtimeRegistrator);
57 assertEquals(value, runtimeRegistration);
61 public void closeTest() throws Exception {
62 final RestconfProviderImpl draft2 = mock(RestconfProviderImpl.class);
63 final RestConnectorProvider draft18 = mock(RestConnectorProvider.class);
65 setDeclaredField(rwp, "providerDraft02", draft2);
66 setDeclaredField(rwp, "providerDraft18", draft18);
70 verify(draft2, times(1)).close();
71 verify(draft18, times(1)).close();
74 private static void setDeclaredField(final Object rwp, final String name, final Object value) throws Exception {
75 final Field declaredField = rwp.getClass().getDeclaredField(name);
76 declaredField.setAccessible(true);
77 declaredField.set(rwp, value);