/** * Compares the contents of the expected DbUnitDataSet with the contents of the database. Only the tables and columns that occur in the * expected DbUnitDataSet are compared with the database contents. * * @param testMethod The test method, not null * @param testObject The test object, not null */ public void assertDbContentAsExpected(Method testMethod, Object testObject) { Class<?> testClass = testObject.getClass(); ExpectedDataSets expectedsDataSetAnnotation = getMethodOrClassLevelAnnotation(ExpectedDataSets.class, testMethod, testClass); if (expectedsDataSetAnnotation != null) { assertMultipleExpectedDataSets(expectedsDataSetAnnotation, testObject, testMethod); } ExpectedDataSet expectedDataSetAnnotation = getMethodOrClassLevelAnnotation(ExpectedDataSet.class, testMethod, testClass); if (expectedDataSetAnnotation != null) { assertExpectedDataSets(expectedDataSetAnnotation, testObject, testMethod); } }
/** * This method will first try to load a method level defined dataset. If no such file exists, a class level defined dataset will be * loaded. If neither of these files exist, nothing is done. The name of the test data file at both method level and class level can be * overridden using the {@link DataSet} annotation. If specified using this annotation but not found, a {@link UnitilsException} is * thrown. * * @param testMethod The method, not null * @param testObject The test object, not null */ public void insertDataSet(Method testMethod, Object testObject) { Class<?> testClass = testObject.getClass(); try { DataSets dataSetsAnnotation = getMethodOrClassLevelAnnotation(DataSets.class, testMethod, testClass); if (dataSetsAnnotation != null) { insertDataSets(dataSetsAnnotation, testObject, testMethod); } DataSet dataSetAnnotation = getMethodOrClassLevelAnnotation(DataSet.class, testMethod, testClass); if (dataSetAnnotation != null) { insertDataSet(dataSetAnnotation, testObject, testMethod); } } catch (Exception e) { throw new UnitilsException("Error inserting test data from DbUnit dataset for method " + testMethod, e); } finally { closeJdbcConnection(); } }
/** * @see org.unitils.orm.common.OrmModule#getDatabaseName(java.lang.Object, java.lang.reflect.Method) */ @Override protected void getDatabaseName(Object testObject, Method testMethod) { JpaEntityManagerFactory dataSource = AnnotationUtils.getMethodOrClassLevelAnnotation(JpaEntityManagerFactory.class, testMethod, testObject.getClass()); if (dataSource != null) { wrappers.add(getDatabaseModule().getWrapper(dataSource.databaseName())); } Set<JpaEntityManagerFactory> lstDataSources = AnnotationUtils.getFieldLevelAnnotations(testObject.getClass(), JpaEntityManagerFactory.class); if (!lstDataSources.isEmpty()) { for (JpaEntityManagerFactory testDataSource : lstDataSources) { wrappers.add(getDatabaseModule().getWrapper(testDataSource.databaseName())); } } } }
/** * @see org.unitils.orm.common.OrmModule#getDatabaseName(java.lang.Object, java.lang.reflect.Method) */ @Override protected void getDatabaseName(Object testObject, Method testMethod) { //List<String> dataSources = new ArrayList<String>(); HibernateSessionFactory dataSource = AnnotationUtils.getMethodOrClassLevelAnnotation(HibernateSessionFactory.class, testMethod, testObject.getClass()); if (dataSource != null) { wrappers.add(getDatabaseModule().getWrapper(dataSource.databaseName())); //dataSources.add(dataSource.databaseName()); } Set<HibernateSessionFactory> lstDataSources = AnnotationUtils.getFieldLevelAnnotations(testObject.getClass(), HibernateSessionFactory.class); if (!lstDataSources.isEmpty()) { for (HibernateSessionFactory testDataSource : lstDataSources) { //ataSources.add(testDataSource.databaseName()); wrappers.add(getDatabaseModule().getWrapper(testDataSource.databaseName())); } } //return dataSources; }