parent
a50e1fb99b
commit
04789fd327
|
|
@ -46,7 +46,7 @@ public class DatasetsTest extends DatasetsVerifier {
|
||||||
@Parameterized.Parameters(name = "Dataset {0}")
|
@Parameterized.Parameters(name = "Dataset {0}")
|
||||||
public static Collection<String> data() {
|
public static Collection<String> data() {
|
||||||
return Arrays.asList(new String[]{
|
return Arrays.asList(new String[]{
|
||||||
"/datasets/org/libreccm/modules/ConfigurationLoaderTest/after-load.yml",});
|
"/datasets/org/libreccm/modules/ConfigurationLoaderTest/after-load.x,l",});
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatasetsTest(final String datasetPath) {
|
public DatasetsTest(final String datasetPath) {
|
||||||
|
|
@ -60,7 +60,7 @@ public class DatasetsTest extends DatasetsVerifier {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatasetType getDatasetType() {
|
public DatasetType getDatasetType() {
|
||||||
return YAML;
|
return FLAT_XML;
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
-- create schema CCM_CORE;
|
-- create schema CCM_CORE;
|
||||||
|
|
||||||
create table CCM_CORE.APPLICATIONS (
|
create table CCM_CORE.APPLICATIONS (
|
||||||
APPLICATION_TYPE varchar(1024) not null,
|
APPLICATION_TYPE varchar(1024) not null,
|
||||||
PRIMARY_URL varchar(1024) not null,
|
PRIMARY_URL varchar(1024) not null,
|
||||||
OBJECT_ID bigint not null,
|
OBJECT_ID bigint not null,
|
||||||
|
|
@ -148,7 +148,7 @@
|
||||||
|
|
||||||
create table CCM_CORE.FORMBUILDER_DATA_QUERIES (
|
create table CCM_CORE.FORMBUILDER_DATA_QUERIES (
|
||||||
DESCRIPTION json,
|
DESCRIPTION json,
|
||||||
NAME json,
|
QUERY_NAME json,
|
||||||
QUERY_ID varchar(255),
|
QUERY_ID varchar(255),
|
||||||
OBJECT_ID bigint not null,
|
OBJECT_ID bigint not null,
|
||||||
primary key (OBJECT_ID)
|
primary key (OBJECT_ID)
|
||||||
|
|
@ -194,7 +194,7 @@
|
||||||
create table CCM_CORE.FORMBUILDER_PROCESS_LISTENERS (
|
create table CCM_CORE.FORMBUILDER_PROCESS_LISTENERS (
|
||||||
DESCRIPTION json,
|
DESCRIPTION json,
|
||||||
LISTENER_CLASS varchar(255),
|
LISTENER_CLASS varchar(255),
|
||||||
NAME json,
|
LISTENER_NAME json,
|
||||||
PROCESS_LISTENER_ORDER bigint,
|
PROCESS_LISTENER_ORDER bigint,
|
||||||
OBJECT_ID bigint not null,
|
OBJECT_ID bigint not null,
|
||||||
formSection_OBJECT_ID bigint,
|
formSection_OBJECT_ID bigint,
|
||||||
|
|
@ -452,12 +452,12 @@
|
||||||
SETTING_ID bigint not null,
|
SETTING_ID bigint not null,
|
||||||
CONFIGURATION_CLASS varchar(512) not null,
|
CONFIGURATION_CLASS varchar(512) not null,
|
||||||
NAME varchar(512) not null,
|
NAME varchar(512) not null,
|
||||||
SETTING_VALUE_DOUBLE double,
|
|
||||||
SETTING_VALUE_BIG_DECIMAL decimal(19,2),
|
|
||||||
SETTING_VALUE json,
|
|
||||||
SETTING_VALUE_BOOLEAN boolean,
|
|
||||||
SETTING_VALUE_LONG bigint,
|
SETTING_VALUE_LONG bigint,
|
||||||
|
SETTING_VALUE_LOCALIZED_STRING json,
|
||||||
|
SETTING_VALUE_DOUBLE double,
|
||||||
SETTING_VALUE_STRING varchar(1024),
|
SETTING_VALUE_STRING varchar(1024),
|
||||||
|
SETTING_VALUE_BIG_DECIMAL decimal(19,2),
|
||||||
|
SETTING_VALUE_BOOLEAN boolean,
|
||||||
primary key (SETTING_ID)
|
primary key (SETTING_ID)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -446,12 +446,12 @@
|
||||||
SETTING_ID int8 not null,
|
SETTING_ID int8 not null,
|
||||||
CONFIGURATION_CLASS varchar(512) not null,
|
CONFIGURATION_CLASS varchar(512) not null,
|
||||||
NAME varchar(512) not null,
|
NAME varchar(512) not null,
|
||||||
SETTING_VALUE_DOUBLE float8,
|
|
||||||
SETTING_VALUE_BIG_DECIMAL numeric(19, 2),
|
|
||||||
SETTING_VALUE_LOCALIZED_STRING jsonb,
|
|
||||||
SETTING_VALUE_BOOLEAN boolean,
|
|
||||||
SETTING_VALUE_LONG int8,
|
SETTING_VALUE_LONG int8,
|
||||||
|
SETTING_VALUE_LOCALIZED_STRING jsonb,
|
||||||
|
SETTING_VALUE_DOUBLE float8,
|
||||||
SETTING_VALUE_STRING varchar(1024),
|
SETTING_VALUE_STRING varchar(1024),
|
||||||
|
SETTING_VALUE_BIG_DECIMAL numeric(19, 2),
|
||||||
|
SETTING_VALUE_BOOLEAN boolean,
|
||||||
primary key (SETTING_ID)
|
primary key (SETTING_ID)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<dataset>
|
||||||
|
<ccm_core.settings
|
||||||
|
dtype="LocalizedStringSetting"
|
||||||
|
setting_id="120"
|
||||||
|
configuration_class="org.libreccm.configuration.ExampleConfiguration"
|
||||||
|
name="title"
|
||||||
|
setting_value_localized_string="{'de': 'Versuch', 'en': 'Test'}"
|
||||||
|
/>
|
||||||
|
<ccm_core.settings
|
||||||
|
dtype="BooleanSetting"
|
||||||
|
setting_id="100"
|
||||||
|
configuration_class="org.libreccm.configuration.ExampleConfiguration"
|
||||||
|
name="enabled"
|
||||||
|
setting_value_boolean="true"
|
||||||
|
/>
|
||||||
|
<ccm_core.settings
|
||||||
|
dtype="LongSetting"
|
||||||
|
setting_id="110"
|
||||||
|
configuration_class="org.libreccm.configuration.ExampleConfiguration"
|
||||||
|
name="itemsPerPage"
|
||||||
|
setting_value_long="100"
|
||||||
|
/>
|
||||||
|
</dataset>
|
||||||
|
|
@ -1,23 +1,31 @@
|
||||||
ccm_core.settings:
|
ccm_core.settings:
|
||||||
- setting_id: 100
|
- dtype: LocalizedStringSetting
|
||||||
|
setting_id: 120
|
||||||
|
configuration_class: org.libreccm.configuration.ExampleConfiguration
|
||||||
|
name: title
|
||||||
|
setting_value_long: null
|
||||||
|
setting_value_localized_string: "{\"de\": \"Versuch\", \"en\": \"Test\"}"
|
||||||
|
setting_value_double: null
|
||||||
|
setting_value_string: null
|
||||||
|
setting_value_big_decimal: null
|
||||||
|
setting_value_boolean: null
|
||||||
|
- dtype: BooleanSetting
|
||||||
|
setting_id: 100
|
||||||
configuration_class: org.libreccm.configuration.ExampleConfiguration
|
configuration_class: org.libreccm.configuration.ExampleConfiguration
|
||||||
name: enabled
|
name: enabled
|
||||||
|
setting_value_long: null
|
||||||
|
setting_value_localized_string: null
|
||||||
|
setting_value_double: null
|
||||||
|
setting_value_string: null
|
||||||
|
setting_value_big_decimal: null
|
||||||
setting_value_boolean: true
|
setting_value_boolean: true
|
||||||
dtype: BooleanSetting
|
- dtype: LongSetting
|
||||||
- setting_id: 110
|
setting_id: 110
|
||||||
configuration_class: org.libreccm.configuration.ExampleConfiguration
|
configuration_class: org.libreccm.configuration.ExampleConfiguration
|
||||||
name: itemsPerPage
|
name: itemsPerPage
|
||||||
setting_value_long: 100
|
setting_value_long: 100
|
||||||
dtype: LongSetting
|
setting_value_localized_string: null
|
||||||
- setting_id: 120
|
setting_value_double: null
|
||||||
configuration_class: org.libreccm.configuration.ExampleConfiguration
|
setting_value_string: null
|
||||||
name: title
|
setting_value_big_decimal: null
|
||||||
dtype: LocalizedStringSetting
|
setting_value_boolean: null
|
||||||
ccm_core.settings_l10n_str_values:
|
|
||||||
- entry_id: 120
|
|
||||||
locale: de
|
|
||||||
localized_value: Versuch
|
|
||||||
- entry_id: 120
|
|
||||||
locale: en
|
|
||||||
localized_value: Test
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,14 @@ import org.junit.runners.Parameterized;
|
||||||
|
|
||||||
import static org.libreccm.testutils.DatasetType.*;
|
import static org.libreccm.testutils.DatasetType.*;
|
||||||
|
|
||||||
|
import org.dbunit.database.DatabaseConfig;
|
||||||
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
|
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
|
||||||
import org.jboss.arquillian.persistence.dbunit.dataset.yaml.YamlDataSet;
|
import org.jboss.arquillian.persistence.dbunit.dataset.yaml.YamlDataSet;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -75,39 +77,38 @@ import java.nio.charset.StandardCharsets;
|
||||||
*/
|
*/
|
||||||
public class DatasetsVerifier {
|
public class DatasetsVerifier {
|
||||||
|
|
||||||
private final String datasetPath;
|
private final String datasetPath;
|
||||||
|
|
||||||
public DatasetsVerifier(final String datasetsPath) {
|
public DatasetsVerifier(final String datasetsPath) {
|
||||||
this.datasetPath = datasetsPath;
|
this.datasetPath = datasetsPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrite this method if you are using another schema than the default
|
* Overwrite this method if you are using another schema than the default one.
|
||||||
* one.
|
*
|
||||||
*
|
* @return An string array contains the names of the database schemata used by
|
||||||
* @return An string array contains the names of the database schemata used
|
* the datasets the test.
|
||||||
* by the datasets the test.
|
*/
|
||||||
*/
|
public String[] getSchemas() {
|
||||||
public String[] getSchemas() {
|
return new String[]{};
|
||||||
return new String[]{};
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public DatasetType getDatasetType() {
|
public DatasetType getDatasetType() {
|
||||||
return JSON;
|
return JSON;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
|
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
|
||||||
value = "DMI_EMPTY_DB_PASSWORD",
|
value = "DMI_EMPTY_DB_PASSWORD",
|
||||||
justification = "H2 in mem database does not need a password")
|
justification = "H2 in mem database does not need a password")
|
||||||
public void verifyDataset() throws SQLException,
|
public void verifyDataset() throws SQLException,
|
||||||
URISyntaxException,
|
URISyntaxException,
|
||||||
IOException,
|
IOException,
|
||||||
DatabaseUnitException {
|
DatabaseUnitException {
|
||||||
//Create database connection to an in memory h2 database. Placed in
|
//Create database connection to an in memory h2 database. Placed in
|
||||||
//try-with-resources block to ensure that the connection is closed.
|
//try-with-resources block to ensure that the connection is closed.
|
||||||
final StringBuffer buffer = new StringBuffer("jdbc:h2:mem:testdatabase");
|
final StringBuffer buffer = new StringBuffer("jdbc:h2:mem:testdatabase");
|
||||||
//Create schema if necssary
|
//Create schema if necssary
|
||||||
// if (getSchemas().length > 0) {
|
// if (getSchemas().length > 0) {
|
||||||
// buffer.append(";INIT=");
|
// buffer.append(";INIT=");
|
||||||
// for (final String schema : getSchemas()) {
|
// for (final String schema : getSchemas()) {
|
||||||
|
|
@ -118,90 +119,122 @@ public class DatasetsVerifier {
|
||||||
// schema));
|
// schema));
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
final String connectionStr = buffer.toString();
|
final String connectionStr = buffer.toString();
|
||||||
try (final Connection connection = DriverManager
|
try (final Connection connection = DriverManager
|
||||||
.getConnection(connectionStr, "sa", "")) {
|
.getConnection(connectionStr, "sa", "")) {
|
||||||
final StringBuffer schemaCreateBuffer = new StringBuffer();
|
final StringBuffer schemaCreateBuffer = new StringBuffer();
|
||||||
for (final String schema : getSchemas()) {
|
for (final String schema : getSchemas()) {
|
||||||
schemaCreateBuffer.append(String
|
schemaCreateBuffer.append(String
|
||||||
.format("CREATE SCHEMA IF NOT EXISTS %s;%n", schema));
|
.format("CREATE SCHEMA IF NOT EXISTS %s;%n", schema));
|
||||||
}
|
}
|
||||||
|
|
||||||
try (final StringReader schemaCreateReader = new StringReader(
|
try (final StringReader schemaCreateReader = new StringReader(
|
||||||
schemaCreateBuffer.toString())) {
|
schemaCreateBuffer.toString())) {
|
||||||
RunScript.execute(connection, schemaCreateReader);
|
RunScript.execute(connection, schemaCreateReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Create DB tables etc
|
||||||
|
for (final String ddlFile : getDdlFiles()) {
|
||||||
|
processDdlFile(connection, ddlFile);
|
||||||
|
}
|
||||||
|
|
||||||
//Create DB tables etc
|
|
||||||
for (final String ddlFile : getDdlFiles()) {
|
|
||||||
processDdlFile(connection, ddlFile);
|
|
||||||
}
|
|
||||||
// final Path schemaPath = Paths.get(getClass().getResource(
|
// final Path schemaPath = Paths.get(getClass().getResource(
|
||||||
// "/sql/ddl/auto/h2.sql").toURI());
|
// "/sql/ddl/auto/h2.sql").toURI());
|
||||||
// RunScript.execute(connection, Files.newBufferedReader(
|
// RunScript.execute(connection, Files.newBufferedReader(
|
||||||
// schemaPath, StandardCharsets.UTF_8));
|
// schemaPath, StandardCharsets.UTF_8));
|
||||||
connection.commit();
|
connection.commit();
|
||||||
|
|
||||||
//Get dataset to test
|
System.out.println("DB Info:");
|
||||||
final IDataSet dataSet;
|
System.out.println("Catalogs:");
|
||||||
try (final InputStream inputStream = getClass().getResourceAsStream(
|
try (ResultSet resultSet = connection.getMetaData().getCatalogs()) {
|
||||||
datasetPath)) {
|
while(resultSet.next()) {
|
||||||
switch (getDatasetType()) {
|
System.out.println(resultSet.getString("table_cat"));
|
||||||
case FLAT_XML:
|
}
|
||||||
final FlatXmlDataSetBuilder builder
|
}
|
||||||
= new FlatXmlDataSetBuilder();
|
System.out.println("Schemas");
|
||||||
dataSet = builder.build(inputStream);
|
try(ResultSet resultSet = connection.getMetaData().getSchemas()) {
|
||||||
break;
|
while(resultSet.next()) {
|
||||||
case JSON:
|
System.out.println(resultSet.getString("TABLE_SCHEM"));
|
||||||
dataSet = new JsonDataSet(inputStream);
|
}
|
||||||
break;
|
}
|
||||||
case YAML:
|
System.out.println("Tables");
|
||||||
dataSet = new YamlDataSet(inputStream);
|
try (ResultSet resultSet = connection.getMetaData().getTables("TESTDATABASE", "CCM_CORE", null, null)) {
|
||||||
break;
|
while(resultSet.next()) {
|
||||||
default:
|
System.out.println(resultSet.getString("table_name"));
|
||||||
throw new IllegalArgumentException(String.format(
|
}
|
||||||
"Unsupported DatasetType \"%s\"",
|
}
|
||||||
getDatasetType()));
|
System.out.println("settings columns:");
|
||||||
}
|
try (ResultSet resultSet = connection.getMetaData().getColumns(
|
||||||
|
"TESTDATABASE", "CCM_CORE", "SETTINGS", null
|
||||||
|
)) {
|
||||||
|
while (resultSet.next()) {
|
||||||
|
System.out.printf("table_name = %s%n", resultSet.getString(
|
||||||
|
"table_name"));
|
||||||
|
System.out.printf("col_name = %s%n", resultSet.getString(
|
||||||
|
"column_name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create DBUnit DB connection
|
|
||||||
final IDatabaseConnection dbUnitConn
|
|
||||||
= new DatabaseConnection(connection);
|
|
||||||
dbUnitConn.getConfig().setProperty(
|
|
||||||
"http://www.dbunit.org/features/qualifiedTableNames", true);
|
|
||||||
//Check if dumping works the DB works before loading the dataset.
|
|
||||||
System.out.println("Dump before loading dataset...");
|
|
||||||
verifyDumping(dbUnitConn);
|
|
||||||
|
|
||||||
//Put dataset into DB
|
|
||||||
DatabaseOperation.CLEAN_INSERT.execute(dbUnitConn, dataSet);
|
|
||||||
|
|
||||||
//Check if dumping works after loading the dataset
|
|
||||||
System.out.println("Dump after loading dataset...");
|
|
||||||
verifyDumping(dbUnitConn);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected String[] getDdlFiles() {
|
//Get dataset to test
|
||||||
return new String[]{"/sql/ddl/auto/libreccmh2.sql"};
|
final IDataSet dataSet;
|
||||||
}
|
try (final InputStream inputStream = getClass().getResourceAsStream(
|
||||||
|
datasetPath)) {
|
||||||
|
switch (getDatasetType()) {
|
||||||
|
case FLAT_XML:
|
||||||
|
final FlatXmlDataSetBuilder builder
|
||||||
|
= new FlatXmlDataSetBuilder();
|
||||||
|
dataSet = builder.build(inputStream);
|
||||||
|
break;
|
||||||
|
case JSON:
|
||||||
|
dataSet = new JsonDataSet(inputStream);
|
||||||
|
break;
|
||||||
|
case YAML:
|
||||||
|
dataSet = new YamlDataSet(inputStream);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException(String.format(
|
||||||
|
"Unsupported DatasetType \"%s\"",
|
||||||
|
getDatasetType()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void processDdlFile(final Connection connection,
|
//Create DBUnit DB connection
|
||||||
final String ddlFile) throws URISyntaxException,
|
final IDatabaseConnection dbUnitConn
|
||||||
SQLException,
|
= new DatabaseConnection(connection);
|
||||||
IOException {
|
dbUnitConn.getConfig().setProperty(
|
||||||
final Path schemaPath = Paths.get(getClass().getResource(ddlFile)
|
"http://www.dbunit.org/features/qualifiedTableNames", true);
|
||||||
.toURI());
|
//Check if dumping works the DB works before loading the dataset.
|
||||||
RunScript.execute(connection,
|
System.out.println("Dump before loading dataset...");
|
||||||
Files.newBufferedReader(schemaPath,
|
verifyDumping(dbUnitConn);
|
||||||
StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void verifyDumping(final IDatabaseConnection connection)
|
//Put dataset into DB
|
||||||
throws SQLException, IOException, DataSetException {
|
DatabaseOperation.CLEAN_INSERT.execute(dbUnitConn, dataSet);
|
||||||
final IDataSet data = connection.createDataSet();
|
|
||||||
FlatXmlDataSet.write(data, System.out);
|
//Check if dumping works after loading the dataset
|
||||||
|
System.out.println("Dump after loading dataset...");
|
||||||
|
verifyDumping(dbUnitConn);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String[] getDdlFiles() {
|
||||||
|
return new String[]{"/sql/ddl/auto/libreccmh2.sql"};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processDdlFile(final Connection connection,
|
||||||
|
final String ddlFile) throws URISyntaxException,
|
||||||
|
SQLException,
|
||||||
|
IOException {
|
||||||
|
final Path schemaPath = Paths.get(getClass().getResource(ddlFile)
|
||||||
|
.toURI());
|
||||||
|
RunScript.execute(connection,
|
||||||
|
Files.newBufferedReader(schemaPath,
|
||||||
|
StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyDumping(final IDatabaseConnection connection)
|
||||||
|
throws SQLException, IOException, DataSetException {
|
||||||
|
final IDataSet data = connection.createDataSet();
|
||||||
|
FlatXmlDataSet.write(data, System.out);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue