Update license header in misc appc files
[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  * 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  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.provider.topology;
25
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.Mock;
30 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.UUID;
31 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.common.request.header.CommonRequestHeader;
32 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.config.payload.ConfigPayload;
33 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.vnf.resource.VnfResource;
34 import org.onap.appc.configuration.Configuration;
35 import org.onap.appc.configuration.ConfigurationFactory;
36 import org.onap.appc.provider.AppcProvider;
37 import org.powermock.api.mockito.PowerMockito;
38 import org.powermock.core.classloader.annotations.PrepareForTest;
39 import org.powermock.modules.junit4.PowerMockRunner;
40
41 import static org.mockito.Matchers.any;
42 import static org.mockito.Mockito.doReturn;
43 import static org.mockito.Mockito.mock;
44 import static org.mockito.internal.verification.VerificationModeFactory.times;
45 import static org.powermock.api.mockito.PowerMockito.mockStatic;
46 import static org.powermock.api.mockito.PowerMockito.spy;
47 import static org.powermock.api.mockito.PowerMockito.verifyPrivate;
48 import static org.powermock.api.mockito.PowerMockito.when;
49
50 @RunWith(PowerMockRunner.class)
51 @PrepareForTest({TopologyService.class, ConfigurationFactory.class})
52 public class TopologyServiceTest {
53     @Mock
54     private AppcProvider appcProvider;
55     private TopologyService topologyService;
56
57     @Before
58     public void setUp() throws Exception {
59         mockStatic(ConfigurationFactory.class);
60         Configuration configuration = mock(Configuration.class);
61         when(ConfigurationFactory.getConfiguration()).thenReturn(configuration);
62         doReturn("NODE_NAME").when(configuration).getProperty("appc.provider.vfodl.url");
63
64         topologyService = spy(new TopologyService(appcProvider));
65     }
66
67     @Test
68     public void modifyConfig() throws Exception {
69         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
70         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
71         ConfigPayload configPayload = mock(ConfigPayload.class);
72         doReturn("url").when(configPayload).getConfigUrl();
73         doReturn("configJson").when(configPayload).getConfigJson();
74         PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
75
76         topologyService.modifyConfig(commonRequestHeader, configPayload);
77
78         verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
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         PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
90
91         topologyService.migrate(commonRequestHeader, vnfResource);
92
93         verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
94     }
95
96     @Test
97     public void restart() throws Exception {
98         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
99         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
100         VnfResource vnfResource = mock(VnfResource.class);
101         UUID uuid = mock(UUID.class);
102         doReturn("uuid-value").when(uuid).getValue();
103         doReturn(uuid).when(vnfResource).getVmId();
104         PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
105
106         topologyService.restart(commonRequestHeader, vnfResource);
107
108         verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
109     }
110
111     @Test
112     public void rebuild() throws Exception {
113         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
114         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
115         VnfResource vnfResource = mock(VnfResource.class);
116         UUID uuid = mock(UUID.class);
117         doReturn("uuid-value").when(uuid).getValue();
118         doReturn(uuid).when(vnfResource).getVmId();
119         PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
120
121         topologyService.rebuild(commonRequestHeader, vnfResource);
122
123         verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
124     }
125
126     @Test
127     public void snapshot() throws Exception {
128         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
129         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
130         VnfResource vnfResource = mock(VnfResource.class);
131         UUID uuid = mock(UUID.class);
132         doReturn("uuid-value").when(uuid).getValue();
133         doReturn(uuid).when(vnfResource).getVmId();
134         PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
135
136         topologyService.snapshot(commonRequestHeader, vnfResource);
137
138         verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
139     }
140
141     @Test
142     public void vmstatuscheck() throws Exception {
143         CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
144         doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
145         VnfResource vnfResource = mock(VnfResource.class);
146         UUID uuid = mock(UUID.class);
147         doReturn("uuid-value").when(uuid).getValue();
148         doReturn(uuid).when(vnfResource).getVmId();
149         PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
150
151         topologyService.vmstatuscheck(commonRequestHeader, vnfResource);
152
153         verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
154     }
155
156 }