Search in sources :

Example 31 with TrustBundleDaoImpl

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

the class TrustBundleDaoImpl_disassociateTrustBundleFromDomainTest method testDisassociateTrustBundleFromDomain_unknownErrorInRemove_assertException.

@Test
public void testDisassociateTrustBundleFromDomain_unknownErrorInRemove_assertException() {
    boolean exceptionOccured = false;
    final EntityManager mgr = mock(EntityManager.class);
    doThrow(new RuntimeException("Just Passing Through")).when(mgr).remove((TrustBundleDomainReltn) any());
    final Domain domain = mock(Domain.class);
    final DomainDao domainDao = mock(DomainDao.class);
    when(domainDao.getDomain(new Long(1234))).thenReturn(domain);
    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 TrustBundleDomainReltn reltn = mock(TrustBundleDomainReltn.class);
    final Query findReltnQeury = mock(Query.class);
    when(findReltnQeury.getSingleResult()).thenReturn(reltn);
    when(mgr.createQuery("SELECT tbd from TrustBundleDomainReltn tbd where tbd.domain  = ?1 " + " and tbd.trustBundle = ?2 ")).thenReturn(findReltnQeury);
    final TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    dao.setDomainDao(domainDao);
    dao.setEntityManager(mgr);
    final 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, times(1)).getTrustBundleById(5678);
    verify(mgr, times(1)).remove((TrustBundleDomainReltn) any());
}
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 32 with TrustBundleDaoImpl

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

the class TrustBundleDaoImpl_disassociateTrustBundleFromDomainTest method testDisassociateTrustBundleFromDomain_unknownTrustBundle_assertException.

@Test
public void testDisassociateTrustBundleFromDomain_unknownTrustBundle_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 TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    final Query query = mock(Query.class);
    doThrow(new NoResultException()).when(query).getSingleResult();
    when(mgr.createQuery("SELECT tb from TrustBundle tb WHERE tb.id = ?1")).thenReturn(query);
    dao.setDomainDao(domainDao);
    dao.setEntityManager(mgr);
    final 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, times(1)).getTrustBundleById(5678);
    verify(mgr, never()).remove((TrustBundleDomainReltn) any());
}
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) NoResultException(javax.persistence.NoResultException) Test(org.junit.Test)

Example 33 with TrustBundleDaoImpl

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

the class TrustBundleDaoImpl_disassociateTrustBundleFromDomainTest method testDisassociateTrustBundleFromDomain_noEntityManager_assertException.

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

Example 34 with TrustBundleDaoImpl

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

the class TrustBundleDaoImpl_disassociateTrustBundleFromDomainsTest method testDisassociateTrustBundleFromDomains_noEntityManager_assertException.

@Test
public void testDisassociateTrustBundleFromDomains_noEntityManager_assertException() {
    final TrustBundleDaoImpl dao = new TrustBundleDaoImpl();
    boolean exceptionOccured = false;
    try {
        dao.disassociateTrustBundleFromDomains(1234);
    } catch (IllegalStateException ex) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : 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