-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
780 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
226 changes: 226 additions & 0 deletions
226
brmo-loader/src/test/java/nl/b3p/NhrToStagingToRsgbIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
/* | ||
* Copyright (C) 2018 B3Partners B.V. | ||
*/ | ||
package nl.b3p; | ||
|
||
import nl.b3p.brmo.loader.BrmoFramework; | ||
import nl.b3p.brmo.loader.entity.Bericht; | ||
import nl.b3p.brmo.loader.entity.LaadProces; | ||
import nl.b3p.brmo.test.util.database.dbunit.CleanUtil; | ||
import nl.b3p.loader.jdbc.OracleConnectionUnwrapper; | ||
import org.apache.commons.dbcp.BasicDataSource; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.dbunit.database.DatabaseConfig; | ||
import org.dbunit.database.DatabaseConnection; | ||
import org.dbunit.database.DatabaseDataSourceConnection; | ||
import org.dbunit.database.IDatabaseConnection; | ||
import org.dbunit.dataset.IDataSet; | ||
import org.dbunit.dataset.ITable; | ||
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; | ||
import org.dbunit.ext.mssql.MsSqlDataTypeFactory; | ||
import org.dbunit.ext.oracle.Oracle10DataTypeFactory; | ||
import org.dbunit.ext.postgresql.PostgresqlDataTypeFactory; | ||
import org.dbunit.operation.DatabaseOperation; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.locks.Lock; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assume.assumeNotNull; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
/** | ||
* Integratie test om een nhr dataservice sopa bericht te laden en te | ||
* transformeren, bevat een testcase voor mantis10752. | ||
* <br>Draaien met: | ||
* {@code mvn -Dit.test=NhrToStagingToRsgbIntegrationTest -Dtest.onlyITs=true verify -Ppostgresql > target/postgresql.log} | ||
* voor bijvoorbeeld PostgreSQL of | ||
* {@code mvn -Dit.test=NhrToStagingToRsgbIntegrationTest -Dtest.onlyITs=true verify -Pmssql > target/mssql.log} | ||
* voor bijvoorbeeld MS SQL. | ||
* | ||
* @author Mark Prins | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class NhrToStagingToRsgbIntegrationTest extends AbstractDatabaseIntegrationTest { | ||
|
||
private static final Log LOG = LogFactory.getLog(NhrToStagingToRsgbIntegrationTest.class); | ||
|
||
@Parameterized.Parameters(name = "{index}: type: {0}, bestand: {1}") | ||
public static Collection params() { | ||
return Arrays.asList(new Object[][]{ | ||
// {"type","filename", aantalBerichten, aantalProcessen, aantalPrs, aantalNiet_nat_prs, aantalNat_prs, vestgID, aantalVestg_activiteit}, | ||
{"nhr", "/mantis10752/52019667.xml", 2, 1, 2, 1, 1, "nhr.comVestg.000021991235", 1}, | ||
{"nhr", "/nl/b3p/brmo/loader/xml/nhr-2.5_0.xml", 3, 1, 2, 2, 0, "nhr.comVestg.000016444663", 3} | ||
}); | ||
} | ||
|
||
/** | ||
* test parameter. | ||
*/ | ||
private final String bestandNaam; | ||
/** | ||
* test parameter. | ||
*/ | ||
private final String bestandType; | ||
/** | ||
* test parameter. | ||
*/ | ||
private final long aantalBerichten; | ||
/** | ||
* test parameter. | ||
*/ | ||
private final long aantalProcessen; | ||
/** | ||
* test parameter. | ||
*/ | ||
private final long aantalPrs; | ||
/** | ||
* test parameter. | ||
*/ | ||
private final long aantalNiet_nat_prs; | ||
/** | ||
* test parameter. | ||
*/ | ||
private final long aantalNat_prs; | ||
/** | ||
* test param | ||
*/ | ||
private final String vestgID; | ||
/** | ||
* test parameter. | ||
*/ | ||
private final long aantalVestg_activiteit; | ||
|
||
private BrmoFramework brmo; | ||
|
||
// dbunit | ||
private IDatabaseConnection staging; | ||
private IDatabaseConnection rsgb; | ||
|
||
private final Lock sequential = new ReentrantLock(true); | ||
|
||
public NhrToStagingToRsgbIntegrationTest(String bestandType, String bestandNaam, long aantalBerichten, long aantalProcessen, | ||
long aantalPrs, long aantalNiet_nat_prs, long aantalNat_prs, String vestgID, long aantalVestg_activiteit) { | ||
this.bestandType = bestandType; | ||
this.bestandNaam = bestandNaam; | ||
this.aantalBerichten = aantalBerichten; | ||
this.aantalProcessen = aantalProcessen; | ||
this.aantalPrs = aantalPrs; | ||
this.aantalNiet_nat_prs = aantalNiet_nat_prs; | ||
this.aantalNat_prs = aantalNat_prs; | ||
this.vestgID = vestgID; | ||
this.aantalVestg_activiteit = aantalVestg_activiteit; | ||
} | ||
|
||
@Before | ||
@Override | ||
public void setUp() throws Exception { | ||
BasicDataSource dsStaging = new BasicDataSource(); | ||
dsStaging.setUrl(params.getProperty("staging.jdbc.url")); | ||
dsStaging.setUsername(params.getProperty("staging.user")); | ||
dsStaging.setPassword(params.getProperty("staging.passwd")); | ||
dsStaging.setAccessToUnderlyingConnectionAllowed(true); | ||
|
||
BasicDataSource dsRsgb = new BasicDataSource(); | ||
dsRsgb.setUrl(params.getProperty("rsgb.jdbc.url")); | ||
dsRsgb.setUsername(params.getProperty("rsgb.user")); | ||
dsRsgb.setPassword(params.getProperty("rsgb.passwd")); | ||
dsRsgb.setAccessToUnderlyingConnectionAllowed(true); | ||
|
||
staging = new DatabaseDataSourceConnection(dsStaging); | ||
rsgb = new DatabaseDataSourceConnection(dsRsgb); | ||
|
||
if (this.isMsSQL) { | ||
staging.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MsSqlDataTypeFactory()); | ||
rsgb.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MsSqlDataTypeFactory()); | ||
} else if (this.isOracle) { | ||
staging = new DatabaseConnection(OracleConnectionUnwrapper.unwrap(dsStaging.getConnection()), params.getProperty("staging.user").toUpperCase()); | ||
staging.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new Oracle10DataTypeFactory()); | ||
staging.getConfig().setProperty(DatabaseConfig.FEATURE_SKIP_ORACLE_RECYCLEBIN_TABLES, true); | ||
|
||
rsgb = new DatabaseConnection(OracleConnectionUnwrapper.unwrap(dsRsgb.getConnection()), params.getProperty("rsgb.user").toUpperCase()); | ||
rsgb.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new Oracle10DataTypeFactory()); | ||
rsgb.getConfig().setProperty(DatabaseConfig.FEATURE_SKIP_ORACLE_RECYCLEBIN_TABLES, true); | ||
} else if (this.isPostgis) { | ||
// we hebben alleen nog postgres over | ||
staging.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new PostgresqlDataTypeFactory()); | ||
rsgb.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new PostgresqlDataTypeFactory()); | ||
} | ||
|
||
brmo = new BrmoFramework(dsStaging, dsRsgb); | ||
brmo.setOrderBerichten(true); | ||
|
||
FlatXmlDataSetBuilder fxdb = new FlatXmlDataSetBuilder(); | ||
fxdb.setCaseSensitiveTableNames(false); | ||
IDataSet stagingDataSet = fxdb.build(new FileInputStream(new File(NhrToStagingToRsgbIntegrationTest.class.getResource("/staging-empty-flat.xml").toURI()))); | ||
|
||
sequential.lock(); | ||
|
||
DatabaseOperation.CLEAN_INSERT.execute(staging, stagingDataSet); | ||
|
||
assumeTrue("Er zijn geen STAGING_OK berichten", 0l == brmo.getCountBerichten(null, null, "nhr", "STAGING_OK")); | ||
assumeTrue("Er zijn geen STAGING_OK laadprocessen", 0l == brmo.getCountLaadProcessen(null, null, "nhr", "STAGING_OK")); | ||
} | ||
|
||
@After | ||
public void cleanup() throws Exception { | ||
brmo.closeBrmoFramework(); | ||
|
||
CleanUtil.cleanSTAGING(staging); | ||
staging.close(); | ||
|
||
CleanUtil.cleanRSGB_NHR(rsgb); | ||
rsgb.close(); | ||
|
||
sequential.unlock(); | ||
} | ||
|
||
@Test | ||
public void testNhrXMLToStagingToRsgb() throws Exception { | ||
assumeNotNull("Het test bestand moet er zijn.", NhrToStagingToRsgbIntegrationTest.class.getResource(bestandNaam)); | ||
|
||
brmo.loadFromFile(bestandType, NhrToStagingToRsgbIntegrationTest.class.getResource(bestandNaam).getFile()); | ||
LOG.debug("klaar met laden van berichten in staging DB."); | ||
|
||
List<Bericht> berichten = brmo.listBerichten(); | ||
List<LaadProces> processen = brmo.listLaadProcessen(); | ||
assertNotNull("De verzameling berichten bestaat niet.", berichten); | ||
assertEquals("Het aantal berichten is niet als verwacht.", aantalBerichten, berichten.size()); | ||
assertNotNull("De verzameling processen bestaat niet.", processen); | ||
assertEquals("Het aantal processen is niet als verwacht.", aantalProcessen, processen.size()); | ||
|
||
LOG.debug("Transformeren berichten naar rsgb DB."); | ||
Thread t = brmo.toRsgb(); | ||
t.join(); | ||
|
||
assertEquals("Niet alle berichten zijn OK getransformeerd", aantalBerichten, brmo.getCountBerichten(null, null, "nhr", "RSGB_OK")); | ||
berichten = brmo.listBerichten(); | ||
for (Bericht b : berichten) { | ||
assertNotNull("Bericht is 'null'", b); | ||
assertNotNull("'db-xml' van bericht is 'null'", b.getDbXml()); | ||
} | ||
|
||
ITable prs = rsgb.createDataSet().getTable("prs"); | ||
ITable niet_nat_prs = rsgb.createDataSet().getTable("niet_nat_prs"); | ||
ITable nat_prs = rsgb.createDataSet().getTable("nat_prs"); | ||
ITable vestg = rsgb.createDataSet().getTable("vestg"); | ||
ITable vestg_activiteit = rsgb.createDataSet().getTable("vestg_activiteit"); | ||
|
||
assertEquals("Het aantal 'prs' records klopt niet", aantalPrs, prs.getRowCount()); | ||
assertEquals("Het aantal 'niet_nat_prs' records klopt niet", aantalNiet_nat_prs, niet_nat_prs.getRowCount()); | ||
assertEquals("Het aantal 'nat_prs' records klopt niet", aantalNat_prs, nat_prs.getRowCount()); | ||
assertEquals("De 'sc_identif' van vestiging klopt niet", vestgID, vestg.getValue(0, "sc_identif")); | ||
assertEquals("Het aantal 'vestg_activiteit' records klopt niet", aantalVestg_activiteit, vestg_activiteit.getRowCount()); | ||
|
||
} | ||
} |
Oops, something went wrong.