aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be/src/test/java/org
diff options
context:
space:
mode:
authortalig <talig@amdocs.com>2018-09-26 09:33:04 +0300
committertalig <talig@amdocs.com>2018-09-26 09:33:04 +0300
commit373f52e9080ec7b5c0fb0b2c371bd557060bc9ae (patch)
tree3b8ac1ec3222314f81d97d46721d81df052e2146 /workflow-designer-be/src/test/java/org
parentac89252d0999c9916915e7997261a681b39544a1 (diff)
Add version request/response DTOs.
In order to prevent duplicate key error when updating input/output parameters - hide their internal Ids. Change-Id: I9bd23cb0b6559a94e32c5c7d75f3e0135822bcb1 Issue-ID: SDC-1793 Signed-off-by: talig <talig@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.java72
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidatorTest.java27
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java41
3 files changed, 69 insertions, 71 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 2ed1cc16..954839c0 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
@@ -4,7 +4,6 @@ import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -23,12 +22,14 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.sdc.workflow.RestPath;
-import org.onap.sdc.workflow.persistence.types.ParameterEntity;
+import org.onap.sdc.workflow.api.mappers.WorkflowVersionDtoMapper;
+import org.onap.sdc.workflow.api.types.Parameter;
+import org.onap.sdc.workflow.api.types.WorkflowVersionRequest;
+import org.onap.sdc.workflow.api.types.WorkflowVersionResponse;
import org.onap.sdc.workflow.persistence.types.ParameterType;
import org.onap.sdc.workflow.services.WorkflowVersionManager;
import org.onap.sdc.workflow.services.types.WorkflowVersion;
import org.onap.sdc.workflow.services.utilities.JsonUtil;
-import org.openecomp.sdc.versioning.dao.types.Version;
import org.springframework.http.HttpStatus;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.MockMvc;
@@ -46,7 +47,8 @@ public class WorkflowVersionControllerTest {
@Mock
private WorkflowVersionManager workflowVersionManagerMock;
-
+ @Mock
+ private WorkflowVersionDtoMapper versionDtoMapperMock;
@InjectMocks
private WorkflowVersionController workflowVersionController;
@@ -57,77 +59,91 @@ public class WorkflowVersionControllerTest {
@Test
public void shouldReturnWorkflowVersionListWhenCallingVersionGetREST() throws Exception {
- doReturn(Arrays.asList(new Version(VERSION1_ID), new Version(VERSION2_ID))).when(workflowVersionManagerMock)
- .list(ITEM1_ID, null);
+ WorkflowVersion version1 = new WorkflowVersion(VERSION1_ID);
+ WorkflowVersion version2 = new WorkflowVersion(VERSION2_ID);
+ doReturn(Arrays.asList(version1, version2)).when(workflowVersionManagerMock).list(ITEM1_ID, null);
+
+ WorkflowVersionResponse response1 = new WorkflowVersionResponse();
+ response1.setId(VERSION1_ID);
+ doReturn(response1).when(versionDtoMapperMock).workflowVersionToResponse(version1);
+ WorkflowVersionResponse response2 = new WorkflowVersionResponse();
+ response2.setId(VERSION2_ID);
+ doReturn(response2).when(versionDtoMapperMock).workflowVersionToResponse(version2);
+
mockMvc.perform(get(RestPath.getWorkflowVersions(ITEM1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
.contentType(APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(jsonPath("$.items", hasSize(2))).andExpect(jsonPath("$.items[0].id", is(VERSION1_ID)))
.andExpect(jsonPath("$.items[1].id", is(VERSION2_ID)));
- verify(workflowVersionManagerMock, times(1)).list(ITEM1_ID, null);
+ verify(workflowVersionManagerMock).list(ITEM1_ID, null);
}
-
@Test
public void shouldCreateWorkflowVersionWhenCallingVersionsPostREST() throws Exception {
+ WorkflowVersionRequest request = new WorkflowVersionRequest();
+ request.setDescription("Updated");
WorkflowVersion version = new WorkflowVersion();
- version.setDescription("VersionDescription");
+ version.setDescription("Updated");
+ doReturn(version).when(versionDtoMapperMock).requestToWorkflowVersion(request);
+
mockMvc.perform(post(RestPath.getWorkflowVersions(ITEM1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
- .contentType(APPLICATION_JSON).content(JsonUtil.object2Json(version)))
+ .contentType(APPLICATION_JSON).content(JsonUtil.object2Json(request)))
.andExpect(status().isCreated());
- verify(workflowVersionManagerMock, times(1)).create(ITEM1_ID, null, version);
+ verify(workflowVersionManagerMock).create(ITEM1_ID, null, version);
}
@Test
public void shouldFailCreateWorkflowVersionWhenCallingVersionsPostRESTWithDuplicateInput() throws Exception {
- WorkflowVersion version = new WorkflowVersion();
- Collection<ParameterEntity> inputs =
- Arrays.asList(createParameterEntity("name1"), createParameterEntity("name1"));
+ WorkflowVersionRequest version = new WorkflowVersionRequest();
+ Collection<Parameter> inputs = Arrays.asList(createParameter("name1"), createParameter("name1"));
version.setInputs(inputs);
version.setDescription("VersionDescription");
mockMvc.perform(post(RestPath.getWorkflowVersions(ITEM1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
.contentType(APPLICATION_JSON).content(JsonUtil.object2Json(version)))
.andExpect(status().isBadRequest());
-
}
-
@Test
public void shouldReturnWorkflowVersionWhenExists() throws Exception {
WorkflowVersion version = new WorkflowVersion(VERSION1_ID);
doReturn(version).when(workflowVersionManagerMock).get(ITEM1_ID, VERSION1_ID);
+ WorkflowVersionResponse response = new WorkflowVersionResponse();
+ response.setId(VERSION1_ID);
+ doReturn(response).when(versionDtoMapperMock).workflowVersionToResponse(version);
+
mockMvc.perform(
get(RestPath.getWorkflowVersion(ITEM1_ID, VERSION1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
.contentType(APPLICATION_JSON)).andDo(print()).andExpect(status().isOk())
- .andExpect(jsonPath("$.id", is(version.getId())));
- verify(workflowVersionManagerMock, times(1)).get(ITEM1_ID, VERSION1_ID);
+ .andExpect(jsonPath("$.id", is(VERSION1_ID)));
+ verify(workflowVersionManagerMock).get(ITEM1_ID, VERSION1_ID);
}
@Test
public void shouldUpdateWorkflowVersionWhenCallingPutREST() throws Exception {
+ WorkflowVersionRequest request = new WorkflowVersionRequest();
+ request.setDescription("Updated");
WorkflowVersion version = new WorkflowVersion();
version.setDescription("Updated");
+ doReturn(version).when(versionDtoMapperMock).requestToWorkflowVersion(request);
MockHttpServletResponse result = mockMvc.perform(
put(RestPath.getWorkflowVersion(ITEM1_ID, VERSION1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
- .contentType(APPLICATION_JSON).content(JsonUtil.object2Json(version))).andReturn()
+ .contentType(APPLICATION_JSON).content(JsonUtil.object2Json(request))).andReturn()
.getResponse();
assertEquals(HttpStatus.OK.value(), result.getStatus());
- version.setId(VERSION1_ID);
- verify(workflowVersionManagerMock, times(1)).update(ITEM1_ID, version);
+ verify(workflowVersionManagerMock).update(ITEM1_ID, version);
}
- private ParameterEntity createParameterEntity(String name) {
- ParameterEntity parameterEntity = new ParameterEntity();
- parameterEntity.setName(name);
- parameterEntity.setMandatory(false);
- parameterEntity.setType(ParameterType.STRING);
- return parameterEntity;
+ private Parameter createParameter(String name) {
+ Parameter parameter = new Parameter();
+ parameter.setName(name);
+ parameter.setMandatory(false);
+ parameter.setType(ParameterType.STRING);
+ return parameter;
}
-
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidatorTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidatorTest.java
index bfc7dc36..2d7d6d28 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidatorTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidatorTest.java
@@ -3,26 +3,25 @@ package org.onap.sdc.workflow.api.validation;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.List;
+import java.util.Collections;
import javax.validation.ConstraintValidatorContext;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.onap.sdc.workflow.persistence.types.ParameterEntity;
+import org.onap.sdc.workflow.api.types.Parameter;
public class NoDuplicatesValidatorTest {
class AnnotationWrapper {
@NoDuplicates(message = "test message")
- public Collection<ParameterEntity> collection;
+ public Collection<Parameter> collection;
}
private NoDuplicatesValidator noDuplicatesValidator;
@@ -32,7 +31,8 @@ public class NoDuplicatesValidatorTest {
@Mock
private ConstraintValidatorContext.ConstraintViolationBuilder constraintViolationBuilder;
@Mock
- private ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext nodeBuilderCustomizableContext;
+ private ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext
+ nodeBuilderCustomizableContext;
@Before
public void init() throws NoSuchFieldException {
@@ -44,24 +44,21 @@ public class NoDuplicatesValidatorTest {
@Test
public void shouldFailIfCollectionHaveMoreThen1ParameterEntityWithSameName() {
- Collection<ParameterEntity> inputs =
- Arrays.asList(createParameterEntity("name1"), createParameterEntity("name1"));
+ Collection<Parameter> inputs = Arrays.asList(createParameter("name1"), createParameter("name1"));
assertFalse(noDuplicatesValidator.isValid(inputs, context));
}
@Test
public void shouldPassIfCollectionDontHaveMoreThen1ParameterEntityWithSameName() {
- Collection<ParameterEntity> inputs =
- Arrays.asList(createParameterEntity("name2"), createParameterEntity("name1"));
+ Collection<Parameter> inputs = Arrays.asList(createParameter("name2"), createParameter("name1"));
assertTrue(noDuplicatesValidator.isValid(inputs, context));
}
@Test
public void shouldPassIfCollectionContainsOnlyOneObject() {
- Collection<ParameterEntity> inputs =
- Arrays.asList(createParameterEntity("name2"));
+ Collection<Parameter> inputs = Collections.singletonList(createParameter("name2"));
assertTrue(noDuplicatesValidator.isValid(inputs, context));
}
@@ -83,9 +80,9 @@ public class NoDuplicatesValidatorTest {
return validator;
}
- private ParameterEntity createParameterEntity(String name) {
- ParameterEntity parameterEntity = new ParameterEntity();
- parameterEntity.setName(name);
- return parameterEntity;
+ private Parameter createParameter(String name) {
+ Parameter parameter = new Parameter();
+ parameter.setName(name);
+ return parameter;
}
} \ No newline at end of file
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
index 9640fa1b..57829875 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
@@ -21,7 +21,6 @@ import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
-import org.mockito.ArgumentMatcher;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
@@ -30,13 +29,13 @@ import org.onap.sdc.workflow.persistence.ArtifactRepository;
import org.onap.sdc.workflow.persistence.ParameterRepository;
import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
import org.onap.sdc.workflow.persistence.types.ParameterRole;
-import org.onap.sdc.workflow.services.types.WorkflowVersion;
-import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
import org.onap.sdc.workflow.services.exceptions.VersionCreationException;
import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException;
import org.onap.sdc.workflow.services.impl.mappers.VersionMapper;
import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper;
+import org.onap.sdc.workflow.services.types.WorkflowVersion;
+import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionState;
@@ -77,10 +76,11 @@ public class WorkflowVersionManagerImplTest {
Version version = new Version(VERSION1_ID);
WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(any(Version.class));
- doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID),any(Version.class));
- doReturn(new ArrayList()).when(parameterRepositoryMock).list(eq(ITEM1_ID), eq(VERSION1_ID), any(ParameterRole.class));
- workflowVersionManager.get(ITEM1_ID,VERSION1_ID);
- verify(versioningManagerMock).get(ITEM1_ID,version);
+ doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), any(Version.class));
+ doReturn(new ArrayList()).when(parameterRepositoryMock)
+ .list(eq(ITEM1_ID), eq(VERSION1_ID), any(ParameterRole.class));
+ workflowVersionManager.get(ITEM1_ID, VERSION1_ID);
+ verify(versioningManagerMock).get(ITEM1_ID, version);
}
/* @Test
@@ -130,18 +130,18 @@ public class WorkflowVersionManagerImplTest {
@Test
- public void shouldCreateWorkflowVersion(){
+ public void shouldCreateWorkflowVersion() {
Version version = new Version(VERSION1_ID);
version.setDescription("version desc");
- doReturn(version).when(versioningManagerMock).create(ITEM1_ID,version, VersionCreationMethod.major);
+ doReturn(version).when(versioningManagerMock).create(ITEM1_ID, version, VersionCreationMethod.major);
WorkflowVersion versionRequest = new WorkflowVersion();
versionRequest.setDescription("version desc");
versionRequest.setInputs(new ArrayList<>());
versionRequest.setOutputs(new ArrayList<>());
WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
- doReturn(workflowVersion).when(workflowVersionManager).get(ITEM1_ID,VERSION1_ID);
+ doReturn(workflowVersion).when(workflowVersionManager).get(ITEM1_ID, VERSION1_ID);
workflowVersionManager.create(ITEM1_ID, null, versionRequest);
- verify(versioningManagerMock).create(ITEM1_ID,version, VersionCreationMethod.major);
+ verify(versioningManagerMock).create(ITEM1_ID, version, VersionCreationMethod.major);
}
@Test(expected = VersionCreationException.class)
@@ -196,7 +196,7 @@ public class WorkflowVersionManagerImplTest {
doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
doReturn(CERTIFIED).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus());
doThrow(new RuntimeException()).when(versioningManagerMock)
- .submit(eq(ITEM1_ID), eqVersion(VERSION1_ID), anyString());
+ .submit(eq(ITEM1_ID), eqVersion(VERSION1_ID), anyString());
workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED);
}
@@ -249,21 +249,6 @@ public class WorkflowVersionManagerImplTest {
}
private static Version eqVersion(String versionId) {
- return argThat(new EqVersion(versionId));
+ return argThat(version -> versionId.equals(version.getId()));
}
-
- private static class EqVersion implements ArgumentMatcher<Version> {
-
- private final String versionId;
-
- EqVersion(String versionId) {
- this.versionId = versionId;
- }
-
- @Override
- public boolean matches(Version version) {
- return versionId.equals(version.getId());
- }
- }
-
} \ No newline at end of file