Search in sources :

Example 56 with Schema

use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.

the class TestSettings method testTableSettings.

@Test
public void testTableSettings() {
    database.tx(// prevent side effect of user changes on other tests using tx
    db -> {
        Schema s = db.dropCreateSchema("testTableSettings");
        // set roles
        // viewer should only be able to see, not change
        // editor should be able to set values
        s.addMember("testtablesettingsviewer", VIEWER.toString());
        s.addMember("testtablesettingseditor", EDITOR.toString());
        s.create(table("test").add(column("test")));
        db.setActiveUser("testtablesettingsviewer");
        try {
            Table t = db.getSchema("testTableSettings").getTable("test");
            t.getMetadata().setSetting("key", "value");
            fail("viewers should not be able to change schema settings");
        } catch (Exception e) {
        // failed correctly
        }
        db.setActiveUser("testtablesettingseditor");
        try {
            Table t = db.getSchema("testTableSettings").getTable("test");
            t.getMetadata().setSetting("key", "value");
        } catch (Exception e) {
            e.printStackTrace();
            fail("managers should  be able to change schema settings");
        }
        db.clearCache();
        List<Setting> test = db.getSchema("testTableSettings").getTable("test").getMetadata().getSettings();
        assertEquals(1, test.size());
        assertEquals("key", test.get(0).key());
        assertEquals("value", test.get(0).value());
        assertEquals("key", db.getSchema("testTableSettings").getTable("test").getMetadata().getSettings().get(0).key());
        assertEquals("value", db.getSchema("testTableSettings").getTable("test").getMetadata().getSettings().get(0).value());
        db.becomeAdmin();
    });
}
Also used : Table(org.molgenis.emx2.Table) Schema(org.molgenis.emx2.Schema) Setting(org.molgenis.emx2.Setting) MolgenisException(org.molgenis.emx2.MolgenisException) Test(org.junit.Test)

Example 57 with Schema

use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.

the class TestMetaDataIsStoredForNextSessions method testSimpleTypesTest.

@Test
public void testSimpleTypesTest() {
    Schema schema = database.dropCreateSchema(SCHEMA_NAME + "2");
    SimpleTypeTestExample.createSimpleTypeTest(schema.getMetadata());
    try {
        CompareTools.reloadAndCompare(database, schema);
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Schema(org.molgenis.emx2.Schema) Test(org.junit.Test)

Example 58 with Schema

use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.

the class TestMetaDataIsStoredForNextSessions method testProductComponentsPartsModel.

@Test
public void testProductComponentsPartsModel() {
    Schema schema = database.dropCreateSchema(SCHEMA_NAME + "1");
    ProductComponentPartsExample.create(schema.getMetadata());
    try {
        CompareTools.reloadAndCompare(database, schema);
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Schema(org.molgenis.emx2.Schema) Test(org.junit.Test)

Example 59 with Schema

use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.

the class TestMetaDataIsStoredForNextSessions method testArrayTypesTest.

@Test
public void testArrayTypesTest() {
    Schema schema = database.dropCreateSchema(SCHEMA_NAME + "3");
    ArrayTypeTestExample.createSimpleTypeTest(schema.getMetadata());
    try {
        CompareTools.reloadAndCompare(database, schema);
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Schema(org.molgenis.emx2.Schema) Test(org.junit.Test)

Example 60 with Schema

use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.

the class TestTruncate method testTruncate.

@Test
public void testTruncate() {
    Database db = TestDatabaseFactory.getTestDatabase();
    Schema schema = db.dropCreateSchema(TestTruncate.class.getSimpleName());
    // create simple table, add data, and truncate
    Table table1 = schema.create(table("Table1", column("name").setPkey()));
    table1.insert(row("name", "a"));
    Assert.assertEquals(1, table1.retrieveRows().size());
    table1.truncate();
    Assert.assertEquals(0, table1.retrieveRows().size());
    // create with subclass
    Table table2 = schema.create(table("Table2").setInherit("Table1").add(column("col1")));
    table1.insert(row("name", "a"));
    table2.insert(row("name", "b", "col1", "checkb"));
    Assert.assertEquals(2, table1.retrieveRows().size());
    Assert.assertEquals(1, table2.retrieveRows().size());
    table1.truncate();
    Assert.assertEquals(1, table1.retrieveRows().size());
    Assert.assertEquals(1, table2.retrieveRows().size());
    table2.truncate();
    Assert.assertEquals(0, table1.retrieveRows().size());
    Assert.assertEquals(0, table2.retrieveRows().size());
    // create with subclass of a subclass
    Table table3 = schema.create(table("Table3").setInherit("Table2").add(column("col2")));
    table1.insert(row("name", "a"));
    table2.insert(row("name", "b", "col1", "checkb"));
    table3.insert(row("name", "c", "col1", "checkc", "col2", "checkc"));
    Assert.assertEquals(3, table1.retrieveRows().size());
    Assert.assertEquals(2, table2.retrieveRows().size());
    Assert.assertEquals(1, table3.retrieveRows().size());
    // leaves subclass?!!! is this expected behavior?
    table2.truncate();
    Assert.assertEquals(2, table1.retrieveRows().size());
    // !!!
    Assert.assertEquals(1, table2.retrieveRows().size());
    Assert.assertEquals(1, table3.retrieveRows().size());
    table3.truncate();
    Assert.assertEquals(1, table1.retrieveRows().size());
    Assert.assertEquals(0, table2.retrieveRows().size());
    Assert.assertEquals(0, table3.retrieveRows().size());
    table1.truncate();
    Assert.assertEquals(0, table1.retrieveRows().size());
    Assert.assertEquals(0, table2.retrieveRows().size());
    Assert.assertEquals(0, table3.retrieveRows().size());
}
Also used : Table(org.molgenis.emx2.Table) Schema(org.molgenis.emx2.Schema) Database(org.molgenis.emx2.Database) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)65 Schema (com.google.pubsub.v1.Schema)38 Schema (org.molgenis.emx2.Schema)38 ByteString (com.google.protobuf.ByteString)19 SchemaServiceClient (com.google.cloud.pubsub.v1.SchemaServiceClient)18 AbstractMessage (com.google.protobuf.AbstractMessage)18 QName (javax.xml.namespace.QName)16 SchemaName (com.google.pubsub.v1.SchemaName)15 File (java.io.File)15 Schema (org.geosdi.geoplatform.xml.xsd.v2001.Schema)15 ProjectName (com.google.pubsub.v1.ProjectName)14 IOException (java.io.IOException)14 URL (java.net.URL)14 LayerSchemaDTO (org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO)14 StringWriter (java.io.StringWriter)13 Schema (org.oasisopen.odata.csdl.v4.Schema)13 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)12 StatusRuntimeException (io.grpc.StatusRuntimeException)12 Schema (com.reprezen.kaizen.oasparser.model3.Schema)11 JAXBElement (javax.xml.bind.JAXBElement)10