diff options
author | Christian Wagner <c.wagner@datentechnik-innovation.com> | 2015-02-06 09:12:22 +0100 |
---|---|---|
committer | Christian Wagner <c.wagner@datentechnik-innovation.com> | 2015-02-06 09:12:22 +0100 |
commit | 01b98af095d8b7f4c33b89e321b3c4c17c597307 (patch) | |
tree | b14bca309fc4504b1ef6ebb698c89c540d775aa0 /id/server/idserverlib/src/test/java/at/gv | |
parent | 859f8eb5138ee33380ccc31cdfb03e292a2bb8fc (diff) | |
download | moa-id-spss-01b98af095d8b7f4c33b89e321b3c4c17c597307.tar.gz moa-id-spss-01b98af095d8b7f4c33b89e321b3c4c17c597307.tar.bz2 moa-id-spss-01b98af095d8b7f4c33b89e321b3c4c17c597307.zip |
adjust process engine tests to process instance persistence
Diffstat (limited to 'id/server/idserverlib/src/test/java/at/gv')
2 files changed, 99 insertions, 24 deletions
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"); |