From 01b98af095d8b7f4c33b89e321b3c4c17c597307 Mon Sep 17 00:00:00 2001 From: Christian Wagner Date: Fri, 6 Feb 2015 09:12:22 +0100 Subject: adjust process engine tests to process instance persistence --- id/server/idserverlib/pom.xml | 7 +++ .../SpringExpressionAwareProcessEngineTest.java | 58 +++++++++++++++---- .../moa/id/process/test/ProcessEngineTest.java | 65 ++++++++++++++++++---- .../hibernate.configuration.test.properties | 12 ++++ ...ingExpressionAwareProcessEngineTest-context.xml | 21 +------ 5 files changed, 119 insertions(+), 44 deletions(-) create mode 100644 id/server/idserverlib/src/test/resources/at/gv/egovernment/moa/id/process/hibernate.configuration.test.properties (limited to 'id/server') diff --git a/id/server/idserverlib/pom.xml b/id/server/idserverlib/pom.xml index 102bec7bd..15a1e8cfc 100644 --- a/id/server/idserverlib/pom.xml +++ b/id/server/idserverlib/pom.xml @@ -419,6 +419,13 @@ test + + com.h2database + h2 + 1.4.178 + runtime + + org.apache.commons diff --git a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest.java b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest.java index 57b1d2a3a..5355f14d3 100644 --- a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest.java +++ b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest.java @@ -5,20 +5,27 @@ import static org.junit.Assert.*; import java.io.IOException; import java.io.InputStream; +import java.util.Properties; +import org.hibernate.cfg.Configuration; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import at.gv.egovernment.moa.id.commons.db.ConfigurationDBUtils; +import at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils; +import at.gv.egovernment.moa.id.commons.db.dao.session.InterfederationSessionStore; +import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException; import at.gv.egovernment.moa.id.process.ProcessDefinitionParserException; import at.gv.egovernment.moa.id.process.ProcessEngine; import at.gv.egovernment.moa.id.process.ProcessEngineImpl; import at.gv.egovernment.moa.id.process.ProcessExecutionException; import at.gv.egovernment.moa.id.process.ProcessInstance; import at.gv.egovernment.moa.id.process.api.ExecutionContext; +import at.gv.egovernment.moa.id.process.dao.ProcessInstanceStore; import at.gv.egovernment.moa.id.process.spring.SpringExpressionEvaluator; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Tests the process engine using processes based on Spring EL referencing the process context and further Spring beans. @@ -35,7 +42,7 @@ public class SpringExpressionAwareProcessEngineTest { @BeforeClass public static void init() throws IOException, ProcessDefinitionParserException { - + pe = new ProcessEngineImpl(); ((ProcessEngineImpl) pe).setTransitionConditionExpressionEvaluator(new SpringExpressionEvaluator()); try (InputStream in = SpringExpressionAwareProcessEngineTest.class.getResourceAsStream("SampleProcessDefinitionWithExpression1.xml")) { @@ -44,29 +51,56 @@ public class SpringExpressionAwareProcessEngineTest { try (InputStream in = SpringExpressionAwareProcessEngineTest.class.getResourceAsStream("SampleProcessDefinitionForSAML1Authentication.xml")) { ((ProcessEngineImpl) pe).registerProcessDefinition(in); } + + initHibernateForTesting(); } - + + private static void initHibernateForTesting() throws IOException{ + + InputStream in = SpringExpressionAwareProcessEngineTest.class.getResourceAsStream("/at/gv/egovernment/moa/id/process/hibernate.configuration.test.properties"); + Properties props = new Properties(); + props.load(in); + + try { + ConfigurationDBUtils.initHibernate(props); + Configuration config = new Configuration(); + config.addProperties(props); + config.addAnnotatedClass(ProcessInstanceStore.class); + config.addAnnotatedClass(InterfederationSessionStore.class); + MOASessionDBUtils.initHibernate(config, props); + } catch (MOADatabaseException e) { + e.printStackTrace(); + } + } + + @Test - public void testSampleProcessDefinitionWithExpression1() throws IOException, ProcessDefinitionParserException, - ProcessExecutionException { + public void testSampleProcessDefinitionWithExpression1() throws IOException, ProcessDefinitionParserException, ProcessExecutionException { + + String piId = pe.createProcessInstance("SampleProcessWithExpression1"); + ProcessInstance pi = pe.getProcessInstance(piId); + assertEquals(NOT_STARTED, pi.getState()); - ProcessInstance pi = pe.createProcessInstance("SampleProcessWithExpression1"); - assertEquals(NOT_STARTED, pi.getState()); // start process - pe.start(pi); + pe.start(piId); + pi = pe.getProcessInstance(piId); assertEquals(ENDED, pi.getState()); } @Test - public void testSampleProcessDefinitionForSAML1Authentication() throws IOException, - ProcessDefinitionParserException, ProcessExecutionException { - ProcessInstance pi = pe.createProcessInstance("SampleProcessDefinitionForSAML1Authentication"); + public void testSampleProcessDefinitionForSAML1Authentication() throws IOException, ProcessDefinitionParserException, ProcessExecutionException { + + String piId = pe.createProcessInstance("SampleProcessDefinitionForSAML1Authentication"); + ProcessInstance pi = pe.getProcessInstance(piId); assertEquals(NOT_STARTED, pi.getState()); + // start process - pe.start(pi); + pe.start(piId); + pi = pe.getProcessInstance(piId); assertEquals(ENDED, pi.getState()); + pi = pe.getProcessInstance(piId); ExecutionContext ec = pi.getExecutionContext(); assertNotNull(ec); System.out.println(ec.keySet()); diff --git a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/test/ProcessEngineTest.java b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/test/ProcessEngineTest.java index 8c718a9e4..4f24468fe 100644 --- a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/test/ProcessEngineTest.java +++ b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/test/ProcessEngineTest.java @@ -1,31 +1,39 @@ package at.gv.egovernment.moa.id.process.test; -import static at.gv.egovernment.moa.id.process.ProcessInstanceState.ENDED; -import static at.gv.egovernment.moa.id.process.ProcessInstanceState.NOT_STARTED; -import static at.gv.egovernment.moa.id.process.ProcessInstanceState.SUSPENDED; -import static org.junit.Assert.assertEquals; +import static at.gv.egovernment.moa.id.process.ProcessInstanceState.*; +import static org.junit.Assert.*; import java.io.IOException; import java.io.InputStream; +import java.util.Properties; +import org.hibernate.cfg.Configuration; import org.junit.BeforeClass; import org.junit.Test; +import at.gv.egovernment.moa.id.commons.db.ConfigurationDBUtils; +import at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils; +import at.gv.egovernment.moa.id.commons.db.dao.session.InterfederationSessionStore; +import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException; import at.gv.egovernment.moa.id.process.ProcessDefinitionParser; import at.gv.egovernment.moa.id.process.ProcessDefinitionParserException; import at.gv.egovernment.moa.id.process.ProcessEngine; import at.gv.egovernment.moa.id.process.ProcessEngineImpl; import at.gv.egovernment.moa.id.process.ProcessExecutionException; import at.gv.egovernment.moa.id.process.ProcessInstance; +import at.gv.egovernment.moa.id.process.dao.ProcessInstanceStore; public class ProcessEngineTest { private static ProcessEngine pe; - + @BeforeClass public static void init() throws IOException, ProcessDefinitionParserException { + ProcessDefinitionParser pdp = new ProcessDefinitionParser(); + pe = new ProcessEngineImpl(); + ((ProcessEngineImpl) pe).setTransitionConditionExpressionEvaluator(new BooleanStringExpressionEvaluator()); try (InputStream in = ProcessEngineTest.class.getResourceAsStream("SampleProcessDefinition1.xml")) { ((ProcessEngineImpl) pe).registerProcessDefinition(pdp.parse(in)); @@ -33,32 +41,65 @@ public class ProcessEngineTest { try (InputStream in = ProcessEngineTest.class.getResourceAsStream("SampleProcessDefinition2.xml")) { ((ProcessEngineImpl) pe).registerProcessDefinition(pdp.parse(in)); } + + initHibernateForTesting(); + } + + + private static void initHibernateForTesting() throws IOException{ + + InputStream in = ProcessEngineTest.class.getResourceAsStream("/at/gv/egovernment/moa/id/process/hibernate.configuration.test.properties"); + Properties props = new Properties(); + props.load(in); + + try { + ConfigurationDBUtils.initHibernate(props); + Configuration config = new Configuration(); + config.addProperties(props); + config.addAnnotatedClass(ProcessInstanceStore.class); + config.addAnnotatedClass(InterfederationSessionStore.class); + MOASessionDBUtils.initHibernate(config, props); + } catch (MOADatabaseException e) { + e.printStackTrace(); + } } @Test public void testSampleProcess1() throws IOException, ProcessDefinitionParserException, ProcessExecutionException { - ProcessInstance pi = pe.createProcessInstance("SampleProcess1"); + + String piId = pe.createProcessInstance("SampleProcess1"); + ProcessInstance pi = pe.getProcessInstance(piId); assertEquals(NOT_STARTED, pi.getState()); + // start process - pe.start(pi); + pe.start(piId); + pi = pe.getProcessInstance(piId); assertEquals(SUSPENDED, pi.getState()); + System.out.println("Do something asynchronously"); - pe.signal(pi); + pe.signal(piId); + pi = pe.getProcessInstance(piId); assertEquals(ENDED, pi.getState()); } @Test public void testSampleProcess2() throws IOException, ProcessDefinitionParserException, ProcessExecutionException { - ProcessInstance pi = pe.createProcessInstance("SampleProcess2"); + + String piId = pe.createProcessInstance("SampleProcess2"); + ProcessInstance pi = pe.getProcessInstance(piId); assertEquals(NOT_STARTED, pi.getState()); + // start process - pe.start(pi); + pe.start(piId); + pi = pe.getProcessInstance(piId); assertEquals(SUSPENDED, pi.getState()); + System.out.println("Do something asynchronously"); - pe.signal(pi); + pe.signal(piId); + pi = pe.getProcessInstance(piId); assertEquals(ENDED, pi.getState()); } - + @Test(expected = IllegalArgumentException.class) public void testProcessInstanceDoesNotExist() { pe.getProcessInstance("does not exist"); diff --git a/id/server/idserverlib/src/test/resources/at/gv/egovernment/moa/id/process/hibernate.configuration.test.properties b/id/server/idserverlib/src/test/resources/at/gv/egovernment/moa/id/process/hibernate.configuration.test.properties new file mode 100644 index 000000000..c4faa6d09 --- /dev/null +++ b/id/server/idserverlib/src/test/resources/at/gv/egovernment/moa/id/process/hibernate.configuration.test.properties @@ -0,0 +1,12 @@ +# minimal Hibnerate configuration for testing the process engine +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.connection.url=jdbc:h2:mem:moa.id-session;DB_CLOSE_DELAY=-1 +hibernate.connection.charSet=utf-8 +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.username= +hibernate.connection.password= + +hibernate.format_sql=true +hibernate.show_sql=false +hibernate.transaction.auto_close_session=true +hibernate.hbm2ddl.auto=update diff --git a/id/server/idserverlib/src/test/resources/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest-context.xml b/id/server/idserverlib/src/test/resources/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest-context.xml index 1b6b7658e..9a381d83a 100644 --- a/id/server/idserverlib/src/test/resources/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest-context.xml +++ b/id/server/idserverlib/src/test/resources/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest-context.xml @@ -6,27 +6,8 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - + - - - - - - - - -- cgit v1.2.3