Search in sources :

Example 1 with FieldAccessJPAEntity

use of org.activiti.standalone.jpa.FieldAccessJPAEntity in project Activiti by Activiti.

the class FullHistoryTest method testReadJpaVariableValueFromHistoricVariableUpdate.

@Deployment(resources = { "org/activiti/standalone/jpa/JPAVariableTest.testQueryJPAVariable.bpmn20.xml" })
public void testReadJpaVariableValueFromHistoricVariableUpdate() {
    EntityManagerSessionFactory entityManagerSessionFactory = (EntityManagerSessionFactory) processEngineConfiguration.getSessionFactories().get(EntityManagerSession.class);
    EntityManagerFactory entityManagerFactory = entityManagerSessionFactory.getEntityManagerFactory();
    String executionId = runtimeService.startProcessInstanceByKey("JPAVariableProcess").getProcessInstanceId();
    String variableName = "name";
    FieldAccessJPAEntity entity = new FieldAccessJPAEntity();
    entity.setId(1L);
    entity.setValue("Test");
    EntityManager manager = entityManagerFactory.createEntityManager();
    manager.getTransaction().begin();
    manager.persist(entity);
    manager.flush();
    manager.getTransaction().commit();
    manager.close();
    Task task = taskService.createTaskQuery().processInstanceId(executionId).taskName("my task").singleResult();
    runtimeService.setVariable(executionId, variableName, entity);
    taskService.complete(task.getId());
    List<HistoricDetail> variableUpdates = historyService.createHistoricDetailQuery().processInstanceId(executionId).variableUpdates().list();
    assertEquals(1, variableUpdates.size());
    HistoricVariableUpdate update = (HistoricVariableUpdate) variableUpdates.get(0);
    assertNotNull(update.getValue());
    assertTrue(update.getValue() instanceof FieldAccessJPAEntity);
    assertEquals(entity.getId(), ((FieldAccessJPAEntity) update.getValue()).getId());
}
Also used : EntityManagerSession(org.activiti.engine.impl.variable.EntityManagerSession) HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) EntityManagerSessionFactory(org.activiti.engine.impl.variable.EntityManagerSessionFactory) HistoricDetail(org.activiti.engine.history.HistoricDetail) EntityManager(javax.persistence.EntityManager) Task(org.activiti.engine.task.Task) EntityManagerFactory(javax.persistence.EntityManagerFactory) FieldAccessJPAEntity(org.activiti.standalone.jpa.FieldAccessJPAEntity) Deployment(org.activiti.engine.test.Deployment)

Aggregations

EntityManager (javax.persistence.EntityManager)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 HistoricDetail (org.activiti.engine.history.HistoricDetail)1 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)1 EntityManagerSession (org.activiti.engine.impl.variable.EntityManagerSession)1 EntityManagerSessionFactory (org.activiti.engine.impl.variable.EntityManagerSessionFactory)1 Task (org.activiti.engine.task.Task)1 Deployment (org.activiti.engine.test.Deployment)1 FieldAccessJPAEntity (org.activiti.standalone.jpa.FieldAccessJPAEntity)1