Search in sources :

Example 1 with AggregationDAOException

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);
}
Also used : EntityManager(javax.persistence.EntityManager) AggregationDAOException(org.nhindirect.monitor.dao.AggregationDAOException) AggregationDAOImpl(org.nhindirect.monitor.dao.impl.AggregationDAOImpl) Test(org.junit.Test)

Example 2 with AggregationDAOException

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);
}
Also used : EntityManager(javax.persistence.EntityManager) AggregationDAOException(org.nhindirect.monitor.dao.AggregationDAOException) AggregationDAOImpl(org.nhindirect.monitor.dao.impl.AggregationDAOImpl) Test(org.junit.Test)

Example 3 with AggregationDAOException

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);
}
Also used : Aggregation(org.nhindirect.monitor.dao.entity.Aggregation) AggregationDAOException(org.nhindirect.monitor.dao.AggregationDAOException) Test(org.junit.Test)

Example 4 with AggregationDAOException

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);
    }
}
Also used : AggregationCompleted(org.nhindirect.monitor.dao.entity.AggregationCompleted) AggregationDAOException(org.nhindirect.monitor.dao.AggregationDAOException) OptimisticLockException(javax.persistence.OptimisticLockException) AggregationDAOException(org.nhindirect.monitor.dao.AggregationDAOException) AggregationVersionException(org.nhindirect.monitor.dao.AggregationVersionException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with AggregationDAOException

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;
}
Also used : Query(javax.persistence.Query) AggregationDAOException(org.nhindirect.monitor.dao.AggregationDAOException) OptimisticLockException(javax.persistence.OptimisticLockException) AggregationDAOException(org.nhindirect.monitor.dao.AggregationDAOException) AggregationVersionException(org.nhindirect.monitor.dao.AggregationVersionException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AggregationDAOException (org.nhindirect.monitor.dao.AggregationDAOException)17 Test (org.junit.Test)10 OptimisticLockException (javax.persistence.OptimisticLockException)7 AggregationVersionException (org.nhindirect.monitor.dao.AggregationVersionException)7 Aggregation (org.nhindirect.monitor.dao.entity.Aggregation)7 Transactional (org.springframework.transaction.annotation.Transactional)7 EntityManager (javax.persistence.EntityManager)6 AggregationDAOImpl (org.nhindirect.monitor.dao.impl.AggregationDAOImpl)6 Query (javax.persistence.Query)3 AggregationCompleted (org.nhindirect.monitor.dao.entity.AggregationCompleted)3 Calendar (java.util.Calendar)1