Search in sources :

Example 1 with AggregationDAOImpl

use of org.nhindirect.monitor.dao.impl.AggregationDAOImpl in project nhin-d by DirectProject.

the class AggregationDAOImpl_getAggregationCompletedKeysTest method testGetAggregationCompletedKeys_emptyListResultSet_assertEmptyList.

@Test
public void testGetAggregationCompletedKeys_emptyListResultSet_assertEmptyList() throws Exception {
    Query query = mock(Query.class);
    when(query.getResultList()).thenReturn(Collections.emptyList());
    EntityManager mgr = mock(EntityManager.class);
    when(mgr.createQuery((String) any())).thenReturn(query);
    final AggregationDAOImpl dao = new AggregationDAOImpl();
    dao.setEntityManager(mgr);
    assertEquals(0, dao.getAggregationCompletedKeys().size());
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) AggregationDAOImpl(org.nhindirect.monitor.dao.impl.AggregationDAOImpl) Test(org.junit.Test)

Example 2 with AggregationDAOImpl

use of org.nhindirect.monitor.dao.impl.AggregationDAOImpl in project nhin-d by DirectProject.

the class AggregationDAOImpl_getAggregationCompletedTest method testGetAggregationCompleted_optomisticLockException_assertAggregationCompletedNotFound.

@Test
public void testGetAggregationCompleted_optomisticLockException_assertAggregationCompletedNotFound() throws Exception {
    EntityManager mgr = mock(EntityManager.class);
    doThrow(new OptimisticLockException()).when(mgr).find((Class<?>) any(), any());
    final AggregationDAOImpl dao = new AggregationDAOImpl();
    dao.setEntityManager(mgr);
    final AggregationCompleted lockedAggr = dao.getAggregationCompleted("12345", true);
    assertNull(lockedAggr);
}
Also used : EntityManager(javax.persistence.EntityManager) OptimisticLockException(javax.persistence.OptimisticLockException) AggregationCompleted(org.nhindirect.monitor.dao.entity.AggregationCompleted) AggregationDAOImpl(org.nhindirect.monitor.dao.impl.AggregationDAOImpl) Test(org.junit.Test)

Example 3 with AggregationDAOImpl

use of org.nhindirect.monitor.dao.impl.AggregationDAOImpl 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 4 with AggregationDAOImpl

use of org.nhindirect.monitor.dao.impl.AggregationDAOImpl in project nhin-d by DirectProject.

the class AggregationDAOImpl_getAggregationKeysTest method testGetAggregationKeys_emptyListResultSet_assertEmptyList.

@Test
public void testGetAggregationKeys_emptyListResultSet_assertEmptyList() throws Exception {
    Query query = mock(Query.class);
    when(query.getResultList()).thenReturn(Collections.emptyList());
    EntityManager mgr = mock(EntityManager.class);
    when(mgr.createQuery((String) any())).thenReturn(query);
    final AggregationDAOImpl dao = new AggregationDAOImpl();
    dao.setEntityManager(mgr);
    assertEquals(0, dao.getAggregationKeys().size());
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) AggregationDAOImpl(org.nhindirect.monitor.dao.impl.AggregationDAOImpl) Test(org.junit.Test)

Example 5 with AggregationDAOImpl

use of org.nhindirect.monitor.dao.impl.AggregationDAOImpl 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)

Aggregations

Test (org.junit.Test)15 AggregationDAOImpl (org.nhindirect.monitor.dao.impl.AggregationDAOImpl)15 EntityManager (javax.persistence.EntityManager)14 AggregationDAOException (org.nhindirect.monitor.dao.AggregationDAOException)6 Query (javax.persistence.Query)4 OptimisticLockException (javax.persistence.OptimisticLockException)2 Aggregation (org.nhindirect.monitor.dao.entity.Aggregation)2 AggregationVersionException (org.nhindirect.monitor.dao.AggregationVersionException)1 AggregationCompleted (org.nhindirect.monitor.dao.entity.AggregationCompleted)1