Search in sources :

Example 1 with TrustBundleDaoImpl

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

the class TrustBundleDaoImpl_updateLastUpdateErrorTest method testUpdateLastUpdateError_noEntityManager_assertException.

@Test
public void testUpdateLastUpdateError_noEntityManager_assertException() {
    final Calendar now = Calendar.getInstance(Locale.getDefault());
    final TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    boolean exceptionOccured = false;
    try {
        dao.updateLastUpdateError(1234, now, BundleRefreshError.NOT_FOUND);
    } catch (IllegalStateException ex) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : TrustBundleDaoImpl(org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl) Calendar(java.util.Calendar) Test(org.junit.Test)

Example 2 with TrustBundleDaoImpl

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

the class TrustBundleDaoImpl_updateTrustBundleAttributesTest method testUpdateTrustBundleAttributes_noEntityManager_assertException.

@Test
public void testUpdateTrustBundleAttributes_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 3 with TrustBundleDaoImpl

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

the class TrustBundleDaoImpl_updateTrustBundleSigningCertificateTest method testUpdateTrustBundleSigningCertificate_exceptionInQuery_assertException.

@Test
public void testUpdateTrustBundleSigningCertificate_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)

Example 4 with TrustBundleDaoImpl

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

the class TrustBundleDaoImpl_disassociateTrustBundlesFromDomainTest method testDisassociateTrustBundlesFromDomain_unknownErrorInRemove_assertException.

@Test
public void testDisassociateTrustBundlesFromDomain_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.domain  = ?1")).thenReturn(deleteQuery);
    final TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    dao.setDomainDao(domainDao);
    dao.setEntityManager(mgr);
    final TrustBundleDaoImpl spyDao = spy(dao);
    try {
        spyDao.disassociateTrustBundlesFromDomain(1234);
    } catch (ConfigurationStoreException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
    verify(domainDao, times(1)).getDomain(new Long(1234));
    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 5 with TrustBundleDaoImpl

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

the class TrustBundleDaoImpl_disassociateTrustBundlesFromDomainTest method testDisassociateTrustBundlesFromDomain_unknownDomain_assertException.

@Test
public void testDisassociateTrustBundlesFromDomain_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.disassociateTrustBundlesFromDomain(1234);
    } catch (ConfigurationStoreException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
    verify(domainDao, times(1)).getDomain(new Long(1234));
}
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)

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