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");
}
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");
}
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()));
}
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);
}
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();
}));
}));
}));
}));
}));
});
});
}
Aggregations