Beispiel #1
0
  /**
   * DO NOT OVERRIDE.
   *
   * <p>DO NOT DEFINE AN @BeforeMethod Instead, override {@link #beforeMethod()}. If you must
   * override, for example, if you need to use special attributes on your annotation, then ensure
   * you protect the code with and {@link #inContainer()} call.
   */
  @BeforeMethod
  protected void __beforeMethod(Method method) throws Throwable {
    // Note that Arquillian calls the testng BeforeMethod twice (as of 1.0.2.Final, once
    // out of container and once in container. In general the expectation is to execute it
    // one time, and doing it in container allows for the expected injections and context.
    if (inContainer()) {
      try {
        // Make sure we set the db type for tests that may need it (normally done in StartupBean)
        if (null == DatabaseTypeFactory.getDefaultDatabaseType()) {
          Connection conn = null;
          try {
            conn = getConnection();
            DatabaseTypeFactory.setDefaultDatabaseType(DatabaseTypeFactory.getDatabaseType(conn));
          } catch (Exception e) {
            System.err.println(
                "!!! WARNING !!! cannot set default database type, some tests may fail");
            e.printStackTrace();
          } finally {
            if (null != conn) {
              conn.close();
            }
          }
        }

        beforeMethod();
        beforeMethod(method);

      } catch (Throwable t) {
        // Arquillian is eating these, make sure they show up in some way
        System.out.println("BEFORE METHOD FAILURE, TEST DID NOT RUN!!! [" + method.getName() + "]");
        t.printStackTrace();
        throw t;
      }
    }
  }
Beispiel #2
0
  @BeforeMethod
  public static void startTest() {
    if (DatabaseTypeFactory.getDefaultDatabaseType() == null) {
      try {
        Connection conn = getConnection();
        DatabaseTypeFactory.setDefaultDatabaseType(DatabaseTypeFactory.getDatabaseType(conn));
      } catch (Exception e) {
        System.err.println("!!! WARNING !!! cannot set default database type, some tests may fail");
        e.printStackTrace();
      }
    }

    if (stats != null) start = stats.getQueryExecutionCount();
    else start = 0;
  }