Test coverage for appc-provider-topology
[appc.git] / appc-provider / appc-provider-bundle / src / test / java / org / onap / appc / provider / topology / TopologyServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * ================================================================================
9  * Modifications (C) 2019 Ericsson
10  * =============================================================================
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.appc.provider.topology;
27
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.mockito.Mockito;
33 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.UUID;
34 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.common.request.header.CommonRequestHeader;
35 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.config.payload.ConfigPayload;
36 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.vnf.resource.VnfResource;
37 import org.onap.appc.configuration.Configuration;
38 import org.onap.appc.configuration.ConfigurationFactory;
39 import org.onap.appc.provider.AppcProvider;
40 import org.powermock.core.classloader.annotations.PrepareForTest;
41 import org.powermock.modules.junit4.PowerMockRunner;
42
43 import static org.mockito.Mockito.doReturn;
44 import static org.mockito.Mockito.mock;
45 import static org.mockito.internal.verification.VerificationModeFactory.times;
46 import static org.powermock.api.mockito.PowerMockito.mockStatic;
47 import static org.powermock.api.mockito.PowerMockito.spy;
48 import static org.powermock.api.mockito.PowerMockito.when;
49 import java.util.Properties;
50
51 @RunWith(PowerMockRunner.class)
52 @PrepareForTest(ConfigurationFactory.class)
53 public class TopologyServiceTest {
54     @Mock
55     private AppcProvider appcProvider;
56     private TopologyService topologyService;
57
58     @Before
59     public void setUp() throws Exception {
60         mockStatic(ConfigurationFactory.class);
61         Configuration configuration = mock(Configuration.class);
62         when(ConfigurationFactory.getConfiguration()).thenReturn(configuration);
63         doReturn("NODE_NAME").when(configuration).getProperty("appc.provider.vfodl.url");
64
65         topologyService = spy(new TopologyService(appcProvider));
66     }
67
68     @Test
69     public void modifyConfig() throws Exception {
70         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
71         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
72         ConfigPayload configPayload = mock(ConfigPayload.class);
73         doReturn("url").when(configPayload).getConfigUrl();
74         doReturn("configJson").when(configPayload).getConfigJson();
75
76         topologyService.modifyConfig(commonRequestHeader, configPayload);
77
78         Mockito.verify(topologyService, times(1)).callGraph(Mockito.any(Properties.class));
79     }
80
81     @Test
82     public void migrate() throws Exception {
83         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
84         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
85         VnfResource vnfResource = mock(VnfResource.class);
86         UUID uuid = mock(UUID.class);
87         doReturn("uuid-value").when(uuid).getValue();
88         doReturn(uuid).when(vnfResource).getVmId();
89
90         topologyService.migrate(commonRequestHeader, vnfResource);
91
92         Mockito.verify(topologyService, times(1)).callGraph(Mockito.any(Properties.class));
93     }
94
95     @Test
96     public void restart() throws Exception {
97         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
98         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
99         VnfResource vnfResource = mock(VnfResource.class);
100         UUID uuid = mock(UUID.class);
101         doReturn("uuid-value").when(uuid).getValue();
102         doReturn(uuid).when(vnfResource).getVmId();
103
104         topologyService.restart(commonRequestHeader, vnfResource);
105
106         Mockito.verify(topologyService, times(1)).callGraph(Mockito.any(Properties.class));
107     }
108
109     @Test
110     public void rebuild() throws Exception {
111         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
112         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
113         VnfResource vnfResource = mock(VnfResource.class);
114         UUID uuid = mock(UUID.class);
115         doReturn("uuid-value").when(uuid).getValue();
116         doReturn(uuid).when(vnfResource).getVmId();
117
118         topologyService.rebuild(commonRequestHeader, vnfResource);
119
120         Mockito.verify(topologyService, times(1)).callGraph(Mockito.any(Properties.class));
121     }
122
123     @Test
124     public void snapshot() throws Exception {
125         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
126         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
127         VnfResource vnfResource = mock(VnfResource.class);
128         UUID uuid = mock(UUID.class);
129         doReturn("uuid-value").when(uuid).getValue();
130         doReturn(uuid).when(vnfResource).getVmId();
131
132         topologyService.snapshot(commonRequestHeader, vnfResource);
133
134         Mockito.verify(topologyService, times(1)).callGraph(Mockito.any(Properties.class));
135     }
136
137     @Test
138     public void vmstatuscheck() throws Exception {
139         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
140         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
141         VnfResource vnfResource = mock(VnfResource.class);
142         UUID uuid = mock(UUID.class);
143         doReturn("uuid-value").when(uuid).getValue();
144         doReturn(uuid).when(vnfResource).getVmId();
145
146         topologyService.vmstatuscheck(commonRequestHeader, vnfResource);
147
148         Mockito.verify(topologyService, times(1)).callGraph(Mockito.any(Properties.class));
149     }
150
151 }