aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be
diff options
context:
space:
mode:
authortalig <talig@amdocs.com>2019-11-20 15:13:47 +0200
committertalig <talig@amdocs.com>2019-11-20 15:14:44 +0200
commitc54aacb32df8fcb27375d1b131f76afc0a34d0c7 (patch)
tree8f2f0d927051a65a391744af845fdd760fbd523a /workflow-designer-be
parent820f4ec65a28ed822d4205b05ac6fbbd910a46cc (diff)
Use versioning, zusammen and session libs from sdc-common-be
zusammen-lib in sdc-common-be uses cassandra 3.6.0 withoutJMXReporting (cassandra 3.4.0 with spring boot 2.1.0 caused: java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter) Change-Id: I248442d519b2ad5f4869e9384e447e9004d24586 Issue-ID: SDC-2541 Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'workflow-designer-be')
-rw-r--r--workflow-designer-be/pom.xml74
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java2
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ActivitySpecController.java11
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ExceptionsHandler.java3
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImpl.java28
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java33
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java60
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecEntity.java7
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WorkflowZusammenConfigProvider.java48
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ZusammenConfig.java96
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java25
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStatusModificationException.java2
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowStatusModificationException.java26
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImpl.java159
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/CollaborationConfiguration.java45
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java71
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java52
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ActivitySpecMapper.java19
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ArchivingStatusMapper.java36
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java18
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java11
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java32
-rw-r--r--workflow-designer-be/src/main/resources/application-dev.properties58
-rw-r--r--workflow-designer-be/src/main/resources/application.properties1
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java16
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImplTest.java285
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java36
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java36
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImplTest.java98
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java71
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java180
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java19
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java9
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java19
34 files changed, 641 insertions, 1045 deletions
diff --git a/workflow-designer-be/pom.xml b/workflow-designer-be/pom.xml
index 601f10ee..8dd35566 100644
--- a/workflow-designer-be/pom.xml
+++ b/workflow-designer-be/pom.xml
@@ -15,7 +15,7 @@
<properties>
<spring.boot.version>2.1.0.RELEASE</spring.boot.version>
- <mapstruct.version>1.2.0.Final</mapstruct.version>
+ <mapstruct.version>1.3.1.Final</mapstruct.version>
<lombok.version>1.18.0</lombok.version>
<springfox.version>2.8.0</springfox.version>
</properties>
@@ -73,11 +73,6 @@
</dependency>
<dependency>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-versioning-api</artifactId>
- <version>${onap.version}</version>
- </dependency>
- <dependency>
- <groupId>org.openecomp.sdc</groupId>
<artifactId>openecomp-sdc-logging-api</artifactId>
<version>${onap.version}</version>
</dependency>
@@ -98,35 +93,12 @@
<scope>runtime</scope>
</dependency>
<dependency>
- <groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-versioning-core</artifactId>
- <version>${onap.version}</version>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.openecomp.sdc.core</groupId>
- <artifactId>openecomp-zusammen-api</artifactId>
- <version>${onap.version}</version>
- </dependency>
- <dependency>
- <groupId>org.openecomp.sdc.core</groupId>
- <artifactId>openecomp-zusammen-core</artifactId>
- <version>${onap.version}</version>
- <scope>runtime</scope>
- <exclusions>
- <exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
- <artifactId>mapstruct-jdk8</artifactId>
+ <artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
@@ -146,6 +118,48 @@
<artifactId>spring-boot-starter-actuator</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-text</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.sdc.sdc-be-common</groupId>
+ <artifactId>session-lib</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.sdc.sdc-be-common</groupId>
+ <artifactId>versioning-lib</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-cassandra</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.sdc.sdc-be-common</groupId>
+ <artifactId>zusammen-lib</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-cassandra</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
<build>
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java
index 0feafd2a..87de212e 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java
@@ -21,8 +21,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
+@ComponentScan( {"org.onap.sdc.common", "org.onap.sdc.workflow"})
public class SpringBootWebApplication {
public static void main(String[] args) {
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ActivitySpecController.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ActivitySpecController.java
index dca6c695..ac72d46e 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ActivitySpecController.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ActivitySpecController.java
@@ -23,7 +23,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
-import java.util.Objects;
import java.util.stream.Collectors;
import javax.validation.Valid;
import org.onap.sdc.workflow.api.mappers.ActivitySpecDtoMapper;
@@ -35,7 +34,6 @@ import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecRequest;
import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecResponse;
import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity;
import org.onap.sdc.workflow.services.ActivitySpecManager;
-import org.openecomp.sdc.versioning.dao.types.Version;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
@@ -83,8 +81,7 @@ public class ActivitySpecController {
public ResponseEntity<ActivitySpecCreateResponse> create(@Valid @RequestBody ActivitySpecRequest request) {
ActivitySpecEntity activitySpec =
activitySpecManager.createActivitySpec(activitySpecDtoMapper.fromActivitySpecRequest(request));
- return new ResponseEntity<>(new ActivitySpecCreateResponse(activitySpec.getId(),
- Objects.nonNull(activitySpec.getVersion()) ? activitySpec.getVersion().getId() : null),
+ return new ResponseEntity<>(new ActivitySpecCreateResponse(activitySpec.getId(),activitySpec.getVersionId()),
HttpStatus.CREATED);
}
@@ -95,7 +92,7 @@ public class ActivitySpecController {
@ApiParam(value = "Version Id", defaultValue = VERSION_ID_DEFAULT_VALUE) @PathVariable("versionId")
String versionId) {
return activitySpecDtoMapper.toActivitySpecDataResponse(
- activitySpecManager.get(new ActivitySpecEntity(activitySpecId, new Version(versionId))));
+ activitySpecManager.get(new ActivitySpecEntity(activitySpecId, versionId)));
}
@PutMapping("/{id}/versions/{versionId}")
@@ -107,7 +104,7 @@ public class ActivitySpecController {
String versionId) {
ActivitySpecEntity activitySpec = activitySpecDtoMapper.fromActivitySpecRequest(request);
activitySpec.setId(activitySpecId);
- activitySpec.setVersion(new Version(versionId));
+ activitySpec.setVersionId(versionId);
activitySpecManager.update(activitySpec);
}
@@ -122,6 +119,6 @@ public class ActivitySpecController {
@ApiParam(value = "Version Id", defaultValue = VERSION_ID_DEFAULT_VALUE) @PathVariable("versionId")
String versionId) {
activitySpecManager
- .actOnAction(new ActivitySpecEntity(activitySpecId, new Version(versionId)), request.getAction());
+ .actOnAction(new ActivitySpecEntity(activitySpecId, versionId), request.getAction());
}
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ExceptionsHandler.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ExceptionsHandler.java
index 083206c8..70633d41 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ExceptionsHandler.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ExceptionsHandler.java
@@ -35,7 +35,6 @@ import org.onap.sdc.workflow.services.exceptions.VersionStateModificationExcepti
import org.onap.sdc.workflow.services.exceptions.VersionStateModificationMissingArtifactException;
import org.onap.sdc.workflow.services.exceptions.VersionStatusModificationException;
import org.onap.sdc.workflow.services.exceptions.WorkflowModificationException;
-import org.onap.sdc.workflow.services.exceptions.WorkflowStatusModificationException;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.springframework.context.support.DefaultMessageSourceResolvable;
@@ -96,7 +95,7 @@ public class ExceptionsHandler extends ResponseEntityExceptionHandler {
VersionStateModificationException.class,
VersionStateModificationMissingArtifactException.class,
VersionStatusModificationException.class,
- UniqueValueViolationException.class, WorkflowStatusModificationException.class,
+ UniqueValueViolationException.class,
WorkflowModificationException.class})
public final ResponseEntity<ErrorResponse> handleUnprocessableEntityException(Exception exception) {
LOG.debug(LOG_MSG, UNPROCESSABLE_ENTITY, exception);
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImpl.java
index 726e831c..b304f900 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImpl.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImpl.java
@@ -16,12 +16,10 @@
package org.onap.sdc.workflow.persistence.impl;
-import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
-import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
+import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.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.SessionContext;
import com.amdocs.zusammen.datatypes.item.Action;
import com.amdocs.zusammen.datatypes.item.ElementContext;
import com.amdocs.zusammen.datatypes.item.Info;
@@ -29,13 +27,14 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Objects;
import java.util.Optional;
+import org.onap.sdc.common.versioning.persistence.zusammen.ZusammenSessionContextCreator;
+import org.onap.sdc.common.zusammen.services.ZusammenAdaptor;
import org.onap.sdc.workflow.persistence.ActivitySpecRepository;
import org.onap.sdc.workflow.persistence.impl.types.ActivitySpecData;
import org.onap.sdc.workflow.persistence.impl.types.ActivitySpecElementType;
import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity;
import org.onap.sdc.workflow.services.ActivitySpecConstant;
import org.onap.sdc.workflow.services.utilities.JsonUtil;
-import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@@ -43,40 +42,39 @@ import org.springframework.stereotype.Repository;
public class ActivitySpecRepositoryImpl implements ActivitySpecRepository {
private final ZusammenAdaptor zusammenAdaptor;
+ private final ZusammenSessionContextCreator contextCreator;
@Autowired
- public ActivitySpecRepositoryImpl(ZusammenAdaptor zusammenAdaptor) {
+ public ActivitySpecRepositoryImpl(ZusammenAdaptor zusammenAdaptor, ZusammenSessionContextCreator contextCreator) {
this.zusammenAdaptor = zusammenAdaptor;
+ this.contextCreator = contextCreator;
}
@Override
public void create(ActivitySpecEntity activitySpec) {
- SessionContext context = createSessionContext();
ZusammenElement generalElement = mapActivityDetailsToZusammenElement(activitySpec, Action.CREATE);
- ElementContext elementContext = new ElementContext(activitySpec.getId(), activitySpec.getVersion().getId());
+ ElementContext elementContext = new ElementContext(activitySpec.getId(), activitySpec.getVersionId());
zusammenAdaptor
- .saveElement(context, elementContext, generalElement, "Create Activity Spec General Info Element");
+ .saveElement(contextCreator.create(), elementContext, generalElement, "Create Activity Spec General Info Element");
}
@Override
public ActivitySpecEntity get(ActivitySpecEntity entity) {
- SessionContext context = createSessionContext();
-
- ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersion().getId());
+ ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersionId());
Optional<Element> element =
- zusammenAdaptor.getElementByName(context, elementContext, null, ActivitySpecElementType.ACTIVITYSPEC.name());
+ zusammenAdaptor.getElementByName(contextCreator.create(), elementContext, null, ActivitySpecElementType.ACTIVITYSPEC.name());
return element.map(this::mapZusammenElementToActivityDetails).orElse(null);
}
@Override
public void update(ActivitySpecEntity entity) {
- SessionContext context = createSessionContext();
+
ZusammenElement generalElement = mapActivityDetailsToZusammenElement(entity, Action.UPDATE);
- ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersion().getId());
+ ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersionId());
zusammenAdaptor
- .saveElement(context, elementContext, generalElement, "Update Activity Spec General Info Element");
+ .saveElement(contextCreator.create(), elementContext, generalElement, "Update Activity Spec General Info Element");
}
private ZusammenElement mapActivityDetailsToZusammenElement(ActivitySpecEntity entity, Action action) {
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java
index 06e2a638..4ad54614 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java
@@ -16,13 +16,11 @@
package org.onap.sdc.workflow.persistence.impl;
-import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
-import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
+import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.buildStructuralElement;
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.SessionContext;
import com.amdocs.zusammen.datatypes.item.Action;
import com.amdocs.zusammen.datatypes.item.ElementContext;
import java.io.ByteArrayInputStream;
@@ -31,10 +29,11 @@ import java.io.InputStream;
import java.util.Arrays;
import java.util.Optional;
import org.apache.commons.io.IOUtils;
+import org.onap.sdc.common.versioning.persistence.zusammen.ZusammenSessionContextCreator;
+import org.onap.sdc.common.zusammen.services.ZusammenAdaptor;
import org.onap.sdc.workflow.persistence.ArtifactRepository;
-import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType;
-import org.openecomp.core.zusammen.api.ZusammenAdaptor;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@@ -45,10 +44,12 @@ public class ArtifactRepositoryImpl implements ArtifactRepository {
private static final String EMPTY_DATA = "{}";
private final ZusammenAdaptor zusammenAdaptor;
+ private final ZusammenSessionContextCreator contextCreator;
@Autowired
- public ArtifactRepositoryImpl(ZusammenAdaptor zusammenAdaptor) {
+ public ArtifactRepositoryImpl(ZusammenAdaptor zusammenAdaptor, ZusammenSessionContextCreator contextCreator) {
this.zusammenAdaptor = zusammenAdaptor;
+ this.contextCreator = contextCreator;
}
@Override
@@ -58,20 +59,20 @@ public class ArtifactRepositoryImpl implements ArtifactRepository {
artifactElement.setData(artifactEntity.getArtifactData());
artifactElement.getInfo().addProperty(FILE_NAME_PROPERTY, artifactEntity.getFileName());
- SessionContext context = createSessionContext();
+
ElementContext elementContext = new ElementContext(workflowId, versionId);
zusammenAdaptor
- .saveElement(context, elementContext, artifactElement, "Update WorkflowVersion Artifact Element");
+ .saveElement(contextCreator.create(), elementContext, artifactElement, "Update WorkflowVersion Artifact Element");
}
@Override
public Optional<ArtifactEntity> get(String workflowId, String versionId) {
- SessionContext context = createSessionContext();
+
ElementContext elementContext = new ElementContext(workflowId, versionId);
Optional<Element> elementOptional =
- zusammenAdaptor.getElementByName(context, elementContext, null, WorkflowElementType.ARTIFACT.name());
+ zusammenAdaptor.getElementByName(contextCreator.create(), elementContext, null, WorkflowElementType.ARTIFACT.name());
if (!elementOptional.isPresent() || hasEmptyData(elementOptional.get().getData())) {
return Optional.empty();
@@ -87,10 +88,10 @@ public class ArtifactRepositoryImpl implements ArtifactRepository {
@Override
public boolean isExist(String workflowId, String versionId) {
- SessionContext context = createSessionContext();
+
ElementContext elementContext = new ElementContext(workflowId, versionId);
- Optional<ElementInfo> optionalElementInfo = zusammenAdaptor.getElementInfoByName(context, elementContext, null,
+ Optional<ElementInfo> optionalElementInfo = zusammenAdaptor.getElementInfoByName(contextCreator.create(), elementContext, null,
WorkflowElementType.ARTIFACT.name());
return optionalElementInfo.isPresent() && optionalElementInfo.get().getInfo().getProperties()
.containsKey(FILE_NAME_PROPERTY);
@@ -98,27 +99,27 @@ public class ArtifactRepositoryImpl implements ArtifactRepository {
@Override
public void createStructure(String workflowId, String versionId) {
- SessionContext context = createSessionContext();
+
ElementContext elementContext = new ElementContext(workflowId, versionId);
ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.CREATE);
artifactElement.setData(new ByteArrayInputStream(EMPTY_DATA.getBytes()));
zusammenAdaptor
- .saveElement(context, elementContext, artifactElement, "Create WorkflowVersion Artifact Element");
+ .saveElement(contextCreator.create(), elementContext, artifactElement, "Create WorkflowVersion Artifact Element");
}
@Override
public void delete(String workflowId, String versionId) {
- SessionContext context = createSessionContext();
+
ElementContext elementContext = new ElementContext(workflowId, versionId);
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, "Delete WorkflowVersion Artifact Data");
+ zusammenAdaptor.saveElement(contextCreator.create(), elementContext, artifactElement, "Delete WorkflowVersion Artifact Data");
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java
index 00dadead..eeef2477 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java
@@ -16,29 +16,28 @@
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 static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.ELEMENT_TYPE_PROPERTY;
+import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.buildElement;
+import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.buildStructuralElement;
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.Collection;
import java.util.Optional;
import java.util.stream.Collectors;
+import org.onap.sdc.common.versioning.persistence.zusammen.ZusammenSessionContextCreator;
+import org.onap.sdc.common.zusammen.services.ZusammenAdaptor;
import org.onap.sdc.workflow.persistence.ParameterRepository;
import org.onap.sdc.workflow.persistence.impl.types.ParameterPropertyName;
import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType;
import org.onap.sdc.workflow.persistence.types.ParameterEntity;
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.types.ElementPropertyName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@@ -46,90 +45,80 @@ import org.springframework.stereotype.Repository;
public class ParameterRepositoryImpl implements ParameterRepository {
private final ZusammenAdaptor zusammenAdaptor;
+ private final ZusammenSessionContextCreator contextCreator;
@Autowired
- public ParameterRepositoryImpl(ZusammenAdaptor zusammenAdaptor) {
+ public ParameterRepositoryImpl(ZusammenAdaptor zusammenAdaptor, ZusammenSessionContextCreator contextCreator) {
this.zusammenAdaptor = zusammenAdaptor;
+ this.contextCreator = contextCreator;
}
@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");
+ zusammenAdaptor.saveElement(contextCreator.create(), elementContext, inputsElement, "Create WorkflowVersion INPUTS Element");
+ zusammenAdaptor.saveElement(contextCreator.create(), 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, getParentElementType(role)).stream()
- .map(this::mapElementInfoToParameter).collect(Collectors.toList());
-
+ return zusammenAdaptor.listElementsByName(contextCreator.create(), elementContext, null, getParentElementType(role)).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));
+ zusammenAdaptor.getElementInfoByName(contextCreator.create(), elementContext, null, getParentElementType(role));
if (!optionalParentElement.isPresent()) {
- throw new IllegalStateException(String.format("Missing data for workflow id %s version id %s",id,versionId));
+ throw new IllegalStateException(
+ String.format("Missing data for workflow id %s version id %s", id, versionId));
}
ZusammenElement parentElement = buildElement(optionalParentElement.get().getId(), Action.IGNORE);
parentElement.setSubElements(optionalParentElement.get().getSubElements().stream()
- .map(parameter -> buildElement(parameter.getId(),
- Action.DELETE)).collect(Collectors.toList()));
+ .map(parameter -> buildElement(parameter.getId(), Action.DELETE))
+ .collect(Collectors.toList()));
- zusammenAdaptor.saveElement(context, elementContext, parentElement, "Delete all " + role);
+ zusammenAdaptor.saveElement(contextCreator.create(), 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));
+ Optional<ElementInfo> element = zusammenAdaptor.getElementInfo(contextCreator.create(), 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,
+ zusammenAdaptor.saveElement(contextCreator.create(), 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,
+ Element savedElement = zusammenAdaptor.saveElement(contextCreator.create(), elementContext, parentElement,
"Create WorkflowVersion Parameter Element");
parameter.setId(savedElement.getSubElements().iterator().next().getElementId().getValue());
@@ -138,22 +127,19 @@ public class ParameterRepositoryImpl implements ParameterRepository {
@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");
+ zusammenAdaptor.saveElement(contextCreator.create(), 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(ELEMENT_TYPE_PROPERTY, WorkflowElementType.valueOf(role.name()));
info.addProperty(ParameterPropertyName.TYPE.name(), parameter.getType());
info.addProperty(ParameterPropertyName.MANDATORY.name(), parameter.isMandatory());
parameterElement.setInfo(info);
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecEntity.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecEntity.java
index cf2db9a1..cf3be394 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecEntity.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecEntity.java
@@ -18,14 +18,13 @@ package org.onap.sdc.workflow.persistence.types;
import java.util.List;
import lombok.NoArgsConstructor;
-import org.openecomp.sdc.versioning.dao.types.Version;
@lombok.Data
@NoArgsConstructor
public class ActivitySpecEntity {
private String id;
- private Version version;
+ private String versionId;
private String name;
private String description;
@@ -38,8 +37,8 @@ public class ActivitySpecEntity {
//Not to be maintained in activityspec element
private String status;
- public ActivitySpecEntity(String id, Version version) {
+ public ActivitySpecEntity(String id, String versionId) {
this.id = id;
- this.version = version;
+ this.versionId = versionId;
}
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WorkflowZusammenConfigProvider.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WorkflowZusammenConfigProvider.java
new file mode 100644
index 00000000..dbd2d6de
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WorkflowZusammenConfigProvider.java
@@ -0,0 +1,48 @@
+/*
+ * 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.server.config;
+
+import lombok.Getter;
+import org.onap.sdc.common.zusammen.config.ZusammenConfigProvider;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@Getter
+public class WorkflowZusammenConfigProvider implements ZusammenConfigProvider {
+
+ @Value("${spring.data.cassandra.keyspace-name}")
+ private String tenant;
+ @Value("${spring.data.cassandra.contact-points}")
+ private String cassandraAddresses;
+ @Value("${spring.data.cassandra.port}")
+ private String cassandraPort;
+
+ @Value("${spring.data.cassandra.username}")
+ private String cassandraUser;
+ @Value("${spring.data.cassandra.password}")
+ private String cassandraPassword;
+ @Value("${zusammen.cassandra.isAuthenticate}")
+ private String cassandraAuth;
+ @Value("${spring.data.cassandra.ssl}")
+
+ private String cassandraSSL;
+ @Value("${zusammen.cassandra.trustStorePath}")
+ private String cassandraTrustStorePath;
+ @Value("${zusammen.cassandra.trustStorePassword}")
+ private String cassandraTrustStorePassword;
+} \ No newline at end of file
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ZusammenConfig.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ZusammenConfig.java
deleted file mode 100644
index 700b1b9f..00000000
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ZusammenConfig.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.server.config;
-
-import com.datastax.driver.core.RemoteEndpointAwareJdkSSLOptions;
-import com.datastax.driver.core.SSLOptions;
-import java.io.FileInputStream;
-import java.security.KeyStore;
-import java.security.SecureRandom;
-import javax.annotation.PostConstruct;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManagerFactory;
-import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.autoconfigure.cassandra.ClusterBuilderCustomizer;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class ZusammenConfig {
-
- @Value("${spring.data.cassandra.keyspace-name}")
- private String tenant;
- @Value("${spring.data.cassandra.contact-points}")
- private String cassandraAddress;
- @Value("${spring.data.cassandra.username}")
- private String cassandraUser;
- @Value("${spring.data.cassandra.password}")
- private String cassandraPassword;
- @Value("${zusammen.cassandra.isAuthenticate}")
- private String cassandraAuth;
- @Value("${spring.data.cassandra.ssl}")
- private String cassandraSSL;
- @Value("${zusammen.cassandra.trustStorePath}")
- private String cassandraTrustStorePath;
- @Value("${zusammen.cassandra.trustStorePassword}")
- private String cassandraTrustStorePassword;
-
- private static final String[] CIPHER_SUITES = {"TLS_RSA_WITH_AES_128_CBC_SHA"};
- private static final String KEYSTORE_TYPE = "JKS";
- private static final String SECURE_SOCKET_PROTOCOL = "SSL";
-
- @PostConstruct
- public void init() {
- System.setProperty("cassandra.nodes", cassandraAddress);
- System.setProperty("cassandra.user", cassandraUser);
- System.setProperty("cassandra.password", cassandraPassword);
- System.setProperty("cassandra.authenticate", Boolean.toString(Boolean.valueOf(cassandraAuth)));
- System.setProperty("cassandra.ssl", Boolean.toString(Boolean.valueOf(cassandraSSL)));
- System.setProperty("cassandra.truststore", cassandraTrustStorePath);
- System.setProperty("cassandra.truststore.password", cassandraTrustStorePassword);
- }
-
- public String getTenant() {
- return tenant;
- }
-
- @Bean
- @ConditionalOnProperty("spring.data.cassandra.ssl")
- ClusterBuilderCustomizer clusterBuilderCustomizer() {
- SSLOptions sslOptions = RemoteEndpointAwareJdkSSLOptions
- .builder()
- .withSSLContext(getSslContext())
- .withCipherSuites(CIPHER_SUITES).build();
- return builder -> builder.withSSL(sslOptions);
- }
-
- private SSLContext getSslContext() {
- try (FileInputStream tsf = new FileInputStream(cassandraTrustStorePath)) {
- SSLContext ctx = SSLContext.getInstance(SECURE_SOCKET_PROTOCOL);
- KeyStore ts = KeyStore.getInstance(KEYSTORE_TYPE);
- ts.load(tsf, cassandraTrustStorePassword.toCharArray());
- TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- tmf.init(ts);
- ctx.init(null, tmf.getTrustManagers(), new SecureRandom());
- return ctx;
- } catch (Exception ex) {
- throw new BeanCreationException(ex.getMessage(), ex);
- }
- }
-} \ No newline at end of file
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java
index e9742fcd..57cda856 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java
@@ -24,20 +24,21 @@ import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
-import org.onap.sdc.workflow.server.config.ZusammenConfig;
-import org.openecomp.sdc.common.session.SessionContextProvider;
-import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+import org.onap.sdc.common.session.SessionContextProvider;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class SessionContextFilter implements Filter {
- private ZusammenConfig zusammenConfig;
+ private final SessionContextProvider sessionContextProvider;
+ @Value("${spring.data.cassandra.keyspace-name}")
+ private String tenant;
@Autowired
- public SessionContextFilter(ZusammenConfig zusammenConfig) {
- this.zusammenConfig = zusammenConfig;
+ public SessionContextFilter(SessionContextProvider sessionContextProvider) {
+ this.sessionContextProvider = sessionContextProvider;
}
@Override
@@ -48,16 +49,14 @@ public class SessionContextFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
- SessionContextProvider contextProvider = SessionContextProviderFactory.getInstance().createInterface();
-
try {
if (servletRequest instanceof HttpServletRequest) {
- contextProvider.create(getUser(servletRequest), getTenant());
+ sessionContextProvider.create(getUser(servletRequest), tenant);
}
filterChain.doFilter(servletRequest, servletResponse);
} finally {
- contextProvider.close();
+ sessionContextProvider.close();
}
}
@@ -69,10 +68,6 @@ public class SessionContextFilter implements Filter {
private String getUser(ServletRequest servletRequest) {
return "GLOBAL_USER";
// TODO: 7/11/2018 get user from header when collaboration will be supported
- //((HttpServletRequest) servletRequest).getHeader(USER_ID_HEADER_PARAM);
- }
-
- private String getTenant() {
- return zusammenConfig.getTenant();
+ //((HttpServletRequest) servletRequest).getHeader(USER_ID_HEADER_PARAM);
}
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStatusModificationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStatusModificationException.java
index 4eb8af42..917a8384 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStatusModificationException.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStatusModificationException.java
@@ -16,7 +16,7 @@
package org.onap.sdc.workflow.services.exceptions;
-import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.onap.sdc.common.versioning.services.types.VersionStatus;
public class VersionStatusModificationException extends RuntimeException {
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowStatusModificationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowStatusModificationException.java
deleted file mode 100644
index 380b1405..00000000
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowStatusModificationException.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.services.exceptions;
-
-import org.openecomp.sdc.common.errors.CoreException;
-
-public class WorkflowStatusModificationException extends RuntimeException {
-
- public WorkflowStatusModificationException(CoreException ex) {
- super(ex.getMessage());
- }
-}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImpl.java
index 640affe8..e1849b9f 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImpl.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImpl.java
@@ -16,12 +16,12 @@
package org.onap.sdc.workflow.services.impl;
+import static org.onap.sdc.common.versioning.services.types.VersionStatus.Certified;
+import static org.onap.sdc.common.versioning.services.types.VersionStatus.Deleted;
+import static org.onap.sdc.common.versioning.services.types.VersionStatus.Deprecated;
+import static org.onap.sdc.common.versioning.services.types.VersionStatus.Draft;
import static org.onap.sdc.workflow.services.ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND;
import static org.onap.sdc.workflow.services.ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Deleted;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Deprecated;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Draft;
import java.util.Collection;
import java.util.Collections;
@@ -32,6 +32,12 @@ import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
+import org.onap.sdc.common.versioning.services.ItemManager;
+import org.onap.sdc.common.versioning.services.VersioningManager;
+import org.onap.sdc.common.versioning.services.types.Item;
+import org.onap.sdc.common.versioning.services.types.Version;
+import org.onap.sdc.common.versioning.services.types.VersionCreationMethod;
+import org.onap.sdc.common.versioning.services.types.VersionStatus;
import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecAction;
import org.onap.sdc.workflow.persistence.ActivitySpecRepository;
import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity;
@@ -40,15 +46,8 @@ import org.onap.sdc.workflow.services.UniqueValueService;
import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
import org.onap.sdc.workflow.services.exceptions.VersionStatusModificationException;
import org.onap.sdc.workflow.services.impl.mappers.ActivitySpecMapper;
-import org.openecomp.sdc.common.errors.SdcRuntimeException;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.sdc.versioning.ItemManager;
-import org.openecomp.sdc.versioning.VersioningManager;
-import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.sdc.versioning.dao.types.VersionStatus;
-import org.openecomp.sdc.versioning.types.Item;
-import org.openecomp.sdc.versioning.types.VersionCreationMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@@ -91,13 +90,15 @@ public class ActivitySpecManagerImpl implements ActivitySpecManager {
uniqueValueService.validateUniqueValue(ACTIVITY_SPEC_NAME, activitySpec.getName());
- Item item = activitySpecMapper.activitySpecToItem(activitySpec);
- item = itemManager.create(item);
+ Item item = new Item();
+ activitySpecMapper.toItem(activitySpec, item);
+ Item createdItem = itemManager.create(item);
- Version version = getActivitySpecVersion(activitySpec);
- versioningManager.create(item.getId(), version, VersionCreationMethod.major);
+ Version createdVersion =
+ versioningManager.create(createdItem.getId(), null, new Version(), VersionCreationMethod.major);
- enrichActivitySpec(item, version, activitySpec);
+ activitySpec.setId(createdItem.getId());
+ activitySpec.setVersionId(createdVersion.getId());
activitySpecDao.create(activitySpec);
uniqueValueService.createUniqueValue(ACTIVITY_SPEC_NAME, activitySpec.getName());
@@ -106,18 +107,18 @@ public class ActivitySpecManagerImpl implements ActivitySpecManager {
@Override
public ActivitySpecEntity get(ActivitySpecEntity activitySpec) {
- activitySpec.setVersion(calculateLatestVersion(activitySpec));
+ activitySpec.setVersionId(calculateLatestVersion(activitySpec));
ActivitySpecEntity retrieved;
try {
+
retrieved = activitySpecDao.get(activitySpec);
- } catch (SdcRuntimeException runtimeException) {
- LOGGER.debug(
- "Failed to retrieve activity spec for activitySpecId: " + activitySpec.getId() + " and version: "
- + activitySpec.getVersion().getId(), runtimeException);
+ } catch (RuntimeException e) {
+ LOGGER.error("Failed to retrieve activity spec for activitySpecId: {} and version: {}",
+ activitySpec.getId(), activitySpec.getVersionId(), e);
throw new EntityNotFoundException(ACTIVITY_SPEC_NOT_FOUND);
}
if (retrieved != null) {
- final Version retrievedVersion = versioningManager.get(activitySpec.getId(), activitySpec.getVersion());
+ final Version retrievedVersion = versioningManager.get(activitySpec.getId(), activitySpec.getVersionId());
retrieved.setStatus(Objects.nonNull(retrievedVersion) ? retrievedVersion.getStatus().name() : null);
}
return retrieved;
@@ -125,74 +126,66 @@ public class ActivitySpecManagerImpl implements ActivitySpecManager {
@Override
public void update(ActivitySpecEntity activitySpec) {
- Item retrievedItem = itemManager.get(activitySpec.getId());
- if (retrievedItem == null) {
+ Item item = itemManager.get(activitySpec.getId());
+ if (item == null) {
LOGGER.error("Activity Spec with id {} was not found", activitySpec.getId());
throw new EntityNotFoundException(ACTIVITY_SPEC_NOT_FOUND);
}
- uniqueValueService.updateUniqueValue(ACTIVITY_SPEC_NAME, retrievedItem.getName(), activitySpec.getName());
+ uniqueValueService.updateUniqueValue(ACTIVITY_SPEC_NAME, item.getName(), activitySpec.getName());
- Item item = activitySpecMapper.activitySpecToItem(activitySpec);
- item.setId(activitySpec.getId());
- item.setStatus(retrievedItem.getStatus());
- item.setVersionStatusCounters(retrievedItem.getVersionStatusCounters());
- itemManager.update(item);
+ activitySpecMapper.toItem(activitySpec, item);
+ itemManager.update(activitySpec.getId(), item);
- activitySpec.setVersion(calculateLatestVersion(activitySpec));
+ activitySpec.setVersionId(calculateLatestVersion(activitySpec));
activitySpecDao.update(activitySpec);
}
@Override
public void actOnAction(ActivitySpecEntity activitySpec, ActivitySpecAction action) {
- Version version = calculateLatestVersion(activitySpec);
- if (action == ActivitySpecAction.CERTIFY) {
- version.setStatus(Certified);
- }
- if (action == ActivitySpecAction.DEPRECATE) {
- version.setStatus(Deprecated);
- }
- if (action == ActivitySpecAction.DELETE) {
- version.setStatus(Deleted);
- }
-
- updateVersionStatus(activitySpec.getId(), action, version);
- if (action == ActivitySpecAction.DELETE) {
- final String activitySpecName = get(new ActivitySpecEntity(activitySpec.getId(), version)).getName();
- uniqueValueService.deleteUniqueValue(ACTIVITY_SPEC_NAME, activitySpecName);
- }
- }
+ VersionStatus newStatus = getVersionStatusByAction(action);
- private void updateVersionStatus(String activitySpecId, ActivitySpecAction action, Version version) {
- VersionStatus prevVersionStatus = null;
+ String versionId = calculateLatestVersion(activitySpec);
Version retrievedVersion;
try {
- retrievedVersion = versioningManager.get(activitySpecId, version);
- } catch (SdcRuntimeException exception) {
- LOGGER.debug(
- "Failed to get version for activitySpecId: " + activitySpecId + " and version: " + version.getId(),
- exception);
+ retrievedVersion = versioningManager.get(activitySpec.getId(), versionId);
+ } catch (RuntimeException e) {
+ LOGGER.error("failed to get activity {}, version {}", activitySpec.getId(), versionId, e);
+ throw new EntityNotFoundException(ACTIVITY_SPEC_NOT_FOUND);
+ }
+ if (retrievedVersion == null) {
throw new EntityNotFoundException(ACTIVITY_SPEC_NOT_FOUND);
+ }
+ VersionStatus retrievedStatus = retrievedVersion.getStatus();
+ VersionStatus expectedPrevStatus = EXPECTED_PREV_STATUS.get(newStatus);
+ if (expectedPrevStatus != null && retrievedStatus != expectedPrevStatus) {
+ LOGGER.debug("Failed to {} since activity spec is in status {}", action.name(), retrievedStatus);
+ throw new VersionStatusModificationException(activitySpec.getId(), versionId, retrievedStatus,
+ newStatus);
}
- VersionStatus status = version.getStatus();
- VersionStatus expectedPrevStatus = EXPECTED_PREV_STATUS.get(status);
- if (expectedPrevStatus != null) {
+ versioningManager.updateStatus(activitySpec.getId(), retrievedVersion.getId(), newStatus,
+ "actionOnActivitySpec :" + action.name());
- VersionStatus retrievedStatus = Objects.nonNull(retrievedVersion) ? retrievedVersion.getStatus() : null;
- if (retrievedStatus != expectedPrevStatus) {
- LOGGER.debug("Failed to " + version.getStatus() + " since activity spec is in " + retrievedStatus);
- throw new VersionStatusModificationException(activitySpecId, version.getId(), retrievedStatus, status);
- }
- prevVersionStatus = expectedPrevStatus;
+ if (action == ActivitySpecAction.DELETE) {
+ final String activitySpecName = get(new ActivitySpecEntity(activitySpec.getId(), versionId)).getName();
+ uniqueValueService.deleteUniqueValue(ACTIVITY_SPEC_NAME, activitySpecName);
}
+ }
- if (Objects.nonNull(retrievedVersion)) {
- retrievedVersion.setStatus(status);
- versioningManager.updateVersion(activitySpecId, retrievedVersion);
- itemManager.updateVersionStatus(activitySpecId, status, prevVersionStatus);
- versioningManager.publish(activitySpecId, retrievedVersion, "actionOnActivitySpec :" + action.name());
+ private VersionStatus getVersionStatusByAction(ActivitySpecAction action) {
+ switch (action) {
+ case DELETE:
+ return Deleted;
+ case DEPRECATE:
+ return Deprecated;
+ case CERTIFY:
+ return Certified;
+ default:
+ throw new UnsupportedOperationException(
+ String.format("Activity Spec action %s is not supported", action.name()));
}
+
}
@Override
@@ -220,29 +213,19 @@ public class ActivitySpecManagerImpl implements ActivitySpecManager {
.map(activitySpecMapper::itemToActivitySpec).collect(Collectors.toList());
}
- private Version calculateLatestVersion(ActivitySpecEntity activitySpec) {
- if (VERSION_ID_DEFAULT_VALUE.equalsIgnoreCase(activitySpec.getVersion().getId())) {
- List<Version> list;
+ private String calculateLatestVersion(ActivitySpecEntity activitySpec) {
+ if (VERSION_ID_DEFAULT_VALUE.equalsIgnoreCase(activitySpec.getVersionId())) {
+ List<Version> versions;
try {
- list = versioningManager.list(activitySpec.getId());
- } catch (SdcRuntimeException runtimeException) {
- LOGGER.debug("Failed to list versions for activitySpecId " + activitySpec.getId(), runtimeException);
+ versions = versioningManager.list(activitySpec.getId());
+ } catch (RuntimeException e) {
+ LOGGER.error("Failed to list versions for activitySpecId {}", activitySpec.getId(), e);
throw new EntityNotFoundException(ACTIVITY_SPEC_NOT_FOUND);
}
- if (Objects.nonNull(list) && !list.isEmpty()) {
- return list.get(0);
+ if (Objects.nonNull(versions) && !versions.isEmpty()) {
+ return versions.get(0).getId();
}
}
- return activitySpec.getVersion();
- }
-
- private Version getActivitySpecVersion(ActivitySpecEntity activitySpecEntity) {
- return activitySpecEntity.getVersion() == null ? new Version() : activitySpecEntity.getVersion();
-
- }
-
- private void enrichActivitySpec(Item item, Version version, ActivitySpecEntity activitySpecEntity) {
- activitySpecEntity.setId(item.getId());
- activitySpecEntity.setVersion(version);
+ return activitySpec.getVersionId();
}
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/CollaborationConfiguration.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/CollaborationConfiguration.java
deleted file mode 100644
index c0612436..00000000
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/CollaborationConfiguration.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.services.impl;
-
-import org.openecomp.core.zusammen.api.ZusammenAdaptor;
-import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
-import org.openecomp.sdc.versioning.ItemManager;
-import org.openecomp.sdc.versioning.ItemManagerFactory;
-import org.openecomp.sdc.versioning.VersioningManager;
-import org.openecomp.sdc.versioning.VersioningManagerFactory;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class CollaborationConfiguration {
-
- @Bean
- public ItemManager itemManager() {
- return ItemManagerFactory.getInstance().createInterface();
- }
-
- @Bean
- public VersioningManager versioningManager() {
- return VersioningManagerFactory.getInstance().createInterface();
- }
-
- @Bean
- public ZusammenAdaptor zusammenAdaptor() {
- return ZusammenAdaptorFactory.getInstance().createInterface();
- }
-}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java
index 3d9cda51..fc135621 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java
@@ -27,28 +27,27 @@ import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
+import org.onap.sdc.common.versioning.services.ItemManager;
+import org.onap.sdc.common.versioning.services.types.Item;
+import org.onap.sdc.common.versioning.services.types.ItemStatus;
+import org.onap.sdc.common.versioning.services.types.VersionStatus;
import org.onap.sdc.workflow.services.UniqueValueService;
import org.onap.sdc.workflow.services.WorkflowManager;
import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
import org.onap.sdc.workflow.services.exceptions.WorkflowModificationException;
-import org.onap.sdc.workflow.services.exceptions.WorkflowStatusModificationException;
+import org.onap.sdc.workflow.services.impl.mappers.ArchivingStatusMapper;
import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper;
import org.onap.sdc.workflow.services.impl.mappers.WorkflowMapper;
+import org.onap.sdc.workflow.services.types.ArchivingStatus;
import org.onap.sdc.workflow.services.types.Page;
import org.onap.sdc.workflow.services.types.PagingRequest;
import org.onap.sdc.workflow.services.types.RequestSpec;
import org.onap.sdc.workflow.services.types.Sort;
import org.onap.sdc.workflow.services.types.SortingRequest;
import org.onap.sdc.workflow.services.types.Workflow;
-import org.onap.sdc.workflow.services.types.ArchivingStatus;
import org.onap.sdc.workflow.services.types.WorkflowVersionState;
-import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.sdc.versioning.ItemManager;
-import org.openecomp.sdc.versioning.dao.types.VersionStatus;
-import org.openecomp.sdc.versioning.types.Item;
-import org.openecomp.sdc.versioning.types.ItemStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@@ -69,15 +68,17 @@ public class WorkflowManagerImpl implements WorkflowManager {
private final ItemManager itemManager;
private final UniqueValueService uniqueValueService;
private final WorkflowMapper workflowMapper;
+ private final ArchivingStatusMapper archivingStatusMapper;
private final VersionStateMapper versionStateMapper;
@Autowired
public WorkflowManagerImpl(ItemManager itemManager,
@Qualifier("uniqueValueService") UniqueValueService uniqueValueService, WorkflowMapper workflowMapper,
- VersionStateMapper versionStateMapper) {
+ ArchivingStatusMapper archivingStatusMapper, VersionStateMapper versionStateMapper) {
this.itemManager = itemManager;
this.uniqueValueService = uniqueValueService;
this.workflowMapper = workflowMapper;
+ this.archivingStatusMapper = archivingStatusMapper;
this.versionStateMapper = versionStateMapper;
}
@@ -89,11 +90,10 @@ public class WorkflowManagerImpl implements WorkflowManager {
Collection<Item> workflowItems =
itemManager.list(createFilter(statusFilter, searchNameFilter, versionStatesFilter));
- List<Workflow> workflowsSlice = workflowItems.stream().map(workflowMapper::itemToWorkflow)
- .sorted(getWorkflowComparator(requestSpec.getSorting()))
- .skip(requestSpec.getPaging().getOffset())
- .limit(requestSpec.getPaging().getLimit())
- .collect(Collectors.toList());
+ List<Workflow> workflowsSlice = workflowItems.stream().map(workflowMapper::fromItem)
+ .sorted(getWorkflowComparator(requestSpec.getSorting()))
+ .skip(requestSpec.getPaging().getOffset())
+ .limit(requestSpec.getPaging().getLimit()).collect(Collectors.toList());
return new Page<>(workflowsSlice, requestSpec.getPaging(), workflowItems.size());
}
@@ -104,56 +104,41 @@ public class WorkflowManagerImpl implements WorkflowManager {
if (retrievedItem == null) {
throw new EntityNotFoundException(String.format(WORKFLOW_NOT_FOUND_ERROR_MSG, workflow.getId()));
}
- return this.workflowMapper.itemToWorkflow(retrievedItem);
+ return this.workflowMapper.fromItem(retrievedItem);
}
@Override
public Workflow create(Workflow workflow) {
- Item item = workflowMapper.workflowToItem(workflow);
- item.setStatus(ItemStatus.ACTIVE);
+ Item item = new Item();
+ workflowMapper.toItem(workflow, item);
uniqueValueService.validateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, workflow.getName());
Item createdItem = itemManager.create(item);
uniqueValueService.createUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, workflow.getName());
- return workflowMapper.itemToWorkflow(createdItem);
+ return workflowMapper.fromItem(createdItem);
}
@Override
public void update(Workflow workflow) {
- Item retrievedItem = itemManager.get(workflow.getId());
- if (retrievedItem == null) {
+ Item item = itemManager.get(workflow.getId());
+ if (item == null) {
throw new EntityNotFoundException(String.format(WORKFLOW_NOT_FOUND_ERROR_MSG, workflow.getId()));
}
- if (ItemStatus.ARCHIVED.equals(retrievedItem.getStatus())) {
+ if (ItemStatus.ARCHIVED.equals(item.getStatus())) {
throw new WorkflowModificationException(workflow.getId());
}
- uniqueValueService.updateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, retrievedItem.getName(), workflow.getName());
+ uniqueValueService.updateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, item.getName(), workflow.getName());
- Item item = workflowMapper.workflowToItem(workflow);
- item.setId(workflow.getId());
- item.setStatus(retrievedItem.getStatus());
- item.setVersionStatusCounters(retrievedItem.getVersionStatusCounters());
- itemManager.update(item);
+ workflowMapper.toItem(workflow, item);
+ itemManager.update(workflow.getId(), item);
}
@Override
public void updateStatus(String workflowId, ArchivingStatus status) {
- Item item = itemManager.get(workflowId);
- if (item == null) {
- throw new EntityNotFoundException(String.format(WORKFLOW_NOT_FOUND_ERROR_MSG, workflowId));
- }
- try {
- if (ArchivingStatus.ARCHIVED.equals(status)) {
- itemManager.archive(item);
- } else if (ArchivingStatus.ACTIVE.equals(status)) {
- itemManager.restore(item);
- }
- } catch (CoreException ex) {
- throw new WorkflowStatusModificationException(ex);
- }
+ itemManager.updateStatus(workflowId, archivingStatusMapper.toItemStatus(status));
}
private static RequestSpec getRequestSpec(RequestSpec requestSpec) {
@@ -184,8 +169,8 @@ public class WorkflowManagerImpl implements WorkflowManager {
private static Comparator<Workflow> getWorkflowComparator(SortingRequest sorting) {
Boolean byNameAscending = sorting.getSorts().stream()
- .filter(sort -> WORKSPACES_SORT_PROPERTY.equalsIgnoreCase(sort.getProperty()))
- .findFirst().map(Sort::isAscendingOrder).orElse(true);
+ .filter(sort -> WORKSPACES_SORT_PROPERTY.equalsIgnoreCase(sort.getProperty()))
+ .findFirst().map(Sort::isAscendingOrder).orElse(true);
Comparator<Workflow> byName = Comparator.comparing(Workflow::getName);
return byNameAscending ? byName : byName.reversed();
@@ -209,12 +194,12 @@ public class WorkflowManagerImpl implements WorkflowManager {
private static Predicate<Item> addSearchNameFilter(Predicate<Item> filter, String searchNameFilter) {
return filter.and(item -> searchNameFilter == null || item.getName().toLowerCase()
- .contains(searchNameFilter.toLowerCase()));
+ .contains(searchNameFilter.toLowerCase()));
}
private static Predicate<Item> addVersionStatusFilter(Predicate<Item> filter, Set<VersionStatus> versionStatuses) {
return filter.and(item -> versionStatuses == null || item.getVersionStatusCounters().keySet().stream()
- .anyMatch(versionStatuses::contains));
+ .anyMatch(versionStatuses::contains));
}
private static Predicate<Item> addItemStatusFilter(Predicate<Item> filter, String itemStatusFilter) {
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java
index 33210778..f95e6a1f 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java
@@ -29,7 +29,13 @@ import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
-
+import org.onap.sdc.common.versioning.services.ItemManager;
+import org.onap.sdc.common.versioning.services.VersioningManager;
+import org.onap.sdc.common.versioning.services.types.Item;
+import org.onap.sdc.common.versioning.services.types.ItemStatus;
+import org.onap.sdc.common.versioning.services.types.Version;
+import org.onap.sdc.common.versioning.services.types.VersionCreationMethod;
+import org.onap.sdc.common.versioning.services.types.VersionStatus;
import org.onap.sdc.workflow.persistence.ArtifactRepository;
import org.onap.sdc.workflow.persistence.ParameterRepository;
import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
@@ -49,13 +55,6 @@ import org.onap.sdc.workflow.services.types.WorkflowVersion;
import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.sdc.versioning.ItemManager;
-import org.openecomp.sdc.versioning.VersioningManager;
-import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.sdc.versioning.dao.types.VersionStatus;
-import org.openecomp.sdc.versioning.types.Item;
-import org.openecomp.sdc.versioning.types.ItemStatus;
-import org.openecomp.sdc.versioning.types.VersionCreationMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@@ -95,7 +94,7 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
return versioningManager.list(workflowId).stream()
.filter(version -> versionStatusFilter == null || versionStatusFilter.contains(
version.getStatus()))
- .map(versionMapper::versionToWorkflowVersion)
+ .map(versionMapper::fromVersion)
.sorted(Comparator.comparing(WorkflowVersion::getName).reversed())
.peek(workflowVersion -> loadAndAddParameters(workflowId, workflowVersion))
.collect(Collectors.toList());
@@ -103,7 +102,7 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
@Override
public WorkflowVersion get(String workflowId, String versionId) {
- WorkflowVersion workflowVersion = versionMapper.versionToWorkflowVersion(getVersion(workflowId, versionId));
+ WorkflowVersion workflowVersion = versionMapper.fromVersion(getVersion(workflowId, versionId));
loadAndAddParameters(workflowId, workflowVersion);
workflowVersion.setHasArtifact(artifactRepository.isExist(workflowId,versionId));
return workflowVersion;
@@ -125,14 +124,13 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
Version version = new Version();
version.setDescription(workflowVersion.getDescription());
- version.setBaseId(baseVersionId);
- Version createdVersion = versioningManager.create(workflowId, version, VersionCreationMethod.major);
+ Version createdVersion = versioningManager.create(workflowId, baseVersionId, version, VersionCreationMethod.major);
- if (versions.isEmpty()) { // only for first version
+ if (versions.isEmpty()) { // only for first versionId
artifactRepository.createStructure(workflowId, createdVersion.getId());
parameterRepository.createStructure(workflowId, createdVersion.getId());
updateParameters(workflowId, createdVersion.getId(), workflowVersion.getInputs(), workflowVersion.getOutputs());
- versioningManager.publish(workflowId, createdVersion, "Add initial data");
+ versioningManager.publish(workflowId, createdVersion.getId(), "Add initial data");
}
return get(workflowId, createdVersion.getId());
@@ -141,22 +139,20 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
@Override
public void update(String workflowId, WorkflowVersion workflowVersion) {
validateWorkflowStatus(workflowId);
- Version retrievedVersion = getVersion(workflowId, workflowVersion.getId());
- if (CERTIFIED.equals(versionStateMapper.versionStatusToWorkflowVersionState(retrievedVersion.getStatus()))) {
+ Version version = getVersion(workflowId, workflowVersion.getId());
+ if (CERTIFIED.equals(versionStateMapper.versionStatusToWorkflowVersionState(version.getStatus()))) {
throw new VersionModificationException(workflowId, workflowVersion.getId());
}
- Version version = versionMapper.workflowVersionToVersion(workflowVersion);
- version.setName(retrievedVersion.getName());
- version.setStatus(retrievedVersion.getStatus());
+ versionMapper.toVersion(workflowVersion, version);
updateParameters(workflowId, version.getId(), workflowVersion.getInputs(), workflowVersion.getOutputs());
- versioningManager.updateVersion(workflowId, version);
+ versioningManager.update(workflowId, version.getId(), version);
- Version updatedVersion = versioningManager.get(workflowId, version);
- if(updatedVersion.getState().isDirty()) {
- versioningManager.publish(workflowId, version, "Update version");
+ Version updatedVersion = versioningManager.get(workflowId, version.getId());
+ if (updatedVersion.getState().isDirty()) {
+ versioningManager.publish(workflowId, version.getId(), "Update version");
}
}
@@ -175,7 +171,7 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
newState);
}
try {
- versioningManager.submit(workflowId, new Version(versionId),
+ versioningManager.updateStatus(workflowId, versionId, VersionStatus.Certified,
String.format("Update version state to %s", newState.name()));
} catch (Exception submitException) {
throw new VersionStateModificationException(workflowId, versionId, currentState, newState,
@@ -198,9 +194,9 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
ArtifactEntity artifactEntity =
new ArtifactEntity(StringUtils.cleanPath(artifact.getOriginalFilename()), artifactData);
artifactRepository.update(workflowId, versionId, artifactEntity);
- Version updatedVersion = versioningManager.get(workflowId, new Version(versionId));
+ Version updatedVersion = versioningManager.get(workflowId, versionId);
if(updatedVersion.getState().isDirty()) {
- versioningManager.publish(workflowId, updatedVersion, "Update artifact");
+ versioningManager.publish(workflowId, updatedVersion.getId(), "Update artifact");
}
} catch (IOException e) {
@@ -234,7 +230,7 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
}
if(retrievedVersion.isHasArtifact()) {
artifactRepository.delete(workflowId, versionId);
- versioningManager.publish(workflowId, new Version(versionId), "Delete Artifact");
+ versioningManager.publish(workflowId, versionId, "Delete Artifact");
}
}
@@ -249,7 +245,7 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
private Version getVersion(String workflowId, String versionId) {
try {
- Version version = versioningManager.get(workflowId, new Version(versionId));
+ Version version = versioningManager.get(workflowId, versionId);
if (version == null) {
throw new EntityNotFoundException(String.format(VERSION_NOT_EXIST_MSG, versionId, workflowId));
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ActivitySpecMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ActivitySpecMapper.java
index d9e5a109..09e96c3e 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ActivitySpecMapper.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ActivitySpecMapper.java
@@ -24,25 +24,26 @@ import java.util.Map;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
-import org.mapstruct.Mappings;
+import org.mapstruct.MappingTarget;
+import org.onap.sdc.common.versioning.services.types.Item;
+import org.onap.sdc.common.versioning.services.types.VersionStatus;
import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity;
import org.onap.sdc.workflow.services.ActivitySpecConstant;
import org.onap.sdc.workflow.services.impl.ItemType;
-import org.openecomp.sdc.versioning.dao.types.VersionStatus;
-import org.openecomp.sdc.versioning.types.Item;
@Mapper(componentModel = "spring", imports = {ItemType.class, ActivitySpecConstant.class})
public interface ActivitySpecMapper {
- @Mappings({@Mapping(source = "versionStatusCounters", target = "status"),
- @Mapping(source = "properties", target = "categoryList")})
+ @Mapping(source = "versionStatusCounters", target = "status")
+ @Mapping(source = "properties", target = "categoryList")
ActivitySpecEntity itemToActivitySpec(Item item);
@InheritInverseConfiguration
- @Mappings({@Mapping(expression = "java(ItemType.ACTIVITYSPEC.name())", target = "type"),
- @Mapping(target = "versionStatusCounters", ignore = true), @Mapping(target = "status", ignore = true),
- @Mapping(source = "categoryList", target = "properties")})
- Item activitySpecToItem(ActivitySpecEntity activitySpec);
+ @Mapping(expression = "java(ItemType.ACTIVITYSPEC.name())", target = "type")
+ @Mapping(target = "versionStatusCounters", ignore = true)
+ @Mapping(target = "status", ignore = true)
+ @Mapping(source = "categoryList", target = "properties")
+ void toItem(ActivitySpecEntity activitySpec, @MappingTarget Item retrievedItem);
default String versionStatusCountersToStatus(Map<VersionStatus, Integer> versionStatusCounters) {
return versionStatusCounters.keySet().stream().findFirst().map(Enum::name).orElse(null);
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ArchivingStatusMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ArchivingStatusMapper.java
new file mode 100644
index 00000000..702815f6
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ArchivingStatusMapper.java
@@ -0,0 +1,36 @@
+/*
+ * 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.services.impl.mappers;
+
+import org.mapstruct.InheritInverseConfiguration;
+import org.mapstruct.Mapper;
+import org.mapstruct.ValueMapping;
+import org.onap.sdc.common.versioning.services.types.ItemStatus;
+import org.onap.sdc.workflow.services.types.ArchivingStatus;
+
+@Mapper(componentModel = "spring")
+public interface ArchivingStatusMapper {
+
+ @ValueMapping(source = "ACTIVE", target = "ACTIVE")
+ @ValueMapping(source = "ARCHIVED", target = "ARCHIVED")
+ @ValueMapping(source = "<ANY_REMAINING>", target = "ACTIVE")
+ ArchivingStatus fromItemStatus(ItemStatus status);
+
+ @InheritInverseConfiguration
+ ItemStatus toItemStatus(ArchivingStatus status);
+
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java
index 6dffb369..145c79fe 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java
@@ -19,17 +19,27 @@ package org.onap.sdc.workflow.services.impl.mappers;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
+import org.mapstruct.MappingTarget;
+import org.onap.sdc.common.versioning.services.convertors.VersionConvertor;
+import org.onap.sdc.common.versioning.services.types.Version;
+import org.onap.sdc.workflow.services.impl.ItemType;
import org.onap.sdc.workflow.services.types.WorkflowVersion;
-import org.openecomp.sdc.versioning.dao.types.Version;
@Mapper(componentModel = "spring", uses = VersionStateMapper.class)
-public interface VersionMapper {
+public interface VersionMapper extends VersionConvertor<WorkflowVersion> {
+ @Override
+ default String getItemType(){
+ return ItemType.WORKFLOW.name();
+ }
+ @Override
@Mapping(source = "status", target = "state")
- WorkflowVersion versionToWorkflowVersion(Version version);
+ WorkflowVersion fromVersion(Version version);
+ @Override
@InheritInverseConfiguration
- Version workflowVersionToVersion(WorkflowVersion workflowVersion);
+ @Mapping(target = "status", ignore = true)
+ void toVersion(WorkflowVersion workflowVersion, @MappingTarget Version retrievedVersion);
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java
index 82f5814b..05772f4f 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java
@@ -22,16 +22,15 @@ import java.util.stream.Collectors;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.ValueMapping;
-import org.mapstruct.ValueMappings;
+import org.onap.sdc.common.versioning.services.types.VersionStatus;
import org.onap.sdc.workflow.services.types.WorkflowVersionState;
-import org.openecomp.sdc.versioning.dao.types.VersionStatus;
@Mapper(componentModel = "spring")
public interface VersionStateMapper {
- @ValueMappings({@ValueMapping(source = "Certified", target = "CERTIFIED"),
- @ValueMapping(source = "Draft", target = "DRAFT"),
- @ValueMapping(source = "<ANY_REMAINING>", target = "DRAFT")})
+ @ValueMapping(source = "Certified", target = "CERTIFIED")
+ @ValueMapping(source = "Draft", target = "DRAFT")
+ @ValueMapping(source = "<ANY_REMAINING>", target = "DRAFT")
WorkflowVersionState versionStatusToWorkflowVersionState(VersionStatus status);
@InheritInverseConfiguration
@@ -40,7 +39,7 @@ public interface VersionStateMapper {
default Set<WorkflowVersionState> versionStatusCountersToWorkflowVersionStates(
Map<VersionStatus, Integer> versionStatusCounters) {
return versionStatusCounters.keySet().stream().map(this::versionStatusToWorkflowVersionState)
- .collect(Collectors.toSet());
+ .collect(Collectors.toSet());
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java
index b7426670..214d2ac6 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java
@@ -19,21 +19,31 @@ package org.onap.sdc.workflow.services.impl.mappers;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
-import org.mapstruct.Mappings;
-import org.onap.sdc.workflow.services.types.Workflow;
+import org.mapstruct.MappingTarget;
+import org.onap.sdc.common.versioning.services.convertors.ItemConvertor;
+import org.onap.sdc.common.versioning.services.types.Item;
import org.onap.sdc.workflow.services.impl.ItemType;
-import org.openecomp.sdc.versioning.types.Item;
+import org.onap.sdc.workflow.services.types.Workflow;
+
+@Mapper(componentModel = "spring", imports = ItemType.class,
+ uses = {VersionStateMapper.class, ArchivingStatusMapper.class})
+public interface WorkflowMapper extends ItemConvertor<Workflow> {
-@Mapper(componentModel = "spring", imports = ItemType.class, uses = VersionStateMapper.class)
-public interface WorkflowMapper {
+ @Override
+ default String getItemType() {
+ return ItemType.WORKFLOW.name();
+ }
- @Mappings({@Mapping(source = "versionStatusCounters", target = "versionStates"),
- @Mapping(source = "status", target = "archiving")})
- Workflow itemToWorkflow(Item item);
+ @Override
+ @Mapping(source = "versionStatusCounters", target = "versionStates")
+ @Mapping(source = "status", target = "archiving")
+ Workflow fromItem(Item item);
+ @Override
@InheritInverseConfiguration
- @Mappings({@Mapping(expression = "java(ItemType.WORKFLOW.name())", target = "type"),
- @Mapping(target = "versionStatusCounters", ignore = true)})
- Item workflowToItem(Workflow workflow);
+ @Mapping(target = "status", ignore = true)
+ @Mapping(target = "versionStatusCounters", ignore = true)
+ @Mapping(expression = "java(ItemType.WORKFLOW.name())", target = "type")
+ void toItem(Workflow workflow, @MappingTarget Item item);
}
diff --git a/workflow-designer-be/src/main/resources/application-dev.properties b/workflow-designer-be/src/main/resources/application-dev.properties
deleted file mode 100644
index 2fdd9076..00000000
--- a/workflow-designer-be/src/main/resources/application-dev.properties
+++ /dev/null
@@ -1,58 +0,0 @@
-#/
-# Copyright � 2016-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.
-#/
-server.servlet.context-path=/
-http.port=${HTTP_PORT:8080}
-
-server.port=${SERVER_PORT:8443}
-server.ssl.enabled=${SERVER_SSL_ENABLED:true}
-server.ssl.key-password=${SERVER_SSL_KEY_PASSWORD:!ppJ.JvWn0hGh)oVF]([Kv)^}
-server.ssl.key-store=${SERVER_SSL_KEYSTORE_PATH:/etc/server-https-keystore/org.onap.sdc.p12}
-server.ssl.key-store-type=${SERVER_SSL_KEYSTORE_TYPE:PKCS12}
-
-sdc.be.protocol=${SDC_PROTOCOL:https}
-sdc.be.endpoint=${SDC_ENDPOINT:}
-sdc.be.external.user=${SDC_USER:}
-sdc.be.external.password=${SDC_PASSWORD:}
-
-#CASSANDRA
-spring.data.cassandra.contact-points=${CS_HOSTS:localhost}
-spring.data.cassandra.keyspace-name=workflow
-spring.data.cassandra.port=${CS_PORT:9042}
-spring.data.cassandra.username=${CS_USER:}
-spring.data.cassandra.password=${CS_PASSWORD:}
-zusammen.cassandra.isAuthenticate=${CS_AUTHENTICATE:false}
-spring.data.cassandra.ssl=${CS_SSL_ENABLED:false}
-zusammen.cassandra.trustStorePath=${CS_TRUST_STORE_PATH:}
-zusammen.cassandra.trustStorePassword=${CS_TRUST_STORE_PASSWORD:}
-
-#Actuators
-management.endpoint.health.show-details=always
-
-#Headers are comma separated list
-onap.logging.requestIdHeader=X-ECOMP-RequestID,X-ONAP-RequestID
-onap.logging.partnerNameHeader=USER_ID
-
-logging.level.org.springframework=INFO
-logging.level.org.onap.sdc.workflow=INFO
-
-#output to a temp_folder/file
-logging.file=${java.io.tmpdir}/application.log
-
-# Logging pattern for the console
-logging.pattern.console= %d{yyyy-MM-dd HH:mm:ss} - %msg%n
-
-# Logging pattern for file
-logging.pattern.file= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%
diff --git a/workflow-designer-be/src/main/resources/application.properties b/workflow-designer-be/src/main/resources/application.properties
index 5a4b7af7..7dcc2c4b 100644
--- a/workflow-designer-be/src/main/resources/application.properties
+++ b/workflow-designer-be/src/main/resources/application.properties
@@ -44,6 +44,7 @@ zusammen.cassandra.isAuthenticate=${CS_AUTHENTICATE:false}
spring.data.cassandra.ssl=${CS_SSL_ENABLED:false}
zusammen.cassandra.trustStorePath=${CS_TRUST_STORE_PATH:}
zusammen.cassandra.trustStorePassword=${CS_TRUST_STORE_PASSWORD:}
+spring.data.cassandra.jmx-enabled=false
#Actuators
management.endpoint.health.show-details=always
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java
index 8ea8e9f3..33cc0700 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java
@@ -18,10 +18,13 @@ package org.onap.sdc.workflow;
import static org.onap.sdc.workflow.services.impl.ItemType.WORKFLOW;
+import org.onap.sdc.common.versioning.persistence.types.InternalItem;
+import org.onap.sdc.common.versioning.persistence.types.InternalVersion;
+import org.onap.sdc.common.versioning.services.types.VersionStatus;
import org.onap.sdc.workflow.services.types.Workflow;
import org.onap.sdc.workflow.services.types.ArchivingStatus;
-import org.openecomp.sdc.versioning.types.Item;
-import org.openecomp.sdc.versioning.types.ItemStatus;
+import org.onap.sdc.common.versioning.services.types.Item;
+import org.onap.sdc.common.versioning.services.types.ItemStatus;
public class TestUtil {
@@ -38,7 +41,7 @@ public class TestUtil {
}
public static Item createItem(int itemNum, boolean setType, boolean setId, ItemStatus archivingStatus) {
- Item item = new Item();
+ InternalItem item = new InternalItem();
if (setId) {
item.setId(String.valueOf(itemNum));
}
@@ -51,5 +54,12 @@ public class TestUtil {
return item;
}
+ public static InternalVersion createRetrievedVersion(String id, VersionStatus status) {
+ InternalVersion version = new InternalVersion();
+ version.setId(id);
+ version.setStatus(status);
+ return version;
+ }
+
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImplTest.java
index bbae56e3..e69d4984 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImplTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImplTest.java
@@ -16,76 +16,66 @@
package org.onap.sdc.workflow.persistence.impl;
-import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.ELEMENT_TYPE_PROPERTY;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
-import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementConflict;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
-import com.amdocs.zusammen.adaptor.inbound.api.types.item.ItemVersionConflict;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
-import com.amdocs.zusammen.commons.health.data.HealthInfo;
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 com.amdocs.zusammen.datatypes.item.Item;
import com.amdocs.zusammen.datatypes.item.ItemVersion;
-import com.amdocs.zusammen.datatypes.item.ItemVersionData;
-import com.amdocs.zusammen.datatypes.item.ItemVersionStatus;
-import com.amdocs.zusammen.datatypes.item.Resolution;
-import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions;
-import com.amdocs.zusammen.datatypes.itemversion.Tag;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
-import java.util.stream.Collectors;
-import org.junit.After;
import org.junit.Assert;
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.common.versioning.persistence.zusammen.ZusammenSessionContextCreator;
+import org.onap.sdc.common.zusammen.services.ZusammenAdaptor;
import org.onap.sdc.workflow.persistence.impl.ActivitySpecRepositoryImpl.InfoPropertyName;
import org.onap.sdc.workflow.persistence.impl.types.ActivitySpecData;
import org.onap.sdc.workflow.persistence.impl.types.ActivitySpecElementType;
import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity;
import org.onap.sdc.workflow.persistence.types.ActivitySpecParameter;
import org.onap.sdc.workflow.services.utilities.JsonUtil;
-import org.openecomp.core.zusammen.api.ZusammenAdaptor;
-import org.openecomp.sdc.common.session.SessionContextProviderFactory;
-import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.types.ElementPropertyName;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-@RunWith(SpringJUnit4ClassRunner.class)
+@RunWith(MockitoJUnitRunner.class)
public class ActivitySpecRepositoryImplTest {
- private static final Version version = new Version();
private static final String versionId = "1234";
private static final String itemId = "5678";
- private static final String tenant = "dox";
- private ZusammenAdaptorMock zusammenAdaptor;
+ @Mock
+ private ZusammenAdaptor zusammenAdaptor;
+ @Mock
+ private ZusammenSessionContextCreator contextCreator;
+ @InjectMocks
private ActivitySpecRepositoryImpl daoImpl;
- private ActivitySpecEntity entity;
+ private ActivitySpecEntity entity;
+ private final Map<String, Element> elementMap = new HashMap<>();
+ private String elementId;
@Before
public void setUp() {
- SessionContextProviderFactory.getInstance().createInterface().create("test", tenant);
- zusammenAdaptor = new ZusammenAdaptorMock();
- daoImpl = new ActivitySpecRepositoryImpl(zusammenAdaptor);
+ daoImpl = new ActivitySpecRepositoryImpl(zusammenAdaptor, contextCreator);
entity = new ActivitySpecEntity();
entity = new ActivitySpecEntity();
entity.setId(itemId);
- version.setId(versionId);
- entity.setVersion(version);
+ entity.setVersionId(versionId);
entity.setName("activitySpec");
List<String> categoryList = new ArrayList<>();
categoryList.add("category1");
@@ -95,11 +85,9 @@ public class ActivitySpecRepositoryImplTest {
List<ActivitySpecParameter> inputs = new ArrayList<>();
inputs.add(inputParams);
entity.setInputs(inputs);
- }
- @After
- public void tearDown() {
- SessionContextProviderFactory.getInstance().createInterface().close();
+
+ mockZusammenAdapter();
}
@Test
@@ -108,10 +96,10 @@ public class ActivitySpecRepositoryImplTest {
itemVersionmock.setId(new Id());
daoImpl.create(entity);
- SessionContext context = createSessionContext();
- ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersion().getId());
- Optional<ElementInfo> testElementInfo = zusammenAdaptor.getElementInfoByName(context, elementContext, Id.ZERO,
- ActivitySpecElementType.ACTIVITYSPEC.name());
+ ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersionId());
+ Optional<ElementInfo> testElementInfo = zusammenAdaptor
+ .getElementInfoByName(contextCreator.create(), elementContext,
+ Id.ZERO, ActivitySpecElementType.ACTIVITYSPEC.name());
Assert.assertTrue(testElementInfo.isPresent());
Assert.assertEquals(testElementInfo.get().getInfo().getName(), ActivitySpecElementType.ACTIVITYSPEC.name());
Assert.assertEquals(testElementInfo.get().getInfo()
@@ -124,7 +112,7 @@ public class ActivitySpecRepositoryImplTest {
entity.getName());
final Optional<Element> testElement =
- zusammenAdaptor.getElement(context, elementContext, zusammenAdaptor.elementId);
+ zusammenAdaptor.getElement(contextCreator.create(), elementContext, new Id(elementId));
final InputStream data = testElement.get().getData();
final ActivitySpecData activitySpecData = JsonUtil.json2Object(data, ActivitySpecData.class);
Assert.assertEquals(activitySpecData.getInputs().get(0).getName(), entity.getInputs().get(0).getName());
@@ -148,123 +136,15 @@ public class ActivitySpecRepositoryImplTest {
Assert.assertEquals(retrieved.getCategoryList(), entity.getCategoryList());
}
- private class ZusammenAdaptorMock implements ZusammenAdaptor {
-
- private final Map<String, Element> elementMap = new HashMap<>();
- String elementId;
- private ItemVersion itemVersion;
-
- @Override
- public Collection<Item> listItems(SessionContext context) {
- return null;
- }
-
- @Override
- public Item getItem(SessionContext context, Id itemId) {
- return null;
- }
-
- @Override
- public void deleteItem(SessionContext context, Id itemId) {
-
- }
-
- @Override
- public Id createItem(SessionContext context, Info info) {
- return null;
- }
-
- @Override
- public void updateItem(SessionContext context, Id itemId, Info info) {
-
- }
-
- @Override
- public Optional<ItemVersion> getFirstVersion(SessionContext context, Id itemId) {
-
- return Optional.ofNullable(itemVersion);
- }
-
- @Override
- public Collection<ItemVersion> listPublicVersions(SessionContext context, Id itemId) {
- return null;
- }
-
- @Override
- public ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId) {
- return null;
- }
-
- @Override
- public Id createVersion(SessionContext context, Id itemId, Id baseVersionId, ItemVersionData itemVersionData) {
- return null;
- }
-
- @Override
- public void updateVersion(SessionContext context, Id itemId, Id versionId, ItemVersionData itemVersionData) {
-
- }
-
- @Override
- public ItemVersion getVersion(SessionContext context, Id itemId, Id versionId) {
- return null;
- }
-
- @Override
- public ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId) {
- return null;
- }
-
- @Override
- public ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId) {
- return null;
- }
-
- @Override
- public void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag) {
-
- }
-
- @Override
- public void resetVersionHistory(SessionContext context, Id itemId, Id versionId, String changeRef) {
-
- }
-
- @Override
- public void publishVersion(SessionContext context, Id itemId, Id versionId, String message) {
-
- }
- @Override
- public void syncVersion(SessionContext sessionContext, Id itemId, Id versionId) {
+ private void mockZusammenAdapter() {
- }
+ doAnswer(invocationOnMock -> {
+ Id elementId = invocationOnMock.getArgument(2);
+ return Optional.of(elementMap.get(elementId.getValue()));
+ }).when(zusammenAdaptor).getElement(any(), any(), any());
- @Override
- public void forceSyncVersion(SessionContext context, Id itemId, Id versionId) {
-
- }
-
- @Override
- public void cleanVersion(SessionContext sessionContext, Id itemId, Id versionId) {
-
- }
-
- @Override
- public Optional<ElementInfo> getElementInfo(SessionContext context, ElementContext elementContext,
- Id elementId) {
- return Optional.empty();
- }
-
- @Override
- public Optional<Element> getElement(SessionContext context, ElementContext elementContext, String elementId) {
- return Optional.of(elementMap.get(elementId));
- }
-
- @Override
- public Optional<Element> getElementByName(SessionContext context, ElementContext elementContext,
- Id parentElementId, String elementName) {
- //return Optional.empty();
+ doAnswer(invocationOnMock -> {
ZusammenElement element = new ZusammenElement();
Info info = new Info();
element.setElementId(Id.ZERO);
@@ -272,94 +152,29 @@ public class ActivitySpecRepositoryImplTest {
info.addProperty("description", entity.getDescription());
info.addProperty("category", entity.getCategoryList());
element.setInfo(info);
- return Optional.ofNullable(element);
- }
-
- @Override
- public Collection<ElementInfo> listElements(SessionContext context, ElementContext elementContext,
- Id parentElementId) {
- return null;
- }
-
- @Override
- public Collection<Element> listElementData(SessionContext context, ElementContext elementContext,
- Id parentElementId) {
- return elementMap.values();
- }
-
- @Override
- public Collection<ElementInfo> listElementsByName(SessionContext context, ElementContext elementContext,
- Id parentElementId, String elementName) {
-
- return elementMap.values().stream().filter(element -> elementName.equals(element.getInfo().getProperty(
- ElementPropertyName.elementType.name()))).map(element -> {
- ElementInfo elementInfo = new ElementInfo();
- elementInfo.setId(element.getElementId());
- elementInfo.setInfo(element.getInfo());
- return elementInfo;
- }).collect(Collectors.toList());
-
- }
-
- @Override
- public Optional<ElementInfo> getElementInfoByName(SessionContext context, ElementContext elementContext,
- Id parentElementId, String elementName) {
-
-
- return elementMap.values().stream().filter(element -> elementName.equals(element.getInfo().getProperty(
- ElementPropertyName.elementType.name()))).map(element -> {
- ElementInfo elementInfo = new ElementInfo();
- elementInfo.setId(element.getElementId());
- elementInfo.setInfo(element.getInfo());
- return elementInfo;
- }).findAny();
-
-
- }
-
- @Override
- public Optional<ElementConflict> getElementConflict(SessionContext context, ElementContext elementContext,
- Id id) {
- return Optional.empty();
- }
-
- @Override
- public Element saveElement(SessionContext context, ElementContext elementContext, ZusammenElement element,
- String message) {
+ return Optional.of(element);
+ }).when(zusammenAdaptor).getElementByName(any(), any(), any(), any());
+
+ doAnswer(invocationOnMock -> {
+ String elementName = invocationOnMock.getArgument(3);
+ return elementMap.values().stream()
+ .filter(element -> elementName.equals(element.getInfo().getProperty(ELEMENT_TYPE_PROPERTY)))
+ .map(element -> {
+ ElementInfo elementInfo = new ElementInfo();
+ elementInfo.setId(element.getElementId());
+ elementInfo.setInfo(element.getInfo());
+ return elementInfo;
+ }).findAny();
+ }).when(zusammenAdaptor).getElementInfoByName(any(), any(), any(), any());
+
+ doAnswer(invocationOnMock -> {
+ ZusammenElement element = invocationOnMock.getArgument(2);
if (element.getAction().equals(Action.CREATE) || element.getAction().equals(Action.UPDATE)) {
element.setElementId(new Id(UUID.randomUUID().toString()));
}
elementMap.put(element.getElementId().getValue(), element);
elementId = element.getElementId().getValue();
return element;
- }
-
- @Override
- public void resolveElementConflict(SessionContext context, ElementContext elementContext,
- ZusammenElement element, Resolution resolution) {
-
- }
-
- @Override
- public void revert(SessionContext sessionContext, Id itemId, Id versionId, Id revisionId) {
-
- }
-
- @Override
- public ItemVersionRevisions listRevisions(SessionContext sessionContext, Id itemId, Id versionId) {
- return null;
- }
-
- @Override
- public Collection<HealthInfo> checkHealth(SessionContext context) {
- return null;
- }
-
- @Override
- public String getVersion(SessionContext sessionContext) {
- return null;
- }
-
+ }).when(zusammenAdaptor).saveElement(any(), any(), any(), any());
}
-
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java
index 0fa67a9a..96f74d58 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java
@@ -19,12 +19,12 @@ package org.onap.sdc.workflow.persistence.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.isNull;
+import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
-import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
+import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.buildStructuralElement;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
@@ -44,10 +44,10 @@ 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.common.versioning.persistence.zusammen.ZusammenSessionContextCreator;
+import org.onap.sdc.common.zusammen.services.ZusammenAdaptor;
import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType;
-import org.openecomp.core.zusammen.api.ZusammenAdaptor;
-import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
@RunWith(MockitoJUnitRunner.class)
public class ArtifactRepositoryTest {
@@ -56,17 +56,19 @@ public class ArtifactRepositoryTest {
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";
+ private static final SessionContext SESSION_CONTEXT = new SessionContext();
@Mock
private ZusammenAdaptor zusammenAdaptorMock;
-
+ @Mock
+ private ZusammenSessionContextCreator contextCreatorMock;
@InjectMocks
private ArtifactRepositoryImpl artifactRepository;
@Before
public void setUp() {
- SessionContextProviderFactory.getInstance().createInterface().create("test_user", "workflow");
+ doReturn(SESSION_CONTEXT).when(contextCreatorMock).create();
}
@Test
@@ -77,7 +79,7 @@ public class ArtifactRepositoryTest {
artifactRepository.update(ITEM1_ID, VERSION1_ID, artifactMock);
verify(zusammenAdaptorMock)
- .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class),
+ .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class),
eq("Update WorkflowVersion Artifact Element"));
}
@@ -90,25 +92,25 @@ public class ArtifactRepositoryTest {
Optional<Element> elementOptional = Optional.of(artifactElement);
doReturn(elementOptional).when(zusammenAdaptorMock)
- .getElementByName(any(SessionContext.class), any(ElementContext.class), isNull(Id.class),
+ .getElementByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(),
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),
+ verify(zusammenAdaptorMock).getElementByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(),
eq(WorkflowElementType.ARTIFACT.name()));
}
@Test
- public void shouldReturnOptionalEmptyWhenDoesNotExist() throws IOException {
+ public void shouldReturnOptionalEmptyWhenDoesNotExist() {
doReturn(Optional.empty()).when(zusammenAdaptorMock)
- .getElementByName(any(SessionContext.class), any(ElementContext.class), isNull(Id.class),
+ .getElementByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(),
eq(WorkflowElementType.ARTIFACT.name()));
Optional<ArtifactEntity> result = artifactRepository.get(ITEM1_ID, VERSION1_ID);
- verify(zusammenAdaptorMock).getElementByName(any(SessionContext.class), any(ElementContext.class), isNull(Id.class),
+ verify(zusammenAdaptorMock).getElementByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(),
eq(WorkflowElementType.ARTIFACT.name()));
assertFalse(result.isPresent());
}
@@ -117,14 +119,14 @@ public class ArtifactRepositoryTest {
public void shouldCreateArtifactStructure() {
artifactRepository.createStructure(ITEM1_ID, VERSION1_ID);
verify(zusammenAdaptorMock)
- .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class),
+ .saveElement(eq(SESSION_CONTEXT), 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),
+ verify(zusammenAdaptorMock).saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class),
eq("Delete WorkflowVersion Artifact Data"));
}
@@ -137,7 +139,7 @@ public class ArtifactRepositoryTest {
elementInfo.setInfo(info);
doReturn(Optional.of(elementInfo)).when(zusammenAdaptorMock)
- .getElementInfoByName(any(SessionContext.class), any(ElementContext.class), isNull(),
+ .getElementInfoByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(),
eq(WorkflowElementType.ARTIFACT.name()));
assertTrue(artifactRepository.isExist(ITEM1_ID, VERSION1_ID));
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java
index 2953d0c2..4112ab4e 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java
@@ -41,13 +41,13 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.sdc.common.versioning.persistence.zusammen.ZusammenSessionContextCreator;
+import org.onap.sdc.common.zusammen.services.ZusammenAdaptor;
import org.onap.sdc.workflow.persistence.impl.types.ParameterPropertyName;
import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType;
import org.onap.sdc.workflow.persistence.types.ParameterEntity;
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 {
@@ -57,17 +57,19 @@ public class ParameterRepositoryTest {
private static final String PARAMETER1_ID = "parameter_id_1";
private static final String PARAMETER2_ID = "parameter_id_2";
private static final String PARAMETERS_PARENT_ID = "parameters_id";
-
+ private static final SessionContext SESSION_CONTEXT = new SessionContext();
@Mock
private ZusammenAdaptor zusammenAdaptorMock;
+ @Mock
+ private ZusammenSessionContextCreator contextCreatorMock;
@Spy
@InjectMocks
private ParameterRepositoryImpl parameterRepository;
@Before
public void setUp() {
- SessionContextProviderFactory.getInstance().createInterface().create("test_user", "workflow");
+ doReturn(SESSION_CONTEXT).when(contextCreatorMock).create();
}
@Test
@@ -81,11 +83,11 @@ public class ParameterRepositoryTest {
info.addProperty(ParameterPropertyName.MANDATORY.name(), true);
element.setInfo(info);
doReturn(Optional.of(element)).when(zusammenAdaptorMock)
- .getElementInfo(any(SessionContext.class), any(ElementContext.class),
+ .getElementInfo(eq(SESSION_CONTEXT), any(ElementContext.class),
eq(new Id(PARAMETER1_ID)));
ParameterEntity result = parameterRepository.get(ITEM1_ID, VERSION1_ID, PARAMETER1_ID);
verify(zusammenAdaptorMock)
- .getElementInfo(any(SessionContext.class), any(ElementContext.class), eq(new Id(PARAMETER1_ID)));
+ .getElementInfo(eq(SESSION_CONTEXT), any(ElementContext.class), eq(new Id(PARAMETER1_ID)));
assertEquals("testInput", result.getName());
}
@@ -101,7 +103,7 @@ public class ParameterRepositoryTest {
parameterRepository.update(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT, parameterEntityToUpdate);
verify(zusammenAdaptorMock)
- .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class),
+ .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class),
eq("Update WorkflowVersion Parameter"));
}
@@ -110,10 +112,10 @@ public class ParameterRepositoryTest {
public void shouldCreateParameterStructure() {
parameterRepository.createStructure(ITEM1_ID, VERSION1_ID);
verify(zusammenAdaptorMock)
- .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class),
+ .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class),
eq("Create WorkflowVersion INPUTS Element"));
verify(zusammenAdaptorMock)
- .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class),
+ .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class),
eq("Create WorkflowVersion OUTPUTS Element"));
}
@@ -121,7 +123,7 @@ public class ParameterRepositoryTest {
public void shouldDeleteParameter() {
parameterRepository.delete(ITEM1_ID, VERSION1_ID, PARAMETER1_ID);
verify(zusammenAdaptorMock)
- .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class),
+ .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class),
eq("Delete Parameter with id parameter_id_1"));
}
@@ -145,11 +147,11 @@ public class ParameterRepositoryTest {
parameter2.setInfo(info2);
Collection<ElementInfo> parameters = Collections.asSet(parameter1, parameter2);
doReturn(parameters).when(zusammenAdaptorMock)
- .listElementsByName(any(SessionContext.class), any(ElementContext.class), isNull(),
+ .listElementsByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(),
eq(WorkflowElementType.INPUTS.name()));
Collection<ParameterEntity> results = parameterRepository.list(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT);
- verify(zusammenAdaptorMock).listElementsByName(any(SessionContext.class), any(ElementContext.class), isNull(),
+ verify(zusammenAdaptorMock).listElementsByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(),
eq(WorkflowElementType.INPUTS.name()));
assertTrue(results.stream().anyMatch(parameterEntity -> parameterEntity.getId().equals(PARAMETER1_ID)));
assertTrue(results.stream().anyMatch(parameterEntity -> parameterEntity.getId().equals(PARAMETER2_ID)));
@@ -170,19 +172,19 @@ public class ParameterRepositoryTest {
Optional<ElementInfo> elementOptional = Optional.of(parameterParentElement);
doReturn(elementOptional).when(zusammenAdaptorMock)
- .getElementInfoByName(any(SessionContext.class), any(ElementContext.class), isNull(),
+ .getElementInfoByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(),
eq(WorkflowElementType.INPUTS.name()));
parameterRepository.deleteAll(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT);
verify(zusammenAdaptorMock)
- .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class),
+ .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class),
eq("Delete all INPUT"));
}
@Test(expected = IllegalStateException.class)
public void shouldFailIfParentElementDoesNotExist() {
doReturn(Optional.empty()).when(zusammenAdaptorMock)
- .getElementInfoByName(any(SessionContext.class), any(ElementContext.class), isNull(),
+ .getElementInfoByName(eq(SESSION_CONTEXT), any(ElementContext.class), isNull(),
eq(WorkflowElementType.INPUTS.name()));
parameterRepository.deleteAll(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT);
}
@@ -195,7 +197,7 @@ public class ParameterRepositoryTest {
zusammenElement.setElementId(new Id(PARAMETER1_ID));
zusammenParentElement.addSubElement(zusammenElement);
doReturn(zusammenParentElement).when(zusammenAdaptorMock)
- .saveElement(any(SessionContext.class), any(ElementContext.class),
+ .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class),
any(ZusammenElement.class), eq("Create WorkflowVersion Parameter Element"));
ParameterEntity parameterEntity = new ParameterEntity("test_input_parameter");
parameterEntity.setType(ParameterType.INTEGER);
@@ -204,7 +206,7 @@ public class ParameterRepositoryTest {
ParameterEntity returnedParameter =
parameterRepository.create(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT, parameterEntity);
verify(zusammenAdaptorMock)
- .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class),
+ .saveElement(eq(SESSION_CONTEXT), any(ElementContext.class), any(ZusammenElement.class),
eq("Create WorkflowVersion Parameter Element"));
assertEquals(PARAMETER1_ID, returnedParameter.getId());
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImplTest.java
index 719531bf..3166e06f 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImplTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImplTest.java
@@ -17,8 +17,12 @@
package org.onap.sdc.workflow.services.impl;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
+import static org.onap.sdc.workflow.TestUtil.createRetrievedVersion;
import static org.onap.sdc.workflow.services.ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND;
import static org.onap.sdc.workflow.services.ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE;
@@ -35,6 +39,14 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.onap.sdc.common.versioning.persistence.types.InternalItem;
+import org.onap.sdc.common.versioning.persistence.types.InternalVersion;
+import org.onap.sdc.common.versioning.services.ItemManager;
+import org.onap.sdc.common.versioning.services.VersioningManager;
+import org.onap.sdc.common.versioning.services.types.Item;
+import org.onap.sdc.common.versioning.services.types.Version;
+import org.onap.sdc.common.versioning.services.types.VersionCreationMethod;
+import org.onap.sdc.common.versioning.services.types.VersionStatus;
import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecAction;
import org.onap.sdc.workflow.persistence.ActivitySpecRepository;
import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity;
@@ -43,19 +55,13 @@ import org.onap.sdc.workflow.services.UniqueValueService;
import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
import org.onap.sdc.workflow.services.exceptions.VersionStatusModificationException;
import org.onap.sdc.workflow.services.impl.mappers.ActivitySpecMapper;
-import org.openecomp.sdc.common.errors.SdcRuntimeException;
-import org.openecomp.sdc.versioning.ItemManager;
-import org.openecomp.sdc.versioning.VersioningManager;
-import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.sdc.versioning.dao.types.VersionStatus;
-import org.openecomp.sdc.versioning.types.Item;
public class ActivitySpecManagerImplTest {
private static final String STRING_TYPE = "String";
private static final String TEST_ERROR_MSG = "Test Error";
private static final String ID = "ID1";
- private Version version01 = new Version("12345");
+ private String version01 = "12345";
private ActivitySpecEntity input;
@Spy
@@ -87,7 +93,7 @@ public class ActivitySpecManagerImplTest {
ActivitySpecEntity activitySpecToCreate = new ActivitySpecEntity();
activitySpecToCreate.setName("startserver");
activitySpecToCreate.setDescription("start the server");
- activitySpecToCreate.setVersion(version01);
+ activitySpecToCreate.setVersionId(version01);
List<String> categoryList = new ArrayList<>();
categoryList.add("category1");
@@ -109,17 +115,21 @@ public class ActivitySpecManagerImplTest {
outputs.add(outputParams);
activitySpecToCreate.setOutputs(outputs);
- activitySpecToCreate.setId("ID1");
- activitySpecToCreate.setVersion(version01);
+ activitySpecToCreate.setVersionId(version01);
- Item mappedItem = new Item();
- doReturn(mappedItem).when(activitySpecMapperMock).activitySpecToItem(activitySpecToCreate);
- doReturn(new Item()).when(itemManagerMock).create(mappedItem);
+ String itemId = "ID1";
+
+ InternalItem createdItem = new InternalItem();
+ createdItem.setId(itemId);
+ doReturn(createdItem).when(itemManagerMock).create(any());
+
+ doReturn(createRetrievedVersion(version01, VersionStatus.Draft)).when(versionManagerMock)
+ .create(eq(itemId), isNull(), any(Version.class), eq(VersionCreationMethod.major));
ActivitySpecEntity activitySpec = activitySpecManager.createActivitySpec(activitySpecToCreate);
Assert.assertNotNull(activitySpec);
- activitySpec.setId("ID1");
+ activitySpec.setId(itemId);
activitySpec.setStatus(VersionStatus.Draft.name());
assertActivitySpecEquals(activitySpec, activitySpecToCreate);
}
@@ -136,7 +146,6 @@ public class ActivitySpecManagerImplTest {
@Test
public void testList() {
Item item = new Item();
- item.setId(ID);
doReturn(Collections.singletonList(item)).when(itemManagerMock).list(any());
doReturn(new ActivitySpecEntity(ID, null)).when(activitySpecMapperMock).itemToActivitySpec(item);
@@ -161,35 +170,33 @@ public class ActivitySpecManagerImplTest {
public void testGet() {
input = new ActivitySpecEntity();
input.setId(ID);
- input.setVersion(version01);
+ input.setVersionId(version01);
mockListVersions();
doReturn(input).when(activitySpecRepositoryMock).get(any());
- version01.setStatus(VersionStatus.Draft);
- doReturn(version01).when(versionManagerMock).get(any(), any());
+ doReturn(createRetrievedVersion(version01,VersionStatus.Draft)).when(versionManagerMock).get(any(), any());
ActivitySpecEntity retrieved = activitySpecManager.get(input);
assertActivitySpecEquals(retrieved, input);
Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name());
- input.setVersion(new Version(VERSION_ID_DEFAULT_VALUE));
retrieved = activitySpecManager.get(input);
assertActivitySpecEquals(retrieved, input);
Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name());
}
private void mockListVersions() {
- doReturn(Collections.singletonList(version01)).when(versionManagerMock).list(any());
+ doReturn(Collections.singletonList((Version)createRetrievedVersion(version01,VersionStatus.Draft))).when(versionManagerMock).list(any());
}
@Test
public void testGetActivitySpecDaoFail() {
input = new ActivitySpecEntity();
input.setId(ID);
- input.setVersion(version01);
+ input.setVersionId(version01);
mockListVersions();
doReturn(input).when(activitySpecRepositoryMock).get(any());
- Mockito.doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(activitySpecRepositoryMock).get(any());
+ Mockito.doThrow(new RuntimeException(TEST_ERROR_MSG)).when(activitySpecRepositoryMock).get(any());
try {
activitySpecManager.get(input);
Assert.fail();
@@ -202,9 +209,8 @@ public class ActivitySpecManagerImplTest {
public void testListVersionFail() {
input = new ActivitySpecEntity();
input.setId(ID);
- input.setVersion(version01);
- input.getVersion().setId(VERSION_ID_DEFAULT_VALUE);
- Mockito.doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).list(any());
+ input.setVersionId(VERSION_ID_DEFAULT_VALUE);
+ Mockito.doThrow(new RuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).list(any());
try {
activitySpecManager.get(input);
Assert.fail();
@@ -215,8 +221,7 @@ public class ActivitySpecManagerImplTest {
@Test(expected = VersionStatusModificationException.class)
public void testInvalidDeprecate() {
- Version version = new Version(version01.getId());
- version.setStatus(VersionStatus.Draft);
+ InternalVersion version = createRetrievedVersion(version01, VersionStatus.Draft);
doReturn(version).when(versionManagerMock).get(ID, version01);
activitySpecManager.actOnAction(new ActivitySpecEntity(ID, version01), ActivitySpecAction.DEPRECATE);
}
@@ -228,8 +233,7 @@ public class ActivitySpecManagerImplTest {
}
private void mockCertifiedVersion() {
- Version version = new Version(version01.getId());
- version.setStatus(VersionStatus.Certified);
+ InternalVersion version = createRetrievedVersion(version01, VersionStatus.Certified);
doReturn(version).when(versionManagerMock).get(ID, version01);
}
@@ -241,22 +245,18 @@ public class ActivitySpecManagerImplTest {
@Test
public void testCertify() {
- Version retrievedVersion = new Version(version01.getId());
- retrievedVersion.setStatus(VersionStatus.Draft);
+ InternalVersion retrievedVersion = createRetrievedVersion(version01, VersionStatus.Draft);
doReturn(Collections.singletonList(retrievedVersion)).when(versionManagerMock).list(any());
doReturn(retrievedVersion).when(versionManagerMock).get(any(), any());
activitySpecManager.actOnAction(new ActivitySpecEntity(ID, version01), ActivitySpecAction.CERTIFY);
- verify(versionManagerMock).updateVersion(ID, retrievedVersion);
- verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Certified, VersionStatus.Draft);
- verify(versionManagerMock).publish(ID, retrievedVersion, "actionOnActivitySpec :CERTIFY");
+ verify(versionManagerMock).updateStatus(eq(ID), eq(version01), eq(VersionStatus.Certified), anyString());
}
@Test
public void testGetVersionFailOnStatusChangeAction() {
mockListVersions();
- Mockito.doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).get(any(), any());
try {
activitySpecManager.actOnAction(new ActivitySpecEntity(ID, version01), ActivitySpecAction.CERTIFY);
Assert.fail();
@@ -267,35 +267,27 @@ public class ActivitySpecManagerImplTest {
@Test
public void testDeprecate() {
- version01.setStatus(VersionStatus.Certified);
- Version retrivedVersion = new Version("12");
- retrivedVersion.setStatus(VersionStatus.Certified);
+ InternalVersion retrievedVersion = createRetrievedVersion(version01, VersionStatus.Certified);
mockListVersions();
- doReturn(retrivedVersion).when(versionManagerMock).get(any(), any());
- activitySpecManager.actOnAction(new ActivitySpecEntity(ID, new Version(VERSION_ID_DEFAULT_VALUE)), ActivitySpecAction.DEPRECATE);
+ doReturn(retrievedVersion).when(versionManagerMock).get(any(), any());
+ activitySpecManager
+ .actOnAction(new ActivitySpecEntity(ID, VERSION_ID_DEFAULT_VALUE), ActivitySpecAction.DEPRECATE);
- verify(versionManagerMock).updateVersion(ID, retrivedVersion);
- verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deprecated, VersionStatus.Certified);
- verify(versionManagerMock).publish(any(), any(), any());
+ verify(versionManagerMock).updateStatus(eq(ID), eq(version01), eq(VersionStatus.Deprecated), anyString());
}
@Test
public void testDelete() {
ActivitySpecEntity activitySpec = new ActivitySpecEntity();
- version01.setStatus(VersionStatus.Deprecated);
activitySpec.setName("stopServer");
- activitySpec.setVersion(version01);
-
- Version retrivedVersion = new Version("12");
- retrivedVersion.setStatus(VersionStatus.Deprecated);
+ activitySpec.setVersionId(version01);
mockListVersions();
- doReturn(retrivedVersion).when(versionManagerMock).get(any(), any());
+ doReturn(createRetrievedVersion(version01, VersionStatus.Deprecated)).when(versionManagerMock).get(any(), any());
doReturn(activitySpec).when(activitySpecRepositoryMock).get(any());
- activitySpecManager.actOnAction(new ActivitySpecEntity(ID, new Version(VERSION_ID_DEFAULT_VALUE)), ActivitySpecAction.DELETE);
+ activitySpecManager
+ .actOnAction(new ActivitySpecEntity(ID, VERSION_ID_DEFAULT_VALUE), ActivitySpecAction.DELETE);
- verify(versionManagerMock).updateVersion(ID, version01);
- verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deleted, VersionStatus.Deprecated);
- verify(versionManagerMock).publish(any(), any(), any());
+ verify(versionManagerMock).updateStatus(eq(ID), eq(version01), eq(VersionStatus.Deleted), anyString());
}
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java
index 2a69dbd6..1db24092 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java
@@ -19,16 +19,16 @@ package org.onap.sdc.workflow.services.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.onap.sdc.common.versioning.services.types.VersionStatus.Certified;
import static org.onap.sdc.workflow.TestUtil.createItem;
import static org.onap.sdc.workflow.TestUtil.createWorkflow;
import static org.onap.sdc.workflow.services.types.PagingConstants.DEFAULT_LIMIT;
import static org.onap.sdc.workflow.services.types.PagingConstants.DEFAULT_OFFSET;
import static org.onap.sdc.workflow.services.types.PagingConstants.MAX_LIMIT;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified;
import java.util.ArrayList;
import java.util.Arrays;
@@ -42,9 +42,11 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.onap.sdc.common.versioning.services.ItemManager;
+import org.onap.sdc.common.versioning.services.types.Item;
+import org.onap.sdc.common.versioning.services.types.ItemStatus;
import org.onap.sdc.workflow.services.UniqueValueService;
import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
-import org.onap.sdc.workflow.services.exceptions.WorkflowStatusModificationException;
import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper;
import org.onap.sdc.workflow.services.impl.mappers.WorkflowMapper;
import org.onap.sdc.workflow.services.types.ArchivingStatus;
@@ -56,11 +58,6 @@ import org.onap.sdc.workflow.services.types.Sort;
import org.onap.sdc.workflow.services.types.SortingRequest;
import org.onap.sdc.workflow.services.types.Workflow;
import org.onap.sdc.workflow.services.types.WorkflowVersionState;
-import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.errors.ErrorCode;
-import org.openecomp.sdc.versioning.ItemManager;
-import org.openecomp.sdc.versioning.types.Item;
-import org.openecomp.sdc.versioning.types.ItemStatus;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@@ -118,8 +115,8 @@ public class WorkflowManagerImplTest {
doReturn(Certified).when(versionStateMapperMock)
.workflowVersionStateToVersionStatus(WorkflowVersionState.CERTIFIED);
doReturn(Arrays.asList(ITEMS.get(0), ITEMS.get(2))).when(itemManagerMock).list(any());
- doReturn(MAPPED_WORKFLOWS.get(0)).when(workflowMapperMock).itemToWorkflow(ITEMS.get(0));
- doReturn(MAPPED_WORKFLOWS.get(2)).when(workflowMapperMock).itemToWorkflow(ITEMS.get(2));
+ doReturn(MAPPED_WORKFLOWS.get(0)).when(workflowMapperMock).fromItem(ITEMS.get(0));
+ doReturn(MAPPED_WORKFLOWS.get(2)).when(workflowMapperMock).fromItem(ITEMS.get(2));
RequestSpec requestSpec = createRequestSpec(0, 20, true);
Page<Workflow> workflows =
@@ -135,48 +132,12 @@ public class WorkflowManagerImplTest {
}
@Test(expected = EntityNotFoundException.class)
- public void shouldThrowExceptionWhenWorkflowDontExistTryingToUpdateStatus() {
- doReturn(null).when(itemManagerMock).get(ITEM1_ID);
- workflowManager.updateStatus(ITEM1_ID, ArchivingStatus.ARCHIVED);
- }
-
- @Test(expected = WorkflowStatusModificationException.class)
- public void shouldThrowExceptionWhenFailingToUpdateStatus() {
- Item mockItem = new Item();
- mockItem.setId(ITEM1_ID);
- mockItem.setStatus(ItemStatus.ARCHIVED);
- doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID);
- doThrow(new CoreException(new ErrorCode.ErrorCodeBuilder().build())).when(itemManagerMock).archive(mockItem);
- workflowManager.updateStatus(ITEM1_ID, ArchivingStatus.ARCHIVED);
- }
-
- @Test
- public void shouldArchiveWorkflow() {
- Item mockItem = new Item();
- mockItem.setId(ITEM1_ID);
- mockItem.setStatus(ItemStatus.ACTIVE);
- doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID);
- workflowManager.updateStatus(ITEM1_ID, ArchivingStatus.ARCHIVED);
- verify(itemManagerMock).archive(mockItem);
- }
-
- @Test
- public void shouldRestoreWorkflow() {
- Item mockItem = new Item();
- mockItem.setId(ITEM1_ID);
- mockItem.setStatus(ItemStatus.ARCHIVED);
- doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID);
- workflowManager.updateStatus(ITEM1_ID, ArchivingStatus.ACTIVE);
- verify(itemManagerMock).restore(mockItem);
- }
-
- @Test(expected = EntityNotFoundException.class)
public void shouldThrowExceptionWhenWorkflowDontExist() {
Workflow nonExistingWorkflow = new Workflow();
nonExistingWorkflow.setId(ITEM1_ID);
doReturn(null).when(itemManagerMock).get(ITEM1_ID);
workflowManager.get(nonExistingWorkflow);
- verify(workflowMapperMock, times(3)).itemToWorkflow(any(Item.class));
+ verify(workflowMapperMock, times(3)).fromItem(any(Item.class));
}
@Test
@@ -186,22 +147,15 @@ public class WorkflowManagerImplTest {
Workflow workflow = createWorkflow(1, true, ArchivingStatus.ACTIVE);
workflowManager.get(workflow);
verify(itemManagerMock).get(ITEM1_ID);
- verify(workflowMapperMock).itemToWorkflow(retrievedItem);
+ verify(workflowMapperMock).fromItem(retrievedItem);
}
@Test
public void shouldCreateWorkflowItemFromWorkflow() {
Workflow workflowToBeCreated = createWorkflow(1, false, ArchivingStatus.ACTIVE);
- Item createdWorkflowItem = createItem(1, false, true, ItemStatus.ACTIVE);
- doReturn(createdWorkflowItem).when(workflowMapperMock).workflowToItem(workflowToBeCreated);
- doReturn(createdWorkflowItem).when(itemManagerMock).create(createdWorkflowItem);
workflowManager.create(workflowToBeCreated);
+ verify(itemManagerMock).create(any(Item.class));
verify(uniqueValueServiceMock).validateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, workflowToBeCreated.getName());
-
- createdWorkflowItem.setStatus(ItemStatus.ACTIVE);
- createdWorkflowItem.setType(WORKFLOW_TYPE);
- verify(itemManagerMock).create(createdWorkflowItem);
- verify(uniqueValueServiceMock).createUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, workflowToBeCreated.getName());
}
@Test
@@ -209,9 +163,8 @@ public class WorkflowManagerImplTest {
Item workflowItem = createItem(1, true, true, ItemStatus.ACTIVE);
doReturn(workflowItem).when(itemManagerMock).get(ITEM1_ID);
Workflow workflowToBeUpdated = createWorkflow(1, true, ArchivingStatus.ACTIVE);
- doReturn(workflowItem).when(workflowMapperMock).workflowToItem(workflowToBeUpdated);
workflowManager.update(workflowToBeUpdated);
- verify(itemManagerMock).update(workflowItem);
+ verify(itemManagerMock).update(eq(ITEM1_ID),any(Item.class));
verify(uniqueValueServiceMock)
.updateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, workflowItem.getName(), workflowToBeUpdated.getName());
@@ -389,7 +342,7 @@ public class WorkflowManagerImplTest {
private void mockItemToWorkflowMaps() {
for (int i = 0; i < ITEMS.size(); i++) {
- doReturn(MAPPED_WORKFLOWS.get(i)).when(workflowMapperMock).itemToWorkflow(ITEMS.get(i));
+ doReturn(MAPPED_WORKFLOWS.get(i)).when(workflowMapperMock).fromItem(ITEMS.get(i));
}
}
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 db4cfa32..6648f376 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
@@ -19,13 +19,15 @@ package org.onap.sdc.workflow.services.impl;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.onap.sdc.workflow.TestUtil.createRetrievedVersion;
import static org.onap.sdc.workflow.services.types.WorkflowVersionState.CERTIFIED;
import static org.onap.sdc.workflow.services.types.WorkflowVersionState.DRAFT;
@@ -36,7 +38,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
-
import org.apache.commons.io.IOUtils;
import org.junit.Rule;
import org.junit.Test;
@@ -47,6 +48,15 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.sdc.common.versioning.persistence.types.InternalItem;
+import org.onap.sdc.common.versioning.persistence.types.InternalVersion;
+import org.onap.sdc.common.versioning.services.ItemManager;
+import org.onap.sdc.common.versioning.services.VersioningManager;
+import org.onap.sdc.common.versioning.services.types.ItemStatus;
+import org.onap.sdc.common.versioning.services.types.Version;
+import org.onap.sdc.common.versioning.services.types.VersionCreationMethod;
+import org.onap.sdc.common.versioning.services.types.VersionState;
+import org.onap.sdc.common.versioning.services.types.VersionStatus;
import org.onap.sdc.workflow.persistence.ArtifactRepository;
import org.onap.sdc.workflow.persistence.ParameterRepository;
import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
@@ -62,14 +72,6 @@ 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.ItemManager;
-import org.openecomp.sdc.versioning.VersioningManager;
-import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.sdc.versioning.dao.types.VersionState;
-import org.openecomp.sdc.versioning.dao.types.VersionStatus;
-import org.openecomp.sdc.versioning.types.Item;
-import org.openecomp.sdc.versioning.types.ItemStatus;
-import org.openecomp.sdc.versioning.types.VersionCreationMethod;
import org.springframework.mock.web.MockMultipartFile;
@RunWith(MockitoJUnitRunner.class)
@@ -99,14 +101,13 @@ public class WorkflowVersionManagerImplTest {
@Test(expected = EntityNotFoundException.class)
public void shouldThrowExceptionWhenVersionDontExist() {
- Version nonExistingVersion = new Version(VERSION1_ID);
- doThrow(new RuntimeException()).when(versioningManagerMock).get(ITEM1_ID, nonExistingVersion);
+ doThrow(new RuntimeException()).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
workflowVersionManager.get(ITEM1_ID, VERSION1_ID);
}
@Test(expected = WorkflowModificationException.class)
public void shouldThrowExceptionWhenCreatingVersionForArchivedWorkflow() {
- Item mockItem = new Item();
+ InternalItem mockItem = new InternalItem();
mockItem.setId(ITEM1_ID);
mockItem.setStatus(ItemStatus.ARCHIVED);
doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID);
@@ -115,7 +116,7 @@ public class WorkflowVersionManagerImplTest {
@Test(expected = WorkflowModificationException.class)
public void shouldThrowExceptionWhenUpdatingVersionForArchivedWorkflow() {
- Item mockItem = new Item();
+ InternalItem mockItem = new InternalItem();
mockItem.setId(ITEM1_ID);
mockItem.setStatus(ItemStatus.ARCHIVED);
doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID);
@@ -124,7 +125,7 @@ public class WorkflowVersionManagerImplTest {
@Test(expected = WorkflowModificationException.class)
public void shouldThrowExceptionWhenUploadingArtifactForArchivedWorkflow() {
- Item mockItem = new Item();
+ InternalItem mockItem = new InternalItem();
mockItem.setId(ITEM1_ID);
mockItem.setStatus(ItemStatus.ARCHIVED);
doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID);
@@ -134,7 +135,7 @@ public class WorkflowVersionManagerImplTest {
@Test(expected = WorkflowModificationException.class)
public void shouldThrowExceptionWhenDeletingArtifactForArchivedWorkflow() {
- Item mockItem = new Item();
+ InternalItem mockItem = new InternalItem();
mockItem.setId(ITEM1_ID);
mockItem.setStatus(ItemStatus.ARCHIVED);
doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID);
@@ -143,65 +144,65 @@ public class WorkflowVersionManagerImplTest {
@Test
public void shouldReturnWorkflowVersionWhenExist() {
- 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(workflowVersion).when(versionMapperMock).fromVersion(any(Version.class));
+ doReturn(new Version()).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
doReturn(Collections.emptyList()).when(parameterRepositoryMock)
.list(eq(ITEM1_ID), eq(VERSION1_ID), any(ParameterRole.class));
workflowVersionManager.get(ITEM1_ID, VERSION1_ID);
- verify(versioningManagerMock).get(ITEM1_ID, version);
+ verify(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
}
@Test
public void shouldReturnWorkflowVersionList() {
- Version version1 = new Version(VERSION1_ID);
- Version version2 = new Version(VERSION2_ID);
+ InternalVersion version1 = createRetrievedVersion(VERSION1_ID, VersionStatus.Certified);
+ InternalVersion version2 = createRetrievedVersion(VERSION2_ID, VersionStatus.Draft);
List<Version> versionList = Arrays.asList(version1, version2);
doReturn(versionList).when(versioningManagerMock).list(ITEM1_ID);
+
WorkflowVersion workflowVersion1 = new WorkflowVersion();
workflowVersion1.setId(VERSION1_ID);
workflowVersion1.setName(VERSION1_ID);
+ doReturn(workflowVersion1).when(versionMapperMock).fromVersion(version1);
+
WorkflowVersion workflowVersion2 = new WorkflowVersion();
workflowVersion2.setId(VERSION2_ID);
workflowVersion2.setName(VERSION2_ID);
- doReturn(workflowVersion2).when(versionMapperMock).versionToWorkflowVersion(version2);
+ doReturn(workflowVersion2).when(versionMapperMock).fromVersion(version2);
+
doReturn(Collections.emptyList()).when(parameterRepositoryMock)
.list(eq(ITEM1_ID), anyString(), eq(ParameterRole.INPUT));
doReturn(Collections.emptyList()).when(parameterRepositoryMock)
.list(eq(ITEM1_ID), anyString(), eq(ParameterRole.OUTPUT));
+
workflowVersionManager.list(ITEM1_ID, null);
verify(versioningManagerMock).list(ITEM1_ID);
- verify(versionMapperMock, times(2)).versionToWorkflowVersion(any(Version.class));
+ verify(versionMapperMock, times(2)).fromVersion(any(Version.class));
}
@Test
public void shouldReturnCertifiedWorkflowVersionList() {
- Version version1 = new Version(VERSION1_ID);
- version1.setStatus(VersionStatus.Certified);
- Version version2 = new Version(VERSION2_ID);
- version2.setStatus(VersionStatus.Draft);
+ InternalVersion version1 = createRetrievedVersion(VERSION1_ID, VersionStatus.Certified);
+ InternalVersion version2 = createRetrievedVersion(VERSION2_ID, VersionStatus.Draft);
List<Version> versionList = Arrays.asList(version1, version2);
+
doReturn(versionList).when(versioningManagerMock).list(ITEM1_ID);
WorkflowVersion workflowVersion1 = new WorkflowVersion();
workflowVersion1.setId(VERSION1_ID);
workflowVersion1.setName(VERSION1_ID);
- WorkflowVersion workflowVersion2 = new WorkflowVersion();
- workflowVersion2.setId(VERSION2_ID);
- workflowVersion2.setName(VERSION2_ID);
- doReturn(workflowVersion1).when(versionMapperMock).versionToWorkflowVersion(version1);
+ doReturn(workflowVersion1).when(versionMapperMock).fromVersion(version1);
+
doReturn(Collections.emptyList()).when(parameterRepositoryMock)
.list(eq(ITEM1_ID), anyString(), eq(ParameterRole.INPUT));
doReturn(Collections.emptyList()).when(parameterRepositoryMock)
.list(eq(ITEM1_ID), anyString(), eq(ParameterRole.OUTPUT));
doReturn(VersionStatus.Certified).when(versionStateMapperMock)
- .workflowVersionStateToVersionStatus(
- WorkflowVersionState.CERTIFIED);
+ .workflowVersionStateToVersionStatus(WorkflowVersionState.CERTIFIED);
assertEquals(1,
workflowVersionManager.list(ITEM1_ID, Collections.singleton(WorkflowVersionState.CERTIFIED)).size());
verify(versioningManagerMock).list(ITEM1_ID);
- verify(versionMapperMock, times(1)).versionToWorkflowVersion(any(Version.class));
+ verify(versionMapperMock, times(1)).fromVersion(any(Version.class));
}
@@ -209,15 +210,18 @@ public class WorkflowVersionManagerImplTest {
public void shouldUpdateWorkflowVersion() {
doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
String updatedDescription = "WorkflowVersion description updated";
- Version retrievedVersion = new Version(VERSION1_ID);
+ InternalVersion retrievedVersion = new InternalVersion();
+ retrievedVersion.setId(VERSION1_ID);
retrievedVersion.setName("1.0");
retrievedVersion.setDescription("WorkflowVersion description");
retrievedVersion.setStatus(VersionStatus.Draft);
VersionState versionState = new VersionState();
versionState.setDirty(true);
retrievedVersion.setState(versionState);
- doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
+ doReturn(retrievedVersion).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(retrievedVersion.getStatus());
+ doReturn(Collections.emptyList()).when(parameterRepositoryMock)
+ .list(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT);
WorkflowVersion inputVersion = new WorkflowVersion(VERSION1_ID);
inputVersion.setName("1.0");
@@ -226,27 +230,28 @@ public class WorkflowVersionManagerImplTest {
inputVersion.setInputs(Collections.singleton(toBeCreated));
ParameterEntity toBeUpdated = new ParameterEntity("Output1");
inputVersion.setOutputs(Collections.singleton(toBeUpdated));
- doReturn(Collections.emptyList()).when(parameterRepositoryMock)
- .list(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT);
+
ParameterEntity toBeDeleted = new ParameterEntity("Output2");
toBeDeleted.setId("parameter_id_1");
Collection<ParameterEntity> currentOutputs = Arrays.asList(toBeDeleted, toBeUpdated);
doReturn(currentOutputs).when(parameterRepositoryMock).list(ITEM1_ID, VERSION1_ID, ParameterRole.OUTPUT);
- Version mappedInputVersion = new Version(VERSION1_ID);
- mappedInputVersion.setName("1.0");
- mappedInputVersion.setDescription(updatedDescription);
- doReturn(mappedInputVersion).when(versionMapperMock).workflowVersionToVersion(inputVersion);
+ doAnswer(invocationOnMock -> {
+ WorkflowVersion workflowVersion = invocationOnMock.getArgument(0);
+ Version version = invocationOnMock.getArgument(1);
+ version.setDescription(workflowVersion.getDescription());
+ return null;
+ }).when(versionMapperMock).toVersion(inputVersion, retrievedVersion);
ArgumentCaptor<Version> versionArgCaptor = ArgumentCaptor.forClass(Version.class);
workflowVersionManager.update(ITEM1_ID, inputVersion);
- verify(versioningManagerMock).updateVersion(eq(ITEM1_ID), versionArgCaptor.capture());
+ verify(versioningManagerMock).update(eq(ITEM1_ID), eq(VERSION1_ID), versionArgCaptor.capture());
Version captorVersion = versionArgCaptor.getValue();
assertEquals("1.0", captorVersion.getName());
assertEquals(updatedDescription, captorVersion.getDescription());
assertEquals(VersionStatus.Draft, captorVersion.getStatus());
- verify(versioningManagerMock).publish(ITEM1_ID, mappedInputVersion, "Update version");
+ verify(versioningManagerMock).publish(ITEM1_ID, VERSION1_ID, "Update version");
verify(parameterRepositoryMock).delete(ITEM1_ID, VERSION1_ID, "parameter_id_1");
verify(parameterRepositoryMock).create(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT, toBeCreated);
@@ -258,17 +263,18 @@ public class WorkflowVersionManagerImplTest {
@Test
public void shouldCreateWorkflowVersion() {
doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
- Version version = new Version(VERSION1_ID);
- version.setDescription("version desc");
- doReturn(version).when(versioningManagerMock).create(ITEM1_ID, version, VersionCreationMethod.major);
+ Version version = createRetrievedVersion(VERSION1_ID, VersionStatus.Draft);
+ doReturn(version).when(versioningManagerMock)
+ .create(eq(ITEM1_ID), isNull(), any(Version.class), eq(VersionCreationMethod.major));
+
WorkflowVersion versionRequest = new WorkflowVersion();
versionRequest.setDescription("version desc");
versionRequest.setInputs(Collections.emptyList());
versionRequest.setOutputs(Collections.emptyList());
WorkflowVersion workflowVersion = new WorkflowVersion(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);
}
@Test(expected = VersionCreationException.class)
@@ -276,8 +282,7 @@ public class WorkflowVersionManagerImplTest {
doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
WorkflowVersion versionRequestDto = new WorkflowVersion();
- Version baseVersion = new Version(VERSION2_ID);
- baseVersion.setStatus(VersionStatus.Draft);
+ Version baseVersion = createRetrievedVersion(VERSION2_ID, VersionStatus.Draft);
List<Version> versions = Collections.singletonList(baseVersion);
doReturn(versions).when(versioningManagerMock).list(ITEM1_ID);
@@ -289,25 +294,24 @@ public class WorkflowVersionManagerImplTest {
doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
WorkflowVersion versionRequestDto = new WorkflowVersion();
versionRequestDto.setInputs(Collections.singleton(new ParameterEntity()));
- Version baseVersion = new Version(VERSION2_ID);
- baseVersion.setStatus(VersionStatus.Draft);
+ InternalVersion baseVersion = createRetrievedVersion(VERSION2_ID, VersionStatus.Draft);
List<Version> versions = Collections.singletonList(baseVersion);
doReturn(versions).when(versioningManagerMock).list(ITEM1_ID);
workflowVersionManager.create(ITEM1_ID, VERSION2_ID, versionRequestDto);
}
+
@Test(expected = EntityNotFoundException.class)
public void getStateOfNonExisting() {
- doThrow(new RuntimeException()).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
+ doThrow(new RuntimeException()).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
workflowVersionManager.getState(ITEM1_ID, VERSION1_ID);
}
@Test
public void getState() {
- Version version = new Version(VERSION1_ID);
- version.setStatus(VersionStatus.Certified);
- doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
+ InternalVersion version = createRetrievedVersion(VERSION1_ID, VersionStatus.Certified);
+ doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
doReturn(CERTIFIED).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus());
WorkflowVersionState state = workflowVersionManager.getState(ITEM1_ID, VERSION1_ID);
@@ -316,15 +320,14 @@ public class WorkflowVersionManagerImplTest {
@Test(expected = EntityNotFoundException.class)
public void updateStateOfNonExisting() {
- doThrow(new RuntimeException()).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
+ doThrow(new RuntimeException()).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED);
}
@Test(expected = VersionStateModificationException.class)
public void updateStateToCurrentState() {
- Version version = new Version(VERSION1_ID);
- version.setStatus(VersionStatus.Draft);
- doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
+ InternalVersion version = createRetrievedVersion(VERSION1_ID, VersionStatus.Draft);
+ doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus());
workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, DRAFT);
@@ -332,9 +335,8 @@ public class WorkflowVersionManagerImplTest {
@Test(expected = VersionStateModificationMissingArtifactException.class)
public void updateStateWhenCertified() {
- Version version = new Version(VERSION1_ID);
- version.setStatus(VersionStatus.Certified);
- doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
+ InternalVersion version = createRetrievedVersion(VERSION1_ID, VersionStatus.Certified);
+ doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
doReturn(CERTIFIED).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus());
workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED);
@@ -342,9 +344,8 @@ public class WorkflowVersionManagerImplTest {
@Test
public void shouldFailUpdateStateWhenNoArtifact() {
- Version retrievedVersion = new Version(VERSION1_ID);
- retrievedVersion.setStatus(VersionStatus.Draft);
- doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
+ InternalVersion retrievedVersion = createRetrievedVersion(VERSION1_ID, VersionStatus.Draft);
+ doReturn(retrievedVersion).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(VersionStatus.Draft);
exceptionRule.expect(VersionStateModificationMissingArtifactException.class);
@@ -353,29 +354,28 @@ public class WorkflowVersionManagerImplTest {
ITEM1_ID, VERSION1_ID, DRAFT, CERTIFIED));
workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED);
- verify(versioningManagerMock).submit(eq(ITEM1_ID), eqVersion(VERSION1_ID), anyString());
+ verify(versioningManagerMock).updateStatus(ITEM1_ID, VERSION1_ID, VersionStatus.Certified, anyString());
}
@Test
public void shouldSuccessUpdateStateWhenArtifactExist() {
- Version retrievedVersion = new Version(VERSION1_ID);
- retrievedVersion.setStatus(VersionStatus.Draft);
- doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
+ InternalVersion retrievedVersion = createRetrievedVersion(VERSION1_ID, VersionStatus.Draft);
+ doReturn(retrievedVersion).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(VersionStatus.Draft);
doReturn(true).when(artifactRepositoryMock).isExist(ITEM1_ID, VERSION1_ID);
workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED);
- verify(versioningManagerMock).submit(eq(ITEM1_ID), eqVersion(VERSION1_ID), anyString());
+ verify(versioningManagerMock)
+ .updateStatus(eq(ITEM1_ID), eq(VERSION1_ID), eq(VersionStatus.Certified), anyString());
}
@Test
public void shouldUploadArtifact() {
doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
- Version version = new Version(VERSION1_ID);
- version.setStatus(VersionStatus.Draft);
+ InternalVersion version = createRetrievedVersion(VERSION1_ID, VersionStatus.Draft);
VersionState versionState = new VersionState();
versionState.setDirty(false);
version.setState(versionState);
- doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
+ doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus());
MockMultipartFile mockFile = new MockMultipartFile("data", "filename.txt", "text/plain", "some xml".getBytes());
@@ -386,7 +386,7 @@ public class WorkflowVersionManagerImplTest {
@Test(expected = EntityNotFoundException.class)
public void shouldThrowExceptionWhenArtifactNotFound() {
- doReturn(new Version(VERSION1_ID)).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
+ doReturn(new Version()).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
doReturn(Optional.empty()).when(artifactRepositoryMock).get(ITEM1_ID, VERSION1_ID);
workflowVersionManager.getArtifact(ITEM1_ID, VERSION1_ID);
@@ -394,7 +394,7 @@ public class WorkflowVersionManagerImplTest {
@Test
public void shouldReturnArtifact() throws IOException {
- doReturn(new Version(VERSION1_ID)).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
+ doReturn(new Version()).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
InputStream inputStreamMock = IOUtils.toInputStream("some test data for my input stream", "UTF-8");
ArtifactEntity artifactMock = new ArtifactEntity("fileName.txt", inputStreamMock);
@@ -406,40 +406,36 @@ public class WorkflowVersionManagerImplTest {
@Test(expected = VersionModificationException.class)
public void shouldThrowExceptionInDeleteArtifactWhenVersionIsCertified() {
doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
- Version version = new Version(VERSION1_ID);
- doReturn(version).when(versioningManagerMock).get(ITEM1_ID, version);
+ Version version = new Version();
+ doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
workflowVersion.setState(WorkflowVersionState.CERTIFIED);
- doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(version);
+ doReturn(workflowVersion).when(versionMapperMock).fromVersion(version);
workflowVersionManager.deleteArtifact(ITEM1_ID, VERSION1_ID);
}
@Test
public void shouldNotDeleteArtifactIfNotExist() {
doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
- Version version = new Version(VERSION1_ID);
- doReturn(version).when(versioningManagerMock).get(ITEM1_ID, version);
+ Version version = new Version();
+ doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
- doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(version);
+ doReturn(workflowVersion).when(versionMapperMock).fromVersion(version);
workflowVersionManager.deleteArtifact(ITEM1_ID, VERSION1_ID);
verify(artifactRepositoryMock, times(0)).delete(ITEM1_ID, VERSION1_ID);
- verify(versioningManagerMock, times(0)).publish(ITEM1_ID, version, "Delete Artifact");
+ verify(versioningManagerMock, times(0)).publish(ITEM1_ID, VERSION1_ID, "Delete Artifact");
}
@Test
public void shouldDeleteArtifactIfExist() {
doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
- Version version = new Version(VERSION1_ID);
- doReturn(version).when(versioningManagerMock).get(ITEM1_ID, version);
+ Version version = new Version();
+ doReturn(version).when(versioningManagerMock).get(ITEM1_ID, VERSION1_ID);
WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
doReturn(true).when(artifactRepositoryMock).isExist(ITEM1_ID, VERSION1_ID);
- doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(version);
+ doReturn(workflowVersion).when(versionMapperMock).fromVersion(version);
workflowVersionManager.deleteArtifact(ITEM1_ID, VERSION1_ID);
verify(artifactRepositoryMock, times(1)).delete(ITEM1_ID, VERSION1_ID);
- verify(versioningManagerMock, times(1)).publish(ITEM1_ID, version, "Delete Artifact");
- }
-
- private static Version eqVersion(String versionId) {
- return argThat(version -> versionId.equals(version.getId()));
+ verify(versioningManagerMock, times(1)).publish(ITEM1_ID, VERSION1_ID, "Delete Artifact");
}
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java
index 0bf4c1f0..8bffc3e1 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java
@@ -21,10 +21,11 @@ import static org.junit.Assert.assertEquals;
import java.util.Date;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.onap.sdc.common.versioning.persistence.types.InternalVersion;
+import org.onap.sdc.common.versioning.services.types.Version;
+import org.onap.sdc.common.versioning.services.types.VersionStatus;
import org.onap.sdc.workflow.services.types.WorkflowVersion;
import org.onap.sdc.workflow.services.types.WorkflowVersionState;
-import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@@ -42,11 +43,10 @@ public class VersionMapperTest {
@Autowired
VersionMapper versionMapper;
-
@Test
public void shouldMapVersionToWorkflowVersion() {
Version version = createVersion();
- WorkflowVersion mappedWorkflowVersion = versionMapper.versionToWorkflowVersion(version);
+ WorkflowVersion mappedWorkflowVersion = versionMapper.fromVersion(version);
assertEquals(mappedWorkflowVersion.getId(), version.getId());
assertEquals(mappedWorkflowVersion.getBaseId(), version.getBaseId());
assertEquals(mappedWorkflowVersion.getDescription(), version.getDescription());
@@ -58,18 +58,15 @@ public class VersionMapperTest {
@Test
public void shouldMapWorkflowVersionToVersion() {
WorkflowVersion workflowVersion = createWorkflowVersion();
- Version mappedVersion = versionMapper.workflowVersionToVersion(workflowVersion);
- assertEquals(mappedVersion.getId(), workflowVersion.getId());
- assertEquals(mappedVersion.getBaseId(), workflowVersion.getBaseId());
+ Version mappedVersion = new Version();
+ versionMapper.toVersion(workflowVersion, mappedVersion);
assertEquals(mappedVersion.getDescription(), workflowVersion.getDescription());
- assertEquals(mappedVersion.getName(), workflowVersion.getName());
- assertEquals(mappedVersion.getCreationTime(), workflowVersion.getCreationTime());
- assertEquals(mappedVersion.getModificationTime(), workflowVersion.getModificationTime());
}
private Version createVersion() {
- Version version = new Version("version_id");
+ InternalVersion version = new InternalVersion();
+ version.setId("version_id");
version.setBaseId("base_version_id");
version.setName("1.0");
version.setCreationTime(new Date());
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java
index ba5c8730..c0804eb8 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java
@@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.sdc.workflow.services.types.WorkflowVersionState;
-import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.onap.sdc.common.versioning.services.types.VersionStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@@ -62,13 +62,6 @@ public class VersionStateMapperTest {
}
@Test
- public void shouldMapLockedVersionStatusToWorkflowVersionStatus() {
- WorkflowVersionState mappedVersionStatus =
- versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Locked);
- assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus);
- }
-
- @Test
public void shouldMapDeprecatedVersionStatusToWorkflowVersionStatus() {
WorkflowVersionState mappedVersionStatus =
versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Deprecated);
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java
index 723a2eff..ef84190a 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java
@@ -23,10 +23,11 @@ import static org.onap.sdc.workflow.TestUtil.createWorkflow;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.onap.sdc.workflow.services.types.Workflow;
+import org.onap.sdc.common.versioning.services.types.Item;
+import org.onap.sdc.common.versioning.services.types.ItemStatus;
+import org.onap.sdc.workflow.services.impl.ItemType;
import org.onap.sdc.workflow.services.types.ArchivingStatus;
-import org.openecomp.sdc.versioning.types.Item;
-import org.openecomp.sdc.versioning.types.ItemStatus;
+import org.onap.sdc.workflow.services.types.Workflow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@@ -48,7 +49,7 @@ public class WorkflowMapperTest {
public void shouldMapItemToWorkflow() {
Item item = createItem(1, false, true, ItemStatus.ACTIVE);
- Workflow mappedWorkflow = workflowMapper.itemToWorkflow(item);
+ Workflow mappedWorkflow = workflowMapper.fromItem(item);
assertEquals(mappedWorkflow.getId(), item.getId());
assertEquals(mappedWorkflow.getDescription(), item.getDescription());
assertEquals(mappedWorkflow.getName(), item.getName());
@@ -59,11 +60,11 @@ public class WorkflowMapperTest {
public void shouldMapWorkflowToItem() {
Workflow workflow = createWorkflow(1, true, ArchivingStatus.ARCHIVED);
- Item mappedItem = workflowMapper.workflowToItem(workflow);
- assertEquals(mappedItem.getId(), workflow.getId());
- assertEquals(mappedItem.getDescription(), workflow.getDescription());
- assertEquals(mappedItem.getName(), workflow.getName());
- assertEquals(mappedItem.getStatus().name(), workflow.getArchiving().name());
+ Item mappedItem = new Item();
+ workflowMapper.toItem(workflow, mappedItem);
+ assertEquals(ItemType.WORKFLOW.name(), mappedItem.getType());
+ assertEquals(workflow.getDescription(), mappedItem.getDescription());
+ assertEquals(workflow.getName(), mappedItem.getName());
}
}