Introduced mocked SO workflows in VID FE
[vid.git] / vid-app-common / src / test / java / org / onap / vid / services / ExtWorkflowServiceImplTest.java
1 package org.onap.vid.services;
2
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.hamcrest.MatcherAssert.assertThat;
5
6 import io.joshworks.restclient.http.HttpResponse;
7 import java.util.Collections;
8 import java.util.List;
9 import org.mockito.Mock;
10 import org.mockito.Mockito;
11 import org.mockito.MockitoAnnotations;
12 import org.onap.vid.model.SOWorkflow;
13 import org.onap.vid.model.SOWorkflows;
14 import org.onap.vid.mso.MsoResponseWrapper2;
15 import org.onap.vid.mso.rest.MockedWorkflowsRestClient;
16 import org.onap.vid.services.ExtWorkflowsServiceImpl.BadResponseFromMso;
17 import org.testng.annotations.BeforeMethod;
18 import org.testng.annotations.Test;
19
20 public class ExtWorkflowServiceImplTest {
21
22     @Mock
23     private MockedWorkflowsRestClient client;
24     @Mock
25     private HttpResponse<SOWorkflows> response;
26
27     @BeforeMethod
28     public void init(){
29         MockitoAnnotations.initMocks(this);
30     }
31
32     @Test
33     public void shouldReturnWorkflowsOnValidResponse(){
34         // given
35         ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client);
36         Mockito.when(response.getStatus()).thenReturn(200);
37         Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz"))));
38         MsoResponseWrapper2<SOWorkflows> msoResponseStub = new MsoResponseWrapper2<>(response);
39         Mockito.when(client.getWorkflows("test")).thenReturn(msoResponseStub);
40         // when
41         List<SOWorkflow> workflows = extWorkflowsService.getWorkflows("test");
42         // then
43         Mockito.verify(client).getWorkflows("test");
44         assertThat(workflows.get(0).getName(), is("xyz"));
45     }
46
47     @Test(expectedExceptions = BadResponseFromMso.class)
48     public void shouldThrowBadResponseOnInvalidResponse(){
49         // given
50         ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client);
51         Mockito.when(response.getStatus()).thenReturn(500);
52         Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz"))));
53         MsoResponseWrapper2<SOWorkflows> msoResponseStub = new MsoResponseWrapper2<>(response);
54         Mockito.when(client.getWorkflows("test")).thenReturn(msoResponseStub);
55         // when
56         extWorkflowsService.getWorkflows("test");
57         // then throw exception
58     }
59
60 }