First part of onap rename
[appc.git] / appc-provider / appc-provider-bundle / src / test / java / org / openecomp / appc / provider / topology / TopologyServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.provider.topology;
26
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Mock;
31 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.UUID;
32 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.common.request.header.CommonRequestHeader;
33 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.config.payload.ConfigPayload;
34 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.vnf.resource.VnfResource;
35 import org.onap.appc.configuration.Configuration;
36 import org.onap.appc.configuration.ConfigurationFactory;
37 import org.onap.appc.provider.AppcProvider;
38 import org.powermock.api.mockito.PowerMockito;
39 import org.powermock.core.classloader.annotations.PrepareForTest;
40 import org.powermock.modules.junit4.PowerMockRunner;
41
42 import static org.mockito.Matchers.any;
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.verifyPrivate;
49 import static org.powermock.api.mockito.PowerMockito.when;
50
51 @RunWith(PowerMockRunner.class)
52 @PrepareForTest({TopologyService.class, 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         PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
76
77         topologyService.modifyConfig(commonRequestHeader, configPayload);
78
79         verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
80     }
81
82     @Test
83     public void migrate() throws Exception {
84         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
85         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
86         VnfResource vnfResource = mock(VnfResource.class);
87         UUID uuid = mock(UUID.class);
88         doReturn("uuid-value").when(uuid).getValue();
89         doReturn(uuid).when(vnfResource).getVmId();
90         PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
91
92         topologyService.migrate(commonRequestHeader, vnfResource);
93
94         verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
95     }
96
97     @Test
98     public void restart() throws Exception {
99         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
100         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
101         VnfResource vnfResource = mock(VnfResource.class);
102         UUID uuid = mock(UUID.class);
103         doReturn("uuid-value").when(uuid).getValue();
104         doReturn(uuid).when(vnfResource).getVmId();
105         PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
106
107         topologyService.restart(commonRequestHeader, vnfResource);
108
109         verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
110     }
111
112     @Test
113     public void rebuild() throws Exception {
114         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
115         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
116         VnfResource vnfResource = mock(VnfResource.class);
117         UUID uuid = mock(UUID.class);
118         doReturn("uuid-value").when(uuid).getValue();
119         doReturn(uuid).when(vnfResource).getVmId();
120         PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
121
122         topologyService.rebuild(commonRequestHeader, vnfResource);
123
124         verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
125     }
126
127     @Test
128     public void snapshot() throws Exception {
129         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
130         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
131         VnfResource vnfResource = mock(VnfResource.class);
132         UUID uuid = mock(UUID.class);
133         doReturn("uuid-value").when(uuid).getValue();
134         doReturn(uuid).when(vnfResource).getVmId();
135         PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
136
137         topologyService.snapshot(commonRequestHeader, vnfResource);
138
139         verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
140     }
141
142     @Test
143     public void vmstatuscheck() throws Exception {
144         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
145         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
146         VnfResource vnfResource = mock(VnfResource.class);
147         UUID uuid = mock(UUID.class);
148         doReturn("uuid-value").when(uuid).getValue();
149         doReturn(uuid).when(vnfResource).getVmId();
150         PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
151
152         topologyService.vmstatuscheck(commonRequestHeader, vnfResource);
153
154         verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
155     }
156
157 }