130f6f076803c374772f470be3e6d0285c350a99
[so/adapters/so-cnf-adapter.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
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  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.cnf.service;
22
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.InjectMocks;
26 import org.mockito.Mock;
27 import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
28 import org.springframework.http.ResponseEntity;
29 import org.springframework.test.context.junit4.SpringRunner;
30 import org.springframework.web.client.RestTemplate;
31
32 import java.util.HashMap;
33 import java.util.Map;
34
35 @RunWith(SpringRunner.class)
36
37 public class CnfAdapterServiceTest {
38     private static final String INSTANCE_CREATE_PATH = "/v1/instance";
39     @Mock
40     private RestTemplate restTemplate;
41
42     @InjectMocks
43     CnfAdapterService cnfAdapterService;
44
45     @Mock
46     ResponseEntity<String> instanceResponse;
47
48     @Test
49     public void healthCheckTest() throws Exception {
50         try {
51             cnfAdapterService.healthCheck();
52         }
53         catch (Exception exp) {
54           assert(true);
55         }
56
57     }
58     @Test
59     public void createInstanceTest() throws Exception {
60         Map<String, String> labels = new HashMap<String, String>();
61         labels.put("custom-label-1", "label1");
62         Map<String, String> overrideValues = new HashMap<String, String>();
63         overrideValues.put("a", "b");
64         labels.put("image.tag", "latest");
65         labels.put("dcae_collector_ip", "1.2.3.4");
66         BpmnInstanceRequest bpmnInstanceRequest = new BpmnInstanceRequest();
67         bpmnInstanceRequest.setCloudRegionId("v1");
68         bpmnInstanceRequest.setLabels(labels);
69         bpmnInstanceRequest.setModelInvariantId("krd");
70         bpmnInstanceRequest.setModelVersionId("p1");
71         bpmnInstanceRequest.setOverrideValues(overrideValues);
72         bpmnInstanceRequest.setVfModuleUUID("20200824");
73         bpmnInstanceRequest.setK8sRBProfileName("K8sRBProfileName is required");
74         try {
75             cnfAdapterService.createInstance(bpmnInstanceRequest);
76         }
77         catch (Exception exp) {
78         assert(true);
79         }
80
81     }
82
83     @Test
84     public void getInstanceByInstanceIdTest() throws Exception {
85         String instanceId = "ins";
86         try {
87             cnfAdapterService.getInstanceByInstanceId(instanceId);
88         }
89         catch (Exception exp) {
90          assert(true);
91         }
92
93     }
94
95     @Test
96     public void getInstanceStatusByInstanceIdTest() throws Exception {
97         String instanceId = "ins";
98         try {
99             cnfAdapterService.getInstanceStatusByInstanceId(instanceId);
100         }
101         catch (Exception exp) {
102          assert(true);
103         }
104
105     }
106
107     @Test
108     public void getInstanceByRBNameOrRBVersionOrProfileNameTest() throws Exception {
109         String rbName = "rb";
110         String rbVersion = "rv1";
111         String profileName = "p1";
112         try {
113             cnfAdapterService.getInstanceByRBNameOrRBVersionOrProfileName(rbName, rbVersion, profileName);
114         }
115         catch (Exception exp) {
116          assert(true);
117         }
118
119     }
120
121     @Test
122     public void deleteInstanceByInstanceIdTest() throws Exception {
123         String instanceId = "ins";
124         try {
125             cnfAdapterService.deleteInstanceByInstanceId(instanceId);
126         }
127         catch (Exception exp) {
128          assert(true);
129         }
130
131     }
132 }
133
134