use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class JpaVersionDaoTest method testVersionLifecycle.
@Test
public void testVersionLifecycle() {
final String productName = "TEST_VERSION";
// Doesn't exist
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final Version version = versionDao.getVersion(productName);
assertNull(version);
}
});
// Create
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
Version version = versionDao.getVersion(productName);
assertNull(version);
version = versionDao.setVersion(productName, 1, 2, 3, null);
assertNotNull(version);
assertEquals(1, version.getMajor());
assertEquals(2, version.getMinor());
assertEquals(3, version.getPatch());
assertNull(version.getLocal());
}
});
// Update
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
Version version = versionDao.getVersion(productName);
assertNotNull(version);
assertEquals(1, version.getMajor());
assertEquals(2, version.getMinor());
assertEquals(3, version.getPatch());
assertNull(version.getLocal());
version = versionDao.setVersion(productName, 4, 5, 6, null);
assertNotNull(version);
assertEquals(4, version.getMajor());
assertEquals(5, version.getMinor());
assertEquals(6, version.getPatch());
assertNull(version.getLocal());
}
});
// verify
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
Version version = versionDao.getVersion(productName);
assertNotNull(version);
assertEquals(4, version.getMajor());
assertEquals(5, version.getMinor());
assertEquals(6, version.getPatch());
assertNull(version.getLocal());
}
});
}
use of org.apereo.portal.concurrency.CallableWithoutResult in project uPortal by Jasig.
the class BaseJpaDaoTest method deleteAllEntities.
/**
* Deletes ALL entities from the database
*/
@After
public final void deleteAllEntities() {
final EntityManager entityManager = getEntityManager();
final EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory();
final Metamodel metamodel = entityManagerFactory.getMetamodel();
Set<EntityType<?>> entityTypes = new LinkedHashSet<>(metamodel.getEntities());
do {
final Set<EntityType<?>> failedEntitieTypes = new HashSet<>();
for (final EntityType<?> entityType : entityTypes) {
final String entityClassName = entityType.getBindableJavaType().getName();
try {
this.executeInTransaction(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
logger.trace("Purging all: " + entityClassName);
final Query query = entityManager.createQuery("SELECT e FROM " + entityClassName + " AS e");
final List<?> entities = query.getResultList();
logger.trace("Found " + entities.size() + " " + entityClassName + " to delete");
for (final Object entity : entities) {
entityManager.remove(entity);
}
}
});
} catch (DataIntegrityViolationException e) {
logger.trace("Failed to delete " + entityClassName + ". Must be a dependency of another entity");
failedEntitieTypes.add(entityType);
}
}
entityTypes = failedEntitieTypes;
} while (!entityTypes.isEmpty());
// Reset all spring managed mocks after every test
MockitoFactoryBean.resetAllMocks();
}
Aggregations