From e3f8c6d9b3ff4b9c9b82c795a791ea9b5a014c98 Mon Sep 17 00:00:00 2001 From: golabek Date: Mon, 11 Feb 2019 16:36:49 +0100 Subject: Introduced mocked SO workflows in VID FE Mocked SO workflows joined with list of workflows from VIDs DB. (Contains: Mocked BE service to return workflow list) Change-Id: I10336238cfeb8819e0a2b3e88cd86c338cab86fa Issue-ID: VID-399 Signed-off-by: Tomasz Golabek --- .../vid/services/ExtWorkflowServiceImplTest.java | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java (limited to 'vid-app-common/src/test/java') diff --git a/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java new file mode 100644 index 000000000..1509637bb --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java @@ -0,0 +1,60 @@ +package org.onap.vid.services; + +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; + +import io.joshworks.restclient.http.HttpResponse; +import java.util.Collections; +import java.util.List; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.vid.model.SOWorkflow; +import org.onap.vid.model.SOWorkflows; +import org.onap.vid.mso.MsoResponseWrapper2; +import org.onap.vid.mso.rest.MockedWorkflowsRestClient; +import org.onap.vid.services.ExtWorkflowsServiceImpl.BadResponseFromMso; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class ExtWorkflowServiceImplTest { + + @Mock + private MockedWorkflowsRestClient client; + @Mock + private HttpResponse response; + + @BeforeMethod + public void init(){ + MockitoAnnotations.initMocks(this); + } + + @Test + public void shouldReturnWorkflowsOnValidResponse(){ + // given + ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client); + Mockito.when(response.getStatus()).thenReturn(200); + Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz")))); + MsoResponseWrapper2 msoResponseStub = new MsoResponseWrapper2<>(response); + Mockito.when(client.getWorkflows("test")).thenReturn(msoResponseStub); + // when + List workflows = extWorkflowsService.getWorkflows("test"); + // then + Mockito.verify(client).getWorkflows("test"); + assertThat(workflows.get(0).getName(), is("xyz")); + } + + @Test(expectedExceptions = BadResponseFromMso.class) + public void shouldThrowBadResponseOnInvalidResponse(){ + // given + ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client); + Mockito.when(response.getStatus()).thenReturn(500); + Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz")))); + MsoResponseWrapper2 msoResponseStub = new MsoResponseWrapper2<>(response); + Mockito.when(client.getWorkflows("test")).thenReturn(msoResponseStub); + // when + extWorkflowsService.getWorkflows("test"); + // then throw exception + } + +} -- cgit 1.2.3-korg