Search in sources :

Example 16 with TrustBundleDaoImpl

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

the class TrustBundleDaoImpl_disassociateTrustBundleFromDomainTest method testDisassociateTrustBundleFromDomain_unknownDomain_assertException.

@Test
public void testDisassociateTrustBundleFromDomain_unknownDomain_assertException() {
    boolean exceptionOccured = false;
    final EntityManager mgr = mock(EntityManager.class);
    final DomainDao domainDao = mock(DomainDao.class);
    final TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    dao.setDomainDao(domainDao);
    dao.setEntityManager(mgr);
    TrustBundleDaoImpl spyDao = spy(dao);
    try {
        spyDao.disassociateTrustBundleFromDomain(1234, 5678);
    } catch (ConfigurationStoreException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
    verify(domainDao, times(1)).getDomain(new Long(1234));
    verify(spyDao, never()).getTrustBundleById(5678);
}
Also used : EntityManager(javax.persistence.EntityManager) TrustBundleDaoImpl(org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl) DomainDao(org.nhindirect.config.store.dao.DomainDao) Test(org.junit.Test)

Example 17 with TrustBundleDaoImpl

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

the class TrustBundleDaoImpl_disassociateTrustBundleFromDomainsTest method testDisassociateTrustBundleFromDomains_unknownErrorInRemove_assertException.

@Test
public void testDisassociateTrustBundleFromDomains_unknownErrorInRemove_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 Query deleteQuery = mock(Query.class);
    doThrow(new RuntimeException("Just Passing Through")).when(deleteQuery).executeUpdate();
    when(mgr.createQuery("DELETE from TrustBundleDomainReltn tbd where tbd.trustBundle  = ?1")).thenReturn(deleteQuery);
    final TrustBundle bundle = mock(TrustBundle.class);
    final Query query = mock(Query.class);
    when(query.getSingleResult()).thenReturn(bundle);
    when(mgr.createQuery("SELECT tb from TrustBundle tb WHERE tb.id = ?1")).thenReturn(query);
    final TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    dao.setDomainDao(domainDao);
    dao.setEntityManager(mgr);
    final TrustBundleDaoImpl spyDao = spy(dao);
    try {
        spyDao.disassociateTrustBundleFromDomains(1234);
    } catch (ConfigurationStoreException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
    verify(query, times(1)).getSingleResult();
    verify(deleteQuery, times(1)).executeUpdate();
}
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 18 with TrustBundleDaoImpl

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

the class TrustBundlDaoImpl_deleteTrustBundlesTest method testDeleteTrustBundlesTest_exceptionInQuery_assertNoException.

@Test
public void testDeleteTrustBundlesTest_exceptionInQuery_assertNoException() {
    final EntityManager manager = mock(EntityManager.class);
    doThrow(new RuntimeException("Just Passing Through")).when(manager).remove((TrustBundle) any());
    final TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    dao.setEntityManager(manager);
    boolean exceptionOccured = false;
    try {
        dao.deleteTrustBundles(new long[] { 1234 });
    } catch (ConfigurationStoreException ex) {
        exceptionOccured = true;
    }
    assertFalse(exceptionOccured);
    verify(manager, never()).remove((TrustBundle) any());
    verify(manager, never()).flush();
}
Also used : EntityManager(javax.persistence.EntityManager) TrustBundleDaoImpl(org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl) Test(org.junit.Test)

Example 19 with TrustBundleDaoImpl

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

the class TrustBundleDaoImpl_updateTrustBundleSigningCertificateTest method testUpdateLastUpdateError_noEntityManager_assertException.

@Test
public void testUpdateLastUpdateError_noEntityManager_assertException() throws Exception {
    final TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    boolean exceptionOccured = false;
    try {
        TrustBundleAnchor anchor = new TrustBundleAnchor();
        anchor.setData(loadCertificateData("secureHealthEmailCACert.der"));
        dao.updateTrustBundleSigningCertificate(1234, anchor.toCertificate());
    } catch (IllegalStateException ex) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : TrustBundleDaoImpl(org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl) Test(org.junit.Test)

Example 20 with TrustBundleDaoImpl

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

the class TrustBundleDaoImpl_updateTrustBundleSigningCertificateTest method testUpdateLastUpdateError_exceptionInQuery_assertException.

@Test
public void testUpdateLastUpdateError_exceptionInQuery_assertException() throws Exception {
    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 {
        TrustBundleAnchor anchor = new TrustBundleAnchor();
        anchor.setData(loadCertificateData("secureHealthEmailCACert.der"));
        tbDao.updateTrustBundleSigningCertificate(1234, anchor.toCertificate());
    } 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