Search in sources :

Example 76 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project molgenis-emx2 by molgenis.

the class TestSchemaCreateDestroy method schemaCrudTest.

@Test
public void schemaCrudTest() {
    try {
        db.dropCreateSchema("");
        fail("Schema createTableIfNotExists should fail on empty name");
    } catch (MolgenisException e) {
        System.out.println("Error correctly:\n" + e);
    }
    Schema schema = db.dropCreateSchema(getClass().getSimpleName());
    try {
        db.createSchema(getClass().getSimpleName());
        fail("Schema createTableIfNotExists should fail on duplicated name");
    } catch (MolgenisException e) {
        System.out.println("Error correctly:\n" + e);
    }
    schema.create(table("test"));
    try {
        schema.dropTable("test2");
        fail("Drop schema should fail for unknown table");
    } catch (Exception e) {
        System.out.println("Error correctly:\n" + e);
    }
    schema.dropTable("test");
    assertNull(schema.getTable("test"));
    try {
        db.dropSchema(getClass().getSimpleName() + "fake");
        fail("Drop schema should fail for unknown schema");
    } catch (Exception e) {
        System.out.println("Error correctly:\n" + e);
    }
    db.dropSchema(getClass().getSimpleName());
    assertNull(db.getSchema(getClass().getSimpleName()));
}
Also used : Schema(org.molgenis.emx2.Schema) MolgenisException(org.molgenis.emx2.MolgenisException) MolgenisException(org.molgenis.emx2.MolgenisException) Test(org.junit.Test)

Example 77 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project molgenis-emx2 by molgenis.

the class TestTransaction method testTransaction.

@Test
public void testTransaction() {
    Schema s = db.dropCreateSchema("testTransaction");
    // as long as from same db instance you can use resources in multiple Tx
    try {
        db.tx(db -> {
            Schema s2 = db.getSchema("testTransaction");
            s2.create(table("a"));
            s2.create(table("b"));
            throw new RuntimeException("transaction stopped to check if it rolled back");
        });
    } catch (Exception e) {
        System.out.println(e);
        assertNull(s.getTable("a"));
    }
}
Also used : Schema(org.molgenis.emx2.Schema) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 78 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project molgenis-emx2 by molgenis.

the class TestImportExportEmx2MetadataIODataAndMetadata method test.

@Test
public void test() throws IOException {
    Path tmp = Files.createTempDirectory(null);
    try {
        StopWatch.start("export and then import again test");
        Path directory = tmp.resolve("test");
        Files.createDirectories(directory);
        Schema schema1 = database.dropCreateSchema(getClass().getSimpleName() + "1");
        StopWatch.print("schema1 created, ready to load the example data");
        ProductComponentPartsExample.create(schema1.getMetadata());
        ProductComponentPartsExample.populate(schema1);
        StopWatch.print("example schema loaded");
        MolgenisIO.toDirectory(directory, schema1);
        StopWatch.print("export to directory complete");
        Schema schema2 = database.dropCreateSchema(getClass().getSimpleName() + "2");
        StopWatch.print("schema2 created, ready to reload the exported data");
        MolgenisIO.fromDirectory(directory, schema2, true);
        StopWatch.print("import from directory complete");
        CompareTools.assertEquals(schema1.getMetadata(), schema2.getMetadata());
        Path excelFile = tmp.resolve("test.xlsx");
        MolgenisIO.toExcelFile(excelFile, schema1);
        StopWatch.print("export to excel complete");
        Schema schema3 = database.dropCreateSchema(getClass().getSimpleName() + "3");
        StopWatch.print("schema3 created, ready to reload the exported data");
        MolgenisIO.importFromExcelFile(excelFile, schema3, true);
        StopWatch.print("import from excel complete");
        CompareTools.assertEquals(schema1.getMetadata(), schema3.getMetadata());
        Path zipFile = tmp.resolve("test.zip");
        MolgenisIO.toZipFile(zipFile, schema1);
        StopWatch.print("export to zipfile complete");
        Schema schema4 = database.dropCreateSchema(getClass().getSimpleName() + "4");
        StopWatch.print("schema4 created, ready to reload the exported data");
        MolgenisIO.fromZipFile(zipFile, schema4, true);
        StopWatch.print("import from zipfile complete");
        CompareTools.assertEquals(schema1.getMetadata(), schema4.getMetadata());
        StopWatch.print("schema comparison: all equal");
    } finally {
        Files.walk(tmp).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
    }
}
Also used : Path(java.nio.file.Path) Schema(org.molgenis.emx2.Schema) File(java.io.File) Test(org.junit.Test)

Example 79 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project molgenis-emx2 by molgenis.

the class TestLegacyImport method testLegacyImportDirectory.

@Test
public void testLegacyImportDirectory() {
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("bbmri-nl-complete").getFile());
    TableStoreForCsvFilesDirectory store = new TableStoreForCsvFilesDirectory(file.toPath(), ',');
    Schema schema = db.dropCreateSchema("testImportLegacyFormatDirectory");
    executeTest(store, schema);
}
Also used : Schema(org.molgenis.emx2.Schema) TableStoreForCsvFilesDirectory(org.molgenis.emx2.io.tablestore.TableStoreForCsvFilesDirectory) File(java.io.File) TableStoreForCsvInZipFile(org.molgenis.emx2.io.tablestore.TableStoreForCsvInZipFile) Test(org.junit.Test)

Example 80 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project molgenis-emx2 by molgenis.

the class TestLegacyImport method testLegacyImportZip.

@Test
public void testLegacyImportZip() {
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource("bbmri-nl-complete.zip").getFile());
    TableStore store = new TableStoreForCsvInZipFile(file.toPath());
    Schema schema = db.dropCreateSchema("testImportLegacyFormatZip");
    executeTest(store, schema);
}
Also used : Schema(org.molgenis.emx2.Schema) File(java.io.File) TableStoreForCsvInZipFile(org.molgenis.emx2.io.tablestore.TableStoreForCsvInZipFile) TableStoreForCsvInZipFile(org.molgenis.emx2.io.tablestore.TableStoreForCsvInZipFile) TableStore(org.molgenis.emx2.io.tablestore.TableStore) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)57 Schema (com.google.pubsub.v1.Schema)38 Schema (org.molgenis.emx2.Schema)38 AbstractMessage (com.google.protobuf.AbstractMessage)16 ByteString (com.google.protobuf.ByteString)16 QName (javax.xml.namespace.QName)16 File (java.io.File)15 URL (java.net.URL)15 Schema (org.geosdi.geoplatform.xml.xsd.v2001.Schema)15 SchemaServiceClient (com.google.cloud.pubsub.v1.SchemaServiceClient)14 ProjectName (com.google.pubsub.v1.ProjectName)14 LayerSchemaDTO (org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO)14 IOException (java.io.IOException)13 StringWriter (java.io.StringWriter)13 Schema (org.oasisopen.odata.csdl.v4.Schema)13 Schema (com.reprezen.kaizen.oasparser.model3.Schema)11 JAXBElement (javax.xml.bind.JAXBElement)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 List (java.util.List)8