From b8ce2dc406d23c50d1950e4793eec63dd220f36e Mon Sep 17 00:00:00 2001 From: ayalaben Date: Sun, 5 Aug 2018 12:20:18 +0300 Subject: Workflow version validator Change-Id: I8d3b86ecc03b6b5c36dc0f5c815962561fadbb68 Issue-ID: SDC-1518 Signed-off-by: ayalaben --- .../api/WorkflowVersionControllerTest.java | 11 +++- .../api/types/WorkflowVersionValidatorTest.java | 71 ++++++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/WorkflowVersionValidatorTest.java (limited to 'workflow-designer-be/src/test') diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java index a390ec75..ec27c4be 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java @@ -1,9 +1,10 @@ package org.onap.sdc.workflow.api; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -25,6 +26,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.sdc.workflow.RestPath; +import org.onap.sdc.workflow.api.types.WorkflowVersionValidator; import org.onap.sdc.workflow.persistence.types.WorkflowVersion; import org.onap.sdc.workflow.services.WorkflowVersionManager; import org.openecomp.sdc.versioning.dao.types.Version; @@ -49,6 +51,9 @@ public class WorkflowVersionControllerTest { @Mock private WorkflowVersionManager workflowVersionManagerMock; + @Mock + private WorkflowVersionValidator versionValidator; + @InjectMocks private WorkflowVersionController workflowVersionController; @@ -77,6 +82,7 @@ public class WorkflowVersionControllerTest { WorkflowVersion version = new WorkflowVersion(); version.setDescription("VersionDescription"); + doNothing().when(versionValidator).validate(eq(ITEM1_ID),any(WorkflowVersion.class)); mockMvc.perform(post(RestPath.getWorkflowVersions(ITEM1_ID)).header(RestParams.USER_ID_HEADER, USER_ID) .contentType(APPLICATION_JSON) .content(GSON.toJson(version))) @@ -101,6 +107,7 @@ public class WorkflowVersionControllerTest { public void shouldUpdateWorkflowVersionWhenCallingPutREST() throws Exception { WorkflowVersion version = new WorkflowVersion(); version.setDescription("Updated"); + doNothing().when(versionValidator).validate(eq(ITEM1_ID),any(WorkflowVersion.class)); MockHttpServletResponse result = mockMvc.perform( put(RestPath.getWorkflowVersion(ITEM1_ID, VERSION1_ID)).header(RestParams.USER_ID_HEADER, USER_ID) diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/WorkflowVersionValidatorTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/WorkflowVersionValidatorTest.java new file mode 100644 index 00000000..9ea007ce --- /dev/null +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/WorkflowVersionValidatorTest.java @@ -0,0 +1,71 @@ +/* + * Copyright © 2018 European Support Limited + * + * 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. + */ +package org.onap.sdc.workflow.api.types; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.fail; + +import java.util.Arrays; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.onap.sdc.workflow.persistence.types.ParameterEntity; +import org.onap.sdc.workflow.persistence.types.WorkflowVersion; +import org.onap.sdc.workflow.services.exceptions.VersionValidationException; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +public class WorkflowVersionValidatorTest { + + private static final String ITEM1_ID = "item_id_1"; + + @InjectMocks + private WorkflowVersionValidator versionValidator; + + @Test + public void invalidInputs() { + WorkflowVersion workflowVersion = new WorkflowVersion(); + workflowVersion.setDescription("version description"); + ParameterEntity input = new ParameterEntity(); + input.setName("input1"); + workflowVersion.setInputs(Arrays.asList(input, input)); + try { + versionValidator.validate(ITEM1_ID, workflowVersion); + fail("Should have thrown VersionValidationException but did not!"); + + } catch (VersionValidationException ex) { + assertEquals(String.format("Error creating or modifying version for workflow with id %s: %s", ITEM1_ID, + "Input name must be unique"), ex.getMessage()); + } + } + + @Test + public void invalidOtputs(){ + WorkflowVersion workflowVersion = new WorkflowVersion(); + workflowVersion.setDescription("version description"); + ParameterEntity output = new ParameterEntity(); + output.setName("output1"); + workflowVersion.setOutputs(Arrays.asList(output, output)); + try { + versionValidator.validate(ITEM1_ID, workflowVersion); + fail("Should have thrown VersionValidationException but did not!"); + + } catch (VersionValidationException ex) { + assertEquals(String.format("Error creating or modifying version for workflow with id %s: %s", ITEM1_ID, + "Output name must be unique"), ex.getMessage()); + } + } +} -- cgit 1.2.3-korg