Trying to make DBUnit to work with JSON columns

Former-commit-id: 7d93f4dde4
embedded-to-json
Jens Pelzetter 2020-05-20 06:46:40 +02:00
parent a50e1fb99b
commit 04789fd327
6 changed files with 195 additions and 130 deletions

View File

@ -46,7 +46,7 @@ public class DatasetsTest extends DatasetsVerifier {
@Parameterized.Parameters(name = "Dataset {0}")
public static Collection<String> data() {
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) {
@ -60,7 +60,7 @@ public class DatasetsTest extends DatasetsVerifier {
@Override
public DatasetType getDatasetType() {
return YAML;
return FLAT_XML;
}
@BeforeClass

View File

@ -148,7 +148,7 @@
create table CCM_CORE.FORMBUILDER_DATA_QUERIES (
DESCRIPTION json,
NAME json,
QUERY_NAME json,
QUERY_ID varchar(255),
OBJECT_ID bigint not null,
primary key (OBJECT_ID)
@ -194,7 +194,7 @@
create table CCM_CORE.FORMBUILDER_PROCESS_LISTENERS (
DESCRIPTION json,
LISTENER_CLASS varchar(255),
NAME json,
LISTENER_NAME json,
PROCESS_LISTENER_ORDER bigint,
OBJECT_ID bigint not null,
formSection_OBJECT_ID bigint,
@ -452,12 +452,12 @@
SETTING_ID bigint not null,
CONFIGURATION_CLASS 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_LOCALIZED_STRING json,
SETTING_VALUE_DOUBLE double,
SETTING_VALUE_STRING varchar(1024),
SETTING_VALUE_BIG_DECIMAL decimal(19,2),
SETTING_VALUE_BOOLEAN boolean,
primary key (SETTING_ID)
);

View File

@ -446,12 +446,12 @@
SETTING_ID int8 not null,
CONFIGURATION_CLASS 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_LOCALIZED_STRING jsonb,
SETTING_VALUE_DOUBLE float8,
SETTING_VALUE_STRING varchar(1024),
SETTING_VALUE_BIG_DECIMAL numeric(19, 2),
SETTING_VALUE_BOOLEAN boolean,
primary key (SETTING_ID)
);

View File

@ -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>

View File

@ -1,23 +1,31 @@
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
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
dtype: BooleanSetting
- setting_id: 110
- dtype: LongSetting
setting_id: 110
configuration_class: org.libreccm.configuration.ExampleConfiguration
name: itemsPerPage
setting_value_long: 100
dtype: LongSetting
- setting_id: 120
configuration_class: org.libreccm.configuration.ExampleConfiguration
name: title
dtype: LocalizedStringSetting
ccm_core.settings_l10n_str_values:
- entry_id: 120
locale: de
localized_value: Versuch
- entry_id: 120
locale: en
localized_value: Test
setting_value_localized_string: null
setting_value_double: null
setting_value_string: null
setting_value_big_decimal: null
setting_value_boolean: null

View File

@ -42,12 +42,14 @@ import org.junit.runners.Parameterized;
import static org.libreccm.testutils.DatasetType.*;
import org.dbunit.database.DatabaseConfig;
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
import org.jboss.arquillian.persistence.dbunit.dataset.yaml.YamlDataSet;
import java.io.InputStream;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.sql.ResultSet;
/**
*
@ -82,11 +84,10 @@ public class DatasetsVerifier {
}
/**
* Overwrite this method if you are using another schema than the default
* one.
* Overwrite this method if you are using another schema than the default one.
*
* @return An string array contains the names of the database schemata used
* by the datasets the test.
* @return An string array contains the names of the database schemata used by
* the datasets the test.
*/
public String[] getSchemas() {
return new String[]{};
@ -136,12 +137,44 @@ public class DatasetsVerifier {
for (final String ddlFile : getDdlFiles()) {
processDdlFile(connection, ddlFile);
}
// final Path schemaPath = Paths.get(getClass().getResource(
// "/sql/ddl/auto/h2.sql").toURI());
// RunScript.execute(connection, Files.newBufferedReader(
// schemaPath, StandardCharsets.UTF_8));
connection.commit();
System.out.println("DB Info:");
System.out.println("Catalogs:");
try (ResultSet resultSet = connection.getMetaData().getCatalogs()) {
while(resultSet.next()) {
System.out.println(resultSet.getString("table_cat"));
}
}
System.out.println("Schemas");
try(ResultSet resultSet = connection.getMetaData().getSchemas()) {
while(resultSet.next()) {
System.out.println(resultSet.getString("TABLE_SCHEM"));
}
}
System.out.println("Tables");
try (ResultSet resultSet = connection.getMetaData().getTables("TESTDATABASE", "CCM_CORE", null, null)) {
while(resultSet.next()) {
System.out.println(resultSet.getString("table_name"));
}
}
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"));
}
}
//Get dataset to test
final IDataSet dataSet;
try (final InputStream inputStream = getClass().getResourceAsStream(