Skip to content

Commit

Permalink
Merge pull request #242 from xenit-eu/#199
Browse files Browse the repository at this point in the history
Fixes #199 unable to register bean that implements multiple Activiti listeners
  • Loading branch information
kerkhofsd authored May 10, 2019
2 parents 8e2d330 + 9bc7419 commit 5569c24
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Version template:
### Added
* Alfresco 6 support

### Fixed
* [#189](https://github.com/xenit-eu/dynamic-extensions-for-alfresco/issues/189)
Registering a component implementing multiple Activiti listener Interfaces throws exception on startup

## [1.7.6] - 2018-09-05
* [#189](https://github.com/xenit-eu/dynamic-extensions-for-alfresco/issues/189) Support Json 2 on Alfresco 4

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.dynamicextensionsalfresco.workflow.activiti;

import java.beans.ExceptionListener;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -58,11 +57,11 @@ public void afterPropertiesSet() {
}
logger.debug("registered Bundle component {} (type: {}) -> {}", name, type, bean);

if (bean instanceof JavaDelegate) {
if (JavaDelegate.class.equals(type)) {
this.workflowTaskRegistry.registerDelegate(name, (JavaDelegate) bean);
} else if (bean instanceof TaskListener) {
} else if (TaskListener.class.equals(type)) {
this.workflowTaskRegistry.registerTaskListener(name, (TaskListener) bean);
} else if (bean instanceof ExecutionListener) {
} else if (ExecutionListener.class.equals(type)) {
this.workflowTaskRegistry.registerExecutionListener(name, (ExecutionListener) bean);
}
});
Expand All @@ -77,11 +76,11 @@ public void destroy() {
activitiBeanRegistry.remove(name);
logger.debug("unregistered Bundle component {} (type: {}) -> {}", name, type, bean);

if (bean instanceof JavaDelegate) {
if (JavaDelegate.class.equals(type)) {
this.workflowTaskRegistry.unregisterDelegate(name);
} else if (bean instanceof TaskListener) {
} else if (TaskListener.class.equals(type)) {
this.workflowTaskRegistry.unregisterTaskListener(name);
} else if (bean instanceof ExecutionListener) {
} else if (ExecutionListener.class.equals(type)) {
this.workflowTaskRegistry.unregisterExecutionListener(name);
}
});
Expand All @@ -107,6 +106,6 @@ public final WorkflowTaskRegistry getWorkflowTaskRegistry() {
}

private List<Class<?>> workflowDelegateTypes() {
return Arrays.asList(JavaDelegate.class, TaskListener.class, ExceptionListener.class);
return Arrays.asList(JavaDelegate.class, TaskListener.class, ExecutionListener.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.github.dynamicextensionsalfresco.workflow.activiti;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.Collections;
import java.util.HashMap;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.TaskListener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.context.ApplicationContext;

@RunWith(MockitoJUnitRunner.class)
public class WorkflowTaskRegistrarTest {


@Mock
private WorkflowTaskRegistry workflowTaskRegistry;
@Mock
private ApplicationContext applicationContext;

private WorkflowTaskRegistrar workflowTaskRegistrar;

private static final String BEAN_ID_LISTENER = "TaskAndExceptionListener";
private TaskAndExceptionListener listener = new TaskAndExceptionListener();

@Before
public void setup() {
workflowTaskRegistrar = new WorkflowTaskRegistrar(new HashMap<>(), workflowTaskRegistry);
workflowTaskRegistrar.setApplicationContext(applicationContext);

when(applicationContext.getBeansOfType(TaskListener.class))
.thenReturn(Collections.singletonMap(BEAN_ID_LISTENER, listener));
when(applicationContext.getBeansOfType(ExecutionListener.class))
.thenReturn(Collections.singletonMap(BEAN_ID_LISTENER, listener));
}

@Test
public void afterPropertiesSet_beanImplementingMultipleActivitiListeners_correctlyRegistered() {
// https://github.com/xenit-eu/dynamic-extensions-for-alfresco/issues/199

workflowTaskRegistrar.afterPropertiesSet();

verify(workflowTaskRegistry).registerExecutionListener(BEAN_ID_LISTENER, listener);
verify(workflowTaskRegistry).registerTaskListener(BEAN_ID_LISTENER, listener);
}

@Test
public void destroy_beanImplementingMultipleActivitiListeners_correctlyRemoved() {
workflowTaskRegistrar.destroy();

verify(workflowTaskRegistry).unregisterExecutionListener(BEAN_ID_LISTENER);
verify(workflowTaskRegistry).unregisterTaskListener(BEAN_ID_LISTENER);
}

/**
* Class for testing purposes that implements multiple Activiti listener interfaces
*/
private class TaskAndExceptionListener implements TaskListener, ExecutionListener {

@Override
public void notify(DelegateTask delegateTask) {

}

@Override
public void notify(DelegateExecution execution) {

}
}

}

0 comments on commit 5569c24

Please sign in to comment.