Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
Set process instance name (#142)
Browse files Browse the repository at this point in the history
Process instance name is not available in ProcessCreatedEvent, so we need to update it in ProcessStartedEventHandler
Refs Activiti/Activiti#1952
  • Loading branch information
erdemedeiros authored and mergify[bot] committed Dec 6, 2018
1 parent 87c8a36 commit cc1102f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Expand Up @@ -54,6 +54,8 @@ public void handle(CloudRuntimeEvent<?, ?> event) {
() -> new QueryException("Unable to find process instance with the given id: " + processInstanceId));
if (ProcessInstance.ProcessInstanceStatus.CREATED.equals(processInstanceEntity.getStatus())) {
processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.RUNNING);
//instance name is not available in ProcessCreatedEvent, so we need to updated it here
processInstanceEntity.setName(startedEvent.getEntity().getName());
processInstanceEntity.setLastModified(new Date(startedEvent.getTimestamp()));
processInstanceRepository.save(processInstanceEntity);
}
Expand Down
Expand Up @@ -58,7 +58,7 @@ public void setUp() {
}

@Test
public void handleShouldUpdateProcessInstanceStatusToRunning() {
public void handleShouldUpdateProcessInstanceStatusToRunningAndUpdateInstanceName() {
//given
CloudProcessStartedEvent event = buildProcessStartedEvent();
ProcessInstanceEntity currentProcessInstanceEntity = mock(ProcessInstanceEntity.class);
Expand All @@ -71,6 +71,7 @@ public void handleShouldUpdateProcessInstanceStatusToRunning() {
//then
verify(processInstanceRepository).save(currentProcessInstanceEntity);
verify(currentProcessInstanceEntity).setStatus(ProcessInstance.ProcessInstanceStatus.RUNNING);
verify(currentProcessInstanceEntity).setName(event.getEntity().getName());
}

@Test
Expand All @@ -94,6 +95,7 @@ public void handleShouldIgnoreEventIfProcessInstanceIsAlreadyInRunningStatus() {
private CloudProcessStartedEvent buildProcessStartedEvent() {
ProcessInstanceImpl processInstance = new ProcessInstanceImpl();
processInstance.setId(UUID.randomUUID().toString());
processInstance.setName("my instance name");
return new CloudProcessStartedEventImpl(processInstance);
}

Expand Down
Expand Up @@ -106,10 +106,13 @@ public void shouldGetAvailableProcInstancesAndFilteredProcessInstances() {
Collection<ProcessInstanceEntity> processInstanceEntities = responseEntity.getBody().getContent();
assertThat(processInstanceEntities)
.extracting(ProcessInstanceEntity::getId,
ProcessInstanceEntity::getName,
ProcessInstanceEntity::getStatus)
.contains(tuple(completedProcess.getId(),
"first",
ProcessInstance.ProcessInstanceStatus.COMPLETED),
tuple(runningProcess.getId(),
"second",
ProcessInstance.ProcessInstanceStatus.RUNNING));
});

Expand Down

0 comments on commit cc1102f

Please sign in to comment.