Search in sources :

Example 6 with Schema

use of org.folio.dbschema.Schema in project raml-module-builder by folio-org.

the class DbSchemaUtilsTest method pathForeignKeyNotFound.

@Test
public void pathForeignKeyNotFound() {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("foreignKey not found");
    thrown.expectMessage("fieldName=nonexisting");
    Schema dbSchema = schema("templates/db_scripts/foreignKeyPath.json");
    DbSchemaUtils.findForeignKeysFromSourceTableToTargetAlias(dbSchema, "i", "b");
}
Also used : Schema(org.folio.dbschema.Schema) Test(org.junit.Test)

Example 7 with Schema

use of org.folio.dbschema.Schema in project raml-module-builder by folio-org.

the class DbSchemaUtilsTest method pathTableNotFound.

@Test
public void pathTableNotFound() {
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("table not found");
    thrown.expectMessage("targetPath=[invalidId, invalidId]");
    Schema dbSchema = schema("templates/db_scripts/foreignKeyPath.json");
    DbSchemaUtils.findForeignKeysFromSourceTableToTargetAlias(dbSchema, "i", "a");
}
Also used : Schema(org.folio.dbschema.Schema) Test(org.junit.Test)

Example 8 with Schema

use of org.folio.dbschema.Schema in project raml-module-builder by folio-org.

the class DbSchemaUtilsTest method testFindForeignKeys.

@Test
public void testFindForeignKeys() throws Exception {
    // pathA: f -> e -> d -> c -> b -> a
    // pathB: f -> e -> c -> b -> a
    Schema dbSchema = schema("templates/db_scripts/foreignKeyPath.json");
    // child->parent with targetAlias
    List<DbFkInfo> list = DbSchemaUtils.findForeignKeysFromSourceTableToTargetAlias(dbSchema, "f", "a");
    assertEquals("f", list.get(0).getTable());
    assertEquals("e", list.get(1).getTable());
    assertEquals("c", list.get(2).getTable());
    assertEquals("b", list.get(3).getTable());
    // child->parent with targetAlias
    list = DbSchemaUtils.findForeignKeysFromSourceTableToTargetAlias(dbSchema, "f", "bAlias");
    assertEquals("f", list.get(0).getTable());
    assertEquals("e", list.get(1).getTable());
    assertEquals("c", list.get(2).getTable());
    // parent->child with sourceAlias
    list = DbSchemaUtils.findForeignKeysFromSourceAliasToTargetTable(dbSchema, "eAlias", "b");
    assertEquals("e", list.get(0).getTable());
    assertEquals("d", list.get(1).getTable());
    assertEquals("c", list.get(2).getTable());
    // parent->child with sourceAlias
    list = DbSchemaUtils.findForeignKeysFromSourceAliasToTargetTable(dbSchema, "e2Alias", "b");
    assertEquals("e", list.get(0).getTable());
    assertEquals("c", list.get(1).getTable());
    list = DbSchemaUtils.findForeignKeysFromSourceTableToTargetAlias(dbSchema, "nonexistingTable", "a");
    assertThat(list, is(empty()));
}
Also used : Schema(org.folio.dbschema.Schema) DbFkInfo(org.folio.cql2pgjson.model.DbFkInfo) Test(org.junit.Test)

Example 9 with Schema

use of org.folio.dbschema.Schema in project raml-module-builder by folio-org.

the class SchemaMakerIT method assertIdJsonb.

private void assertIdJsonb(TestContext context, String id, String idInJsonb) {
    Async async = context.async();
    PostgresClient postgresClient = PostgresClient.getInstance(vertx, tenant);
    String sql = "SELECT id, jsonb->>'id' FROM " + schema + ".test_tenantapi";
    postgresClient.selectSingle(sql, context.asyncAssertSuccess(result -> {
        context.assertEquals(id, result.getUUID(0).toString(), "id");
        context.assertEquals(idInJsonb, result.getString(1), "jsonb->>'id'");
        async.complete();
    }));
    async.awaitSuccess(5000);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PostgresClientITBase(org.folio.rest.persist.PostgresClientITBase) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Timeout(io.vertx.ext.unit.junit.Timeout) Test(org.junit.Test) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) PostgresClient(org.folio.rest.persist.PostgresClient) TenantOperation(org.folio.dbschema.TenantOperation) List(java.util.List) Rule(org.junit.Rule) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObjectMapperTool(org.folio.dbschema.ObjectMapperTool) ResourceUtil(org.folio.util.ResourceUtil) Schema(org.folio.dbschema.Schema) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) Async(io.vertx.ext.unit.Async) PostgresClient(org.folio.rest.persist.PostgresClient) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 10 with Schema

