diff options
Diffstat (limited to 'vid-app-common/src/test')
4 files changed, 109 insertions, 117 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java index 11bf364fb..4494f4872 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java @@ -28,7 +28,7 @@ import org.apache.commons.io.IOUtils; import org.jetbrains.annotations.NotNull; import org.mockito.hamcrest.MockitoHamcrest; import org.onap.vid.changeManagement.WorkflowRequestDetail; -import org.onap.vid.controller.ControllersUtils; +import org.onap.vid.model.SOWorkflowList; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -78,6 +78,7 @@ import static org.hamcrest.Matchers.hasEntry; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; @@ -103,6 +104,12 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests { private MsoInterface msoInterface; @Mock + private SOWorkflowList workflowList; + + @Mock + private HttpResponse<SOWorkflowList> workflowListResponse; + + @Mock private RequestDetails msoRequest; @@ -1357,6 +1364,26 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests { assertThat(response).isEqualToComparingFieldByField(okResponse); } + + @Test + public void shouldReturnWorkflowListForGivenModelId() { + given(msoInterface.getWorkflowListByModelId(anyString())).willReturn(workflowListResponse); + given(workflowListResponse.getBody()).willReturn(workflowList); + given(workflowListResponse.getStatus()).willReturn(HttpStatus.ACCEPTED.value()); + + SOWorkflowList workflows = msoBusinessLogic.getWorkflowListByModelId("sampleModelId"); + + assertThat(workflows).isEqualTo(workflowList); + } + + @Test(expectedExceptions = {MsoBusinessLogicImpl.WorkflowListException.class}) + public void shouldRaiseExceptionWhenRetrievingWorkflowsFailed() { + given(msoInterface.getWorkflowListByModelId(anyString())).willReturn(workflowListResponse); + given(workflowListResponse.getStatus()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR.value()); + + msoBusinessLogic.getWorkflowListByModelId("sampleModelId"); + } + private WorkflowRequestDetail createWorkflowRequestDetail() { WorkflowRequestDetail workflowRequestDetail = new WorkflowRequestDetail(); org.onap.vid.changeManagement.RequestParameters requestParameters = new org.onap.vid.changeManagement.RequestParameters(); 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 deleted file mode 100644 index 160ba97a5..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java +++ /dev/null @@ -1,116 +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.ExternalWorkflowsServiceImpl.BadResponseFromMso; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -public class ExternalWorkflowServiceImplTest { - - @Mock - private MockedWorkflowsRestClient client; - @Mock - private HttpResponse<SOWorkflows> response; - - @Mock - private HttpResponse<SOWorkflowParameterDefinitions> 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<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"); - 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<SOWorkflows> 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<SOWorkflowParameterDefinitions> 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<SOWorkflowParameterDefinitions> 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/ExternalWorkflowsServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowsServiceImplTest.java new file mode 100644 index 000000000..94771b29e --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowsServiceImplTest.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2019 Nokia 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 org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.vid.model.ArtifactInfo; +import org.onap.vid.model.SOWorkflow; +import org.onap.vid.model.SOWorkflowList; +import org.onap.vid.model.WorkflowInputParameter; +import org.onap.vid.model.WorkflowSource; +import org.onap.vid.model.WorkflowSpecification; +import org.onap.vid.model.WorkflowSpecificationWrapper; +import org.onap.vid.mso.MsoBusinessLogic; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +public class ExternalWorkflowsServiceImplTest { + + @Mock + private MsoBusinessLogic msoBusinessLogic; + + + private static final UUID SAMPLE_UUID = UUID.randomUUID(); + + @BeforeMethod + public void init() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void shouldReturnWorkflowsOnValidResponse() { + // given + ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(msoBusinessLogic); + WorkflowInputParameter parameter = new WorkflowInputParameter("sampleLabel", "text", + true, Collections.EMPTY_LIST, "sampleName", "userParams", "description"); + SOWorkflowList workflowList = createWorkflowList(parameter); + SOWorkflow workflow = new SOWorkflow(SAMPLE_UUID.toString(), "sampleName", WorkflowSource.SDC, Collections.singletonList(parameter)); + when(msoBusinessLogic.getWorkflowListByModelId("test")).thenReturn(workflowList); + // when + List<SOWorkflow> workflows = extWorkflowsService.getWorkflows("test"); + // then + assertThat(workflows).hasSize(1).contains(workflow); + } + + private SOWorkflowList createWorkflowList(WorkflowInputParameter parameter) { + ArtifactInfo artifactInfo = new ArtifactInfo("workflow", SAMPLE_UUID.toString(), "sampleArtifactName", + "sampleVersion", "sampleDescription", "sampleName", "sampleOperation", "sdc", "vnf"); + WorkflowSpecification specification = new WorkflowSpecification(artifactInfo, Collections.EMPTY_LIST, Collections.singletonList(parameter)); + WorkflowSpecificationWrapper wrapper = new WorkflowSpecificationWrapper(specification); + return new SOWorkflowList(Collections.singletonList(wrapper)); + } + +} diff --git a/vid-app-common/src/test/resources/WEB-INF/conf/system.properties b/vid-app-common/src/test/resources/WEB-INF/conf/system.properties index 71f8eac3b..fce0d1aeb 100644 --- a/vid-app-common/src/test/resources/WEB-INF/conf/system.properties +++ b/vid-app-common/src/test/resources/WEB-INF/conf/system.properties @@ -170,6 +170,7 @@ mso.restapi.operationalEnvironment.create=${mso.restapi.cloudResourcesApiRoot}/o mso.restapi.serviceInstantiationApiRoot=/serviceInstantiation/v7 mso.restapi.serviceInstanceCreate=${mso.restapi.serviceInstantiationApiRoot}/serviceInstances mso.restapi.serviceInstanceAssign=${mso.restapi.serviceInstantiationApiRoot}/serviceInstances/assign +mso.restapi.changeManagement.workflowSpecifications=/workflowSpecifications/v1/workflows?vnfModelVersionId=<model_version_id> vid.truststore.filename=/opt/app/vid/etc/vid_keystore.jks mso.dme2.client.timeout=30000 |