Search in sources :

Example 21 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.

the class TestComputedValue method test1.

@Test
public void test1() {
    Table t = schema.create(table("Test1", column("id").setPkey(), column("computed").setComputed("1;")));
    t.insert(new Row().set("id", 1));
    assertEquals(1, (int) t.query().retrieveRows().get(0).getInteger("computed"));
    t = schema.create(table("Test2", column("id").setPkey(), column("computed").setComputed("id")));
    t.insert(new Row().set("id", 1));
    assertEquals(1, (int) t.query().retrieveRows().get(0).getInteger("computed"));
// t = schema.create(table("Test3", column("id").pkey(), column("computed").computed("id")));
// List<Row> rows = new ArrayList<>();
// for (int i = 0; i < 10000; i++) {
// rows.add(new Row().set("id", i));
// }
// 
// // perf test;
// StopWatch.start("start");
// t.insert(rows);
// StopWatch.print("complete", 10000);
}
Also used : Table(org.molgenis.emx2.Table) Row(org.molgenis.emx2.Row) Test(org.junit.Test)

Example 22 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table 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 23 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.

the class TestMgColumns method testUpdatedOn.

@Test
public void testUpdatedOn() {
    Table t = schema.create(table("UpdatedOn", column("id").setPkey()));
    t.insert(row("id", 1));
    Row r = t.retrieveRows().get(0);
    Assert.assertNotNull(r.getDateTime(MG_INSERTEDON));
    Assert.assertEquals(r.getDateTime(MG_INSERTEDON), r.getDateTime(MG_UPDATEDON));
    Assert.assertNotNull(r.getString(MG_INSERTEDBY));
    Assert.assertEquals(r.getString(MG_UPDATEDBY), r.getString(MG_INSERTEDBY));
    t.update(r);
    r = t.retrieveRows().get(0);
    Assert.assertTrue(r.getDateTime(MG_INSERTEDON).compareTo(r.getDateTime(MG_UPDATEDON)) < 0);
    // to make sure also test with subclass
    t = schema.create(table("UpdatedOnSub").setInherit("UpdatedOn"));
    t.insert(row("id", 2));
    r = t.retrieveRows().get(0);
    Assert.assertNotNull(r.getDateTime(MG_INSERTEDON));
    Assert.assertEquals(r.getDateTime(MG_INSERTEDON), r.getDateTime(MG_UPDATEDON));
    Assert.assertNotNull(r.getString(MG_INSERTEDBY));
    Assert.assertEquals(r.getString(MG_UPDATEDBY), r.getString(MG_INSERTEDBY));
    t.update(r);
    r = t.retrieveRows().get(0);
    Assert.assertTrue(r.getDateTime(MG_INSERTEDON).compareTo(r.getDateTime(MG_UPDATEDON)) < 0);
}
Also used : Table(org.molgenis.emx2.Table) Row(org.molgenis.emx2.Row) Test(org.junit.Test)

Example 24 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table 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)

Example 25 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project java-bigtable by googleapis.

the class EmulatorTest method testTableAdminClient.

@Test
public void testTableAdminClient() {
    Table table = tableAdminStub.createTable(CreateTableRequest.newBuilder().setParent("projects/fake-project/instances/fake-instance").setTableId("fake-table").setTable(Table.newBuilder().putColumnFamilies("cf", ColumnFamily.getDefaultInstance())).build());
    assertThat(table.getName()).isEqualTo("projects/fake-project/instances/fake-instance/tables/fake-table");
}
Also used : Table(com.google.bigtable.admin.v2.Table) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)40 Table (com.google.privacy.dlp.v2.Table)23 Table (org.molgenis.emx2.Table)23 Table (com.google.bigtable.admin.v2.Table)21 ByteString (com.google.protobuf.ByteString)18 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)17 ArrayList (java.util.ArrayList)14 AbstractMessage (com.google.protobuf.AbstractMessage)13 HashMap (java.util.HashMap)13 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)11 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)10 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)10 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)10 Row (org.molgenis.emx2.Row)10 IOException (java.io.IOException)9 List (java.util.List)9 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum)7 DlpServiceClient (com.google.cloud.dlp.v2.DlpServiceClient)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table)6