diff options
author | ayalaben <ayala.benzvi@amdocs.com> | 2018-07-17 11:59:29 +0300 |
---|---|---|
committer | ayalaben <ayala.benzvi@amdocs.com> | 2018-07-17 16:33:08 +0300 |
commit | 30ab38f38ebf9b89d7c0e01409d2af6b5f31d46d (patch) | |
tree | d58fbf27b0365e7e003c6c35ad9b373935888dc4 /workflow | |
parent | 7e78cd19bbb2b0730fafc0b328a71c69f5730e16 (diff) |
Workflow Version Inputs Outputs
Change-Id: Ie09dcd9c7ad5e162ab37513db9f2ad00a0f91388
Issue-ID: SDC-1518
Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
Diffstat (limited to 'workflow')
14 files changed, 528 insertions, 33 deletions
diff --git a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionRequestDto.java b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionRequestDto.java index 92ac3a73..bdd1c4ac 100644 --- a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionRequestDto.java +++ b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionRequestDto.java @@ -1,11 +1,15 @@ package org.onap.sdc.workflow.api.types; +import java.util.Collection; import lombok.Data; +import org.onap.sdc.workflow.persistence.types.ParameterEntity; @Data public class VersionRequestDto { private String description; private String baseVersionId; + private Collection<ParameterEntity> inputs; + private Collection<ParameterEntity> outputs; } diff --git a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ParameterRepository.java b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ParameterRepository.java new file mode 100644 index 00000000..d4465006 --- /dev/null +++ b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ParameterRepository.java @@ -0,0 +1,23 @@ +package org.onap.sdc.workflow.persistence; + +import java.util.Collection; +import org.onap.sdc.workflow.persistence.types.ParameterEntity; +import org.onap.sdc.workflow.persistence.types.ParameterRole; + + +public interface ParameterRepository { + + void createStructure(String id, String versionId); + + Collection<ParameterEntity> list(String id, String versionId, ParameterRole role); + + void deleteAll(String id, String versionId, ParameterRole role); + + ParameterEntity get(String id, String versionId, String parameterId); + + void delete(String id, String versionId, String parameterId); + + ParameterEntity create(String id, String versionId , ParameterRole role, ParameterEntity parameter); + + void update(String id, String versionId, ParameterRole role, ParameterEntity parameter); +} diff --git a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java index 9a449f0d..7e100cf4 100644 --- a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java +++ b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java @@ -12,14 +12,13 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; -import java.util.Map; import java.util.Optional; import org.apache.commons.io.IOUtils; import org.onap.sdc.workflow.persistence.ArtifactRepository; import org.onap.sdc.workflow.persistence.types.ArtifactEntity; +import org.onap.sdc.workflow.persistence.types.WorkflowElementType; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; -import org.openecomp.sdc.datatypes.model.ElementType; import org.springframework.stereotype.Repository; @Repository @@ -33,7 +32,7 @@ public class ArtifactRepositoryImpl implements ArtifactRepository { @Override public void update(String id, String versionId, ArtifactEntity artifactEntity) { - ZusammenElement artifactElement = buildStructuralElement(ElementType.Artifact, Action.UPDATE); + ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.UPDATE); artifactElement.setData(artifactEntity.getArtifactData()); artifactElement.getInfo().addProperty(FILE_NAME_PROPERTY, artifactEntity.getFileName()); @@ -50,7 +49,7 @@ public class ArtifactRepositoryImpl implements ArtifactRepository { ElementContext elementContext = new ElementContext(id, versionId); Optional<Element> elementOptional = - zusammenAdaptor.getElementByName(context, elementContext, null, ElementType.Artifact.name()); + zusammenAdaptor.getElementByName(context, elementContext, null, WorkflowElementType.ARTIFACT.name()); if (!elementOptional.isPresent() || hasEmptyData(elementOptional.get().getData())) { return Optional.empty(); @@ -69,7 +68,7 @@ public class ArtifactRepositoryImpl implements ArtifactRepository { SessionContext context = createSessionContext(); ElementContext elementContext = new ElementContext(id, versionId); - ZusammenElement artifactElement = buildStructuralElement(ElementType.Artifact, Action.CREATE); + ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.CREATE); artifactElement.setData(new ByteArrayInputStream(EMPTY_DATA.getBytes())); zusammenAdaptor @@ -82,12 +81,12 @@ public class ArtifactRepositoryImpl implements ArtifactRepository { SessionContext context = createSessionContext(); ElementContext elementContext = new ElementContext(id, versionId); - ZusammenElement artifactElement = buildStructuralElement(ElementType.Artifact, Action.UPDATE); + ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.UPDATE); artifactElement.setData(new ByteArrayInputStream(EMPTY_DATA.getBytes())); artifactElement.getInfo().getProperties().remove(FILE_NAME_PROPERTY); zusammenAdaptor - .saveElement(context, elementContext, artifactElement, "Update WorkflowVersion Artifact Element"); + .saveElement(context, elementContext, artifactElement, "Delete WorkflowVersion Artifact Data"); } diff --git a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java new file mode 100644 index 00000000..bcca104f --- /dev/null +++ b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java @@ -0,0 +1,183 @@ +package org.onap.sdc.workflow.persistence.impl; + +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.item.Action; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.datatypes.item.Info; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Optional; +import java.util.stream.Collectors; +import javax.swing.DefaultBoundedRangeModel; +import org.onap.sdc.workflow.persistence.ParameterRepository; +import org.onap.sdc.workflow.persistence.types.ParameterEntity; +import org.onap.sdc.workflow.persistence.types.ParameterPropertyName; +import org.onap.sdc.workflow.persistence.types.ParameterRole; +import org.onap.sdc.workflow.persistence.types.ParameterType; +import org.onap.sdc.workflow.persistence.types.WorkflowElementType; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; +import org.openecomp.types.ElementPropertyName; +import org.springframework.stereotype.Repository; + +@Repository +public class ParameterRepositoryImpl implements ParameterRepository { + + private ZusammenAdaptor zusammenAdaptor = ZusammenAdaptorFactory.getInstance().createInterface(); + + @Override + public void createStructure(String id, String versionId) { + + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(id, versionId); + + ZusammenElement inputsElement = buildStructuralElement(WorkflowElementType.INPUTS.name(), Action.CREATE); + ZusammenElement outputsElement = buildStructuralElement(WorkflowElementType.OUTPUTS.name(), Action.CREATE); + + zusammenAdaptor.saveElement(context, elementContext, inputsElement, "Create WorkflowVersion INPUTS Element"); + zusammenAdaptor.saveElement(context, elementContext, outputsElement, "Create WorkflowVersion OUTPUTS Element"); + } + + @Override + public Collection<ParameterEntity> list(String id, String versionId, ParameterRole role) { + + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(id, versionId); + + return zusammenAdaptor.listElementsByName(context, elementContext, null, role.name()).stream() + .map(this::mapElementInfoToParameter).collect(Collectors.toList()); + + } + + @Override + public void deleteAll(String id, String versionId, ParameterRole role) { + + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(id, versionId); + + Optional<ElementInfo> optionalParentElement = zusammenAdaptor.getElementInfoByName(context, elementContext, null, + getParentElementType(role)); + + if (!optionalParentElement.isPresent()) { + return; + } + ZusammenElement parentElement = buildElement(optionalParentElement.get().getId(), Action.IGNORE); + parentElement.setSubElements(optionalParentElement.get().getSubElements().stream() + .map(parameter -> buildElement(parameter.getId(), + Action.DELETE)).collect(Collectors.toList())); + + zusammenAdaptor.saveElement(context, elementContext, parentElement, "Delete all " + role); + } + + @Override + public ParameterEntity get(String id, String versionId, String parameterId) { + + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(id, versionId); + + Optional<ElementInfo> element = zusammenAdaptor.getElementInfo(context, elementContext,new Id(parameterId)); + + return element.map(this::mapElementInfoToParameter).orElse(null); + } + + @Override + public void delete(String id, String versionId, String parameterId){ + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(id, versionId); + + ZusammenElement parameterElement = buildElement(new Id(parameterId),Action.DELETE); + + zusammenAdaptor.saveElement(context, elementContext, parameterElement, + String.format("Delete Parameter with id %s", parameterId)); + + } + + @Override + public ParameterEntity create(String id, String versionId, ParameterRole role, ParameterEntity parameter) { + + ZusammenElement parameterElement = + parameterToZusammenElement(parameter,role, Action.CREATE); + ZusammenElement parentElement = + buildStructuralElement(getParentElementType(role), Action.IGNORE); + parentElement.addSubElement(parameterElement); + + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(id, versionId); + + Element savedElement = zusammenAdaptor.saveElement(context, elementContext, parentElement, + "Create WorkflowVersion Parameter Element"); + + parameter.setId(savedElement.getSubElements().iterator().next().getElementId().getValue()); + return parameter; + } + + @Override + public void update(String id, String versionId, ParameterRole role, ParameterEntity parameter) { + + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(id, versionId); + + ZusammenElement parameterElement = + parameterToZusammenElement(parameter, role, Action.UPDATE); + + zusammenAdaptor.saveElement(context, elementContext, parameterElement, "Update WorkflowVersion Parameter"); + } + + private ZusammenElement parameterToZusammenElement(ParameterEntity parameter, ParameterRole role, + Action action) { + + ZusammenElement parameterElement = + buildElement(parameter.getId() == null ? null : new Id(parameter.getId()), action); + Info info = new Info(); + info.setName(parameter.getName()); + info.addProperty(ElementPropertyName.elementType.name(), WorkflowElementType.valueOf(role.name())); + info.addProperty(ParameterPropertyName.type.name(), parameter.getType()); + info.addProperty(ParameterPropertyName.mandatory.name(), parameter.isMandatory()); + parameterElement.setInfo(info); + + return parameterElement; + } + + ParameterEntity elementToParameterEntity(Element element) { + ParameterEntity parameterEntity = new ParameterEntity(); + parameterEntity.setId(element.getElementId().getValue()); + parameterEntity.setName(element.getInfo().getName()); + parameterEntity.setType(ParameterType.valueOf( + (String) element.getInfo().getProperties().get(ParameterPropertyName.type.name()))); + parameterEntity + .setMandatory((Boolean) element.getInfo().getProperties().get(ParameterPropertyName.mandatory.name())); + + return parameterEntity; + } + + private static String getParentElementType(ParameterRole role) { + switch (role){ + case INPUT: + return WorkflowElementType.INPUTS.name(); + case OUTPUT: + return WorkflowElementType.OUTPUTS.name(); + default: + throw new RuntimeException("Wrong Element Type"); + } + } + + private ParameterEntity mapElementInfoToParameter(ElementInfo elementInfo){ + ParameterEntity parameterEntity = new ParameterEntity(); + parameterEntity.setId(elementInfo.getId().getValue()); + parameterEntity.setName(elementInfo.getInfo().getName()); + parameterEntity.setType(ParameterType.valueOf( + elementInfo.getInfo().getProperty(ParameterPropertyName.type.name()))); + parameterEntity.setMandatory(elementInfo.getInfo().getProperty( + ParameterPropertyName.mandatory.name())); + return parameterEntity; + } + +} diff --git a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java new file mode 100644 index 00000000..bc625b81 --- /dev/null +++ b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java @@ -0,0 +1,12 @@ +package org.onap.sdc.workflow.persistence.types; + +import lombok.Data; + +@Data +public class ParameterEntity { + + private String id; + private String name; + private ParameterType type; + private boolean mandatory; +} diff --git a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterPropertyName.java b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterPropertyName.java new file mode 100644 index 00000000..5024d4a8 --- /dev/null +++ b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterPropertyName.java @@ -0,0 +1,7 @@ +package org.onap.sdc.workflow.persistence.types; + +public enum ParameterPropertyName { + + type, + mandatory +} diff --git a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterRole.java b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterRole.java new file mode 100644 index 00000000..9b5620b3 --- /dev/null +++ b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterRole.java @@ -0,0 +1,8 @@ +package org.onap.sdc.workflow.persistence.types; + +public enum ParameterRole { + + INPUT, + OUTPUT + +} diff --git a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterType.java b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterType.java new file mode 100644 index 00000000..60465824 --- /dev/null +++ b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterType.java @@ -0,0 +1,9 @@ +package org.onap.sdc.workflow.persistence.types; + +public enum ParameterType { + STRING, + INTEGER, + FLOAT, + BOOLEAN, + TIMESTAMP +} diff --git a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowElementType.java b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowElementType.java new file mode 100644 index 00000000..6f473453 --- /dev/null +++ b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowElementType.java @@ -0,0 +1,10 @@ +package org.onap.sdc.workflow.persistence.types; + +public enum WorkflowElementType { + + ARTIFACT, + INPUTS, + OUTPUTS, + INPUT, + OUTPUT +} diff --git a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java index db0999b6..e4158b19 100644 --- a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java +++ b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java @@ -1,5 +1,6 @@ package org.onap.sdc.workflow.persistence.types; +import java.util.Collection; import java.util.Date; import lombok.Data; @@ -14,6 +15,8 @@ public class WorkflowVersion { private Date creationTime; private Date modificationTime; private WorkflowVersionState state; + private Collection<ParameterEntity> inputs; + private Collection<ParameterEntity> outputs; public WorkflowVersion(String id) { diff --git a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java index cdfddf34..0f88d37f 100644 --- a/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java +++ b/workflow/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java @@ -10,7 +10,10 @@ import java.util.Optional; import java.util.stream.Collectors; import org.onap.sdc.workflow.api.types.VersionRequestDto; 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.ParameterEntity; +import org.onap.sdc.workflow.persistence.types.ParameterRole; import org.onap.sdc.workflow.persistence.types.WorkflowVersion; import org.onap.sdc.workflow.persistence.types.WorkflowVersionState; import org.onap.sdc.workflow.services.WorkflowVersionManager; @@ -35,30 +38,41 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { private static final String VERSION_NOT_EXIST_MSG = "version with id '%s' does not exist for workflow with id '%s'"; private final VersioningManager versioningManager; private final ArtifactRepository artifactRepository; + private final ParameterRepository parameterRepository; private final VersionMapper versionMapper; private final VersionStateMapper versionStateMapper; @Autowired public WorkflowVersionManagerImpl(VersioningManager versioningManager, ArtifactRepository artifactRepository, - VersionMapper versionMapper, VersionStateMapper versionStateMapper) { + VersionMapper versionMapper, VersionStateMapper versionStateMapper, + ParameterRepository parameterRepository) { this.versioningManager = versioningManager; this.artifactRepository = artifactRepository; + this.parameterRepository = parameterRepository; this.versionMapper = versionMapper; this.versionStateMapper = versionStateMapper; } @Override public Collection<WorkflowVersion> list(String workflowId) { - return versioningManager.list(workflowId).stream().map(versionMapper::versionToWorkflowVersion) - .collect(Collectors.toList()); + Collection<WorkflowVersion> versions = + versioningManager.list(workflowId).stream().map(versionMapper::versionToWorkflowVersion) + .collect(Collectors.toList()); + versions.forEach(workflowVersion -> addVersionParameters(workflowId,workflowVersion)); + + return versions; } @Override public WorkflowVersion get(String workflowId, String versionId) { - return versionMapper.versionToWorkflowVersion(getVersion(workflowId, versionId)); + WorkflowVersion workflowVersion = versionMapper.versionToWorkflowVersion(getVersion(workflowId, versionId)); + addVersionParameters(workflowId,workflowVersion); + return workflowVersion; + } + @Override public WorkflowVersion create(String workflowId, VersionRequestDto versionRequest) { List<Version> versions = versioningManager.list(workflowId); @@ -76,10 +90,14 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { if (versions.isEmpty()) { // only for first version artifactRepository.createStructure(workflowId, createdVersion.getId()); + parameterRepository.createStructure(workflowId, createdVersion.getId()); versioningManager.publish(workflowId, createdVersion, "Add workflow structure"); } - return versionMapper.versionToWorkflowVersion(createdVersion); + updateVersionParameters(workflowId, createdVersion.getId(), ParameterRole.INPUT, versionRequest.getInputs()); + updateVersionParameters(workflowId, createdVersion.getId(), ParameterRole.OUTPUT, versionRequest.getOutputs()); + + return get(workflowId, createdVersion.getId()); } @Override @@ -94,6 +112,9 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { version.setName(retrievedVersion.getName()); version.setStatus(retrievedVersion.getStatus()); + updateVersionParameters(workflowId, version.getId(), ParameterRole.INPUT, workflowVersion.getInputs()); + updateVersionParameters(workflowId, version.getId(), ParameterRole.OUTPUT, workflowVersion.getOutputs()); + versioningManager.updateVersion(workflowId, version); versioningManager.publish(workflowId, version, "Update version"); } @@ -168,6 +189,7 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { } } + private Version getVersion(String workflowId, String versionId) { try { Version version = versioningManager.get(workflowId, new Version(versionId)); @@ -180,7 +202,34 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { } } + private void updateVersionParameters(String workflowId, String versionId, ParameterRole role, + Collection<ParameterEntity> parameters) { + + Collection<ParameterEntity> retrievedParameters = parameterRepository.list(workflowId, versionId, role); + + parameters.forEach(parameterEntity -> { + if (retrievedParameters.stream().anyMatch( + parameterEntity1 -> parameterEntity.getName().equals(parameterEntity1.getName()))) { + parameterRepository.update(workflowId, versionId, role, parameterEntity); + } else { + parameterRepository.create(workflowId, versionId, role, parameterEntity); + } + }); + + retrievedParameters.forEach(parameterEntity -> { + if (parameters.stream().noneMatch( + parameterEntity1 -> parameterEntity.getName().equals(parameterEntity1.getName()))) { + parameterRepository.delete(workflowId, versionId, parameterEntity.getId()); + } + }); + } + private static Optional<Version> findVersion(List<Version> versions, String versionId) { return versions.stream().filter(version -> versionId.equals(version.getId())).findFirst(); } + + private void addVersionParameters(String workflowId, WorkflowVersion workflowVersion) { + workflowVersion.setInputs(parameterRepository.list(workflowId, workflowVersion.getId(), ParameterRole.INPUT)); + workflowVersion.setOutputs(parameterRepository.list(workflowId, workflowVersion.getId(), ParameterRole.OUTPUT)); + } }
\ No newline at end of file diff --git a/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java b/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java index 4bec8b97..b86b14b9 100644 --- a/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java +++ b/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java @@ -1,15 +1,40 @@ package org.onap.sdc.workflow.persistence.impl; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.isNull; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.item.Action; +import com.amdocs.zusammen.datatypes.item.ElementContext; import java.io.IOException; +import java.io.InputStream; +import java.util.Optional; +import org.apache.commons.io.IOUtils; +import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.sdc.workflow.persistence.types.ArtifactEntity; +import org.onap.sdc.workflow.persistence.types.WorkflowElementType; import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.sdc.common.session.SessionContextProviderFactory; +@RunWith(MockitoJUnitRunner.class) public class ArtifactRepositoryTest { private static final String FILE_NAME_PROPERTY = "fileName"; - private static final String EMPTY_DATA = "{}"; + private static final String FILE_NAME = "fileName.txt"; private static final String ITEM1_ID = "item_id_1"; private static final String VERSION1_ID = "version_id_1"; @@ -20,10 +45,55 @@ public class ArtifactRepositoryTest { @InjectMocks private ArtifactRepositoryImpl artifactRepository; + @Before + public void setUp() { + SessionContextProviderFactory.getInstance().createInterface().create("test_user", "workflow"); + } + @Test public void shouldUpdateArtifact() throws IOException { + InputStream inputStreamMock = IOUtils.toInputStream("some test data for my input stream", "UTF-8"); + ArtifactEntity artifactMock = new ArtifactEntity(FILE_NAME, inputStreamMock); + + artifactRepository.update(ITEM1_ID, VERSION1_ID, artifactMock); + verify(zusammenAdaptorMock) + .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + eq("Update WorkflowVersion Artifact Element")); } + @Test + public void shouldGetArtifactWhenExist() throws IOException { + + ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.UPDATE); + artifactElement.setData(IOUtils.toInputStream("some test data for my input stream", "UTF-8")); + artifactElement.getInfo().addProperty(FILE_NAME_PROPERTY, FILE_NAME); + Optional<Element> elementOptional = Optional.of(artifactElement); + + doReturn(elementOptional).when(zusammenAdaptorMock) + .getElementByName(any(SessionContext.class), any(ElementContext.class), isNull(Id.class), + eq(WorkflowElementType.ARTIFACT.name())); + + Optional<ArtifactEntity> result = artifactRepository.get(ITEM1_ID, VERSION1_ID); + assertTrue(result.isPresent()); + assertEquals(FILE_NAME,result.get().getFileName()); + verify(zusammenAdaptorMock).getElementByName(any(SessionContext.class), any(ElementContext.class), isNull(Id.class), + eq(WorkflowElementType.ARTIFACT.name())); + } + + @Test + public void shouldCreateArtifactStructure() { + artifactRepository.createStructure(ITEM1_ID, VERSION1_ID); + verify(zusammenAdaptorMock) + .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + eq("Create WorkflowVersion Artifact Element")); + } + + @Test + public void shouldDeleteArtifact(){ + artifactRepository.delete(ITEM1_ID,VERSION1_ID); + verify(zusammenAdaptorMock).saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + eq("Delete WorkflowVersion Artifact Data")); + } } diff --git a/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java b/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java new file mode 100644 index 00000000..a1708e67 --- /dev/null +++ b/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java @@ -0,0 +1,109 @@ +package org.onap.sdc.workflow.persistence.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.verify; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.datatypes.item.Info; +import java.util.Optional; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.sdc.workflow.persistence.types.ParameterEntity; +import org.onap.sdc.workflow.persistence.types.ParameterPropertyName; +import org.onap.sdc.workflow.persistence.types.ParameterRole; +import org.onap.sdc.workflow.persistence.types.ParameterType; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.sdc.common.session.SessionContextProviderFactory; + +@RunWith(MockitoJUnitRunner.class) +public class ParameterRepositoryTest { + + private static final String ITEM1_ID = "item_id_1"; + private static final String VERSION1_ID = "version_id_1"; + private static final String PARAMETER1_ID = "parameter_id_1"; + + @Mock + private ZusammenAdaptor zusammenAdaptorMock; + @Spy + @InjectMocks + private ParameterRepositoryImpl parameterRepository; + + @Before + public void setUp() { + SessionContextProviderFactory.getInstance().createInterface().create("test_user", "workflow"); + } + + @Test + public void shouldGetParameterById() { + + ZusammenElement element = new ZusammenElement(); + element.setElementId(new Id(PARAMETER1_ID)); + Info info = new Info(); + info.setName("testInput"); + info.addProperty(ParameterPropertyName.type.name(),ParameterType.FLOAT.name()); + info.addProperty(ParameterPropertyName.mandatory.name(),true); + element.setInfo(info); + doReturn(Optional.of(element)).when(zusammenAdaptorMock) + .getElement(any(SessionContext.class), any(ElementContext.class), + eq(PARAMETER1_ID)); + ParameterEntity result = parameterRepository.get(ITEM1_ID, VERSION1_ID, PARAMETER1_ID); + verify(parameterRepository,times(1)).elementToParameterEntity(element); + verify(zusammenAdaptorMock).getElement(any(SessionContext.class), any(ElementContext.class),eq(PARAMETER1_ID)); + assertEquals("testInput",result.getName()); + + } + + + @Test + public void shouldUpdateParameter() { + ParameterEntity parameterEntityToUpdate = new ParameterEntity(); + parameterEntityToUpdate.setId(PARAMETER1_ID); + parameterEntityToUpdate.setName("Input1"); + parameterEntityToUpdate.setMandatory(true); + parameterEntityToUpdate.setType(ParameterType.STRING); + + parameterRepository.update(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT, parameterEntityToUpdate); + verify(zusammenAdaptorMock) + .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + eq("Update WorkflowVersion Parameter")); + + } + + @Test + public void shouldCreateParameterStructure(){ + parameterRepository.createStructure(ITEM1_ID,VERSION1_ID); + verify(zusammenAdaptorMock) + .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + eq("Create WorkflowVersion INPUTS Element")); + verify(zusammenAdaptorMock) + .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + eq("Create WorkflowVersion OUTPUTS Element")); + } + + @Test + public void shouldDeleteParameter() { + parameterRepository.delete(ITEM1_ID, VERSION1_ID, PARAMETER1_ID); + verify(zusammenAdaptorMock) + .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class), + eq("Delete Parameter with id parameter_id_1")); + } + + + + + + + +} diff --git a/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java b/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java index 144db81e..132d966c 100644 --- a/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java +++ b/workflow/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java @@ -13,9 +13,9 @@ import static org.onap.sdc.workflow.persistence.types.WorkflowVersionState.DRAFT import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Optional; import org.apache.commons.io.IOUtils; @@ -25,10 +25,13 @@ import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatcher; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.sdc.workflow.api.types.VersionRequestDto; 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.persistence.types.WorkflowVersion; import org.onap.sdc.workflow.persistence.types.WorkflowVersionState; import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; @@ -52,11 +55,14 @@ public class WorkflowVersionManagerImplTest { @Mock private VersioningManager versioningManagerMock; @Mock + private ParameterRepository parameterRepositoryMock; + @Mock private ArtifactRepository artifactRepositoryMock; @Mock private VersionMapper versionMapperMock; @Mock private VersionStateMapper versionStateMapperMock; + @Spy @InjectMocks private WorkflowVersionManagerImpl workflowVersionManager; @@ -70,22 +76,19 @@ public class WorkflowVersionManagerImplTest { @Test public void shouldReturnWorkflowVersionWhenExist() { Version version = new Version(VERSION1_ID); - doReturn(version).when(versioningManagerMock).get(ITEM1_ID, version); - workflowVersionManager.get(ITEM1_ID, VERSION1_ID); - verify(versioningManagerMock).get(ITEM1_ID, version); + 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); } @Test public void shouldReturnWorkflowVersionList() { List<Version> versionList = Arrays.asList(new Version(VERSION1_ID), new Version(VERSION2_ID)); - versionList.forEach(version -> { - version.setBaseId("baseVersionId"); - version.setDescription("Version description"); - version.setName("name"); - version.setCreationTime(new Date()); - version.setModificationTime(new Date()); - }); doReturn(versionList).when(versioningManagerMock).list(ITEM1_ID); + doReturn(new WorkflowVersion()).when(versionMapperMock).versionToWorkflowVersion(any(Version.class)); workflowVersionManager.list(ITEM1_ID); verify(versioningManagerMock).list(ITEM1_ID); verify(versionMapperMock, times(2)).versionToWorkflowVersion(any(Version.class)); @@ -93,6 +96,7 @@ public class WorkflowVersionManagerImplTest { @Test public void shouldUpdateWorkflowVersion() { + String updatedDescription = "WorkflowVersion description updated"; Version retrievedVersion = new Version(VERSION1_ID); retrievedVersion.setName("1.0"); retrievedVersion.setDescription("WorkflowVersion description"); @@ -102,11 +106,13 @@ public class WorkflowVersionManagerImplTest { WorkflowVersion inputVersion = new WorkflowVersion(VERSION1_ID); inputVersion.setName("1.0"); - inputVersion.setDescription("WorkflowVersion description updated"); + inputVersion.setDescription(updatedDescription); + inputVersion.setInputs(new ArrayList<>()); + inputVersion.setOutputs(new ArrayList<>()); Version mappedInputVersion = new Version(VERSION1_ID); mappedInputVersion.setName("1.0"); - mappedInputVersion.setDescription("WorkflowVersion description updated"); + mappedInputVersion.setDescription(updatedDescription); doReturn(mappedInputVersion).when(versionMapperMock).workflowVersionToVersion(inputVersion); ArgumentCaptor<Version> versionArgCaptor = ArgumentCaptor.forClass(Version.class); @@ -115,20 +121,23 @@ public class WorkflowVersionManagerImplTest { verify(versioningManagerMock).updateVersion(eq(ITEM1_ID), versionArgCaptor.capture()); Version captorVersion = versionArgCaptor.getValue(); assertEquals("1.0", captorVersion.getName()); - assertEquals("WorkflowVersion description updated", captorVersion.getDescription()); + assertEquals(updatedDescription, captorVersion.getDescription()); assertEquals(VersionStatus.Draft, captorVersion.getStatus()); verify(versioningManagerMock).publish(ITEM1_ID, mappedInputVersion, "Update version"); } + @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); - VersionRequestDto workflowVersion = new VersionRequestDto(); - workflowVersion.setDescription("version desc"); - workflowVersionManager.create(ITEM1_ID, workflowVersion); - verify(versioningManagerMock).create(ITEM1_ID, version, VersionCreationMethod.major); + doReturn(version).when(versioningManagerMock).create(ITEM1_ID,version, VersionCreationMethod.major); + VersionRequestDto versionRequest = new VersionRequestDto(); + versionRequest.setDescription("version desc"); + WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID); + doReturn(workflowVersion).when(workflowVersionManager).get(ITEM1_ID,VERSION1_ID); + workflowVersionManager.create(ITEM1_ID,versionRequest); + verify(versioningManagerMock).create(ITEM1_ID,version, VersionCreationMethod.major); } |