aboutsummaryrefslogtreecommitdiff
path: root/id/server
diff options
context:
space:
mode:
authorGerwin Gsenger <g.gsenger@datentechnik-innovation.at>2015-01-19 16:59:05 +0100
committerThomas Lenz <tlenz@iaik.tugraz.at>2015-06-19 11:07:57 +0200
commitdc50d90a4750600b4555c19c2b939200216b68bd (patch)
tree2b9fb82e84ae4bc8ddd16b100ab0d905a115f4e4 /id/server
parent4791f1f77125e1c4c76d189f441924fd62874091 (diff)
downloadmoa-id-spss-dc50d90a4750600b4555c19c2b939200216b68bd.tar.gz
moa-id-spss-dc50d90a4750600b4555c19c2b939200216b68bd.tar.bz2
moa-id-spss-dc50d90a4750600b4555c19c2b939200216b68bd.zip
add initial version of a moaid-configuration test, does not work if old db is not initialized
Diffstat (limited to 'id/server')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java2
-rw-r--r--id/server/moa-id-commons/pom.xml5
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java3
-rw-r--r--id/server/moa-id-commons/src/test/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBReadTest.java127
-rw-r--r--id/server/moa-id-commons/src/test/resources/at/gv/egovernment/moa/id/commons/db/configuration.beans-test.xml54
-rw-r--r--id/server/moa-id-commons/src/test/resources/at/gv/egovernment/moa/id/commons/db/hibernate.properties20
-rw-r--r--id/server/moa-id-commons/src/test/resources/at/gv/egovernment/moa/id/commons/db/testDatabase.properties7
7 files changed, 214 insertions, 4 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java
index a4eab51d9..a143eb636 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java
@@ -433,7 +433,7 @@ public class AuthConfigurationProvider extends ConfigurationProvider implements
if (oas != null && oas.size() > 0) {
// for (OnlineApplication oa : oas)
// ConfigurationDBUtils.delete(oa);
- NewConfigurationDBWrite.delete("getOnlineApplications");
+ NewConfigurationDBWrite.delete(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY);
}
}
diff --git a/id/server/moa-id-commons/pom.xml b/id/server/moa-id-commons/pom.xml
index 85bd82dd4..b228c4352 100644
--- a/id/server/moa-id-commons/pom.xml
+++ b/id/server/moa-id-commons/pom.xml
@@ -141,6 +141,11 @@
<!-- for testing only ? -->
<dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java
index 124a2e46a..0dd232773 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java
@@ -108,8 +108,6 @@ public class NewConfigurationDBRead {
AuthComponentGeneral.class);
ChainingModes chainingModes = (ChainingModes) conf.get(MOAIDConfigurationConstants.CHAINING_MODES_KEY, ChainingModes.class);
- List<OnlineApplication> oas = (List<OnlineApplication>) conf.getList(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY,
- OnlineApplication.class);
List<GenericConfiguration> genericConfigurations = (List<GenericConfiguration>) conf.getList(
MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, GenericConfiguration.class);
String trustedCaCertificates = (String) conf.get(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY, String.class);
@@ -132,7 +130,6 @@ public class NewConfigurationDBRead {
MOAIDConfiguration result = new MOAIDConfiguration();
result.setAuthComponentGeneral(authComponent);
result.setChainingModes(chainingModes);
- result.setOnlineApplication(oas);
result.setGenericConfiguration(genericConfigurations);
result.setTrustedCACertificates(trustedCaCertificates);
result.setDefaultBKUs(defaultBKUs);
diff --git a/id/server/moa-id-commons/src/test/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBReadTest.java b/id/server/moa-id-commons/src/test/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBReadTest.java
new file mode 100644
index 000000000..7147cd5bc
--- /dev/null
+++ b/id/server/moa-id-commons/src/test/java/at/gv/egovernment/moa/id/commons/db/ConfigurationDBReadTest.java
@@ -0,0 +1,127 @@
+package at.gv.egovernment.moa.id.commons.db;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral;
+import at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration;
+import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException;
+
+import com.datentechnik.moa.id.conf.persistence.Configuration;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("configuration.beans-test.xml")
+public class ConfigurationDBReadTest {
+
+ @Autowired
+ Configuration configDataBase;
+
+ private Properties getHibernateProperties() throws FileNotFoundException, IOException {
+
+ Properties configProp = null;
+ try (InputStream in = ConfigurationDBReadTest.class.getResourceAsStream("hibernate.properties");) {
+ Properties props = new Properties();
+ props.load(in);
+ // read Config Hibernate properties
+ configProp = new Properties();
+ for (Object key : props.keySet()) {
+ String propPrefix = "configuration.";
+ if (key.toString().startsWith(propPrefix + "hibernate")) {
+ String propertyName = key.toString().substring(propPrefix.length());
+ configProp.put(propertyName, props.get(key.toString()));
+ }
+ }
+ }
+
+ return configProp;
+ }
+
+ private void migrateDatabase(List<String> methodNames) throws IllegalAccessException, IllegalArgumentException,
+ InvocationTargetException, NoSuchMethodException, SecurityException {
+ for (String name : methodNames) {
+ Method method = ConfigurationFromDBExtractor.class.getMethod(name);
+ Object tmp = method.invoke(null, new Object[] {});
+ JsonProperty annotation = method.getAnnotation(JsonProperty.class);
+ if (annotation != null) {
+ configDataBase.set(annotation.value(), tmp);
+ } else {
+ System.out.println("Methods must be annotated, annotation is used as key in key-value db.");
+ assertTrue(false);
+ }
+ }
+ }
+
+ @Before
+ public void initialize() throws FileNotFoundException, MOADatabaseException, IOException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
+
+ // initialize the connection to the old database
+ ConfigurationDBUtils.initHibernate(getHibernateProperties());
+
+ // migrate the data in the old database to a new key value database
+ List<String> methodNames = Arrays.asList("getAuthComponentGeneral", "getChainingModes",
+ "getTrustedCACertificates", "getDefaultBKUs", "getSLRequestTemplates", "getTimeStampItem",
+ "getPvp2RefreshItem", "getOnlineApplications", "getGenericConfigurations");
+ migrateDatabase(methodNames);
+
+ // close the session with the old database
+ ConfigurationDBUtils.closeSession();
+ }
+
+ @Test
+ public void testGetMOAIDConfiguration() throws FileNotFoundException, MOADatabaseException, IOException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
+ SecurityException {
+
+ // get the old moaid configuration
+ MOAIDConfiguration oldConfig = ConfigurationDBRead.getMOAIDConfiguration();
+
+ // get the a new moaid configuration from the data in the key value
+ // database
+ MOAIDConfiguration newConfig = NewConfigurationDBRead.getMOAIDConfiguration();
+
+ // check if both configurations yield a similar MOAIDConfiguration
+ // object
+ assertTrue(oldConfig.equals(newConfig));
+
+ }
+
+ @Test
+ public void testGetMOAIDConfigurationNotEqual() throws FileNotFoundException, MOADatabaseException, IOException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
+ SecurityException {
+
+ // get the old moaid configuration
+ MOAIDConfiguration oldConfig = ConfigurationDBRead.getMOAIDConfiguration();
+
+ // delete part of the configuration
+ oldConfig.setAuthComponentGeneral(new AuthComponentGeneral());
+
+ // get the a new moaid configuration from the data in the key value
+ // database
+ MOAIDConfiguration newConfig = NewConfigurationDBRead.getMOAIDConfiguration();
+
+ // check if both configurations yield a similar MOAIDConfiguration
+ // object
+ assertFalse(oldConfig.equals(newConfig));
+
+ }
+
+}
diff --git a/id/server/moa-id-commons/src/test/resources/at/gv/egovernment/moa/id/commons/db/configuration.beans-test.xml b/id/server/moa-id-commons/src/test/resources/at/gv/egovernment/moa/id/commons/db/configuration.beans-test.xml
new file mode 100644
index 000000000..4c7cd3ab1
--- /dev/null
+++ b/id/server/moa-id-commons/src/test/resources/at/gv/egovernment/moa/id/commons/db/configuration.beans-test.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
+
+ <tx:annotation-driven />
+ <context:annotation-config />
+
+ <context:property-placeholder
+ location="classpath:at/gv/egovernment/moa/id/commons/db/testDatabase.properties" />
+
+ <bean id="configPropertyDao"
+ class="com.datentechnik.moa.id.conf.persistence.dal.ConfigPropertyDaoImpl" />
+ <bean id="config" class="com.datentechnik.moa.id.conf.persistence.ConfigurationImpl">
+ <property name="configPropertyDao" ref="configPropertyDao" />
+ </bean>
+
+ <bean id="configRead" class="at.gv.egovernment.moa.id.commons.db.NewConfigurationDBRead"/>
+
+ <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" lazy-init="true" destroy-method="close">
+ <aop:scoped-proxy/>
+ <property name="driverClassName" value="${dataSource.driverClassName}" />
+ <property name="url" value="${dataSource.url}"/>
+ <property name="username" value="${dataSource.username}" />
+ <property name="password" value="${dataSource.password}" />
+ <property name="testOnBorrow" value="true" />
+ <property name="validationQuery" value="SELECT 1" />
+ </bean>
+
+
+ <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
+ <property name="showSql" value="true" />
+ <property name="generateDdl" value="${jpaVendorAdapter.generateDdl}" />
+ <property name="databasePlatform" value="${jpaVendorAdapter.databasePlatform}" />
+ </bean>
+
+
+ <bean name="moaidconf" id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <property name="dataSource" ref="dataSource" />
+ <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
+ <property name="persistenceUnitName" value="moaidconf" />
+ </bean>
+
+ <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
+ <property name="entityManagerFactory" ref="entityManagerFactory" />
+ </bean>
+
+</beans> \ No newline at end of file
diff --git a/id/server/moa-id-commons/src/test/resources/at/gv/egovernment/moa/id/commons/db/hibernate.properties b/id/server/moa-id-commons/src/test/resources/at/gv/egovernment/moa/id/commons/db/hibernate.properties
new file mode 100644
index 000000000..095a5e5ac
--- /dev/null
+++ b/id/server/moa-id-commons/src/test/resources/at/gv/egovernment/moa/id/commons/db/hibernate.properties
@@ -0,0 +1,20 @@
+#Hibnerate configuration for MOA-ID 2.0 configuration
+configuration.hibernate.dialect=org.hibernate.dialect.MySQLDialect
+configuration.hibernate.connection.url=jdbc:mysql://localhost/moa-id-config?charSet=utf-8&autoReconnect=true
+configuration.hibernate.connection.charSet=utf-8
+configuration.hibernate.connection.driver_class=com.mysql.jdbc.Driver
+configuration.hibernate.connection.username=moaid
+configuration.hibernate.connection.password=moaid
+
+configuration.hibernate.hbm2ddl.auto=update
+configuration.hibernate.current_session_context_class=thread
+configuration.hibernate.transaction.auto_close_session=true
+configuration.hibernate.show_sql=false
+configuration.hibernate.format_sql=true
+configuration.hibernate.connection.provider_class=org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
+configuration.hibernate.c3p0.acquire_increment=3
+configuration.hibernate.c3p0.idle_test_period=60
+configuration.hibernate.c3p0.timeout=300
+configuration.hibernate.c3p0.max_size=20
+configuration.hibernate.c3p0.max_statements=0
+configuration.hibernate.c3p0.min_size=3 \ No newline at end of file
diff --git a/id/server/moa-id-commons/src/test/resources/at/gv/egovernment/moa/id/commons/db/testDatabase.properties b/id/server/moa-id-commons/src/test/resources/at/gv/egovernment/moa/id/commons/db/testDatabase.properties
new file mode 100644
index 000000000..6036d2846
--- /dev/null
+++ b/id/server/moa-id-commons/src/test/resources/at/gv/egovernment/moa/id/commons/db/testDatabase.properties
@@ -0,0 +1,7 @@
+dataSource.driverClassName=org.h2.Driver
+dataSource.url=jdbc:h2:mem:moaidconftest
+dataSource.username=
+dataSource.password=
+
+jpaVendorAdapter.databasePlatform=org.hibernate.dialect.H2Dialect
+jpaVendorAdapter.generateDdl=true \ No newline at end of file