Пример #1
0
 private void verifyExpected(
     DbUnitTestContext testContext, Collection<ExpectedDatabase> annotations) throws Exception {
   if (testContext.getTestException() != null) {
     if (logger.isDebugEnabled()) {
       logger.debug(
           "Skipping @DatabaseTest expectation due to test exception "
               + testContext.getTestException().getClass());
     }
     return;
   }
   IDatabaseConnection connection = testContext.getConnection();
   IDataSet actualDataSet = connection.createDataSet();
   for (ExpectedDatabase annotation : annotations) {
     IDataSet expectedDataSet = loadDataset(testContext, annotation.value());
     if (expectedDataSet != null) {
       if (logger.isDebugEnabled()) {
         logger.debug("Veriftying @DatabaseTest expectation using " + annotation.value());
       }
       DatabaseAssertion assertion = annotation.assertionMode().getDatabaseAssertion();
       assertion.assertEquals(expectedDataSet, actualDataSet);
     }
   }
 }
Пример #2
0
 /**
  * Called after a test method is executed to perform any database teardown and to check expected
  * results.
  *
  * @param testContext The test context
  * @throws Exception
  */
 public void afterTestMethod(DbUnitTestContext testContext) throws Exception {
   try {
     verifyExpected(testContext, getAnnotations(testContext, ExpectedDatabase.class));
     Collection<DatabaseTearDown> annotations =
         getAnnotations(testContext, DatabaseTearDown.class);
     try {
       setupOrTeardown(testContext, false, AnnotationAttributes.get(annotations));
     } catch (RuntimeException e) {
       if (testContext.getTestException() == null) {
         throw e;
       }
       if (logger.isWarnEnabled()) {
         logger.warn("Unable to throw database cleanup exception due to existing test error", e);
       }
     }
   } finally {
     testContext.getConnection().close();
   }
 }