bdad34773648906743699bfbc8a8926d8956d5c8
[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.MulticloudConfiguration;
28 import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
29 import org.springframework.http.ResponseEntity;
30 import org.springframework.test.context.junit4.SpringRunner;
31 import org.springframework.web.client.RestTemplate;
32
33 import java.util.HashMap;
34 import java.util.Map;
35
36 @RunWith(SpringRunner.class)
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     private MulticloudConfiguration multicloudConfiguration;
47
48     @Mock
49     ResponseEntity<String> instanceResponse;
50
51     @Test
52     public void healthCheckTest() throws Exception {
53         try {
54             cnfAdapterService.healthCheck();
55         }
56         catch (Exception exp) {
57           assert(true);
58         }
59
60     }
61     @Test
62     public void createInstanceTest() throws Exception {
63         Map<String, String> labels = new HashMap<String, String>();
64         labels.put("custom-label-1", "label1");
65         Map<String, String> overrideValues = new HashMap<String, String>();
66         overrideValues.put("a", "b");
67         labels.put("image.tag", "latest");
68         labels.put("dcae_collector_ip", "1.2.3.4");
69         BpmnInstanceRequest bpmnInstanceRequest = new BpmnInstanceRequest();
70         bpmnInstanceRequest.setCloudRegionId("v1");
71         bpmnInstanceRequest.setLabels(labels);
72         bpmnInstanceRequest.setModelInvariantId("krd");
73         bpmnInstanceRequest.setModelVersionId("p1");
74         bpmnInstanceRequest.setOverrideValues(overrideValues);
75         bpmnInstanceRequest.setVfModuleUUID("20200824");
76         bpmnInstanceRequest.setK8sRBProfileName("K8sRBProfileName is required");
77         try {
78             cnfAdapterService.createInstance(bpmnInstanceRequest);
79         }
80         catch (Exception exp) {
81         assert(true);
82         }
83
84     }
85
86     @Test
87     public void getInstanceByInstanceIdTest() throws Exception {
88         String instanceId = "ins";
89         try {
90             cnfAdapterService.getInstanceByInstanceId(instanceId);
91         }
92         catch (Exception exp) {
93          assert(true);
94         }
95
96     }
97
98     @Test
99     public void getInstanceStatusByInstanceIdTest() throws Exception {
100         String instanceId = "ins";
101         try {
102             cnfAdapterService.getInstanceStatusByInstanceId(instanceId);
103         }
104         catch (Exception exp) {
105          assert(true);
106         }
107
108     }
109
110     @Test
111     public void getInstanceByRBNameOrRBVersionOrProfileNameTest() throws Exception {
112         String rbName = "rb";
113         String rbVersion = "rv1";
114         String profileName = "p1";
115         try {
116             cnfAdapterService.getInstanceByRBNameOrRBVersionOrProfileName(rbName, rbVersion, profileName);
117         }
118         catch (Exception exp) {
119          assert(true);
120         }
121
122     }
123
124     @Test
125     public void deleteInstanceByInstanceIdTest() throws Exception {
126         String instanceId = "ins";
127         try {
128             cnfAdapterService.deleteInstanceByInstanceId(instanceId);
129         }
130         catch (Exception exp) {
131          assert(true);
132         }
133
134     }
135 }
136
137