Search in sources :

Example 6 with Config

use of ch.ehi.ili2db.gui.Config in project ili2db by claeis.

the class SRSVerificationTest method srsAuthLowerCase_False.

@Test
public void srsAuthLowerCase_False() throws Exception {
    Connection jdbcConnection = null;
    try {
        Class driverClass = Class.forName("org.postgresql.Driver");
        jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
        Statement stmt = jdbcConnection.createStatement();
        stmt.execute("DROP SCHEMA IF EXISTS " + DBSCHEMA + " CASCADE");
        {
            File data = new File("test/data/SRSVerification/ModelA.ili");
            Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
            config.setFunction(Config.FC_SCHEMAIMPORT);
            config.setDbschema(DBSCHEMA);
            config.setCreateFk(config.CREATE_FK_YES);
            config.setDefaultSrsAuthority("epsg");
            config.setDefaultSrsCode("2000");
            Ili2db.readSettingsFromDb(config);
            try {
                Ili2db.run(config, null);
                fail();
            } catch (Ili2dbException e) {
                Assert.assertEquals("epsg/2000 does not exist", e.getMessage());
            }
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : Statement(java.sql.Statement) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) File(java.io.File) Test(org.junit.Test)

Example 7 with Config

use of ch.ehi.ili2db.gui.Config in project ili2db by claeis.

the class BlackBoxTypes23Test method exportXtf.

@Test
public void exportXtf() throws Exception {
    Connection jdbcConnection = null;
    try {
        Class driverClass = Class.forName("org.postgresql.Driver");
        jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
        stmt = jdbcConnection.createStatement();
        stmt.execute("DROP SCHEMA IF EXISTS " + DBSCHEMA + " CASCADE");
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/BlackBoxTypes23/CreateTable.sql"));
        DbUtility.executeSqlScript(jdbcConnection, new java.io.FileReader("test/data/BlackBoxTypes23/InsertIntoTable.sql"));
        File data = new File("test/data/BlackBoxTypes23/BlackBoxTypes23a-out.xtf");
        Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
        config.setModels("BlackBoxTypes23");
        config.setFunction(Config.FC_EXPORT);
        Ili2db.readSettingsFromDb(config);
        Ili2db.run(config, null);
        // read objects of db and write objectValue to HashMap
        HashMap<String, IomObject> objs = new HashMap<String, IomObject>();
        XtfReader reader = new XtfReader(data);
        IoxEvent event = null;
        do {
            event = reader.read();
            if (event instanceof StartTransferEvent) {
            } else if (event instanceof StartBasketEvent) {
            } else if (event instanceof ObjectEvent) {
                IomObject iomObj = ((ObjectEvent) event).getIomObject();
                if (iomObj.getobjectoid() != null) {
                    objs.put(iomObj.getobjectoid(), iomObj);
                }
            } else if (event instanceof EndBasketEvent) {
            } else if (event instanceof EndTransferEvent) {
            }
        } while (!(event instanceof EndTransferEvent));
        {
            IomObject obj0 = objs.get("o0");
            Assert.assertNotNull(obj0);
            Assert.assertEquals("BlackBoxTypes23.Topic.ClassA", obj0.getobjecttag());
        }
        {
            IomObject obj1 = objs.get("o1");
            Assert.assertNotNull(obj1);
            Assert.assertEquals("BlackBoxTypes23.Topic.ClassA", obj1.getobjecttag());
            Assert.assertEquals("AAAA", obj1.getattrvalue("binbox"));
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox.ObjectEvent) HashMap(java.util.HashMap) Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) StartTransferEvent(ch.interlis.iox.StartTransferEvent) EndBasketEvent(ch.interlis.iox.EndBasketEvent) IomObject(ch.interlis.iom.IomObject) EndTransferEvent(ch.interlis.iox.EndTransferEvent) XtfReader(ch.interlis.iom_j.xtf.XtfReader) IoxEvent(ch.interlis.iox.IoxEvent) StartBasketEvent(ch.interlis.iox.StartBasketEvent) File(java.io.File) Test(org.junit.Test)

Example 8 with Config

use of ch.ehi.ili2db.gui.Config in project ili2db by claeis.

the class BlackBoxTypes23Test method importIli.

@Test
public void importIli() throws Exception {
    EhiLogger.getInstance().setTraceFilter(false);
    Connection jdbcConnection = null;
    try {
        Class driverClass = Class.forName("org.postgresql.Driver");
        jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
        stmt = jdbcConnection.createStatement();
        stmt.execute("DROP SCHEMA IF EXISTS " + DBSCHEMA + " CASCADE");
        {
            File data = new File("test/data/BlackBoxTypes23/BlackBoxTypes23.ili");
            Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
            config.setFunction(Config.FC_SCHEMAIMPORT);
            config.setCreateFk(config.CREATE_FK_YES);
            config.setTidHandling(Config.TID_HANDLING_PROPERTY);
            config.setBasketHandling(config.BASKET_HANDLING_READWRITE);
            config.setCatalogueRefTrafo(null);
            config.setMultiSurfaceTrafo(null);
            config.setMultilingualTrafo(null);
            config.setInheritanceTrafo(null);
            Ili2db.readSettingsFromDb(config);
            Ili2db.run(config, null);
            {
                String stmtTxt = "SELECT data_type FROM information_schema.columns WHERE table_schema ='blackboxtypes23' AND table_name = 'classa' AND column_name = 'xmlbox'";
                Assert.assertTrue(stmt.execute(stmtTxt));
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("xml", rs.getString("data_type"));
            }
            {
                String stmtTxt = "SELECT data_type FROM information_schema.columns WHERE table_schema ='blackboxtypes23' AND table_name = 'classa' AND column_name = 'binbox'";
                Assert.assertTrue(stmt.execute(stmtTxt));
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("bytea", rs.getString("data_type"));
            }
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) File(java.io.File) Test(org.junit.Test)

Example 9 with Config

use of ch.ehi.ili2db.gui.Config in project ili2db by claeis.

the class BlackBoxTypes23Test method importXtf.

@Test
public void importXtf() throws Exception {
    EhiLogger.getInstance().setTraceFilter(false);
    Connection jdbcConnection = null;
    try {
        Class driverClass = Class.forName("org.postgresql.Driver");
        jdbcConnection = DriverManager.getConnection(dburl, dbuser, dbpwd);
        stmt = jdbcConnection.createStatement();
        stmt.execute("DROP SCHEMA IF EXISTS " + DBSCHEMA + " CASCADE");
        {
            File data = new File("test/data/BlackBoxTypes23/BlackBoxTypes23a.xtf");
            Config config = initConfig(data.getPath(), DBSCHEMA, data.getPath() + ".log");
            config.setFunction(Config.FC_IMPORT);
            config.setCreateFk(config.CREATE_FK_YES);
            config.setTidHandling(Config.TID_HANDLING_PROPERTY);
            config.setBasketHandling(config.BASKET_HANDLING_READWRITE);
            config.setCatalogueRefTrafo(null);
            config.setMultiSurfaceTrafo(null);
            config.setMultilingualTrafo(null);
            config.setInheritanceTrafo(null);
            config.setModels("BlackBoxTypes23");
            Ili2db.readSettingsFromDb(config);
            Ili2db.run(config, null);
            {
                String stmtTxt = "SELECT data_type FROM information_schema.columns WHERE table_schema ='blackboxtypes23' AND table_name = 'classa' AND column_name = 'xmlbox'";
                Assert.assertTrue(stmt.execute(stmtTxt));
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("xml", rs.getString("data_type"));
            }
            {
                String stmtTxt = "SELECT data_type FROM information_schema.columns WHERE table_schema ='blackboxtypes23' AND table_name = 'classa' AND column_name = 'binbox'";
                Assert.assertTrue(stmt.execute(stmtTxt));
                ResultSet rs = stmt.getResultSet();
                Assert.assertTrue(rs.next());
                Assert.assertEquals("bytea", rs.getString("data_type"));
            }
        }
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
}
Also used : Config(ch.ehi.ili2db.gui.Config) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) File(java.io.File) Test(org.junit.Test)

Example 10 with Config

use of ch.ehi.ili2db.gui.Config in project ili2db by claeis.

the class BlackBoxTypes23GpkgTest method initConfig.

public Config initConfig(String xtfFilename, String logfile) {
    Config config = new Config();
    new ch.ehi.ili2gpkg.GpkgMain().initConfig(config);
    config.setDbfile(gpkgFileName);
    config.setDburl("jdbc:sqlite:" + gpkgFileName);
    if (logfile != null) {
        config.setLogfile(logfile);
    }
    config.setXtffile(xtfFilename);
    if (xtfFilename != null && Ili2db.isItfFilename(xtfFilename)) {
        config.setItfTransferfile(true);
    }
    return config;
}
Also used : Config(ch.ehi.ili2db.gui.Config)

Aggregations

Config (ch.ehi.ili2db.gui.Config)207 File (java.io.File)162 Test (org.junit.Test)154 Connection (java.sql.Connection)118 ResultSet (java.sql.ResultSet)72 Statement (java.sql.Statement)44 HashMap (java.util.HashMap)40 IomObject (ch.interlis.iom.IomObject)34 EndBasketEvent (ch.interlis.iox.EndBasketEvent)34 EndTransferEvent (ch.interlis.iox.EndTransferEvent)34 IoxEvent (ch.interlis.iox.IoxEvent)34 ObjectEvent (ch.interlis.iox.ObjectEvent)34 StartBasketEvent (ch.interlis.iox.StartBasketEvent)34 StartTransferEvent (ch.interlis.iox.StartTransferEvent)34 FgdbDriver (ch.ehi.ili2fgdb.jdbc.FgdbDriver)33 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)32 XtfReader (ch.interlis.iom_j.xtf.XtfReader)30 IoxException (ch.interlis.iox.IoxException)15 SQLException (java.sql.SQLException)12 ResultSetMetaData (java.sql.ResultSetMetaData)10