use of org.nhindirect.monitor.dao.AggregationDAOException in project nhin-d by DirectProject.
the class AggregationDAOImpl_getAggregationKeysTest method testGetAggregationKeys_entityManagerException_assertNoAggregation.
@Test
public void testGetAggregationKeys_entityManagerException_assertNoAggregation() throws Exception {
EntityManager mgr = mock(EntityManager.class);
doThrow(new RuntimeException()).when(mgr).createQuery((String) any());
final AggregationDAOImpl dao = new AggregationDAOImpl();
dao.setEntityManager(mgr);
boolean exceptionOccured = false;
try {
dao.getAggregationKeys();
} catch (AggregationDAOException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of org.nhindirect.monitor.dao.AggregationDAOException in project nhin-d by DirectProject.
the class AggregationDAOImpl_getAggregationTest method testGetAggregation_entityManagerException_assertNoAggregation.
@Test
public void testGetAggregation_entityManagerException_assertNoAggregation() throws Exception {
EntityManager mgr = mock(EntityManager.class);
doThrow(new RuntimeException()).when(mgr).find((Class<?>) any(), any());
final AggregationDAOImpl dao = new AggregationDAOImpl();
dao.setEntityManager(mgr);
boolean exceptionOccured = false;
try {
dao.getAggregation("12345");
} catch (AggregationDAOException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of org.nhindirect.monitor.dao.AggregationDAOException in project nhin-d by DirectProject.
the class AggregationDAOImpl_removeAggregationTest method testRemoveAggregation_removeAggregation_incorrectVersion_assertException.
@Test
public void testRemoveAggregation_removeAggregation_incorrectVersion_assertException() throws Exception {
final Aggregation insert = new Aggregation();
insert.setExchangeBlob(new byte[] { 0, 3, 2 });
insert.setId("12345");
insert.setVersion(0);
notifDao.addUpdateAggregation(insert);
assertNotNull(notifDao.getAggregation("12345"));
final Aggregation remove = new Aggregation();
remove.setExchangeBlob(new byte[] { 0, 3, 2 });
remove.setId("12345");
remove.setVersion(3);
boolean exceptionOccured = false;
try {
notifDao.removeAggregation(remove, "12345");
} catch (AggregationDAOException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of org.nhindirect.monitor.dao.AggregationDAOException in project nhin-d by DirectProject.
the class AggregationDAOImpl method confirmAggregation.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = false)
public void confirmAggregation(String id) throws AggregationDAOException {
try {
// find the aggregation
final AggregationCompleted completed = entityManager.find(AggregationCompleted.class, id);
if (completed != null) {
// remove it
entityManager.remove(completed);
entityManager.flush();
}
} catch (Exception e) {
throw new AggregationDAOException("Failed to confirm aggregation.", e);
}
}
use of org.nhindirect.monitor.dao.AggregationDAOException in project nhin-d by DirectProject.
the class AggregationDAOImpl method getAggregationKeys.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public List<String> getAggregationKeys() throws AggregationDAOException {
final String query = "SELECT id from Aggregation agg";
Collection<String> rs;
List<String> retVal = null;
;
try {
// get the list using a simple select
final Query select = entityManager.createQuery(query);
rs = (Collection<String>) select.getResultList();
// no keys... return an empty set
if (rs == null || rs.size() == 0)
return Collections.emptyList();
// put the list into a linked list
retVal = new LinkedList<String>(rs);
} catch (Exception e) {
throw new AggregationDAOException("Failed to get aggregation keys", e);
}
return retVal;
}
Aggregations