2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Ericsson
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.provider;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.Matchers.anyObject;
26 import static org.mockito.Mockito.when;
27 import java.util.concurrent.ExecutionException;
28 import java.util.concurrent.ExecutorService;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mockito;
32 import org.mockito.internal.util.reflection.Whitebox;
33 import org.onap.appc.provider.topology.TopologyService;
34 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
35 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
36 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
37 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.MigrateInput;
38 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.ModifyConfigInput;
39 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.RebuildInput;
40 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.RestartInput;
41 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.SnapshotInput;
42 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.VmstatuscheckInput;
43 import org.opendaylight.yangtools.yang.common.RpcResult;
45 public class TestAppcProvider {
47 private AppcProvider appcProvider;
48 private DataBroker dataBroker2;
49 private NotificationPublishService notificationProviderService;
50 private RpcProviderRegistry rpcProviderRegistry;
51 private AppcProviderClient appcProviderClient;
52 private TopologyService topologyService;
53 private RpcResult result;
58 topologyService = Mockito.mock(TopologyService.class);
59 result = Mockito.mock(RpcResult.class);
61 new AppcProvider(dataBroker2, notificationProviderService, rpcProviderRegistry, appcProviderClient);
65 public void testModifyConfig() throws InterruptedException, ExecutionException {
66 ModifyConfigInput input = Mockito.mock(ModifyConfigInput.class);
67 AppcProvider appcProviderspy = Mockito.spy(appcProvider);
68 when(appcProviderspy.getTopologyService()).thenReturn(topologyService);
69 when(topologyService.modifyConfig(anyObject(), anyObject())).thenReturn(result);
70 assertTrue(appcProviderspy.modifyConfig(input).isDone());
74 public void testRebuild() throws InterruptedException, ExecutionException {
75 RebuildInput input = Mockito.mock(RebuildInput.class);
76 AppcProvider appcProviderspy = Mockito.spy(appcProvider);
77 when(appcProviderspy.getTopologyService()).thenReturn(topologyService);
78 when(topologyService.rebuild(anyObject(), anyObject())).thenReturn(result);
79 assertTrue(appcProviderspy.rebuild(input).isDone());
83 public void testRestart() throws InterruptedException, ExecutionException {
84 RestartInput input = Mockito.mock(RestartInput.class);
85 AppcProvider appcProviderspy = Mockito.spy(appcProvider);
86 when(appcProviderspy.getTopologyService()).thenReturn(topologyService);
87 when(topologyService.restart(anyObject(), anyObject())).thenReturn(result);
88 assertTrue(appcProviderspy.restart(input).isDone());
92 public void testMigrate() throws InterruptedException, ExecutionException {
93 MigrateInput input = Mockito.mock(MigrateInput.class);
94 AppcProvider appcProviderspy = Mockito.spy(appcProvider);
95 when(appcProviderspy.getTopologyService()).thenReturn(topologyService);
96 when(topologyService.migrate(anyObject(), anyObject())).thenReturn(result);
97 assertTrue(appcProviderspy.migrate(input).isDone());
101 public void testSnapshot() throws InterruptedException, ExecutionException {
102 SnapshotInput input = Mockito.mock(SnapshotInput.class);
103 AppcProvider appcProviderspy = Mockito.spy(appcProvider);
104 when(appcProviderspy.getTopologyService()).thenReturn(topologyService);
105 when(topologyService.snapshot(anyObject(), anyObject())).thenReturn(result);
106 assertTrue(appcProviderspy.snapshot(input).isDone());
110 public void testVmstatuscheck() throws InterruptedException, ExecutionException {
111 VmstatuscheckInput input = Mockito.mock(VmstatuscheckInput.class);
112 AppcProvider appcProviderspy = Mockito.spy(appcProvider);
113 when(appcProviderspy.getTopologyService()).thenReturn(topologyService);
114 when(topologyService.vmstatuscheck(anyObject(), anyObject())).thenReturn(result);
115 assertTrue(appcProviderspy.vmstatuscheck(input).isDone());
119 public void testClose() throws Exception {
120 appcProvider.close();
121 ExecutorService executor = (ExecutorService) Whitebox.getInternalState(appcProvider, "executor");
122 assertTrue(executor.isShutdown());