1 package org.onap.so.adapters.cnf.service;
3 import javax.ws.rs.InternalServerErrorException;
4 import org.junit.Assert;
6 import org.junit.runner.RunWith;
7 import org.mockito.InjectMocks;
8 import org.mockito.Matchers;
9 import org.mockito.Mock;
10 import org.mockito.Mockito;
11 import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
12 import org.onap.so.adapters.cnf.model.InstanceMiniResponseList;
13 import org.onap.so.adapters.cnf.model.InstanceResponse;
14 import org.onap.so.adapters.cnf.model.InstanceStatusResponse;
15 import org.springframework.http.HttpEntity;
16 import org.springframework.http.HttpMethod;
17 import org.springframework.http.HttpStatus;
18 import org.springframework.http.ResponseEntity;
19 import org.springframework.test.context.junit4.SpringRunner;
20 import org.springframework.web.client.RestTemplate;
22 @RunWith(SpringRunner.class)
23 public class CnfAdapterServiceTest {
26 CnfAdapterService cnfAdapterService;
29 ResponseEntity<InstanceResponse> createInstanceResponse;
32 ResponseEntity<InstanceMiniResponseList> instacneMiniResponseList;
35 ResponseEntity<InstanceStatusResponse> instanceStatusResponse;
38 private RestTemplate restTemplate;
41 public void healthCheckTest() throws Exception {
43 ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK);
45 Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class),
46 Matchers.<HttpEntity<?>>any(), Matchers.<Class<String>>any())).thenReturn(response);
48 ResponseEntity<String> actualResponse = cnfAdapterService.healthCheck();
49 Assert.assertNotNull(actualResponse);
50 Assert.assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
55 public void createInstanceTest() throws Exception {
57 ResponseEntity<InstanceResponse> response = new ResponseEntity<InstanceResponse>(HttpStatus.OK);
58 BpmnInstanceRequest bpmnInstanceRequest = new BpmnInstanceRequest();
59 bpmnInstanceRequest.setK8sRBProfileName("k8sRBProfileName");
60 Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class),
61 Matchers.<HttpEntity<?>>any(), Matchers.<Class<InstanceResponse>>any())).thenReturn(response);
63 ResponseEntity<InstanceResponse> actualResponse = cnfAdapterService.createInstance(bpmnInstanceRequest);
64 Assert.assertNotNull(response);
65 Assert.assertEquals(actualResponse.getStatusCode(), response.getStatusCode());
70 public void createInstanceExceptionTest() throws Exception {
72 BpmnInstanceRequest bpmnInstanceRequest = new BpmnInstanceRequest();
73 ResponseEntity<InstanceResponse> response = cnfAdapterService.createInstance(bpmnInstanceRequest);
74 Assert.assertNull(response);
79 public void getInstanceByInstanceIdTest() throws Exception {
81 ResponseEntity<InstanceResponse> response = new ResponseEntity<InstanceResponse>(HttpStatus.OK);
82 String instanceId = "123";
83 Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class),
84 Matchers.<HttpEntity<?>>any(), Matchers.<Class<InstanceResponse>>any())).thenReturn(response);
86 ResponseEntity<InstanceResponse> actualResponse = cnfAdapterService.getInstanceByInstanceId(instanceId);
87 Assert.assertNotNull(actualResponse);
88 Assert.assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
93 public void getInstanceStatusByInstanceIdTest() throws Exception {
95 ResponseEntity<InstanceStatusResponse> response = new ResponseEntity<InstanceStatusResponse>(HttpStatus.OK);
96 String instanceId = "123";
97 Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class),
98 Matchers.<HttpEntity<?>>any(), Matchers.<Class<InstanceStatusResponse>>any())).thenReturn(response);
100 ResponseEntity<InstanceStatusResponse> actualResponse =
101 cnfAdapterService.getInstanceStatusByInstanceId(instanceId);
102 Assert.assertNotNull(actualResponse);
103 Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
108 public void getInstanceByRBNameOrRBVersionOrProfileNameTest() throws Exception {
110 ResponseEntity<InstanceMiniResponseList> response = new ResponseEntity<InstanceMiniResponseList>(HttpStatus.OK);
111 String rbName = "xyz";
112 String rbVersion = "v1";
113 String profileName = "p1";
115 Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class),
116 Matchers.<HttpEntity<?>>any(), Matchers.<Class<InstanceMiniResponseList>>any())).thenReturn(response);
118 ResponseEntity<InstanceMiniResponseList> actualResponse =
119 cnfAdapterService.getInstanceByRBNameOrRBVersionOrProfileName(rbName, rbVersion, profileName);
120 Assert.assertNotNull(actualResponse);
121 Assert.assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
126 public void deleteInstanceByInstanceIdTest() throws Exception {
128 ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK);
129 String instanceId = "123";
130 Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class),
131 Matchers.<HttpEntity<?>>any(), Matchers.<Class<String>>any())).thenReturn(response);
133 ResponseEntity<String> actualResponse = cnfAdapterService.deleteInstanceByInstanceId(instanceId);
134 Assert.assertNotNull(response);
135 Assert.assertEquals(HttpStatus.OK, response.getStatusCode());