text: package com.camunda.demo.engine_plugin_custom_history_event_producer;
  
  import static org.camunda.bpm.engine.test.assertions.ProcessEngineAssertions.assertThat;
  import static org.camunda.bpm.engine.test.assertions.ProcessEngineAssertions.init;
  import static org.camunda.bpm.engine.test.assertions.ProcessEngineAssertions.processEngine;
  import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.complete;
  import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.historyService;
  import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.runtimeService;
  import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.task;
  
  import java.util.List;
  
  import org.apache.ibatis.logging.LogFactory;
  import org.camunda.bpm.engine.history.HistoricActivityInstance;
  import org.camunda.bpm.engine.runtime.ProcessInstance;
  import org.camunda.bpm.engine.test.Deployment;
  import org.camunda.bpm.engine.test.ProcessEngineRule;
  import org.junit.Before;
  import org.junit.Rule;
  import org.junit.Test;
  
  /**
   * Test case starting an in-memory database-backed Process Engine.
   */
  public class InMemoryH2Test {
  
    @Rule
    public ProcessEngineRule rule = new ProcessEngineRule();
  
    private static final String PROCESS_DEFINITION_KEY = "custom-history-event-handler";
  
    static {
      LogFactory.useSlf4jLogging(); // MyBatis
    }
  
    @Before
    public void setup() {
      init(rule.getProcessEngine());
    }
  
    @Test
    @Deployment(resources = "process.bpmn")
    public void testHappyPath() {
  	  processEngine().getIdentityService().setAuthenticatedUserId("felix");
  	  ProcessInstance processInstance = processEngine().getRuntimeService().startProcessInstanceByKey(PROCESS_DEFINITION_KEY);
  
  	  assertThat(processInstance).task("Task_DoSomething");
  	  
  	  complete(task());
  	  
  	  runtimeService().createMessageCorrelation("correlateMe").processInstanceId(processInstance.getId()).correlateWithResult();
  	  
  	  List<HistoricActivityInstance> instances = historyService().createHistoricActivityInstanceQuery().taskAssignee("felix").list();
  	  for (HistoricActivityInstance instance: instances) {
  		  System.out.println(instance);
  	  }
  	  assertThat(processInstance).isEnded();
    }
  
  }
  