diff options
author | 2018-07-15 15:41:31 +0300 | |
---|---|---|
committer | 2018-07-15 15:41:31 +0300 | |
commit | 39c01dd3ccb69f53d2e9350994e25f6e64412aa4 (patch) | |
tree | 35e083da4f89b54aa51c1188a36365096500dfdc /workflow-designer-be/src | |
parent | dfdaff5a207726a25a1625a4af88eaededd46a7c (diff) |
Get and update workflow version state
Remove redundant controller interfaces, rename WorkflowVersionStatus to State
Change-Id: I8ddc9cd656fc8bed607c68aa326c7fa7d2980116
Issue-ID: SDC-1503
Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'workflow-designer-be/src')
24 files changed, 583 insertions, 454 deletions
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java index 2173c05a..bb4320cc 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java @@ -1,33 +1,66 @@ package org.onap.sdc.workflow.api; +import static org.onap.sdc.workflow.api.RestConstants.USER_ID_HEADER_PARAM; + import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.onap.sdc.workflow.api.types.CollectionWrapper; import org.onap.sdc.workflow.persistence.types.Workflow; +import org.onap.sdc.workflow.services.WorkflowManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RequestMapping("/workflows") @Api("Workflows") -public interface WorkflowController { +@RestController("workflowController") +public class WorkflowController { + + private final WorkflowManager workflowManager; + + @Autowired + public WorkflowController(@Qualifier("workflowManager") WorkflowManager workflowManager) { + this.workflowManager = workflowManager; + } @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation("List workflows") - CollectionWrapper<Workflow> list(String user); + public CollectionWrapper<Workflow> list(@RequestHeader(USER_ID_HEADER_PARAM) String user) { + return new CollectionWrapper<>(workflowManager.list()); + } @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @ApiOperation("Create workflow") - ResponseEntity<Workflow> create(Workflow workflow, String user); + public ResponseEntity<Workflow> create(@RequestBody Workflow workflow, + @RequestHeader(USER_ID_HEADER_PARAM) String user) { + return new ResponseEntity<>(workflowManager.create(workflow), HttpStatus.CREATED); + } @GetMapping(path = "/{workflowId}") @ApiOperation("Get workflow") - Workflow get(String workflowId, String user); + public Workflow get(@PathVariable("workflowId") String workflowId, + @RequestHeader(USER_ID_HEADER_PARAM) String user) { + Workflow workflow = new Workflow(); + workflow.setId(workflowId); + return workflowManager.get(workflow); + } @PutMapping(path = "/{workflowId}", consumes = MediaType.APPLICATION_JSON_VALUE) @ApiOperation("Update workflow") - Workflow update(Workflow workflow, String workflowId, String user); + public Workflow update(@RequestBody Workflow workflow, @PathVariable("workflowId") String workflowId, + @RequestHeader(USER_ID_HEADER_PARAM) String user) { + workflow.setId(workflowId); + workflowManager.update(workflow); + return workflow; + } } diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java index cb1fb1f3..6214f1bb 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java @@ -1,51 +1,117 @@ package org.onap.sdc.workflow.api; +import static org.onap.sdc.workflow.api.RestConstants.USER_ID_HEADER_PARAM; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.onap.sdc.workflow.api.types.CollectionWrapper; import org.onap.sdc.workflow.api.types.VersionRequestDto; +import org.onap.sdc.workflow.api.types.VersionStateDto; +import org.onap.sdc.workflow.persistence.types.ArtifactEntity; import org.onap.sdc.workflow.persistence.types.WorkflowVersion; +import org.onap.sdc.workflow.services.WorkflowVersionManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.Resource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @RequestMapping("/workflows/{workflowId}/versions") @Api("Workflow versions") -public interface WorkflowVersionController { +@RestController("workflowsVersionController") +public class WorkflowVersionController { + private final WorkflowVersionManager workflowVersionManager; + + @Autowired + public WorkflowVersionController( + @Qualifier("workflowVersionManager") WorkflowVersionManager workflowVersionManager) { + this.workflowVersionManager = workflowVersionManager; + } @GetMapping @ApiOperation("List workflow versions") - CollectionWrapper<WorkflowVersion> list(String workflowId,String user); + public CollectionWrapper<WorkflowVersion> list(@PathVariable("workflowId") String workflowId, + @RequestHeader(USER_ID_HEADER_PARAM) String user) { + return new CollectionWrapper<>(workflowVersionManager.list(workflowId)); + } @PostMapping @ApiOperation("Create workflow version") - ResponseEntity<WorkflowVersion> create(String workflowId, VersionRequestDto versionRequest, String user); + public ResponseEntity<WorkflowVersion> create(@RequestBody VersionRequestDto versionRequest, + @PathVariable("workflowId") String workflowId, @RequestHeader(USER_ID_HEADER_PARAM) String user) { + + WorkflowVersion createdVersion = workflowVersionManager.create(workflowId, versionRequest); + return new ResponseEntity<>(createdVersion, HttpStatus.CREATED); + } @GetMapping("/{versionId}") @ApiOperation("Get workflow version") - WorkflowVersion get(String workflowId,String versionId, String user); + public WorkflowVersion get(@PathVariable("workflowId") String workflowId, + @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) { + return workflowVersionManager.get(workflowId, versionId); + } @PutMapping("/{versionId}") @ApiOperation("Update workflow version") - void update(WorkflowVersion version,String workflowId, String versionId, String user); + public void update(@RequestBody WorkflowVersion version, @PathVariable("workflowId") String workflowId, + @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) { + version.setId(versionId); + workflowVersionManager.update(workflowId, version); + } + @GetMapping("/{versionId}/state") + @ApiOperation("Get workflow version state") + public VersionStateDto getState(@PathVariable("workflowId") String workflowId, + @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) { + return new VersionStateDto(workflowVersionManager.getState(workflowId, versionId)); + } + + @PostMapping("/{versionId}/state") + @ApiOperation("Update workflow version state") + public VersionStateDto updateState(@RequestBody VersionStateDto state, + @PathVariable("workflowId") String workflowId, @PathVariable("versionId") String versionId, + @RequestHeader(USER_ID_HEADER_PARAM) String user) { + workflowVersionManager.updateState(workflowId, versionId, state.getName()); + return new VersionStateDto(state.getName()); + } @PutMapping("/{versionId}/artifact") @ApiOperation("Create/update artifact of a version") - void createArtifact(MultipartFile fileToUpload, String workflowId, String versionId, String user); + public void uploadArtifact(@RequestBody MultipartFile fileToUpload, @PathVariable("workflowId") String workflowId, + @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) { + workflowVersionManager.uploadArtifact(workflowId, versionId, fileToUpload); + } @GetMapping("/{versionId}/artifact") @ApiOperation("Download workflow version artifact") - ResponseEntity<Resource> getArtifact(String workflowId, String versionId, String user); + public ResponseEntity<Resource> getArtifact(@PathVariable("workflowId") String workflowId, + @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) { + ArtifactEntity artifact = workflowVersionManager.getArtifact(workflowId, versionId); + + return ResponseEntity.ok() + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + artifact.getFileName()) + .contentType(MediaType.APPLICATION_OCTET_STREAM) + .body(new InputStreamResource(artifact.getArtifactData())); + } @DeleteMapping("/{versionId}/artifact") @ApiOperation("Delete workflow version artifact") - void deleteArtifact(String workflowId, String versionId, String user); + public void deleteArtifact(@PathVariable("workflowId") String workflowId, + @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) { + workflowVersionManager.deleteArtifact(workflowId, versionId); + } } diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java index 0b5278ac..68fd41a5 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/exceptionshandlers/CustomizedResponseEntityExceptionHandler.java @@ -7,8 +7,9 @@ import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; import org.onap.sdc.workflow.services.exceptions.InvalidArtifactException; import org.onap.sdc.workflow.services.exceptions.UniqueValueViolationException; -import org.onap.sdc.workflow.services.exceptions.CreateVersionException; +import org.onap.sdc.workflow.services.exceptions.VersionCreationException; import org.onap.sdc.workflow.services.exceptions.VersionModificationException; +import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -31,16 +32,17 @@ public class CustomizedResponseEntityExceptionHandler extends ResponseEntityExce return new ResponseEntity<>(exception.getMessage(), NOT_FOUND); } - @ExceptionHandler({InvalidArtifactException.class, VersionModificationException.class}) + @ExceptionHandler({InvalidArtifactException.class, VersionModificationException.class, + VersionStateModificationException.class}) public final ResponseEntity<String> handleInvalidArtifactException( Exception exception) { return new ResponseEntity<>(exception.getMessage(), UNPROCESSABLE_ENTITY); } - @ExceptionHandler(CreateVersionException.class) + @ExceptionHandler(VersionCreationException.class) public final ResponseEntity<String> handleVersioningErrorException( - CreateVersionException exception) { + VersionCreationException exception) { return new ResponseEntity<>(exception.getMessage(), FORBIDDEN); } } diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowControllerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowControllerImpl.java deleted file mode 100644 index 0d9ee4be..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowControllerImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.onap.sdc.workflow.api.impl; - -import static org.onap.sdc.workflow.api.RestConstants.USER_ID_HEADER_PARAM; - -import org.onap.sdc.workflow.api.WorkflowController; -import org.onap.sdc.workflow.api.types.CollectionWrapper; -import org.onap.sdc.workflow.persistence.types.Workflow; -import org.onap.sdc.workflow.services.WorkflowManager; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RestController; - -@RestController("workflowController") -public class WorkflowControllerImpl implements WorkflowController { - - private final WorkflowManager workflowManager; - - @Autowired - public WorkflowControllerImpl(@Qualifier("workflowManager") WorkflowManager workflowManager) { - this.workflowManager = workflowManager; - } - - @Override - public CollectionWrapper<Workflow> list(@RequestHeader(USER_ID_HEADER_PARAM) String user) { - return new CollectionWrapper<>(workflowManager.list()); - } - - @Override - public ResponseEntity<Workflow> create(@RequestBody Workflow workflow, @RequestHeader(USER_ID_HEADER_PARAM) String user) { - return new ResponseEntity<>(workflowManager.create(workflow), HttpStatus.CREATED); - } - - @Override - public Workflow get(@PathVariable("workflowId") String workflowId, @RequestHeader(USER_ID_HEADER_PARAM) String user) { - Workflow workflow = new Workflow(); - workflow.setId(workflowId); - return workflowManager.get(workflow); - } - - @Override - public Workflow update(@RequestBody Workflow workflow, @PathVariable("workflowId") String workflowId, - @RequestHeader(USER_ID_HEADER_PARAM) String user) { - workflow.setId(workflowId); - workflowManager.update(workflow); - return workflow; - } -} diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowVersionControllerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowVersionControllerImpl.java deleted file mode 100644 index 0570ac85..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/impl/WorkflowVersionControllerImpl.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.onap.sdc.workflow.api.impl; - -import static org.onap.sdc.workflow.api.RestConstants.USER_ID_HEADER_PARAM; - -import org.onap.sdc.workflow.api.WorkflowVersionController; -import org.onap.sdc.workflow.api.types.CollectionWrapper; -import org.onap.sdc.workflow.api.types.VersionRequestDto; -import org.onap.sdc.workflow.persistence.types.ArtifactEntity; -import org.onap.sdc.workflow.persistence.types.WorkflowVersion; -import org.onap.sdc.workflow.services.WorkflowVersionManager; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.core.io.InputStreamResource; -import org.springframework.core.io.Resource; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; - -@RestController("workflowsVersionController") -public class WorkflowVersionControllerImpl implements WorkflowVersionController { - - private final WorkflowVersionManager workflowVersionManager; - - @Autowired - public WorkflowVersionControllerImpl(@Qualifier("workflowVersionManager") WorkflowVersionManager workflowVersionManager) { - this.workflowVersionManager = workflowVersionManager; - } - - @Override - public CollectionWrapper<WorkflowVersion> list(@PathVariable("workflowId") String workflowId, - @RequestHeader(USER_ID_HEADER_PARAM) String user) { - return new CollectionWrapper<>(workflowVersionManager.list(workflowId)); - } - - @Override - public ResponseEntity<WorkflowVersion> create(@PathVariable("workflowId") String workflowId,@RequestBody VersionRequestDto versionRequest, - @RequestHeader(USER_ID_HEADER_PARAM) String user) { - - WorkflowVersion createdVersion = workflowVersionManager.create(workflowId, versionRequest); - return new ResponseEntity<>(createdVersion, HttpStatus.CREATED); - } - - @Override - public WorkflowVersion get(@PathVariable("workflowId") String workflowId,@PathVariable("versionId") String versionId, - @RequestHeader(USER_ID_HEADER_PARAM) String user) { - return workflowVersionManager.get(workflowId,versionId); - } - - @Override - public void update(@RequestBody WorkflowVersion version,@PathVariable("workflowId") String workflowId, - @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) { - - version.setId(versionId); - workflowVersionManager.update(workflowId,version); - } - - @Override - public void createArtifact(@RequestBody MultipartFile fileToUpload, @PathVariable("workflowId") String workflowId, - @PathVariable("versionId") String versionId,@RequestHeader(USER_ID_HEADER_PARAM) String user) { - - workflowVersionManager.uploadArtifact(workflowId,new WorkflowVersion(versionId),fileToUpload); - - } - - @Override - public ResponseEntity<Resource> getArtifact(@PathVariable("workflowId") String workflowId, - @PathVariable("versionId") String versionId, @RequestHeader(USER_ID_HEADER_PARAM) String user) { - WorkflowVersion requestedVersion = new WorkflowVersion(versionId); - ArtifactEntity artifact = workflowVersionManager.getArtifact(workflowId, requestedVersion); - - return ResponseEntity.ok() - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + artifact.getFileName()) - .contentType(MediaType.APPLICATION_OCTET_STREAM) - .body(new InputStreamResource(artifact.getArtifactData())); - } - - @Override - public void deleteArtifact(@PathVariable("workflowId") String workflowId, @PathVariable("versionId") String versionId, - @RequestHeader(USER_ID_HEADER_PARAM) String user) { - - } -} diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStateDto.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStateDto.java new file mode 100644 index 00000000..5963a2bf --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStateDto.java @@ -0,0 +1,20 @@ +package org.onap.sdc.workflow.api.types; + +import java.util.List; +import lombok.Data; +import org.onap.sdc.workflow.persistence.types.WorkflowVersionState; + +@Data +public class VersionStateDto { + + private WorkflowVersionState name; + private List<WorkflowVersionState> nextStates; + + public VersionStateDto() { + } + + public VersionStateDto(WorkflowVersionState state) { + name = state; + nextStates = state.getNextStates(); + } +} diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java index ce90e3fd..db0999b6 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersion.java @@ -13,12 +13,12 @@ public class WorkflowVersion { private String baseId; private Date creationTime; private Date modificationTime; - private WorkflowVersionStatus status; + private WorkflowVersionState state; public WorkflowVersion(String id) { this.id = id; - this.status = WorkflowVersionStatus.DRAFT; + this.state = WorkflowVersionState.DRAFT; } public WorkflowVersion() { diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersionState.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersionState.java new file mode 100644 index 00000000..9414fa17 --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersionState.java @@ -0,0 +1,20 @@ +package org.onap.sdc.workflow.persistence.types; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public enum WorkflowVersionState { + + CERTIFIED, DRAFT(CERTIFIED); + + private final List<WorkflowVersionState> nextStates; + + WorkflowVersionState(WorkflowVersionState... nextStates) { + this.nextStates = Collections.unmodifiableList(Arrays.asList(nextStates)); + } + + public List<WorkflowVersionState> getNextStates() { + return nextStates; + } +} diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersionStatus.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersionStatus.java deleted file mode 100644 index 62f5847c..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/WorkflowVersionStatus.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.onap.sdc.workflow.persistence.types; - -public enum WorkflowVersionStatus { - - DRAFT, CERTIFIED; -} diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java index ec9db1f7..30234526 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java @@ -2,8 +2,9 @@ package org.onap.sdc.workflow.services; import java.util.Collection; import org.onap.sdc.workflow.api.types.VersionRequestDto; -import org.onap.sdc.workflow.persistence.types.WorkflowVersion; import org.onap.sdc.workflow.persistence.types.ArtifactEntity; +import org.onap.sdc.workflow.persistence.types.WorkflowVersion; +import org.onap.sdc.workflow.persistence.types.WorkflowVersionState; import org.springframework.web.multipart.MultipartFile; @@ -11,16 +12,19 @@ public interface WorkflowVersionManager { Collection<WorkflowVersion> list(String workflowId); - WorkflowVersion get(String workflowId,String versionId); + WorkflowVersion create(String workflowId, VersionRequestDto versionRequest); + + void update(String id, WorkflowVersion version); - WorkflowVersion create(String workflowId, VersionRequestDto versionRequest); + WorkflowVersion get(String workflowId, String versionId); - void update(String id,WorkflowVersion version); + WorkflowVersionState getState(String workflowId, String versionId); - void uploadArtifact(String workflowId,WorkflowVersion version, MultipartFile artifact); + void updateState(String workflowId, String versionId, WorkflowVersionState state); - ArtifactEntity getArtifact(String workflowId,WorkflowVersion version); + ArtifactEntity getArtifact(String workflowId, String versionId); - void deleteArtifact(String workflowId,WorkflowVersion version); + void deleteArtifact(String workflowId, String versionId); + void uploadArtifact(String workflowId, String versionId, MultipartFile artifact); } diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/CreateVersionException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/CreateVersionException.java deleted file mode 100644 index cadabb4c..00000000 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/CreateVersionException.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.onap.sdc.workflow.services.exceptions; - -public class CreateVersionException extends RuntimeException { - - public CreateVersionException(String workflowId, String version) { - super(String.format("Error creating new version for workflow with id %s. There is already a draft version %s", - workflowId, version)); - } -} diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionCreationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionCreationException.java new file mode 100644 index 00000000..af01c68f --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionCreationException.java @@ -0,0 +1,15 @@ +package org.onap.sdc.workflow.services.exceptions; + +public class VersionCreationException extends RuntimeException { + + private static final String MSG = "Error creating a new version for workflow with id %s"; + private static final String MSG_WITH_BASE_ID = MSG + " based on version %s"; + + public VersionCreationException(String workflowId, String baseVersionId) { + super(String.format(MSG_WITH_BASE_ID, workflowId, baseVersionId)); + } + + public VersionCreationException(String workflowId) { + super(String.format(MSG, workflowId)); + } +} diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java index 35680475..64ab6103 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java @@ -2,8 +2,9 @@ package org.onap.sdc.workflow.services.exceptions; public class VersionModificationException extends RuntimeException { - public VersionModificationException(String workflowId, String version) { - super(String.format("Error while trying to modify version for workflow id %s. " - + "Version %s is CERTIFIED and can not be edited", workflowId, version)); + public VersionModificationException(String workflowId, String versionId) { + super(String.format( + "Error while trying to modify version %s of workflow %s: Version is CERTIFIED and can not be edited", + versionId, workflowId)); } } diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java new file mode 100644 index 00000000..6c4606db --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java @@ -0,0 +1,12 @@ +package org.onap.sdc.workflow.services.exceptions; + +import org.onap.sdc.workflow.persistence.types.WorkflowVersionState; + +public class VersionStateModificationException extends RuntimeException { + + public VersionStateModificationException(String workflowId, String versionId, WorkflowVersionState sourceState, + WorkflowVersionState targetState) { + super(String.format("Workflow %s, version %s: state can not be changed from %s to %s", workflowId, versionId, + sourceState.name(), targetState.name())); + } +} 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 e934efd3..d559f025 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 @@ -6,20 +6,21 @@ import java.io.IOException; import java.io.InputStream; import java.util.Collection; import java.util.List; -import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; import org.onap.sdc.workflow.api.types.VersionRequestDto; import org.onap.sdc.workflow.persistence.ArtifactRepository; import org.onap.sdc.workflow.persistence.types.ArtifactEntity; -import org.onap.sdc.workflow.persistence.types.WorkflowVersionStatus; import org.onap.sdc.workflow.persistence.types.WorkflowVersion; +import org.onap.sdc.workflow.persistence.types.WorkflowVersionState; import org.onap.sdc.workflow.services.WorkflowVersionManager; -import org.onap.sdc.workflow.services.exceptions.CreateVersionException; import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; import org.onap.sdc.workflow.services.exceptions.InvalidArtifactException; +import org.onap.sdc.workflow.services.exceptions.VersionCreationException; import org.onap.sdc.workflow.services.exceptions.VersionModificationException; +import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException; import org.onap.sdc.workflow.services.impl.mappers.VersionMapper; +import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.types.VersionCreationMethod; @@ -31,54 +32,41 @@ import org.springframework.web.multipart.MultipartFile; @Service("workflowVersionManager") public class WorkflowVersionManagerImpl implements WorkflowVersionManager { + private static final String VERSION_NOT_EXIST_MSG = "version with id '%s' does not exist for workflow with id '%s'"; private final VersioningManager versioningManager; private final ArtifactRepository artifactRepository; - private VersionMapper versionMapper; + private final VersionMapper versionMapper; + private final VersionStateMapper versionStateMapper; @Autowired public WorkflowVersionManagerImpl(VersioningManager versioningManager, ArtifactRepository artifactRepository, - VersionMapper versionMapper) { + VersionMapper versionMapper, VersionStateMapper versionStateMapper) { this.versioningManager = versioningManager; this.artifactRepository = artifactRepository; this.versionMapper = versionMapper; + this.versionStateMapper = versionStateMapper; } @Override public Collection<WorkflowVersion> list(String workflowId) { - - return versioningManager.list(workflowId).stream() - .map(version -> versionMapper.versionToWorkflowVersion(version)) + return versioningManager.list(workflowId).stream().map(versionMapper::versionToWorkflowVersion) .collect(Collectors.toList()); } @Override public WorkflowVersion get(String workflowId, String versionId) { - - Version version = new Version(versionId); - try { - return this.versionMapper.versionToWorkflowVersion(versioningManager.get(workflowId, version)); - } catch (Exception e) { - throw new EntityNotFoundException( - String.format("version with id '%s' does not exist for workflow with id %s", version.getId(), - workflowId)); - } + return versionMapper.versionToWorkflowVersion(getVersion(workflowId, versionId)); } @Override public WorkflowVersion create(String workflowId, VersionRequestDto versionRequest) { - List<Version> versions = versioningManager.list(workflowId); if (versionRequest.getBaseVersionId() != null) { - Version baseVersion = findVersion(versions, versionRequest.getBaseVersionId()).orElseThrow( - () -> new EntityNotFoundException( - String.format("version with id '%s' does not exist for workflow with id %s", - versionRequest.getBaseVersionId(), workflowId))); - - if(!Certified.equals(baseVersion.getStatus())){ - throw new CreateVersionException(workflowId, versionRequest.getBaseVersionId()); - } + validateVersionExistAndCertified(workflowId, versions, versionRequest.getBaseVersionId()); + } else if (!versions.isEmpty()) { + throw new VersionCreationException(workflowId); } Version version = new Version(); @@ -86,40 +74,63 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { version.setBaseId(versionRequest.getBaseVersionId()); Version createdVersion = versioningManager.create(workflowId, version, VersionCreationMethod.major); - if (versions.isEmpty()){ + if (versions.isEmpty()) { // only for first version artifactRepository.createStructure(workflowId, createdVersion.getId()); + versioningManager.publish(workflowId, createdVersion, "Add workflow structure"); } - versioningManager.publish(workflowId, createdVersion, "Initial version"); - return versionMapper.versionToWorkflowVersion(createdVersion); } - private Optional<Version> findVersion(List<Version> versions, String baseVersionId) { - return versions.stream().filter(version -> baseVersionId.equals(version.getId())).findFirst(); + @Override + public void update(String workflowId, WorkflowVersion workflowVersion) { + Version retrievedVersion = getVersion(workflowId, workflowVersion.getId()); + if (WorkflowVersionState.CERTIFIED + .equals(versionStateMapper.versionStatusToWorkflowVersionState(retrievedVersion.getStatus()))) { + throw new VersionModificationException(workflowId, workflowVersion.getId()); + } + + Version version = versionMapper.workflowVersionToVersion(workflowVersion); + version.setName(retrievedVersion.getName()); + version.setStatus(retrievedVersion.getStatus()); + + versioningManager.updateVersion(workflowId, version); + versioningManager.publish(workflowId, version, "Update version"); } @Override - public void update(String id, WorkflowVersion version) { - - Version versionToUpdate = mapVersionInfo(id, version); - versioningManager.updateVersion(id, versionToUpdate); - versioningManager.publish(id, versionToUpdate, "Update version"); + public WorkflowVersionState getState(String workflowId, String versionId) { + return versionStateMapper.versionStatusToWorkflowVersionState(getVersion(workflowId, versionId).getStatus()); } + @Override + public void updateState(String workflowId, String versionId, WorkflowVersionState state) { + Version retrievedVersion = getVersion(workflowId, versionId); + WorkflowVersionState retrievedState = + versionStateMapper.versionStatusToWorkflowVersionState(retrievedVersion.getStatus()); + if (WorkflowVersionState.CERTIFIED.equals(retrievedState) || retrievedState.equals(state)) { + throw new VersionStateModificationException(workflowId, versionId, retrievedState, state); + } + + retrievedVersion.setStatus(versionStateMapper.workflowVersionStateToVersionStatus(state)); + versioningManager.updateVersion(workflowId, retrievedVersion); + versioningManager.publish(workflowId, retrievedVersion, + String.format("Update version state from %s to %s", retrievedState.name(), state.name())); + } @Override - public void uploadArtifact(String workflowId, WorkflowVersion version, MultipartFile artifact) { - WorkflowVersion retrievedVersion = get(workflowId, version.getId()); - if (WorkflowVersionStatus.CERTIFIED.equals(retrievedVersion.getStatus())) { - throw new VersionModificationException(workflowId, version.getId()); + public void uploadArtifact(String workflowId, String versionId, MultipartFile artifact) { + Version retrievedVersion = getVersion(workflowId, versionId); + if (WorkflowVersionState.CERTIFIED + .equals(versionStateMapper.versionStatusToWorkflowVersionState(retrievedVersion.getStatus()))) { + throw new VersionModificationException(workflowId, versionId); } try (InputStream artifactData = artifact.getInputStream()) { ArtifactEntity artifactEntity = new ArtifactEntity(StringUtils.cleanPath(artifact.getOriginalFilename()), artifactData); - artifactRepository.update(workflowId, version.getId(), artifactEntity); - versioningManager.publish(workflowId, versionMapper.workflowVersionToVersion(version), "Update Artifact"); + artifactRepository.update(workflowId, versionId, artifactEntity); + versioningManager.publish(workflowId, new Version(versionId), "Update Artifact"); } catch (IOException e) { throw new InvalidArtifactException(e.getMessage()); @@ -127,38 +138,49 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { } @Override - public ArtifactEntity getArtifact(String workflowId, WorkflowVersion version) { - WorkflowVersion retrievedVersion = get(workflowId, version.getId()); - Optional<ArtifactEntity> artifactOptional = artifactRepository.get(workflowId, retrievedVersion.getId()); + public ArtifactEntity getArtifact(String workflowId, String versionId) { + getVersion(workflowId, versionId); + Optional<ArtifactEntity> artifactOptional = artifactRepository.get(workflowId, versionId); if (!artifactOptional.isPresent()) { throw new EntityNotFoundException( - String.format("Artifact for workflow id %S version id %S was not found", workflowId, - version.getId())); + String.format("Artifact for workflow id %S version id %S was not found", workflowId, versionId)); } return artifactOptional.get(); } @Override - public void deleteArtifact(String workflowId, WorkflowVersion version) { - WorkflowVersion retrievedVersion = get(workflowId, version.getId()); - if (WorkflowVersionStatus.CERTIFIED.equals(retrievedVersion.getStatus())) { - throw new VersionModificationException(workflowId, version.getId()); + public void deleteArtifact(String workflowId, String versionId) { + WorkflowVersion retrievedVersion = get(workflowId, versionId); + if (WorkflowVersionState.CERTIFIED.equals(retrievedVersion.getState())) { + throw new VersionModificationException(workflowId, versionId); } - artifactRepository.delete(workflowId, version.getId()); + artifactRepository.delete(workflowId, versionId); + versioningManager.publish(workflowId, new Version(versionId), "Delete Artifact"); } - private boolean isFirstVersionCreation(String id, Version createdVersion) { - return Objects.isNull(createdVersion.getBaseId()) && versioningManager.list(id).size() == 1; - } + private void validateVersionExistAndCertified(String workflowId, List<Version> versions, String versionId) { + Version baseVersion = findVersion(versions, versionId).orElseThrow( + () -> new EntityNotFoundException(String.format(VERSION_NOT_EXIST_MSG, versionId, workflowId))); - protected Version mapVersionInfo(String id, WorkflowVersion workflowVersion) { - WorkflowVersion retrievedVersion = get(id, workflowVersion.getId()); - Version version = new Version(workflowVersion.getId()); - version.setBaseId(retrievedVersion.getBaseId()); - version.setName(retrievedVersion.getName()); - return version; + if (!Certified.equals(baseVersion.getStatus())) { + throw new VersionCreationException(workflowId, versionId); + } } + private Version getVersion(String workflowId, String versionId) { + try { + Version version = versioningManager.get(workflowId, new Version(versionId)); + if (version == null) { + throw new EntityNotFoundException(String.format(VERSION_NOT_EXIST_MSG, versionId, workflowId)); + } + return version; + } catch (Exception e) { + throw new EntityNotFoundException(String.format(VERSION_NOT_EXIST_MSG, versionId, workflowId)); + } + } + private static Optional<Version> findVersion(List<Version> versions, String versionId) { + return versions.stream().filter(version -> versionId.equals(version.getId())).findFirst(); + } } 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 6e0c3d6d..bcf89661 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 @@ -2,13 +2,15 @@ package org.onap.sdc.workflow.services.impl.mappers; import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.onap.sdc.workflow.persistence.types.WorkflowVersion; import org.openecomp.sdc.versioning.dao.types.Version; -@Mapper(componentModel = "spring", uses = VersionStatusMapper.class) +@Mapper(componentModel = "spring", uses = VersionStateMapper.class) public interface VersionMapper { + @Mapping(source = "status", target = "state") WorkflowVersion versionToWorkflowVersion(Version version); @InheritInverseConfiguration diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStatusMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java index 1cdfd69e..0c2f5391 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStatusMapper.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java @@ -4,19 +4,19 @@ import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; import org.mapstruct.ValueMapping; import org.mapstruct.ValueMappings; -import org.onap.sdc.workflow.persistence.types.WorkflowVersionStatus; +import org.onap.sdc.workflow.persistence.types.WorkflowVersionState; import org.openecomp.sdc.versioning.dao.types.VersionStatus; @Mapper(componentModel = "spring") -public interface VersionStatusMapper { +public interface VersionStateMapper { @ValueMappings({@ValueMapping(source = "Certified", target = "CERTIFIED"), @ValueMapping(source = "Draft", target = "DRAFT"), @ValueMapping(source = "<ANY_REMAINING>", target = "DRAFT")}) - WorkflowVersionStatus versionStatusToWorkflowVersionStatus(VersionStatus status); + WorkflowVersionState versionStatusToWorkflowVersionState(VersionStatus status); @InheritInverseConfiguration - VersionStatus workflowVersionStatusToVersionStatus(WorkflowVersionStatus status); + VersionStatus workflowVersionStateToVersionStatus(WorkflowVersionState status); } diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java index d23d3f90..69b25b01 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java @@ -8,6 +8,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.onap.sdc.workflow.TestUtil.createWorkflow; +import static org.onap.sdc.workflow.api.RestConstants.USER_ID_HEADER_PARAM; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -25,7 +26,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.sdc.workflow.RestPath; -import org.onap.sdc.workflow.api.impl.WorkflowControllerImpl; import org.onap.sdc.workflow.persistence.types.Workflow; import org.onap.sdc.workflow.services.WorkflowManager; import org.openecomp.sdc.versioning.types.Item; @@ -42,13 +42,12 @@ public class WorkflowControllerTest { "Missing request header '%s' for method parameter of type String"; private static final String USER_ID = "userId"; private static final Gson GSON = new Gson(); - public static final String USER_ID_HEADER = "USER_ID"; private MockMvc mockMvc; @InjectMocks - private WorkflowControllerImpl workflowController; + private WorkflowController workflowController; @Mock private WorkflowManager workflowManagerMock; @@ -73,7 +72,7 @@ public class WorkflowControllerTest { Workflow workflowMock = createWorkflow(1, true); doReturn(workflowMock).when(workflowManagerMock).get(any(Workflow.class)); mockMvc.perform( - get(RestPath.getWorkflowPath(workflowMock.getId())).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID) + get(RestPath.getWorkflowPath(workflowMock.getId())).header(USER_ID_HEADER_PARAM, USER_ID) .contentType(APPLICATION_JSON)).andDo(print()) .andExpect(status().isOk()).andExpect(jsonPath("$.id", is(workflowMock.getId()))) .andExpect(jsonPath("$.name", is(workflowMock.getName()))); @@ -84,7 +83,7 @@ public class WorkflowControllerTest { MockHttpServletResponse response = mockMvc.perform(get(RestPath.getWorkflowsPath()).contentType(APPLICATION_JSON)).andDo(print()) .andExpect(status().isBadRequest()).andExpect(status().is(400)).andReturn().getResponse(); - assertEquals(String.format(MISSING_REQUEST_HEADER_ERRROR_FORMAT, USER_ID_HEADER), response.getErrorMessage()); + assertEquals(String.format(MISSING_REQUEST_HEADER_ERRROR_FORMAT, USER_ID_HEADER_PARAM), response.getErrorMessage()); } @Test @@ -93,7 +92,7 @@ public class WorkflowControllerTest { List<Workflow> workflowMocks = createWorkflows(numOfWorkflows); doReturn(workflowMocks).when(workflowManagerMock).list(); mockMvc.perform( - get(RestPath.getWorkflowsPath()).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON)) + get(RestPath.getWorkflowsPath()).header(USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON)) .andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.results", hasSize(numOfWorkflows))); } @@ -103,7 +102,7 @@ public class WorkflowControllerTest { item.setId("abc"); Workflow reqWorkflow = createWorkflow(1, false); mockMvc.perform( - post(RestPath.getWorkflowsPath()).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON) + post(RestPath.getWorkflowsPath()).header(USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON) .content(GSON.toJson(reqWorkflow))).andDo(print()).andExpect(status().isCreated()) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); verify(workflowManagerMock, times(1)).create(reqWorkflow); diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java index d38261b7..75b132ad 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java @@ -25,7 +25,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.sdc.workflow.RestPath; -import org.onap.sdc.workflow.api.impl.WorkflowVersionControllerImpl; import org.onap.sdc.workflow.api.types.VersionRequestDto; import org.onap.sdc.workflow.persistence.types.WorkflowVersion; import org.onap.sdc.workflow.services.WorkflowVersionManager; @@ -52,7 +51,7 @@ public class WorkflowVersionControllerTest { private WorkflowVersionManager workflowVersionManagerMock; @InjectMocks - private WorkflowVersionControllerImpl workflowVersionController; + private WorkflowVersionController workflowVersionController; @Before public void setUp() { diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java index 5173b063..3e228759 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java @@ -24,7 +24,7 @@ import org.openecomp.sdc.versioning.types.ItemStatus; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) -public class WorkflowManagerTest { +public class WorkflowManagerImplTest { private static final String ITEM1_ID = "workflowId1"; private static final String WORKFLOW_TYPE = "WORKFLOW"; 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 new file mode 100644 index 00000000..ae69b280 --- /dev/null +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java @@ -0,0 +1,258 @@ +package org.onap.sdc.workflow.services.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.any; +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.persistence.types.WorkflowVersionState.CERTIFIED; +import static org.onap.sdc.workflow.persistence.types.WorkflowVersionState.DRAFT; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Optional; +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.ArgumentMatcher; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.sdc.workflow.api.types.VersionRequestDto; +import org.onap.sdc.workflow.persistence.ArtifactRepository; +import org.onap.sdc.workflow.persistence.types.ArtifactEntity; +import org.onap.sdc.workflow.persistence.types.WorkflowVersion; +import org.onap.sdc.workflow.persistence.types.WorkflowVersionState; +import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; +import org.onap.sdc.workflow.services.exceptions.VersionCreationException; +import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException; +import org.onap.sdc.workflow.services.impl.mappers.VersionMapper; +import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper; +import org.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.VersionCreationMethod; +import org.springframework.mock.web.MockMultipartFile; + +@RunWith(MockitoJUnitRunner.class) +public class WorkflowVersionManagerImplTest { + + private static final String ITEM1_ID = "item_id_1"; + private static final String VERSION1_ID = "version_id_1"; + private static final String VERSION2_ID = "version_id_2"; + + @Mock + private VersioningManager versioningManagerMock; + @Mock + private ArtifactRepository artifactRepositoryMock; + @Mock + private VersionMapper versionMapperMock; + @Mock + private VersionStateMapper versionStateMapperMock; + @InjectMocks + private WorkflowVersionManagerImpl workflowVersionManager; + + @Test(expected = EntityNotFoundException.class) + public void shouldThrowExceptionWhenVersionDontExist() { + Version nonExistingVersion = new Version(VERSION1_ID); + doThrow(new RuntimeException()).when(versioningManagerMock).get(ITEM1_ID, nonExistingVersion); + workflowVersionManager.get(ITEM1_ID, VERSION1_ID); + } + + @Test + public void shouldReturnWorkflowVersionWhenExist() { + Version version = new Version(VERSION1_ID); + doReturn(version).when(versioningManagerMock).get(ITEM1_ID, version); + workflowVersionManager.get(ITEM1_ID, VERSION1_ID); + verify(versioningManagerMock).get(ITEM1_ID, version); + } + + @Test + public void shouldReturnWorkflowVersionList() { + List<Version> versionList = Arrays.asList(new Version(VERSION1_ID), new Version(VERSION2_ID)); + versionList.forEach(version -> { + version.setBaseId("baseVersionId"); + version.setDescription("Version description"); + version.setName("name"); + version.setCreationTime(new Date()); + version.setModificationTime(new Date()); + }); + doReturn(versionList).when(versioningManagerMock).list(ITEM1_ID); + workflowVersionManager.list(ITEM1_ID); + verify(versioningManagerMock).list(ITEM1_ID); + verify(versionMapperMock, times(2)).versionToWorkflowVersion(any(Version.class)); + } + + @Test + public void shouldUpdateWorkflowVersion() { + Version retrievedVersion = new Version(VERSION1_ID); + retrievedVersion.setName("1.0"); + retrievedVersion.setDescription("WorkflowVersion description"); + retrievedVersion.setStatus(VersionStatus.Draft); + doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(retrievedVersion.getStatus()); + + WorkflowVersion inputVersion = new WorkflowVersion(VERSION1_ID); + inputVersion.setName("1.0"); + inputVersion.setDescription("WorkflowVersion description updated"); + + Version mappedInputVersion = new Version(VERSION1_ID); + mappedInputVersion.setName("1.0"); + mappedInputVersion.setDescription("WorkflowVersion description updated"); + doReturn(mappedInputVersion).when(versionMapperMock).workflowVersionToVersion(inputVersion); + + ArgumentCaptor<Version> versionArgCaptor = ArgumentCaptor.forClass(Version.class); + workflowVersionManager.update(ITEM1_ID, inputVersion); + + verify(versioningManagerMock).updateVersion(eq(ITEM1_ID), versionArgCaptor.capture()); + Version captorVersion = versionArgCaptor.getValue(); + assertEquals("1.0", captorVersion.getName()); + assertEquals("WorkflowVersion description updated", captorVersion.getDescription()); + assertEquals(VersionStatus.Draft, captorVersion.getStatus()); + verify(versioningManagerMock).publish(ITEM1_ID, mappedInputVersion, "Update version"); + } + + @Test + public void shouldCreateWorkflowVersion() { + Version version = new Version(VERSION1_ID); + version.setDescription("version desc"); + doReturn(version).when(versioningManagerMock).create(ITEM1_ID, version, VersionCreationMethod.major); + VersionRequestDto workflowVersion = new VersionRequestDto(); + workflowVersion.setDescription("version desc"); + workflowVersionManager.create(ITEM1_ID, workflowVersion); + verify(versioningManagerMock).create(ITEM1_ID, version, VersionCreationMethod.major); + + } + + @Test(expected = VersionCreationException.class) + public void shouldTrowExceptionWhenDraftVersionExists() { + VersionRequestDto versionRequestDto = new VersionRequestDto(); + versionRequestDto.setBaseVersionId(VERSION2_ID); + + Version baseVersion = new Version(VERSION2_ID); + baseVersion.setStatus(VersionStatus.Draft); + List<Version> versions = Collections.singletonList(baseVersion); + doReturn(versions).when(versioningManagerMock).list(ITEM1_ID); + + workflowVersionManager.create(ITEM1_ID, versionRequestDto); + } + + @Test(expected = EntityNotFoundException.class) + public void getStateOfNonExisting() { + doThrow(new RuntimeException()).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(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)); + doReturn(CERTIFIED).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus()); + + WorkflowVersionState state = workflowVersionManager.getState(ITEM1_ID, VERSION1_ID); + assertEquals(CERTIFIED, state); + } + + @Test(expected = EntityNotFoundException.class) + public void updateStateOfNonExisting() { + doThrow(new RuntimeException()).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(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)); + doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus()); + + workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, DRAFT); + } + + @Test(expected = VersionStateModificationException.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)); + doReturn(CERTIFIED).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus()); + + workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED); + } + + @Test + public void updateState() { + Version retrievedVersion = new Version(VERSION1_ID); + retrievedVersion.setStatus(VersionStatus.Draft); + doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(VersionStatus.Draft); + doReturn(VersionStatus.Certified).when(versionStateMapperMock).workflowVersionStateToVersionStatus(CERTIFIED); + + ArgumentCaptor<Version> versionArgCaptor = ArgumentCaptor.forClass(Version.class); + workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED); + + verify(versioningManagerMock).updateVersion(eq(ITEM1_ID), versionArgCaptor.capture()); + assertEquals(VersionStatus.Certified, versionArgCaptor.getValue().getStatus()); + verify(versioningManagerMock) + .publish(eq(ITEM1_ID), eqVersion(VERSION1_ID), eq("Update version state from DRAFT to CERTIFIED")); + } + + @Test + public void shouldUploadArtifact() { + Version version = new Version(VERSION1_ID); + version.setStatus(VersionStatus.Draft); + doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus()); + + MockMultipartFile mockFile = new MockMultipartFile("data", "filename.txt", "text/plain", "some xml".getBytes()); + workflowVersionManager.uploadArtifact(ITEM1_ID, VERSION1_ID, mockFile); + + verify(artifactRepositoryMock).update(eq(ITEM1_ID), eq(VERSION1_ID), any(ArtifactEntity.class)); + } + + @Test(expected = EntityNotFoundException.class) + public void shouldThrowExceptionWhenArtifactNotFound() { + doReturn(new Version(VERSION1_ID)).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + + doReturn(Optional.empty()).when(artifactRepositoryMock).get(ITEM1_ID, VERSION1_ID); + workflowVersionManager.getArtifact(ITEM1_ID, VERSION1_ID); + } + + @Test + public void shouldReturnArtifact() throws IOException { + doReturn(new Version(VERSION1_ID)).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + + InputStream inputStreamMock = IOUtils.toInputStream("some test data for my input stream", "UTF-8"); + ArtifactEntity artifactMock = new ArtifactEntity("fileName.txt", inputStreamMock); + doReturn(Optional.of(artifactMock)).when(artifactRepositoryMock).get(ITEM1_ID, VERSION1_ID); + ArtifactEntity returnedArtifact = workflowVersionManager.getArtifact(ITEM1_ID, VERSION1_ID); + assertEquals(artifactMock, returnedArtifact); + } + + private static Version eqVersion(String versionId) { + return argThat(new EqVersion(versionId)); + } + + private static class EqVersion implements ArgumentMatcher<Version> { + + private final String versionId; + + EqVersion(String versionId) { + this.versionId = versionId; + } + + @Override + public boolean matches(Version version) { + return versionId.equals(version.getId()); + } + } + +} diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerTest.java deleted file mode 100644 index a82b5f3d..00000000 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerTest.java +++ /dev/null @@ -1,168 +0,0 @@ -package org.onap.sdc.workflow.services.impl; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Matchers.any; -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.persistence.types.WorkflowVersionStatus.*; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Optional; -import org.apache.commons.io.IOUtils; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Spy; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.sdc.workflow.api.types.VersionRequestDto; -import org.onap.sdc.workflow.persistence.ArtifactRepository; -import org.onap.sdc.workflow.persistence.types.ArtifactEntity; -import org.onap.sdc.workflow.persistence.types.WorkflowVersion; -import org.onap.sdc.workflow.persistence.types.WorkflowVersionStatus; -import org.onap.sdc.workflow.services.exceptions.CreateVersionException; -import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; -import org.onap.sdc.workflow.services.impl.mappers.VersionMapper; -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.VersionCreationMethod; -import org.springframework.mock.web.MockMultipartFile; - -@RunWith(MockitoJUnitRunner.class) -public class WorkflowVersionManagerTest { - - - private static final String ITEM1_ID = "item_id_1"; - private static final String VERSION1_ID = "version_id_1"; - private static final String VERSION2_ID = "version_id_2"; - - @Mock - private VersionMapper versionMapperMock; - - @Mock - private VersioningManager versioningManagerMock; - - @Mock - private ArtifactRepository artifactRepositoryMock; - - @Spy - @InjectMocks - private WorkflowVersionManagerImpl workflowVersionManager; - - - @Test(expected = EntityNotFoundException.class) - public void shouldThrowExceptionWhenVersionDontExist(){ - Version nonExistingVersion = new Version(VERSION1_ID); - doThrow(new RuntimeException()).when(versioningManagerMock).get(ITEM1_ID, nonExistingVersion); - workflowVersionManager.get(ITEM1_ID, VERSION1_ID); - } - - @Test - public void shouldReturnWorkflowVersionWhenExist(){ - Version version = new Version(VERSION1_ID); - doReturn(version).when(versioningManagerMock).get(ITEM1_ID,version); - workflowVersionManager.get(ITEM1_ID,VERSION1_ID); - verify(versioningManagerMock).get(ITEM1_ID,version); - } - - @Test - public void shouldReturnWorkflowVersionList(){ - List<Version> versionList = - Arrays.asList(new Version(VERSION1_ID), new Version(VERSION2_ID)); - versionList.forEach(version -> { - version.setBaseId("baseVersionId"); - version.setDescription("Version description"); - version.setName("name"); - version.setCreationTime(new Date()); - version.setModificationTime(new Date()); - }); - doReturn(versionList).when(versioningManagerMock).list(ITEM1_ID); - workflowVersionManager.list(ITEM1_ID); - verify(versioningManagerMock).list(ITEM1_ID); - verify(versionMapperMock ,times(2)).versionToWorkflowVersion(any(Version.class)); - } - - @Test - public void shouldUpdateWorkflowVersion(){ - Version version = new Version(VERSION1_ID); - version.setName("1.0"); - version.setDescription("WorkflowVersion description"); - WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID); - workflowVersion.setName("1.0"); - workflowVersion.setDescription("WorkflowVersion description"); - doReturn(version).when(workflowVersionManager).mapVersionInfo(ITEM1_ID,workflowVersion); - workflowVersionManager.update(ITEM1_ID,workflowVersion); - verify(versioningManagerMock).updateVersion(ITEM1_ID,version); - } - - @Test - public void shouldCreateWorkflowVersion(){ - Version version = new Version(VERSION1_ID); - version.setDescription("version desc"); - doReturn(version).when(versioningManagerMock).create(ITEM1_ID,version, VersionCreationMethod.major); - VersionRequestDto workflowVersion = new VersionRequestDto(); - workflowVersion.setDescription("version desc"); - workflowVersionManager.create(ITEM1_ID,workflowVersion); - verify(versioningManagerMock).create(ITEM1_ID,version, VersionCreationMethod.major); - - } - - @Test(expected = CreateVersionException.class) - public void shouldTrowExceptionWhenDraftVersionExists(){ - VersionRequestDto versionRequestDto = new VersionRequestDto(); - versionRequestDto.setBaseVersionId(VERSION2_ID); - - Version baseVersion = new Version(VERSION2_ID); - baseVersion.setStatus(VersionStatus.Draft); - List<Version> versions = Collections.singletonList(baseVersion); - doReturn(versions).when(versioningManagerMock).list(ITEM1_ID); - - workflowVersionManager.create(ITEM1_ID,versionRequestDto); - } - - @Test - public void shouldUploadArtifact() throws IOException { - - String mockFileName = "filename.txt"; - MockMultipartFile mockFile = - new MockMultipartFile("data", mockFileName, "text/plain", "some xml".getBytes()); - WorkflowVersion version = new WorkflowVersion(VERSION1_ID); - version.setStatus(WorkflowVersionStatus.DRAFT); - doReturn(version).when(workflowVersionManager).get(ITEM1_ID,VERSION1_ID); - workflowVersionManager.uploadArtifact(ITEM1_ID,version,mockFile); - - verify(artifactRepositoryMock).update(eq(ITEM1_ID),eq(VERSION1_ID),any(ArtifactEntity.class)); - } - - @Test(expected = EntityNotFoundException.class) - public void shouldThrowExceptionWhenArtifactNotFound(){ - WorkflowVersion version = new WorkflowVersion(VERSION1_ID); - version.setStatus(DRAFT); - doReturn(version).when(workflowVersionManager).get(ITEM1_ID,VERSION1_ID); - doReturn(Optional.empty()).when(artifactRepositoryMock).get(ITEM1_ID,VERSION1_ID); - workflowVersionManager.getArtifact(ITEM1_ID,version); - } - - @Test - public void shouldReturnArtifact() throws IOException { - WorkflowVersion version = new WorkflowVersion(VERSION1_ID); - doReturn(version).when(workflowVersionManager).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); - doReturn(Optional.of(artifactMock)).when(artifactRepositoryMock).get(ITEM1_ID,VERSION1_ID); - ArtifactEntity returnedArtifact = workflowVersionManager.getArtifact(ITEM1_ID, new WorkflowVersion(VERSION1_ID)); - assertEquals(artifactMock,returnedArtifact); - } - -} 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 f9d65bd3..b778de47 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 @@ -6,7 +6,7 @@ import java.util.Date; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.sdc.workflow.persistence.types.WorkflowVersion; -import org.onap.sdc.workflow.persistence.types.WorkflowVersionStatus; +import org.onap.sdc.workflow.persistence.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; @@ -20,7 +20,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; public class VersionMapperTest { @Configuration - @ComponentScan(basePackageClasses = {VersionMapper.class, VersionStatusMapper.class}) + @ComponentScan(basePackageClasses = {VersionMapper.class, VersionStateMapper.class}) public static class VersionMapperSpringTestConfig { } @Autowired @@ -73,7 +73,7 @@ public class VersionMapperTest { workflowVersion.setCreationTime(new Date()); workflowVersion.setModificationTime(new Date()); workflowVersion.setDescription("version_description"); - workflowVersion.setStatus(WorkflowVersionStatus.CERTIFIED); + workflowVersion.setState(WorkflowVersionState.CERTIFIED); return workflowVersion; } diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStatusMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java index 0d4b6cd5..59d16289 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStatusMapperTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; -import org.onap.sdc.workflow.persistence.types.WorkflowVersionStatus; +import org.onap.sdc.workflow.persistence.types.WorkflowVersionState; import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; @@ -12,64 +12,64 @@ import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@ContextConfiguration(classes = VersionStatusMapperTest.VersionStatusMapperSpringTestConfig.class) +@ContextConfiguration(classes = VersionStateMapperTest.VersionStatusMapperSpringTestConfig.class) @RunWith(SpringJUnit4ClassRunner.class) -public class VersionStatusMapperTest { +public class VersionStateMapperTest { @Configuration - @ComponentScan(basePackageClasses = {VersionStatusMapper.class}) + @ComponentScan(basePackageClasses = {VersionStateMapper.class}) public static class VersionStatusMapperSpringTestConfig { } @Autowired - VersionStatusMapper versionStatusMapper; + VersionStateMapper versionStateMapper; @Test public void shouldMapCertifiedVersionStatusToWorkflowVersionStatus() { - WorkflowVersionStatus mappedVersionStatus = - versionStatusMapper.versionStatusToWorkflowVersionStatus(VersionStatus.Certified); - assertEquals(WorkflowVersionStatus.CERTIFIED, mappedVersionStatus); + WorkflowVersionState mappedVersionStatus = + versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Certified); + assertEquals(WorkflowVersionState.CERTIFIED, mappedVersionStatus); } @Test public void shouldMapDraftVersionStatusToWorkflowVersionStatus() { - WorkflowVersionStatus mappedVersionStatus = - versionStatusMapper.versionStatusToWorkflowVersionStatus(VersionStatus.Draft); - assertEquals(WorkflowVersionStatus.DRAFT, mappedVersionStatus); + WorkflowVersionState mappedVersionStatus = + versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Draft); + assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus); } @Test public void shouldMapDeletedVersionStatusToWorkflowVersionStatus() { - WorkflowVersionStatus mappedVersionStatus = - versionStatusMapper.versionStatusToWorkflowVersionStatus(VersionStatus.Deleted); - assertEquals(WorkflowVersionStatus.DRAFT, mappedVersionStatus); + WorkflowVersionState mappedVersionStatus = + versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Deleted); + assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus); } @Test public void shouldMapLockedVersionStatusToWorkflowVersionStatus() { - WorkflowVersionStatus mappedVersionStatus = - versionStatusMapper.versionStatusToWorkflowVersionStatus(VersionStatus.Locked); - assertEquals(WorkflowVersionStatus.DRAFT, mappedVersionStatus); + WorkflowVersionState mappedVersionStatus = + versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Locked); + assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus); } @Test public void shouldMapDeprecatedVersionStatusToWorkflowVersionStatus() { - WorkflowVersionStatus mappedVersionStatus = - versionStatusMapper.versionStatusToWorkflowVersionStatus(VersionStatus.Deprecated); - assertEquals(WorkflowVersionStatus.DRAFT, mappedVersionStatus); + WorkflowVersionState mappedVersionStatus = + versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Deprecated); + assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus); } @Test public void shouldMapCertifiedWorkflowVersionStatusToVersionStatus() { VersionStatus mappedVersionStatus = - versionStatusMapper.workflowVersionStatusToVersionStatus(WorkflowVersionStatus.CERTIFIED); + versionStateMapper.workflowVersionStateToVersionStatus(WorkflowVersionState.CERTIFIED); assertEquals(VersionStatus.Certified, mappedVersionStatus); } @Test public void shouldMapDraftWorkflowVersionStatusToVersionStatus() { VersionStatus mappedVersionStatus = - versionStatusMapper.workflowVersionStatusToVersionStatus(WorkflowVersionStatus.DRAFT); + versionStateMapper.workflowVersionStateToVersionStatus(WorkflowVersionState.DRAFT); assertEquals(VersionStatus.Draft, mappedVersionStatus); } } |