Search in sources :

Example 21 with TrustBundleDaoImpl

use of org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl in project nhin-d by DirectProject.

the class TrustBundlDaoImpl_deleteTrustBundlesTest method testDeleteTrustBundlesTest_noEntityManager_assertException.

@Test
public void testDeleteTrustBundlesTest_noEntityManager_assertException() {
    final TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    boolean exceptionOccured = false;
    try {
        dao.deleteTrustBundles(new long[] { 1234 });
    } catch (IllegalStateException ex) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : TrustBundleDaoImpl(org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl) Test(org.junit.Test)

Example 22 with TrustBundleDaoImpl

use of org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl in project nhin-d by DirectProject.

the class TrustBundleDaoImpl_getTrustBundlesByDomainTest method testGetTrustBundlesByDomain_errorInGet_assertException.

@Test
public void testGetTrustBundlesByDomain_errorInGet_assertException() {
    boolean exceptionOccured = false;
    final EntityManager mgr = mock(EntityManager.class);
    final Domain domain = mock(Domain.class);
    final DomainDao domainDao = mock(DomainDao.class);
    when(domainDao.getDomain(new Long(1234))).thenReturn(domain);
    final TrustBundleDomainReltn reltn = mock(TrustBundleDomainReltn.class);
    final Query findReltnQeury = mock(Query.class);
    when(findReltnQeury.getSingleResult()).thenReturn(reltn);
    doThrow(new RuntimeException("Just Passing Through")).when(findReltnQeury).getResultList();
    when(mgr.createQuery("SELECT tbd from TrustBundleDomainReltn tbd where tbd.domain = ?1")).thenReturn(findReltnQeury);
    final TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    dao.setDomainDao(domainDao);
    dao.setEntityManager(mgr);
    final TrustBundleDaoImpl spyDao = spy(dao);
    try {
        spyDao.getTrustBundlesByDomain(1234);
    } catch (ConfigurationStoreException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
    verify(domainDao, times(1)).getDomain(new Long(1234));
    verify(findReltnQeury, times(1)).getResultList();
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) TrustBundleDaoImpl(org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl) DomainDao(org.nhindirect.config.store.dao.DomainDao) Test(org.junit.Test)

Example 23 with TrustBundleDaoImpl

use of org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl in project nhin-d by DirectProject.

the class TrustBundleDaoImpl_getTrustBundlesByDomainTest method testGetTrustBundlesByDomain_noEntityManager_assertException.

@Test
public void testGetTrustBundlesByDomain_noEntityManager_assertException() {
    final TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    boolean exceptionOccured = false;
    try {
        dao.getTrustBundlesByDomain(1234);
    } catch (IllegalStateException ex) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : TrustBundleDaoImpl(org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl) Test(org.junit.Test)

Example 24 with TrustBundleDaoImpl

use of org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl in project nhin-d by DirectProject.

the class TrustBundleDaoImpl_updateLastUpdateErrorTest method testUpdateLastUpdateError_exceptionInQuery_assertException.

@Test
public void testUpdateLastUpdateError_exceptionInQuery_assertException() {
    final Calendar now = Calendar.getInstance(Locale.getDefault());
    final EntityManager manager = mock(EntityManager.class);
    doThrow(new RuntimeException("Just Passing Through")).when(manager).createQuery((String) any());
    final TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    dao.setEntityManager(manager);
    boolean exceptionOccured = false;
    try {
        tbDao.updateLastUpdateError(1234, now, BundleRefreshError.NOT_FOUND);
    } catch (ConfigurationStoreException ex) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : EntityManager(javax.persistence.EntityManager) TrustBundleDaoImpl(org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl) Calendar(java.util.Calendar) Test(org.junit.Test)

Example 25 with TrustBundleDaoImpl

use of org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl in project nhin-d by DirectProject.

the class TrustBundleDaoImpl_updateTrustBundleAnchorsTest method testUpdateTrustBundleAnchors_exceptionInQuery_assertException.

@Test
public void testUpdateTrustBundleAnchors_exceptionInQuery_assertException() {
    final EntityManager manager = mock(EntityManager.class);
    doThrow(new RuntimeException("Just Passing Through")).when(manager).createQuery((String) any());
    final TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    dao.setEntityManager(manager);
    boolean exceptionOccured = false;
    try {
        dao.updateTrustBundleAnchors(1234, Calendar.getInstance(Locale.getDefault()), new ArrayList<TrustBundleAnchor>(), "6789");
    } catch (ConfigurationStoreException ex) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : EntityManager(javax.persistence.EntityManager) TrustBundleDaoImpl(org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)34 TrustBundleDaoImpl (org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl)34 EntityManager (javax.persistence.EntityManager)19 DomainDao (org.nhindirect.config.store.dao.DomainDao)10 Query (javax.persistence.Query)7 Calendar (java.util.Calendar)2 NoResultException (javax.persistence.NoResultException)2