use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.
the class IdentityLinkEventsTest method testProcessDefinitionIdentityLinkEvents.
/**
* Check identity links on process definitions.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessDefinitionIdentityLinkEvents() throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("oneTaskProcess").singleResult();
assertNotNull(processDefinition);
// Add candidate user and group
repositoryService.addCandidateStarterUser(processDefinition.getId(), "kermit");
repositoryService.addCandidateStarterGroup(processDefinition.getId(), "sales");
assertEquals(4, listener.getEventsReceived().size());
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertTrue(event.getEntity() instanceof IdentityLink);
assertEquals(processDefinition.getId(), event.getProcessDefinitionId());
assertNull(event.getProcessInstanceId());
assertNull(event.getExecutionId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(2);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertTrue(event.getEntity() instanceof IdentityLink);
assertEquals(processDefinition.getId(), event.getProcessDefinitionId());
assertNull(event.getProcessInstanceId());
assertNull(event.getExecutionId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(3);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
listener.clearEventsReceived();
// Delete identity links
repositoryService.deleteCandidateStarterUser(processDefinition.getId(), "kermit");
repositoryService.deleteCandidateStarterGroup(processDefinition.getId(), "sales");
assertEquals(2, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertTrue(event.getEntity() instanceof IdentityLink);
assertEquals(processDefinition.getId(), event.getProcessDefinitionId());
assertNull(event.getProcessInstanceId());
assertNull(event.getExecutionId());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertTrue(event.getEntity() instanceof IdentityLink);
assertEquals(processDefinition.getId(), event.getProcessDefinitionId());
assertNull(event.getProcessInstanceId());
assertNull(event.getExecutionId());
}
use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.
the class IdentityLinkEventsTest method testProcessInstanceIdentityLinkEvents.
/**
* Check identity links on process instances.
*/
@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceIdentityLinkEvents() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// Add identity link
runtimeService.addUserIdentityLink(processInstance.getId(), "kermit", "test");
assertEquals(2, listener.getEventsReceived().size());
ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
assertTrue(event.getEntity() instanceof IdentityLink);
assertEquals(processInstance.getId(), event.getProcessInstanceId());
assertEquals(processInstance.getId(), event.getExecutionId());
assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
IdentityLink link = (IdentityLink) event.getEntity();
assertEquals("kermit", link.getUserId());
assertEquals("test", link.getType());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
listener.clearEventsReceived();
// Deleting process should delete identity link
runtimeService.deleteProcessInstance(processInstance.getId(), "test");
assertEquals(1, listener.getEventsReceived().size());
event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
assertTrue(event.getEntity() instanceof IdentityLink);
link = (IdentityLink) event.getEntity();
assertEquals("kermit", link.getUserId());
assertEquals("test", link.getType());
}
use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.
the class StartAuthorizationTest method testIdentityLinks.
@Deployment
public void testIdentityLinks() throws Exception {
setUpUsersAndGroups();
try {
ProcessDefinition latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process1").singleResult();
assertNotNull(latestProcessDef);
List<IdentityLink> links = repositoryService.getIdentityLinksForProcessDefinition(latestProcessDef.getId());
assertEquals(0, links.size());
latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process2").singleResult();
assertNotNull(latestProcessDef);
links = repositoryService.getIdentityLinksForProcessDefinition(latestProcessDef.getId());
assertEquals(2, links.size());
assertEquals(true, containsUserOrGroup("user1", null, links));
assertEquals(true, containsUserOrGroup("user2", null, links));
latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process3").singleResult();
assertNotNull(latestProcessDef);
links = repositoryService.getIdentityLinksForProcessDefinition(latestProcessDef.getId());
assertEquals(1, links.size());
assertEquals("user1", links.get(0).getUserId());
latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process4").singleResult();
assertNotNull(latestProcessDef);
links = repositoryService.getIdentityLinksForProcessDefinition(latestProcessDef.getId());
assertEquals(4, links.size());
assertEquals(true, containsUserOrGroup("userInGroup2", null, links));
assertEquals(true, containsUserOrGroup(null, "group1", links));
assertEquals(true, containsUserOrGroup(null, "group2", links));
assertEquals(true, containsUserOrGroup(null, "group3", links));
} finally {
tearDownUsersAndGroups();
}
}
use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.
the class TaskIdentityLinksTest method testCustomLinkGroupLink.
@Deployment(resources = "org/activiti/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testCustomLinkGroupLink() {
runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
String taskId = taskService.createTaskQuery().singleResult().getId();
taskService.addGroupIdentityLink(taskId, "muppets", "playing");
List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
IdentityLink identityLink = identityLinks.get(0);
assertEquals("muppets", identityLink.getGroupId());
assertNull("kermit", identityLink.getUserId());
assertEquals("playing", identityLink.getType());
assertEquals(taskId, identityLink.getTaskId());
assertEquals(1, identityLinks.size());
taskService.deleteGroupIdentityLink(taskId, "muppets", "playing");
assertEquals(0, taskService.getIdentityLinksForTask(taskId).size());
}
use of org.activiti.engine.task.IdentityLink in project Activiti by Activiti.
the class TaskIdentityLinksTest method testEmptyCandidateUserLink.
@Deployment(resources = "org/activiti/engine/test/api/task/IdentityLinksProcess.bpmn20.xml")
public void testEmptyCandidateUserLink() {
runtimeService.startProcessInstanceByKey("IdentityLinksProcess");
String taskId = taskService.createTaskQuery().singleResult().getId();
taskService.addCandidateGroup(taskId, "muppets");
taskService.deleteCandidateUser(taskId, "kermit");
List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
assertNotNull(identityLinks);
assertEquals(1, identityLinks.size());
IdentityLink identityLink = identityLinks.get(0);
assertEquals("muppets", identityLink.getGroupId());
assertEquals(null, identityLink.getUserId());
assertEquals(IdentityLinkType.CANDIDATE, identityLink.getType());
assertEquals(taskId, identityLink.getTaskId());
taskService.deleteCandidateGroup(taskId, "muppets");
assertEquals(0, taskService.getIdentityLinksForTask(taskId).size());
}
Aggregations