コード例 #1
0
ファイル: SQLTestHelper.java プロジェクト: ramtej/zest-java
  public static void setUpTest(Module module) {
    Connection connection = null;
    try {

      DataSource ds = module.findService(DataSource.class).get();
      connection = ds.getConnection();
      Assume.assumeNotNull(connection);

    } catch (Throwable t) {

      t.printStackTrace();
      Assume.assumeNoException(t);

    } finally {

      SQLUtil.closeQuietly(connection);
    }
  }
コード例 #2
0
  @Test
  public void createAndRemoveEntityAndVerifyNoExtraDataLeftInDB() throws Exception {
    UnitOfWork uow = this.module.newUnitOfWork();
    TestEntity entity = uow.newEntity(TestEntity.class);
    uow.complete();

    uow = this.module.newUnitOfWork();
    entity = uow.get(entity);
    SQLConfiguration config =
        uow.get(SQLConfiguration.class, PostgreSQLIndexQueryAssembler.DEFAULT_IDENTITY);
    String schemaName = config.schemaName().get();
    if (schemaName == null) {
      schemaName = PostgreSQLAppStartup.DEFAULT_SCHEMA_NAME;
    }
    uow.remove(entity);
    uow.complete();

    Connection connection = this.module.findService(DataSource.class).get().getConnection();
    try {
      GenericDatabaseExplorer.visitDatabaseTables(
          connection,
          null,
          schemaName,
          null,
          new DatabaseProcessorAdapter() {
            @Override
            public void beginProcessRowInfo(
                String schemaNamee, String tableName, Object[] rowContents) {
              if ((tableName.startsWith(DBNames.QNAME_TABLE_NAME_PREFIX)
                      && (tableName.equals(DBNames.QNAME_TABLE_NAME_PREFIX + 0)
                          || tableName.equals(DBNames.QNAME_TABLE_NAME_PREFIX + 1)))
                  || tableName.equals(DBNames.ALL_QNAMES_TABLE_NAME)
                  || tableName.equals(DBNames.ENTITY_TABLE_NAME)) {
                throw new RuntimeException("Table: " + schemaNamee + "." + tableName);
              }
            }
          },
          SQLVendorProvider.createVendor(PostgreSQLVendor.class));
    } finally {
      SQLUtil.closeQuietly(connection);
    }
  }