aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-02-18 13:05:06 +0000
committerGerrit Code Review <gerrit@onap.org>2019-02-18 13:05:06 +0000
commit36baada47134d2e6915baad5627d14d26e4c35ef (patch)
treef9175c70a9be28ddfc589dcfabc66ab00b9554b4 /vid-app-common/src/test/java/org
parent2cfbe3407713a48fb81783ae2a560c5fe6face5e (diff)
parente3f8c6d9b3ff4b9c9b82c795a791ea9b5a014c98 (diff)
Merge "Introduced mocked SO workflows in VID FE"
Diffstat (limited to 'vid-app-common/src/test/java/org')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java60
1 files changed, 60 insertions, 0 deletions
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<SOWorkflows> 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<SOWorkflows> msoResponseStub = new MsoResponseWrapper2<>(response);
+ Mockito.when(client.getWorkflows("test")).thenReturn(msoResponseStub);
+ // when
+ List<SOWorkflow> 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<SOWorkflows> msoResponseStub = new MsoResponseWrapper2<>(response);
+ Mockito.when(client.getWorkflows("test")).thenReturn(msoResponseStub);
+ // when
+ extWorkflowsService.getWorkflows("test");
+ // then throw exception
+ }
+
+}