aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/test
diff options
context:
space:
mode:
authorChristian Wagner <c.wagner@datentechnik-innovation.com>2015-02-06 09:12:22 +0100
committerChristian Wagner <c.wagner@datentechnik-innovation.com>2015-02-06 09:12:22 +0100
commit01b98af095d8b7f4c33b89e321b3c4c17c597307 (patch)
treeb14bca309fc4504b1ef6ebb698c89c540d775aa0 /id/server/idserverlib/src/test
parent859f8eb5138ee33380ccc31cdfb03e292a2bb8fc (diff)
downloadmoa-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')
-rw-r--r--id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest.java58
-rw-r--r--id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/test/ProcessEngineTest.java65
-rw-r--r--id/server/idserverlib/src/test/resources/at/gv/egovernment/moa/id/process/hibernate.configuration.test.properties12
-rw-r--r--id/server/idserverlib/src/test/resources/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest-context.xml21
4 files changed, 112 insertions, 44 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");
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">
<bean id="springElAwareExpressionEvaluator" class="at.gv.egovernment.moa.id.process.spring.SpringExpressionEvaluator" />
-
+
<bean id="processEngine" class="at.gv.egovernment.moa.id.process.ProcessEngineImpl">
<property name="transitionConditionExpressionEvaluator" ref="springElAwareExpressionEvaluator" />
- <property name="processInstanceMaxIdleTimeSeconds" value="600" />
- <!--
- <property name="processDefinitions">
- <list>
- <bean class="com.datentechnik.process_engine.spring.ProcessDefinitionFactoryBean">
- <property name="resource" value="classpath:at/gv/egovernment/moa/id/process/spring/test/SampleProcessDefinitionWithExpression1.xml" />
- </bean>
- <bean class="com.datentechnik.process_engine.spring.ProcessDefinitionFactoryBean">
- <property name="resource" value="classpath:at/gv/egovernment/moa/id/process/spring/test/SampleProcessDefinitionForSAML1Authentication.xml" />
- </bean>
- </list>
- </property>
- -->
</bean>
-
- <task:scheduler id="taskScheduler" pool-size="1" />
- <task:scheduled-tasks scheduler="taskScheduler">
- <task:scheduled ref="processEngine" method="cleanup" fixed-delay="60000" />
- </task:scheduled-tasks>
-
</beans>