aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be/src/test/java/org
diff options
context:
space:
mode:
authorayalaben <ayala.benzvi@amdocs.com>2018-08-05 12:20:18 +0300
committerayalaben <ayala.benzvi@amdocs.com>2018-08-05 13:06:46 +0300
commitb8ce2dc406d23c50d1950e4793eec63dd220f36e (patch)
tree9444acea27190b2e94bc829591fbc88c090f0dd8 /workflow-designer-be/src/test/java/org
parentbc16f708119e8907fd4beb8d1de9c525d4b9d9ee (diff)
Workflow version validator
Change-Id: I8d3b86ecc03b6b5c36dc0f5c815962561fadbb68 Issue-ID: SDC-1518 Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
Diffstat (limited to 'workflow-designer-be/src/test/java/org')
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java11
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/WorkflowVersionValidatorTest.java71
2 files changed, 80 insertions, 2 deletions
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());
+ }
+ }
+}