Search in sources :

Example 1 with ProcessStartedEventImpl

use of org.drools.core.event.ProcessStartedEventImpl in project jbpm by kiegroup.

the class IdentityProviderAwareProcessListenerTest method testSetUser.

@Test
public void testSetUser() {
    final IdentityProvider identityProvider = mock(IdentityProvider.class);
    final String userId = "userId";
    when(identityProvider.getName()).thenReturn(userId);
    when(environment.get("IdentityProvider")).thenReturn(identityProvider);
    final WorkflowProcessInstance processInstance = mock(WorkflowProcessInstance.class);
    final HashMap<String, Object> metaData = new HashMap<>();
    when(processInstance.getMetaData()).thenReturn(metaData);
    final ProcessStartedEvent event = new ProcessStartedEventImpl(processInstance, mock(KieRuntime.class));
    listener.beforeProcessStarted(event);
    assertEquals(userId, metaData.get("OwnerId"));
    verify(processInstance).setVariable("initiator", userId);
}
Also used : HashMap(java.util.HashMap) KieRuntime(org.kie.api.runtime.KieRuntime) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) IdentityProvider(org.kie.internal.identity.IdentityProvider) ProcessStartedEventImpl(org.drools.core.event.ProcessStartedEventImpl) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test)

Example 2 with ProcessStartedEventImpl

use of org.drools.core.event.ProcessStartedEventImpl in project jbpm by kiegroup.

the class IdentityProviderAwareProcessListenerTest method testUserNotSet.

@Test
public void testUserNotSet() {
    final WorkflowProcessInstance processInstance = mock(WorkflowProcessInstance.class);
    final HashMap<String, Object> metaData = new HashMap<>();
    when(processInstance.getMetaData()).thenReturn(metaData);
    final ProcessStartedEvent event = new ProcessStartedEventImpl(processInstance, mock(KieRuntime.class));
    listener.beforeProcessStarted(event);
    assertTrue(metaData.isEmpty());
    verify(processInstance, never()).setVariable(anyString(), anyString());
}
Also used : HashMap(java.util.HashMap) KieRuntime(org.kie.api.runtime.KieRuntime) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) ProcessStartedEventImpl(org.drools.core.event.ProcessStartedEventImpl) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 ProcessStartedEventImpl (org.drools.core.event.ProcessStartedEventImpl)2 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)2 Test (org.junit.Test)2 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)2 KieRuntime (org.kie.api.runtime.KieRuntime)2 IdentityProvider (org.kie.internal.identity.IdentityProvider)1