3 * package org.onap.so.adapters.cnf.service;
5 * import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks;
6 * import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import
7 * org.onap.so.adapters.cnf.model.BpmnInstanceRequest; import org.onap.so.adapters.cnf.model.InstanceMiniResponseList;
8 * import org.onap.so.adapters.cnf.model.InstanceResponse; import org.onap.so.adapters.cnf.model.InstanceStatusResponse;
9 * import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import
10 * org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import
11 * org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.RestTemplate;
13 * @RunWith(SpringRunner.class) public class CnfAdapterServiceTest {
15 * @InjectMocks CnfAdapterService cnfAdapterService;
17 * @Mock ResponseEntity<InstanceResponse> createInstanceResponse;
19 * @Mock ResponseEntity<InstanceMiniResponseList> instacneMiniResponseList;
21 * @Mock ResponseEntity<InstanceStatusResponse> instanceStatusResponse;
23 * @Mock private RestTemplate restTemplate;
25 * @Test public void healthCheckTest() throws Exception {
27 * ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK);
29 * Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class),
30 * Matchers.<HttpEntity<?>>any(), Matchers.<Class<String>>any())).thenReturn(response);
32 * ResponseEntity<String> actualResponse = cnfAdapterService.healthCheck(); Assert.assertNotNull(actualResponse);
33 * Assert.assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
37 * @Test public void createInstanceTest() throws Exception {
39 * ResponseEntity<InstanceResponse> response = new ResponseEntity<InstanceResponse>(HttpStatus.OK); BpmnInstanceRequest
40 * bpmnInstanceRequest = new BpmnInstanceRequest(); bpmnInstanceRequest.setK8sRBProfileName("k8sRBProfileName");
41 * Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class),
42 * Matchers.<HttpEntity<?>>any(), Matchers.<Class<InstanceResponse>>any())).thenReturn(response);
44 * ResponseEntity<InstanceResponse> actualResponse = cnfAdapterService.createInstance(bpmnInstanceRequest);
45 * Assert.assertNotNull(response); Assert.assertEquals(actualResponse.getStatusCode(), response.getStatusCode());
49 * @Test public void createInstanceExceptionTest() throws Exception {
51 * BpmnInstanceRequest bpmnInstanceRequest = new BpmnInstanceRequest(); ResponseEntity<InstanceResponse> response =
52 * cnfAdapterService.createInstance(bpmnInstanceRequest); Assert.assertNull(response);
56 * @Test public void getInstanceByInstanceIdTest() throws Exception {
58 * ResponseEntity<InstanceResponse> response = new ResponseEntity<InstanceResponse>(HttpStatus.OK); String instanceId =
59 * "123"; Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class),
60 * Matchers.<HttpEntity<?>>any(), Matchers.<Class<InstanceResponse>>any())).thenReturn(response);
62 * ResponseEntity<InstanceResponse> actualResponse = cnfAdapterService.getInstanceByInstanceId(instanceId);
63 * Assert.assertNotNull(actualResponse); Assert.assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
67 * @Test public void getInstanceStatusByInstanceIdTest() throws Exception {
69 * ResponseEntity<InstanceStatusResponse> response = new ResponseEntity<InstanceStatusResponse>(HttpStatus.OK); String
70 * instanceId = "123"; Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class),
71 * Matchers.<HttpEntity<?>>any(), Matchers.<Class<InstanceStatusResponse>>any())).thenReturn(response);
73 * ResponseEntity<InstanceStatusResponse> actualResponse = cnfAdapterService .getInstanceStatusByInstanceId(instanceId);
74 * Assert.assertNotNull(actualResponse); Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
78 * @Test public void getInstanceByRBNameOrRBVersionOrProfileNameTest() throws Exception {
80 * ResponseEntity<InstanceMiniResponseList> response = new ResponseEntity<InstanceMiniResponseList>(HttpStatus.OK);
81 * String rbName = "xyz"; String rbVersion = "v1"; String profileName = "p1";
83 * Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class),
84 * Matchers.<HttpEntity<?>>any(), Matchers.<Class<InstanceMiniResponseList>>any())).thenReturn(response);
86 * ResponseEntity<InstanceMiniResponseList> actualResponse = cnfAdapterService
87 * .getInstanceByRBNameOrRBVersionOrProfileName(rbName, rbVersion, profileName); Assert.assertNotNull(actualResponse);
88 * Assert.assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
92 * @Test public void deleteInstanceByInstanceIdTest() throws Exception {
94 * ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK); String instanceId = "123";
95 * Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class),
96 * Matchers.<HttpEntity<?>>any(), Matchers.<Class<String>>any())).thenReturn(response);
98 * ResponseEntity<String> actualResponse = cnfAdapterService.deleteInstanceByInstanceId(instanceId);
99 * Assert.assertNotNull(response); Assert.assertEquals(HttpStatus.OK, response.getStatusCode());