Search in sources :

Example 6 with DomainDao

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

the class CertPolicyDaoImpl_disassociatePolicyGroupFromDomainTest method testDisassociatePolicyGroupFromDomain_unknownErrorInRemove_assertException.

@Test
public void testDisassociatePolicyGroupFromDomain_unknownErrorInRemove_assertException() {
    boolean exceptionOccured = false;
    final EntityManager mgr = mock(EntityManager.class);
    doThrow(new RuntimeException("Just Passing Through")).when(mgr).remove((CertPolicyGroupDomainReltn) any());
    final Domain domain = mock(Domain.class);
    final DomainDao domainDao = mock(DomainDao.class);
    when(domainDao.getDomain(new Long(1234))).thenReturn(domain);
    final CertPolicyGroup group = mock(CertPolicyGroup.class);
    final Query query = mock(Query.class);
    when(query.getSingleResult()).thenReturn(group);
    when(mgr.createQuery("SELECT cpg from CertPolicyGroup cpg WHERE cpg.id = ?1")).thenReturn(query);
    final CertPolicyGroupDomainReltn reltn = mock(CertPolicyGroupDomainReltn.class);
    final Query findReltnQeury = mock(Query.class);
    when(findReltnQeury.getSingleResult()).thenReturn(reltn);
    when(mgr.createQuery("SELECT cpr from CertPolicyGroupDomainReltn cpr where cpr.domain  = ?1 " + " and cpr.certPolicyGroup = ?2 ")).thenReturn(findReltnQeury);
    final CertPolicyDaoImpl dao = new CertPolicyDaoImpl();
    dao.setDomainDao(domainDao);
    dao.setEntityManager(mgr);
    final CertPolicyDaoImpl spyDao = spy(dao);
    try {
        spyDao.disassociatePolicyGroupFromDomain(1234, 5678);
    } catch (ConfigurationStoreException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
    verify(domainDao, times(1)).getDomain(1234L);
    verify(spyDao, times(1)).getPolicyGroupById(5678);
    verify(mgr, times(1)).remove((CertPolicyGroupDomainReltn) any());
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) CertPolicyDaoImpl(org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl) DomainDao(org.nhindirect.config.store.dao.DomainDao) Test(org.junit.Test)

Example 7 with DomainDao

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

the class CertPolicyDaoImpl_disassociatePolicyGroupsFromDomainTest method testDisassociatePolicyGroupsFromDomain_unknownErrorInRemove_assertException.

@Test
public void testDisassociatePolicyGroupsFromDomain_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 CertPolicyGroupDomainReltn cpr where cpr.domain  = ?1")).thenReturn(deleteQuery);
    final CertPolicyDaoImpl dao = new CertPolicyDaoImpl();
    dao.setDomainDao(domainDao);
    dao.setEntityManager(mgr);
    final CertPolicyDaoImpl spyDao = spy(dao);
    try {
        spyDao.disassociatePolicyGroupsFromDomain(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) CertPolicyDaoImpl(org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl) DomainDao(org.nhindirect.config.store.dao.DomainDao) Test(org.junit.Test)

Example 8 with DomainDao

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

the class TrustBundleDaoImpl_associateTrustBundleToDomainTest method testAssociateTrustBundleToDomain_unknownDomain_assertException.

@Test
public void testAssociateTrustBundleToDomain_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.associateTrustBundleToDomain(1234, 5678, true, true);
    } 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 9 with DomainDao

use of org.nhindirect.config.store.dao.DomainDao 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 10 with DomainDao

use of org.nhindirect.config.store.dao.DomainDao 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)

Aggregations

DomainDao (org.nhindirect.config.store.dao.DomainDao)31 EntityManager (javax.persistence.EntityManager)20 Test (org.junit.Test)20 Query (javax.persistence.Query)14 CertPolicyDaoImpl (org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl)10 TrustBundleDaoImpl (org.nhindirect.config.store.dao.impl.TrustBundleDaoImpl)10 Expectations (org.jmock.Expectations)9 DomainServiceImpl (org.nhindirect.config.service.impl.DomainServiceImpl)9 Domain (org.nhindirect.config.store.Domain)7 NoResultException (javax.persistence.NoResultException)4 ArrayList (java.util.ArrayList)2 Address (org.nhindirect.config.store.Address)2 Anchor (org.nhindirect.config.store.Anchor)2 CertPolicy (org.nhindirect.config.store.CertPolicy)2 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)2 Certificate (org.nhindirect.config.store.Certificate)2 DNSRecord (org.nhindirect.config.store.DNSRecord)2 EntityStatus (org.nhindirect.config.store.EntityStatus)2 Setting (org.nhindirect.config.store.Setting)2 TrustBundle (org.nhindirect.config.store.TrustBundle)2