Further changes for cnf-adpter in bpmn infra
[so.git] / adapters / mso-cnf-adapter / src / test / java / org / onap / so / adapters / cnf / rest / CnfAdapterRestTest.java
1 // TODO
2 /*
3  * 
4  * ============LICENSE_START==================================================== === ONAP - SO
5  * ============================================================================= === Copyright (C) 2020 Huawei
6  * Technologies Co., Ltd. All rights reserved.
7  * ============================================================================= === Licensed under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy
9  * 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 distributed under the License is distributed on
14  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
15  * specific language governing permissions and limitations under the License.
16  * ============LICENSE_END====================================================== ===
17  * 
18  * 
19  * package org.onap.so.adapters.cnf.rest;
20  * 
21  * 
22  * import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import
23  * org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import
24  * org.mockito.Mock; import org.mockito.Mockito; import org.onap.so.adapters.cnf.model.BpmnInstanceRequest; import
25  * org.onap.so.adapters.cnf.model.InstanceMiniResponse; import org.onap.so.adapters.cnf.model.InstanceMiniResponseList;
26  * import org.onap.so.adapters.cnf.model.InstanceResponse; import org.onap.so.adapters.cnf.model.InstanceStatusResponse;
27  * import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest; import org.onap.so.adapters.cnf.model.Resource;
28  * import org.onap.so.adapters.cnf.service.CnfAdapterService; import org.springframework.http.HttpStatus; import
29  * org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner;
30  * 
31  * 
32  * @RunWith(SpringRunner.class) public class CnfAdapterRestTest {
33  * 
34  * @InjectMocks CnfAdapterRest cnfAdapterRest;
35  * 
36  * @Mock CnfAdapterService cnfAdapterService;
37  * 
38  * @Mock ResponseEntity<InstanceMiniResponseList> instacneMiniResponseList;
39  * 
40  * @Mock ResponseEntity<InstanceStatusResponse> instanceStatusResponse;
41  * 
42  * @Test public void healthCheckTest() throws Exception {
43  * 
44  * ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK); CnfAdapterService cnfAdapterService =
45  * Mockito.mock(CnfAdapterService.class); Mockito.when(cnfAdapterService.healthCheck()).thenReturn(response);
46  * cnfAdapterRest.healthCheck(); Assert.assertNotNull(response); Assert.assertEquals(HttpStatus.OK,
47  * response.getStatusCode()); }
48  * 
49  * @Test public void createInstanceTest() throws Exception {
50  * 
51  * Map<String, String> labels = new HashMap<String, String>(); labels.put("custom-label-1", "label1"); Map<String,
52  * String> overrideValues = new HashMap<String, String>(); labels.put("image.tag", "latest");
53  * labels.put("dcae_collector_ip", "1.2.3.4"); BpmnInstanceRequest bpmnInstanceRequest = new BpmnInstanceRequest();
54  * bpmnInstanceRequest.setCloudRegionId("v1"); bpmnInstanceRequest.setLabels(labels);
55  * bpmnInstanceRequest.setModelInvariantId("krd"); bpmnInstanceRequest.setModelVersionId("p1");
56  * bpmnInstanceRequest.setOverrideValues(overrideValues); bpmnInstanceRequest.setVfModuleUUID("20200824");
57  * List<Resource> resourceList = new ArrayList<Resource>(); InstanceResponse instanceResponse = new InstanceResponse();
58  * instanceResponse.setId("123"); instanceResponse.setNamespace("testNamespace"); instanceResponse.setRequest(new
59  * MulticloudInstanceRequest()); instanceResponse.setResources(resourceList); String createInstanceResponse = new
60  * ResponseEntity<InstanceResponse>(instanceResponse, HttpStatus.CREATED); CnfAdapterService cnfAdapterService =
61  * Mockito.mock(CnfAdapterService.class); Mockito.when(cnfAdapterService.createInstance(bpmnInstanceRequest)).
62  * thenReturn(createInstanceResponse); cnfAdapterRest.createInstance(bpmnInstanceRequest);
63  * Assert.assertNotNull(createInstanceResponse); Assert.assertEquals(HttpStatus.CREATED,
64  * createInstanceResponse.getStatusCode()); }
65  * 
66  * @Test public void getInstanceByInstanceIdTest() throws Exception {
67  * 
68  * String instanceId = "123"; String createInstanceResponse = new ResponseEntity<InstanceResponse>(HttpStatus.OK);
69  * CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class);
70  * Mockito.when(cnfAdapterService.getInstanceByInstanceId(instanceId)). thenReturn(createInstanceResponse);
71  * cnfAdapterRest.getInstanceByInstanceId(instanceId); Assert.assertNotNull(createInstanceResponse);
72  * Assert.assertEquals(HttpStatus.OK, createInstanceResponse.getStatusCode()); }
73  * 
74  * @Test public void deleteInstanceByInstanceIdTest() throws Exception {
75  * 
76  * String instanceId = "123"; ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK);
77  * CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class);
78  * Mockito.when(cnfAdapterService.deleteInstanceByInstanceId(instanceId)). thenReturn(response);
79  * cnfAdapterRest.deleteInstanceByInstanceId(instanceId); Assert.assertNotNull(response);
80  * Assert.assertEquals(HttpStatus.OK, response.getStatusCode()); }
81  * 
82  * @Test public void getInstanceStatusByInstanceIdTest() throws Exception {
83  * 
84  * String instanceId = "123"; instanceStatusResponse = new ResponseEntity<InstanceStatusResponse>(HttpStatus.OK);
85  * CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class);
86  * Mockito.when(cnfAdapterService.getInstanceStatusByInstanceId(instanceId)). thenReturn(instanceStatusResponse);
87  * cnfAdapterRest.getInstanceStatusByInstanceId(instanceId); Assert.assertNotNull(instanceStatusResponse);
88  * Assert.assertEquals(HttpStatus.OK, instanceStatusResponse.getStatusCode()); }
89  * 
90  * @Test public void getInstanceByRBNameOrRBVersionOrProfileNameTest() throws Exception {
91  * 
92  * String rbName = "xyz"; String rbVersion = "v1"; String profileName = "p1"; InstanceMiniResponse instanceMiniResponse
93  * = new InstanceMiniResponse(HttpStatus.OK.toString()); List<InstanceMiniResponse> instancList = new
94  * ArrayList<InstanceMiniResponse>(); instancList.add(instanceMiniResponse); InstanceMiniResponseList
95  * instanceMiniRespList = new InstanceMiniResponseList(HttpStatus.OK.toString());
96  * instanceMiniRespList.setInstancList(instancList); instanceMiniRespList.setErrorMsg(HttpStatus.OK.toString());
97  * ResponseEntity<InstanceMiniResponseList> respone = new ResponseEntity<InstanceMiniResponseList>(instanceMiniRespList,
98  * HttpStatus.OK); CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class);
99  * Mockito.when(cnfAdapterService.getInstanceByRBNameOrRBVersionOrProfileName( rbName, rbVersion, profileName))
100  * .thenReturn(instacneMiniResponseList); cnfAdapterRest.getInstanceByRBNameOrRBVersionOrProfileName(rbName, rbVersion,
101  * profileName); Assert.assertNotNull(instacneMiniResponseList); Assert.assertEquals(HttpStatus.OK.toString(),
102  * instanceMiniRespList.getErrorMsg()); }
103  * 
104  * }
105  * 
106  */