use of org.folio.dbschema.Schema in project raml-module-builder by folio-org.

the class SchemaMakerIT method canConcurrentlyUseAuditedTable.

@Test
public void canConcurrentlyUseAuditedTable(TestContext context) {
    runSchema(context, TenantOperation.CREATE, "schemaWithAudit.json");
    String table = schema + ".test_tenantapi";
    execute(context, "INSERT INTO " + table + " SELECT md5(username)::uuid, json_build_object('username', username, 'id', md5(username)::uuid)" + " FROM (SELECT 'patron' || generate_series(1, 2) AS username) AS subquery");
    // concurrently update two records: https://issues.folio.org/browse/RMB-430
    Async async = context.async();
    PostgresClient postgresClient = PostgresClient.getInstance(vertx, tenant);
    postgresClient.startTx(tx1 -> {
        context.assertTrue(tx1.succeeded());
        postgresClient.startTx(tx2 -> {
            context.assertTrue(tx2.succeeded());
            String sql = "UPDATE " + table + " SET jsonb=jsonb_set(jsonb, '{x}', to_jsonb('y'::text)) WHERE jsonb->>'username' = ";
            postgresClient.execute(tx1, sql + "'patron1'", context.asyncAssertSuccess(update1 -> {
                postgresClient.execute(tx2, sql + "'patron2'", context.asyncAssertSuccess(update2 -> {
                    postgresClient.endTx(tx1, context.asyncAssertSuccess(endTx1 -> {
                        postgresClient.endTx(tx2, context.asyncAssertSuccess(endTx2 -> {
                            String sql3 = "SELECT * FROM " + table.replace(".", ".audit_");
                            postgresClient.select(sql3, context.asyncAssertSuccess(result -> {
                                context.assertEquals(4, result.rowCount());
                                async.complete();
                            }));
                        }));
                    }));
                }));
            }));
        });
    });
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PostgresClientITBase(org.folio.rest.persist.PostgresClientITBase) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Timeout(io.vertx.ext.unit.junit.Timeout) Test(org.junit.Test) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) PostgresClient(org.folio.rest.persist.PostgresClient) TenantOperation(org.folio.dbschema.TenantOperation) List(java.util.List) Rule(org.junit.Rule) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObjectMapperTool(org.folio.dbschema.ObjectMapperTool) ResourceUtil(org.folio.util.ResourceUtil) Schema(org.folio.dbschema.Schema) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) Async(io.vertx.ext.unit.Async) PostgresClient(org.folio.rest.persist.PostgresClient) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

Schema (org.folio.dbschema.Schema)10 Test (org.junit.Test)5 Async (io.vertx.ext.unit.Async)4 TestContext (io.vertx.ext.unit.TestContext)4 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)4 List (java.util.List)4 UUID (java.util.UUID)4 TenantOperation (org.folio.dbschema.TenantOperation)4 PostgresClient (org.folio.rest.persist.PostgresClient)4 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)4 Before (org.junit.Before)4 RunWith (org.junit.runner.RunWith)4 Timeout (io.vertx.ext.unit.junit.Timeout)3 Arrays (java.util.Arrays)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ObjectMapperTool (org.folio.dbschema.ObjectMapperTool)3 InputStream (java.io.InputStream)2 PostgresClientITBase (org.folio.rest.persist.PostgresClientITBase)2 SchemaMaker (org.folio.rest.persist.ddlgen.SchemaMaker)2