Search in sources :

Example 6 with AggregationDAOImpl

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

the class AggregationDAOImpl_validateStateTest method testValidateState_nullManager_assertIllegalStateException.

@Test
public void testValidateState_nullManager_assertIllegalStateException() throws Exception {
    AggregationDAOImpl impl = new AggregationDAOImpl();
    boolean exceptionOccured = false;
    try {
        impl.validateState();
    } catch (IllegalStateException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : AggregationDAOImpl(org.nhindirect.monitor.dao.impl.AggregationDAOImpl) Test(org.junit.Test)

Example 7 with AggregationDAOImpl

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

the class AggregationDAOImpl_addUpdateAggregationTest method testAddUpdateAggregationTest_entityManagerException_assertNoAggregation.

@Test
public void testAddUpdateAggregationTest_entityManagerException_assertNoAggregation() throws Exception {
    EntityManager mgr = mock(EntityManager.class);
    doThrow(new RuntimeException()).when(mgr).persist(any());
    final AggregationDAOImpl dao = new AggregationDAOImpl();
    dao.setEntityManager(mgr);
    boolean exceptionOccured = false;
    try {
        final Aggregation insert = new Aggregation();
        insert.setExchangeBlob(new byte[] { 0, 3, 2 });
        insert.setId("12345");
        insert.setVersion(0);
        dao.addUpdateAggregation(insert);
    } catch (AggregationDAOException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : Aggregation(org.nhindirect.monitor.dao.entity.Aggregation) EntityManager(javax.persistence.EntityManager) AggregationDAOException(org.nhindirect.monitor.dao.AggregationDAOException) AggregationDAOImpl(org.nhindirect.monitor.dao.impl.AggregationDAOImpl) Test(org.junit.Test)

Example 8 with AggregationDAOImpl

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

the class AggregationDAOImpl_confirmAggregationTest method testConfirmAggregationTest_aggregationNotFound_nothingRemoved.

@Test
public void testConfirmAggregationTest_aggregationNotFound_nothingRemoved() throws Exception {
    EntityManager mgr = mock(EntityManager.class);
    when(mgr.find((Class<?>) any(), any())).thenReturn(null);
    final AggregationDAOImpl dao = new AggregationDAOImpl();
    dao.setEntityManager(mgr);
    dao.confirmAggregation("12345");
    verify(mgr, times(1)).find((Class<?>) any(), any());
    verify(mgr, never()).remove(any());
}
Also used : EntityManager(javax.persistence.EntityManager) AggregationDAOImpl(org.nhindirect.monitor.dao.impl.AggregationDAOImpl) Test(org.junit.Test)

Example 9 with AggregationDAOImpl

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

the class AggregationDAOImpl_getAggregationCompletedKeysTest method testGetAggregationCompletedKeys_nullQueryResult_assertEmptyList.

@Test
public void testGetAggregationCompletedKeys_nullQueryResult_assertEmptyList() throws Exception {
    Query query = mock(Query.class);
    when(query.getResultList()).thenReturn(null);
    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 10 with AggregationDAOImpl

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

the class AggregationDAOImpl_getAggregationCompletedKeysTest method testGetAggregationCompletedKeys_entityManagerException_assertNoAggregation.

@Test
public void testGetAggregationCompletedKeys_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.getAggregationCompletedKeys();
    } 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