mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
[DS-8419] WorkFlow steps preserve order
fix: - Replaced HashMap with LinkedHashMap, to preserve order. feat: - New test to assert steps order; - New matcher for check step.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
package org.dspace.xmlworkflow.state;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -118,7 +118,7 @@ public class Workflow implements BeanNameAware {
|
||||
* @return a map containing the roles, the role name will the key, the role itself the value
|
||||
*/
|
||||
public Map<String, Role> getRoles() {
|
||||
Map<String, Role> roles = new HashMap<>();
|
||||
Map<String, Role> roles = new LinkedHashMap<>();
|
||||
for (Step step : steps) {
|
||||
if (step.getRole() != null) {
|
||||
roles.put(step.getRole().getId(), step.getRole());
|
||||
|
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package org.dspace.app.rest;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalToIgnoringCase;
|
||||
@@ -17,6 +18,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dspace.app.rest.matcher.WorkflowDefinitionMatcher;
|
||||
@@ -29,6 +31,7 @@ import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
|
||||
import org.dspace.xmlworkflow.state.Step;
|
||||
import org.dspace.xmlworkflow.state.Workflow;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
@@ -436,6 +439,34 @@ public class WorkflowDefinitionRestRepositoryIT extends AbstractControllerIntegr
|
||||
.andExpect(jsonPath("$.page.totalElements", is(defaultWorkflow.getSteps().size())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStepsOfWorkflowByName_DefaultWorkflow_Ordered() throws Exception {
|
||||
String token = getAuthToken(eperson.getEmail(), password);
|
||||
Workflow defaultWorkflow = xmlWorkflowFactory.getDefaultWorkflow();
|
||||
List<Step> steps = defaultWorkflow.getSteps();
|
||||
|
||||
//When we call this facets endpoint
|
||||
getClient(token).perform(get(WORKFLOW_DEFINITIONS_ENDPOINT + "/" + defaultWorkflow.getID()
|
||||
+ "/steps")
|
||||
.param("projection", "full"))
|
||||
//We expect a 200 OK status
|
||||
.andExpect(status().isOk())
|
||||
//Number of total workflows is equals to number of non-mapped collections
|
||||
.andExpect(jsonPath("$.page.totalElements", is(steps.size())))
|
||||
// assert the two list equality using ids (preserves order)
|
||||
.andExpect(
|
||||
jsonPath(
|
||||
"$._embedded.steps",
|
||||
contains(
|
||||
steps
|
||||
.stream()
|
||||
.map(WorkflowDefinitionMatcher::matchStep)
|
||||
.collect(Collectors.toList())
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStepsOfWorkflowByName_DefaultWorkflow_NoValidToken() throws Exception {
|
||||
String token = "NonValidToken";
|
||||
|
@@ -17,6 +17,7 @@ import java.util.UUID;
|
||||
import org.dspace.app.rest.model.WorkflowDefinitionRest;
|
||||
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
|
||||
import org.dspace.xmlworkflow.state.Step;
|
||||
import org.dspace.xmlworkflow.state.Workflow;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
@@ -61,4 +62,10 @@ public class WorkflowDefinitionMatcher {
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchStep(Step step) {
|
||||
return allOf(
|
||||
hasJsonPath("$.id", is(step.getId()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user