use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-remote-api by Alfresco.
the class WorkflowModelBuilderTest method testBuildWorkflowTask.
@SuppressWarnings("unchecked")
public void testBuildWorkflowTask() throws Exception {
Date date = new Date();
WorkflowTask task = makeTask(date);
Map<String, Object> model = builder.buildSimple(task, null);
Object id = model.get(WorkflowModelBuilder.TASK_ID);
assertEquals(task.getId(), id);
Object url = model.get(WorkflowModelBuilder.TASK_URL);
assertEquals("api/task-instances/" + task.getId(), url);
assertEquals(task.getName(), model.get(WorkflowModelBuilder.TASK_NAME));
assertEquals(task.getTitle(), model.get(WorkflowModelBuilder.TASK_TITLE));
assertEquals(task.getDescription(), model.get(WorkflowModelBuilder.TASK_DESCRIPTION));
assertEquals(task.getState().name(), model.get(WorkflowModelBuilder.TASK_STATE));
assertNull(model.get(WorkflowModelBuilder.TASK_OUTCOME));
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_POOLED));
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_EDITABLE));
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_REASSIGNABLE));
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_CLAIMABLE));
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_RELEASABLE));
Map<String, Object> owner = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_OWNER);
assertEquals(userName, owner.get(WorkflowModelBuilder.PERSON_USER_NAME));
assertEquals(firstName, owner.get(WorkflowModelBuilder.PERSON_FIRST_NAME));
assertEquals(lastName, owner.get(WorkflowModelBuilder.PERSON_LAST_NAME));
Map<String, Object> props = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_PROPERTIES);
assertEquals(task.getProperties().size() + 1, props.size());
assertEquals(5, props.get("test_int"));
assertEquals(false, props.get("test_boolean"));
assertEquals("foo bar", props.get("test_string"));
String dateStr = (String) props.get("test_date");
assertEquals(date, ISO8601DateFormat.parse(dateStr));
Map<String, Object> workflowInstance = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE);
assertNotNull(workflowInstance);
WorkflowInstance instance = task.getPath().getInstance();
assertEquals(instance.getId(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_ID));
assertEquals(instance.isActive(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_IS_ACTIVE));
String startDateStr = ISO8601DateFormat.format(instance.getStartDate());
String workFlowStartDateStr = (String) workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE);
assertEquals(startDateStr, ISO8601DateFormat.formatToZulu(workFlowStartDateStr));
task.getProperties().put(WorkflowModel.ASSOC_POOLED_ACTORS, new ArrayList<NodeRef>(0));
model = builder.buildSimple(task, null);
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_POOLED));
ArrayList<NodeRef> actors = new ArrayList<NodeRef>(1);
actors.add(person);
task.getProperties().put(WorkflowModel.ASSOC_POOLED_ACTORS, actors);
model = builder.buildSimple(task, null);
assertEquals(true, model.get(WorkflowModelBuilder.TASK_IS_POOLED));
model = builder.buildSimple(task, Arrays.asList("test_int", "test_string"));
// Check task owner still created properly.
owner = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_OWNER);
assertEquals(userName, owner.get(WorkflowModelBuilder.PERSON_USER_NAME));
// Check properties populated correctly
props = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_PROPERTIES);
assertEquals(2, props.size());
assertEquals(5, props.get("test_int"));
assertEquals("foo bar", props.get("test_string"));
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-remote-api by Alfresco.
the class WorkflowModelBuilderTest method testBuildWorkflowInstance.
@SuppressWarnings("unchecked")
public void testBuildWorkflowInstance() throws Exception {
WorkflowInstance workflowInstance = makeWorkflowInstance(null);
Map<String, Object> model = builder.buildSimple(workflowInstance);
assertEquals(workflowInstance.getId(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_ID));
assertTrue(model.containsKey(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_URL));
assertEquals(workflowInstance.getDefinition().getName(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_NAME));
assertEquals(workflowInstance.getDefinition().getTitle(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_TITLE));
assertEquals(workflowInstance.getDefinition().getDescription(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DESCRIPTION));
assertEquals(workflowInstance.getDescription(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_MESSAGE));
assertEquals(workflowInstance.isActive(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_IS_ACTIVE));
String startDate = ISO8601DateFormat.format(workflowInstance.getStartDate());
String endDate = ISO8601DateFormat.format(workflowInstance.getEndDate());
String startDateBuilder = ISO8601DateFormat.formatToZulu((String) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE));
String endDateBuilder = ISO8601DateFormat.formatToZulu((String) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_END_DATE));
assertEquals(startDate, startDateBuilder);
assertEquals(endDate, endDateBuilder);
Map<String, Object> initiator = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_INITIATOR);
if (initiator != null) {
assertEquals(userName, initiator.get(WorkflowModelBuilder.PERSON_USER_NAME));
assertEquals(firstName, initiator.get(WorkflowModelBuilder.PERSON_FIRST_NAME));
assertEquals(lastName, initiator.get(WorkflowModelBuilder.PERSON_LAST_NAME));
}
assertTrue(model.containsKey(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DEFINITION_URL));
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-remote-api by Alfresco.
the class WorkflowModelBuilderTest method testBuildWorkflowInstanceDetailed.
@SuppressWarnings("unchecked")
public void testBuildWorkflowInstanceDetailed() throws Exception {
WorkflowTaskDefinition workflowTaskDefinition = makeTaskDefinition();
QName taskTypeName = WorkflowModel.TYPE_WORKFLOW_TASK;
when(workflowTaskDefinition.getMetadata().getName()).thenReturn(taskTypeName);
when(workflowTaskDefinition.getMetadata().getTitle(dictionaryService)).thenReturn("The Type Title");
when(workflowTaskDefinition.getMetadata().getDescription(dictionaryService)).thenReturn("The Type Description");
WorkflowInstance workflowInstance = makeWorkflowInstance(workflowTaskDefinition);
Map<String, Object> model = builder.buildDetailed(workflowInstance, true);
assertEquals(workflowInstance.getId(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_ID));
assertEquals(workflowInstance.getDefinition().getName(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_NAME));
assertEquals(workflowInstance.getDefinition().getTitle(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_TITLE));
assertEquals(workflowInstance.getDefinition().getDescription(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DESCRIPTION));
assertEquals(workflowInstance.isActive(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_IS_ACTIVE));
String startDateStr = ISO8601DateFormat.format(workflowInstance.getStartDate());
String endDateStr = ISO8601DateFormat.format(workflowInstance.getEndDate());
String startDateBuilderStr = ISO8601DateFormat.formatToZulu((String) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE));
String endDateBuilderStr = ISO8601DateFormat.formatToZulu((String) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_END_DATE));
assertEquals(startDateStr, startDateBuilderStr);
assertEquals(endDateStr, endDateBuilderStr);
Map<String, Object> initiator = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_INITIATOR);
if (initiator != null) {
assertEquals(userName, initiator.get(WorkflowModelBuilder.PERSON_USER_NAME));
assertEquals(firstName, initiator.get(WorkflowModelBuilder.PERSON_FIRST_NAME));
assertEquals(lastName, initiator.get(WorkflowModelBuilder.PERSON_LAST_NAME));
}
assertEquals(workflowInstance.getContext().toString(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_CONTEXT));
assertEquals(workflowInstance.getWorkflowPackage().toString(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_PACKAGE));
Map<String, Object> taskInstanceModel = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DEFINITION);
assertEquals(workflowInstance.getDefinition().getVersion(), taskInstanceModel.get(WorkflowModelBuilder.WORKFLOW_DEFINITION_VERSION));
assertEquals(workflowInstance.getDefinition().getStartTaskDefinition().getMetadata().getName(), taskInstanceModel.get(WorkflowModelBuilder.WORKFLOW_DEFINITION_START_TASK_DEFINITION_TYPE));
}
Aggregations