From ff08d87f973c3aa4c041a55d42ae73a51593b7ca Mon Sep 17 00:00:00 2001 From: golabek Date: Wed, 27 Feb 2019 16:47:09 +0100 Subject: VnfInPlaceFields and ScaleOut rendered dynamically * hardcoded workflows parameters moved to the internal API. * html changed to dynamically render parameters from the new API. Change-Id: Id2f61dbf88ae65401a8974422ab7c6da07053da2 Issue-ID: VID-398 Signed-off-by: Tomasz Golabek --- .../vid/services/ExtWorkflowServiceImplTest.java | 118 --------------------- .../services/ExternalWorkflowServiceImplTest.java | 116 ++++++++++++++++++++ 2 files changed, 116 insertions(+), 118 deletions(-) delete mode 100644 vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java create mode 100644 vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java (limited to 'vid-app-common/src/test/java/org/onap') 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 deleted file mode 100644 index d8d8552ec..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.vid.services; - - - -import com.google.common.collect.Lists; -import io.joshworks.restclient.http.HttpResponse; -import java.util.Collections; -import java.util.List; - -import org.assertj.core.api.Assertions; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.onap.vid.model.SOWorkflow; -import org.onap.vid.model.SOWorkflowParameterDefinition; -import org.onap.vid.model.SOWorkflowParameterDefinitions; -import org.onap.vid.model.SOWorkflowType; -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; - - @Mock - private HttpResponse parameterDefinitionsHttpResponse; - - - @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"); - Assertions.assertThat(workflows.get(0).getName()).isEqualTo("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 - } - @Test - public void shouldReturnWorkflowParametersOnValidResponse() { - SOWorkflowParameterDefinitions parameters = new SOWorkflowParameterDefinitions(Collections.singletonList(new SOWorkflowParameterDefinition(1L, "sample", "[0-9]", SOWorkflowType.STRING, true))); - ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client); - Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200); - Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(parameters); - MsoResponseWrapper2 msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse); - Mockito.when(client.getWorkflowParameterDefinitions(1L)).thenReturn(msoResponseWrapper); - - - SOWorkflowParameterDefinitions workflowParameterDefinitions = extWorkflowsService.getWorkflowParameterDefinitions(1L); - - Assertions.assertThat(workflowParameterDefinitions).isEqualTo(parameters); - } - - @Test - public void shouldProperlyHandleEmptyParametersList(){ - ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client); - Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200); - Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(new SOWorkflowParameterDefinitions(Lists.newArrayList())); - - MsoResponseWrapper2 msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse); - Mockito.when(client.getWorkflowParameterDefinitions(1L)).thenReturn(msoResponseWrapper); - - - SOWorkflowParameterDefinitions workflowParameterDefinitions = extWorkflowsService.getWorkflowParameterDefinitions(1L); - Assertions.assertThat(workflowParameterDefinitions.getParameterDefinitions()).isEmpty(); - } -} diff --git a/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java new file mode 100644 index 000000000..160ba97a5 --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.vid.services; + + + +import com.google.common.collect.Lists; +import io.joshworks.restclient.http.HttpResponse; +import java.util.Collections; +import java.util.List; + +import org.assertj.core.api.Assertions; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.vid.model.SOWorkflow; +import org.onap.vid.model.SOWorkflowParameterDefinition; +import org.onap.vid.model.SOWorkflowParameterDefinitions; +import org.onap.vid.model.SOWorkflowType; +import org.onap.vid.model.SOWorkflows; +import org.onap.vid.mso.MsoResponseWrapper2; +import org.onap.vid.mso.rest.MockedWorkflowsRestClient; +import org.onap.vid.services.ExternalWorkflowsServiceImpl.BadResponseFromMso; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class ExternalWorkflowServiceImplTest { + + @Mock + private MockedWorkflowsRestClient client; + @Mock + private HttpResponse response; + + @Mock + private HttpResponse parameterDefinitionsHttpResponse; + + + @BeforeMethod + public void init(){ + MockitoAnnotations.initMocks(this); + } + + @Test + public void shouldReturnWorkflowsOnValidResponse(){ + // given + ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(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"); + Assertions.assertThat(workflows.get(0).getName()).isEqualTo("xyz"); + } + + @Test(expectedExceptions = BadResponseFromMso.class) + public void shouldThrowBadResponseOnInvalidResponse(){ + // given + ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(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 + } + @Test + public void shouldReturnWorkflowParametersOnValidResponse() { + SOWorkflowParameterDefinitions parameters = new SOWorkflowParameterDefinitions(Collections.singletonList(new SOWorkflowParameterDefinition(1L, "sample", "[0-9]", SOWorkflowType.STRING, true))); + ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client); + Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200); + Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(parameters); + MsoResponseWrapper2 msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse); + Mockito.when(client.getWorkflowParameterDefinitions(1L)).thenReturn(msoResponseWrapper); + + + SOWorkflowParameterDefinitions workflowParameterDefinitions = extWorkflowsService.getWorkflowParameterDefinitions(1L); + + Assertions.assertThat(workflowParameterDefinitions).isEqualTo(parameters); + } + + @Test + public void shouldProperlyHandleEmptyParametersList(){ + ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client); + Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200); + Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(new SOWorkflowParameterDefinitions(Lists.newArrayList())); + + MsoResponseWrapper2 msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse); + Mockito.when(client.getWorkflowParameterDefinitions(1L)).thenReturn(msoResponseWrapper); + + + SOWorkflowParameterDefinitions workflowParameterDefinitions = extWorkflowsService.getWorkflowParameterDefinitions(1L); + Assertions.assertThat(workflowParameterDefinitions.getParameterDefinitions()).isEmpty(); + } +} -- cgit 1.2.3-korg