Merge "Add version request/response DTOs."
diff --git a/workflow-bdd/features/Version.feature b/workflow-bdd/features/Version.feature
index a5327fd..3ca68c9 100644
--- a/workflow-bdd/features/Version.feature
+++ b/workflow-bdd/features/Version.feature
@@ -65,6 +65,24 @@
Then I want to get path "/workflows/{item.id}/versions/{item.versionId}"
And I want to check property "description" for value "workflow version description updated"
+ Scenario: Update version with duplicate input name - invalid
+ And I want to update the input property "description" with value "version with with duplicate input name"
+ And I want to create for path "/workflows/{item.id}/versions" with the input data from the context
+ And I want to copy to property "item.versionId" from response data path "id"
+
+ And I want to set the input data to file "resources/json/versionWithDuplicateInputName.json"
+ Then I want the following to fail with response status code 400
+ When I want to update for path "/workflows/{item.id}/versions/{item.versionId}" with the input data from the context
+
+ Scenario: Update version with duplicate output name - invalid
+ And I want to update the input property "description" with value "version with with duplicate output name"
+ And I want to create for path "/workflows/{item.id}/versions" with the input data from the context
+ And I want to copy to property "item.versionId" from response data path "id"
+
+ And I want to set the input data to file "resources/json/versionWithDuplicateOutputName.json"
+ Then I want the following to fail with response status code 400
+ When I want to update for path "/workflows/{item.id}/versions/{item.versionId}" with the input data from the context
+
Scenario: Update version with inputs/outputs (create/update/delete parameters)
And I want to set the input data to file "resources/json/versionWith2Inputs2Outputs1.json"
And I want to create for path "/workflows/{item.id}/versions" with the input data from the context
diff --git a/workflow-bdd/resources/json/versionWithDuplicateInputName.json b/workflow-bdd/resources/json/versionWithDuplicateInputName.json
new file mode 100644
index 0000000..978d9c0
--- /dev/null
+++ b/workflow-bdd/resources/json/versionWithDuplicateInputName.json
@@ -0,0 +1,27 @@
+{
+ "description": "version with with duplicate input name",
+ "inputs": [
+ {
+ "mandatory": true,
+ "name": "in1",
+ "type": "STRING"
+ },
+ {
+ "mandatory": true,
+ "name": "in1",
+ "type": "INTEGER"
+ }
+ ],
+ "outputs": [
+ {
+ "mandatory": true,
+ "name": "out1",
+ "type": "TIMESTAMP"
+ },
+ {
+ "mandatory": true,
+ "name": "out2",
+ "type": "BOOLEAN"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/workflow-bdd/resources/json/versionWithDuplicateOutputName.json b/workflow-bdd/resources/json/versionWithDuplicateOutputName.json
new file mode 100644
index 0000000..4810ebe
--- /dev/null
+++ b/workflow-bdd/resources/json/versionWithDuplicateOutputName.json
@@ -0,0 +1,27 @@
+{
+ "description": "version with duplicate output name",
+ "inputs": [
+ {
+ "mandatory": true,
+ "name": "in1",
+ "type": "STRING"
+ },
+ {
+ "mandatory": true,
+ "name": "in2",
+ "type": "INTEGER"
+ }
+ ],
+ "outputs": [
+ {
+ "mandatory": true,
+ "name": "out1",
+ "type": "TIMESTAMP"
+ },
+ {
+ "mandatory": true,
+ "name": "out1",
+ "type": "BOOLEAN"
+ }
+ ]
+}
\ No newline at end of file
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 67bea00..213cd71 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
@@ -19,10 +19,14 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
+import java.util.stream.Collectors;
import javax.validation.Valid;
+import org.onap.sdc.workflow.api.mappers.WorkflowVersionDtoMapper;
import org.onap.sdc.workflow.api.types.CollectionResponse;
import org.onap.sdc.workflow.api.types.VersionStateDto;
import org.onap.sdc.workflow.api.types.VersionStatesFormatter;
+import org.onap.sdc.workflow.api.types.WorkflowVersionRequest;
+import org.onap.sdc.workflow.api.types.WorkflowVersionResponse;
import org.onap.sdc.workflow.api.types.dto.ArtifactDeliveriesRequestDto;
import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
import org.onap.sdc.workflow.services.WorkflowVersionManager;
@@ -53,13 +57,16 @@
@RestController("workflowsVersionController")
public class WorkflowVersionController {
- private final WorkflowVersionManager workflowVersionManager;
+ private final WorkflowVersionManager versionManager;
+ private final WorkflowVersionDtoMapper versionDtoMapper;
private final ArtifactAssociationService associationHandler;
@Autowired
- public WorkflowVersionController(@Qualifier("workflowVersionManager") WorkflowVersionManager workflowVersionManager,
+ public WorkflowVersionController(@Qualifier("workflowVersionManager") WorkflowVersionManager versionManager,
+ WorkflowVersionDtoMapper versionDtoMapper,
@Qualifier("ArtifactAssociationHandler") ArtifactAssociationService artifactAssociationHandler) {
- this.workflowVersionManager = workflowVersionManager;
+ this.versionManager = versionManager;
+ this.versionDtoMapper = versionDtoMapper;
this.associationHandler = artifactAssociationHandler;
}
@@ -67,40 +74,45 @@
@ApiOperation("List workflow versions")
@ApiImplicitParam(name = "state", dataType = "string", paramType = "query", allowableValues = "DRAFT,CERTIFIED",
value = "Filter by state")
- public CollectionResponse<WorkflowVersion> list(@PathVariable("workflowId") String workflowId,
+ public CollectionResponse<WorkflowVersionResponse> list(@PathVariable("workflowId") String workflowId,
@ApiIgnore VersionStatesFormatter stateFilter, @UserId String user) {
- return new CollectionResponse<>(workflowVersionManager.list(workflowId, stateFilter.getVersionStates()));
+ return new CollectionResponse<>(versionManager.list(workflowId, stateFilter.getVersionStates()).stream()
+ .map(versionDtoMapper::workflowVersionToResponse)
+ .collect(Collectors.toList()));
}
@PostMapping
@ApiOperation("Create workflow version")
- public ResponseEntity<WorkflowVersion> create(@RequestBody @Valid WorkflowVersion version,
+ public ResponseEntity<WorkflowVersionResponse> create(@RequestBody @Valid WorkflowVersionRequest request,
@PathVariable("workflowId") String workflowId,
@RequestParam(value = "baseVersionId", required = false) String baseVersionId, @UserId String user) {
- WorkflowVersion createdVersion = workflowVersionManager.create(workflowId, baseVersionId, version);
+ WorkflowVersionResponse createdVersion = versionDtoMapper.workflowVersionToResponse(
+ versionManager.create(workflowId, baseVersionId, versionDtoMapper.requestToWorkflowVersion(request)));
return new ResponseEntity<>(createdVersion, HttpStatus.CREATED);
}
@GetMapping("/{versionId}")
@ApiOperation("Get workflow version")
- public WorkflowVersion get(@PathVariable("workflowId") String workflowId,
+ public WorkflowVersionResponse get(@PathVariable("workflowId") String workflowId,
@PathVariable("versionId") String versionId, @UserId String user) {
- return workflowVersionManager.get(workflowId, versionId);
+ return versionDtoMapper.workflowVersionToResponse(versionManager.get(workflowId, versionId));
}
@PutMapping("/{versionId}")
@ApiOperation("Update workflow version")
- public void update(@RequestBody @Valid WorkflowVersion version, @PathVariable("workflowId") String workflowId,
- @PathVariable("versionId") String versionId, @UserId String user) {
+ public void update(@RequestBody @Valid WorkflowVersionRequest request,
+ @PathVariable("workflowId") String workflowId, @PathVariable("versionId") String versionId,
+ @UserId String user) {
+ WorkflowVersion version = versionDtoMapper.requestToWorkflowVersion(request);
version.setId(versionId);
- workflowVersionManager.update(workflowId, version);
+ versionManager.update(workflowId, version);
}
@GetMapping("/{versionId}/state")
@ApiOperation("Get workflow version state")
public VersionStateDto getState(@PathVariable("workflowId") String workflowId,
@PathVariable("versionId") String versionId, @UserId String user) {
- return new VersionStateDto(workflowVersionManager.getState(workflowId, versionId));
+ return new VersionStateDto(versionManager.getState(workflowId, versionId));
}
@PostMapping("/{versionId}/state")
@@ -108,7 +120,7 @@
public VersionStateDto updateState(@RequestBody VersionStateDto state,
@PathVariable("workflowId") String workflowId, @PathVariable("versionId") String versionId,
@UserId String user) {
- workflowVersionManager.updateState(workflowId, versionId, state.getName());
+ versionManager.updateState(workflowId, versionId, state.getName());
return new VersionStateDto(state.getName());
}
@@ -118,21 +130,21 @@
@PathVariable("workflowId") String workflowId, @PathVariable("versionId") String versionId,
@UserId String user) {
return associationHandler
- .execute(user, deliveriesRequestDto, workflowVersionManager.getArtifact(workflowId, versionId));
+ .execute(user, deliveriesRequestDto, versionManager.getArtifact(workflowId, versionId));
}
@PutMapping("/{versionId}/artifact")
@ApiOperation("Create/update artifact of a version")
public void uploadArtifact(@RequestBody MultipartFile fileToUpload, @PathVariable("workflowId") String workflowId,
@PathVariable("versionId") String versionId, @UserId String user) {
- workflowVersionManager.uploadArtifact(workflowId, versionId, fileToUpload);
+ versionManager.uploadArtifact(workflowId, versionId, fileToUpload);
}
@GetMapping("/{versionId}/artifact")
@ApiOperation("Download workflow version artifact")
public ResponseEntity<Resource> getArtifact(@PathVariable("workflowId") String workflowId,
@PathVariable("versionId") String versionId, @UserId String user) {
- ArtifactEntity artifact = workflowVersionManager.getArtifact(workflowId, versionId);
+ ArtifactEntity artifact = versionManager.getArtifact(workflowId, versionId);
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + artifact.getFileName())
@@ -144,6 +156,6 @@
@ApiOperation("Delete workflow version artifact")
public void deleteArtifact(@PathVariable("workflowId") String workflowId,
@PathVariable("versionId") String versionId, @UserId String user) {
- workflowVersionManager.deleteArtifact(workflowId, versionId);
+ versionManager.deleteArtifact(workflowId, versionId);
}
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/WorkflowVersionDtoMapper.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/WorkflowVersionDtoMapper.java
new file mode 100644
index 0000000..120b0d2
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/WorkflowVersionDtoMapper.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+package org.onap.sdc.workflow.api.mappers;
+
+import org.mapstruct.Mapper;
+import org.onap.sdc.workflow.api.types.WorkflowVersionRequest;
+import org.onap.sdc.workflow.api.types.WorkflowVersionResponse;
+import org.onap.sdc.workflow.services.types.WorkflowVersion;
+
+@Mapper(componentModel = "spring")
+public interface WorkflowVersionDtoMapper {
+
+ WorkflowVersion requestToWorkflowVersion(WorkflowVersionRequest request);
+
+ WorkflowVersionResponse workflowVersionToResponse(WorkflowVersion workflowVersion);
+
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Parameter.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Parameter.java
new file mode 100644
index 0000000..f5bbece
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Parameter.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+package org.onap.sdc.workflow.api.types;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import lombok.Data;
+import org.onap.sdc.workflow.persistence.types.ParameterType;
+
+@Data
+public class Parameter {
+ @NotBlank(message = "Parameter Name may not be blank")
+ @Pattern(regexp = "[A-Za-z0-9_ ]+", message = "Parameter name must contain only letters, digits and underscores")
+ private String name;
+ @NotNull
+ private ParameterType type;
+ @NotNull
+ private boolean mandatory;
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionRequest.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionRequest.java
new file mode 100644
index 0000000..090f129
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionRequest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+package org.onap.sdc.workflow.api.types;
+
+import java.util.Collection;
+import java.util.Collections;
+import javax.validation.Valid;
+import lombok.Data;
+import org.onap.sdc.workflow.api.validation.NoDuplicates;
+
+@Data
+public class WorkflowVersionRequest {
+
+ private String name;
+ private String description;
+ @Valid
+ @NoDuplicates(message = "Inputs names must be unique")
+ private Collection<Parameter> inputs = Collections.emptyList();
+ @Valid
+ @NoDuplicates(message = "Outputs names must be unique")
+ private Collection<Parameter> outputs = Collections.emptyList();
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionResponse.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionResponse.java
new file mode 100644
index 0000000..460d3d6
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionResponse.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+package org.onap.sdc.workflow.api.types;
+
+import java.util.Date;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.onap.sdc.workflow.services.types.WorkflowVersionState;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class WorkflowVersionResponse extends WorkflowVersionRequest {
+
+ private String id;
+ private String baseId;
+ private WorkflowVersionState state;
+ private boolean hasArtifact;
+ private Date creationTime;
+ private Date modificationTime;
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidator.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidator.java
index 2020bb8..7ade1ab 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidator.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidator.java
@@ -22,16 +22,16 @@
import java.util.Set;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import org.onap.sdc.workflow.persistence.types.ParameterEntity;
+import org.onap.sdc.workflow.api.types.Parameter;
-public class NoDuplicatesValidator implements ConstraintValidator<NoDuplicates, Collection<ParameterEntity>> {
+public class NoDuplicatesValidator implements ConstraintValidator<NoDuplicates, Collection<Parameter>> {
@Override
- public boolean isValid(Collection<ParameterEntity> parameterEntities, ConstraintValidatorContext context) {
- if (Objects.isNull(parameterEntities) || parameterEntities.size() < 2) {
+ public boolean isValid(Collection<Parameter> parameters, ConstraintValidatorContext context) {
+ if (Objects.isNull(parameters) || parameters.size() < 2) {
return true;
}
Set<String> testSet = new HashSet<>();
- return !parameterEntities.stream().anyMatch(s -> !testSet.add(s.getName()));
+ return parameters.stream().allMatch(parameter -> testSet.add(parameter.getName()));
}
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java
index bc813f2..4b57ba7 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java
@@ -16,20 +16,13 @@
package org.onap.sdc.workflow.persistence.types;
-import javax.validation.constraints.NotBlank;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Pattern;
import lombok.Data;
@Data
public class ParameterEntity {
private String id;
- @NotBlank(message = "Parameter Name may not be blank")
- @Pattern(regexp = "[A-Za-z0-9_ ]+", message = "Parameter name must contain only letters, digits and underscores")
private String name;
- @NotNull
private ParameterType type;
- @NotNull
private boolean mandatory;
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersion.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersion.java
index 8a68db2..0699157 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersion.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersion.java
@@ -19,14 +19,13 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
-import javax.validation.Valid;
import lombok.Data;
-import org.onap.sdc.workflow.api.validation.NoDuplicates;
+import lombok.NoArgsConstructor;
import org.onap.sdc.workflow.persistence.types.ParameterEntity;
-
@Data
+@NoArgsConstructor
public class WorkflowVersion {
private String id;
@@ -34,22 +33,14 @@
private String description;
private String baseId;
private WorkflowVersionState state;
- @Valid
- @NoDuplicates(message = "Inputs names must be unique")
private Collection<ParameterEntity> inputs = Collections.emptyList();
- @Valid
- @NoDuplicates(message = "Outputs names must be unique")
private Collection<ParameterEntity> outputs = Collections.emptyList();
private boolean hasArtifact;
private Date creationTime;
private Date modificationTime;
-
public WorkflowVersion(String id) {
this.id = id;
this.state = WorkflowVersionState.DRAFT;
}
-
- public WorkflowVersion() {
- }
}
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 2ed1cc1..954839c 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java
@@ -4,7 +4,6 @@
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -23,12 +22,14 @@
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.sdc.workflow.RestPath;
-import org.onap.sdc.workflow.persistence.types.ParameterEntity;
+import org.onap.sdc.workflow.api.mappers.WorkflowVersionDtoMapper;
+import org.onap.sdc.workflow.api.types.Parameter;
+import org.onap.sdc.workflow.api.types.WorkflowVersionRequest;
+import org.onap.sdc.workflow.api.types.WorkflowVersionResponse;
import org.onap.sdc.workflow.persistence.types.ParameterType;
import org.onap.sdc.workflow.services.WorkflowVersionManager;
import org.onap.sdc.workflow.services.types.WorkflowVersion;
import org.onap.sdc.workflow.services.utilities.JsonUtil;
-import org.openecomp.sdc.versioning.dao.types.Version;
import org.springframework.http.HttpStatus;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.MockMvc;
@@ -46,7 +47,8 @@
@Mock
private WorkflowVersionManager workflowVersionManagerMock;
-
+ @Mock
+ private WorkflowVersionDtoMapper versionDtoMapperMock;
@InjectMocks
private WorkflowVersionController workflowVersionController;
@@ -57,77 +59,91 @@
@Test
public void shouldReturnWorkflowVersionListWhenCallingVersionGetREST() throws Exception {
- doReturn(Arrays.asList(new Version(VERSION1_ID), new Version(VERSION2_ID))).when(workflowVersionManagerMock)
- .list(ITEM1_ID, null);
+ WorkflowVersion version1 = new WorkflowVersion(VERSION1_ID);
+ WorkflowVersion version2 = new WorkflowVersion(VERSION2_ID);
+ doReturn(Arrays.asList(version1, version2)).when(workflowVersionManagerMock).list(ITEM1_ID, null);
+
+ WorkflowVersionResponse response1 = new WorkflowVersionResponse();
+ response1.setId(VERSION1_ID);
+ doReturn(response1).when(versionDtoMapperMock).workflowVersionToResponse(version1);
+ WorkflowVersionResponse response2 = new WorkflowVersionResponse();
+ response2.setId(VERSION2_ID);
+ doReturn(response2).when(versionDtoMapperMock).workflowVersionToResponse(version2);
+
mockMvc.perform(get(RestPath.getWorkflowVersions(ITEM1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
.contentType(APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(jsonPath("$.items", hasSize(2))).andExpect(jsonPath("$.items[0].id", is(VERSION1_ID)))
.andExpect(jsonPath("$.items[1].id", is(VERSION2_ID)));
- verify(workflowVersionManagerMock, times(1)).list(ITEM1_ID, null);
+ verify(workflowVersionManagerMock).list(ITEM1_ID, null);
}
-
@Test
public void shouldCreateWorkflowVersionWhenCallingVersionsPostREST() throws Exception {
+ WorkflowVersionRequest request = new WorkflowVersionRequest();
+ request.setDescription("Updated");
WorkflowVersion version = new WorkflowVersion();
- version.setDescription("VersionDescription");
+ version.setDescription("Updated");
+ doReturn(version).when(versionDtoMapperMock).requestToWorkflowVersion(request);
+
mockMvc.perform(post(RestPath.getWorkflowVersions(ITEM1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
- .contentType(APPLICATION_JSON).content(JsonUtil.object2Json(version)))
+ .contentType(APPLICATION_JSON).content(JsonUtil.object2Json(request)))
.andExpect(status().isCreated());
- verify(workflowVersionManagerMock, times(1)).create(ITEM1_ID, null, version);
+ verify(workflowVersionManagerMock).create(ITEM1_ID, null, version);
}
@Test
public void shouldFailCreateWorkflowVersionWhenCallingVersionsPostRESTWithDuplicateInput() throws Exception {
- WorkflowVersion version = new WorkflowVersion();
- Collection<ParameterEntity> inputs =
- Arrays.asList(createParameterEntity("name1"), createParameterEntity("name1"));
+ WorkflowVersionRequest version = new WorkflowVersionRequest();
+ Collection<Parameter> inputs = Arrays.asList(createParameter("name1"), createParameter("name1"));
version.setInputs(inputs);
version.setDescription("VersionDescription");
mockMvc.perform(post(RestPath.getWorkflowVersions(ITEM1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
.contentType(APPLICATION_JSON).content(JsonUtil.object2Json(version)))
.andExpect(status().isBadRequest());
-
}
-
@Test
public void shouldReturnWorkflowVersionWhenExists() throws Exception {
WorkflowVersion version = new WorkflowVersion(VERSION1_ID);
doReturn(version).when(workflowVersionManagerMock).get(ITEM1_ID, VERSION1_ID);
+ WorkflowVersionResponse response = new WorkflowVersionResponse();
+ response.setId(VERSION1_ID);
+ doReturn(response).when(versionDtoMapperMock).workflowVersionToResponse(version);
+
mockMvc.perform(
get(RestPath.getWorkflowVersion(ITEM1_ID, VERSION1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
.contentType(APPLICATION_JSON)).andDo(print()).andExpect(status().isOk())
- .andExpect(jsonPath("$.id", is(version.getId())));
- verify(workflowVersionManagerMock, times(1)).get(ITEM1_ID, VERSION1_ID);
+ .andExpect(jsonPath("$.id", is(VERSION1_ID)));
+ verify(workflowVersionManagerMock).get(ITEM1_ID, VERSION1_ID);
}
@Test
public void shouldUpdateWorkflowVersionWhenCallingPutREST() throws Exception {
+ WorkflowVersionRequest request = new WorkflowVersionRequest();
+ request.setDescription("Updated");
WorkflowVersion version = new WorkflowVersion();
version.setDescription("Updated");
+ doReturn(version).when(versionDtoMapperMock).requestToWorkflowVersion(request);
MockHttpServletResponse result = mockMvc.perform(
put(RestPath.getWorkflowVersion(ITEM1_ID, VERSION1_ID)).header(RestParams.USER_ID_HEADER, USER_ID)
- .contentType(APPLICATION_JSON).content(JsonUtil.object2Json(version))).andReturn()
+ .contentType(APPLICATION_JSON).content(JsonUtil.object2Json(request))).andReturn()
.getResponse();
assertEquals(HttpStatus.OK.value(), result.getStatus());
- version.setId(VERSION1_ID);
- verify(workflowVersionManagerMock, times(1)).update(ITEM1_ID, version);
+ verify(workflowVersionManagerMock).update(ITEM1_ID, version);
}
- private ParameterEntity createParameterEntity(String name) {
- ParameterEntity parameterEntity = new ParameterEntity();
- parameterEntity.setName(name);
- parameterEntity.setMandatory(false);
- parameterEntity.setType(ParameterType.STRING);
- return parameterEntity;
+ private Parameter createParameter(String name) {
+ Parameter parameter = new Parameter();
+ parameter.setName(name);
+ parameter.setMandatory(false);
+ parameter.setType(ParameterType.STRING);
+ return parameter;
}
-
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidatorTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidatorTest.java
index bfc7dc3..2d7d6d2 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidatorTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidatorTest.java
@@ -3,26 +3,25 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.List;
+import java.util.Collections;
import javax.validation.ConstraintValidatorContext;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.onap.sdc.workflow.persistence.types.ParameterEntity;
+import org.onap.sdc.workflow.api.types.Parameter;
public class NoDuplicatesValidatorTest {
class AnnotationWrapper {
@NoDuplicates(message = "test message")
- public Collection<ParameterEntity> collection;
+ public Collection<Parameter> collection;
}
private NoDuplicatesValidator noDuplicatesValidator;
@@ -32,7 +31,8 @@
@Mock
private ConstraintValidatorContext.ConstraintViolationBuilder constraintViolationBuilder;
@Mock
- private ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext nodeBuilderCustomizableContext;
+ private ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext
+ nodeBuilderCustomizableContext;
@Before
public void init() throws NoSuchFieldException {
@@ -44,24 +44,21 @@
@Test
public void shouldFailIfCollectionHaveMoreThen1ParameterEntityWithSameName() {
- Collection<ParameterEntity> inputs =
- Arrays.asList(createParameterEntity("name1"), createParameterEntity("name1"));
+ Collection<Parameter> inputs = Arrays.asList(createParameter("name1"), createParameter("name1"));
assertFalse(noDuplicatesValidator.isValid(inputs, context));
}
@Test
public void shouldPassIfCollectionDontHaveMoreThen1ParameterEntityWithSameName() {
- Collection<ParameterEntity> inputs =
- Arrays.asList(createParameterEntity("name2"), createParameterEntity("name1"));
+ Collection<Parameter> inputs = Arrays.asList(createParameter("name2"), createParameter("name1"));
assertTrue(noDuplicatesValidator.isValid(inputs, context));
}
@Test
public void shouldPassIfCollectionContainsOnlyOneObject() {
- Collection<ParameterEntity> inputs =
- Arrays.asList(createParameterEntity("name2"));
+ Collection<Parameter> inputs = Collections.singletonList(createParameter("name2"));
assertTrue(noDuplicatesValidator.isValid(inputs, context));
}
@@ -83,9 +80,9 @@
return validator;
}
- private ParameterEntity createParameterEntity(String name) {
- ParameterEntity parameterEntity = new ParameterEntity();
- parameterEntity.setName(name);
- return parameterEntity;
+ private Parameter createParameter(String name) {
+ Parameter parameter = new Parameter();
+ parameter.setName(name);
+ return parameter;
}
}
\ No newline at end of file
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
index 9640fa1..5782987 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
@@ -21,7 +21,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
-import org.mockito.ArgumentMatcher;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
@@ -30,13 +29,13 @@
import org.onap.sdc.workflow.persistence.ParameterRepository;
import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
import org.onap.sdc.workflow.persistence.types.ParameterRole;
-import org.onap.sdc.workflow.services.types.WorkflowVersion;
-import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
import org.onap.sdc.workflow.services.exceptions.VersionCreationException;
import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException;
import org.onap.sdc.workflow.services.impl.mappers.VersionMapper;
import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper;
+import org.onap.sdc.workflow.services.types.WorkflowVersion;
+import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionState;
@@ -77,10 +76,11 @@
Version version = new Version(VERSION1_ID);
WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(any(Version.class));
- doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID),any(Version.class));
- doReturn(new ArrayList()).when(parameterRepositoryMock).list(eq(ITEM1_ID), eq(VERSION1_ID), any(ParameterRole.class));
- workflowVersionManager.get(ITEM1_ID,VERSION1_ID);
- verify(versioningManagerMock).get(ITEM1_ID,version);
+ doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), any(Version.class));
+ doReturn(new ArrayList()).when(parameterRepositoryMock)
+ .list(eq(ITEM1_ID), eq(VERSION1_ID), any(ParameterRole.class));
+ workflowVersionManager.get(ITEM1_ID, VERSION1_ID);
+ verify(versioningManagerMock).get(ITEM1_ID, version);
}
/* @Test
@@ -130,18 +130,18 @@
@Test
- public void shouldCreateWorkflowVersion(){
+ public void shouldCreateWorkflowVersion() {
Version version = new Version(VERSION1_ID);
version.setDescription("version desc");
- doReturn(version).when(versioningManagerMock).create(ITEM1_ID,version, VersionCreationMethod.major);
+ doReturn(version).when(versioningManagerMock).create(ITEM1_ID, version, VersionCreationMethod.major);
WorkflowVersion versionRequest = new WorkflowVersion();
versionRequest.setDescription("version desc");
versionRequest.setInputs(new ArrayList<>());
versionRequest.setOutputs(new ArrayList<>());
WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
- doReturn(workflowVersion).when(workflowVersionManager).get(ITEM1_ID,VERSION1_ID);
+ doReturn(workflowVersion).when(workflowVersionManager).get(ITEM1_ID, VERSION1_ID);
workflowVersionManager.create(ITEM1_ID, null, versionRequest);
- verify(versioningManagerMock).create(ITEM1_ID,version, VersionCreationMethod.major);
+ verify(versioningManagerMock).create(ITEM1_ID, version, VersionCreationMethod.major);
}
@Test(expected = VersionCreationException.class)
@@ -196,7 +196,7 @@
doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
doReturn(CERTIFIED).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus());
doThrow(new RuntimeException()).when(versioningManagerMock)
- .submit(eq(ITEM1_ID), eqVersion(VERSION1_ID), anyString());
+ .submit(eq(ITEM1_ID), eqVersion(VERSION1_ID), anyString());
workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED);
}
@@ -249,21 +249,6 @@
}
private static Version eqVersion(String versionId) {
- return argThat(new EqVersion(versionId));
+ return argThat(version -> versionId.equals(version.getId()));
}
-
- private static class EqVersion implements ArgumentMatcher<Version> {
-
- private final String versionId;
-
- EqVersion(String versionId) {
- this.versionId = versionId;
- }
-
- @Override
- public boolean matches(Version version) {
- return versionId.equals(version.getId());
- }
- }
-
}
\ No newline at end of file