Search in sources :

Example 11 with AggregationDAOImpl

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

the class AggregationDAOImpl_getAggregationCompletedTest method testGetAggregationCompleted_entityManagerException_assertException.

@Test
public void testGetAggregationCompleted_entityManagerException_assertException() 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.getAggregationCompleted("12345", true);
    } 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 12 with AggregationDAOImpl

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

the class AggregationDAOImpl_getAggregationKeysTest method testGetAggregationKeys_nullQueryResult_assertEmptyList.

@Test
public void testGetAggregationKeys_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.getAggregationKeys().size());
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) AggregationDAOImpl(org.nhindirect.monitor.dao.impl.AggregationDAOImpl) Test(org.junit.Test)

Example 13 with AggregationDAOImpl

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

the class AggregationDAOImpl_validateStateTest method testValidateState_stateOK.

@Test
public void testValidateState_stateOK() throws Exception {
    AggregationDAOImpl impl = new AggregationDAOImpl();
    impl.setEntityManager(mock(EntityManager.class));
    impl.validateState();
}
Also used : EntityManager(javax.persistence.EntityManager) AggregationDAOImpl(org.nhindirect.monitor.dao.impl.AggregationDAOImpl) Test(org.junit.Test)

Example 14 with AggregationDAOImpl

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

the class AggregationDAOImpl_addUpdateAggregationTest method testAddUpdateAggregationTest_optomisticLockException_assertAggregationVersionException.

@Test
public void testAddUpdateAggregationTest_optomisticLockException_assertAggregationVersionException() throws Exception {
    EntityManager mgr = mock(EntityManager.class);
    doThrow(new OptimisticLockException()).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 (AggregationVersionException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : Aggregation(org.nhindirect.monitor.dao.entity.Aggregation) AggregationVersionException(org.nhindirect.monitor.dao.AggregationVersionException) EntityManager(javax.persistence.EntityManager) OptimisticLockException(javax.persistence.OptimisticLockException) AggregationDAOImpl(org.nhindirect.monitor.dao.impl.AggregationDAOImpl) Test(org.junit.Test)

Example 15 with AggregationDAOImpl

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

the class AggregationDAOImpl_confirmAggregationTest method testConfirmAggregationTest_exceptionInRemove_assertException.

@Test
public void testConfirmAggregationTest_exceptionInRemove_assertException() 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.confirmAggregation("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