9affec0756cb4cc343be4638cfd824c9e0c7b867
[appc.git] / appc-provider / appc-provider-bundle / src / test / java / org / onap / appc / provider / TestAppcProvider.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.appc.provider;
23
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;
44
45 public class TestAppcProvider {
46
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;
54
55     @Before
56     public void setUp() {
57
58         topologyService = Mockito.mock(TopologyService.class);
59         result = Mockito.mock(RpcResult.class);
60         appcProvider =
61                 new AppcProvider(dataBroker2, notificationProviderService, rpcProviderRegistry, appcProviderClient);
62     }
63
64     @Test
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());
71     }
72
73     @Test
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());
80     }
81
82     @Test
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());
89     }
90
91     @Test
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());
98     }
99
100     @Test
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());
107     }
108
109     @Test
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());
116     }
117
118     @Test
119     public void testClose() throws Exception {
120         appcProvider.close();
121         ExecutorService executor = (ExecutorService) Whitebox.getInternalState(appcProvider, "executor");
122         assertTrue(executor.isShutdown());
123     }
124 }