Search in sources :

Example 36 with CertPolicyDaoImpl

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

the class CertPolicyDaoImpl_disassociatePolicyGroupFromDomainTest method testDisassociatePolicyGroupFromDomain_unknownDomain_assertException.

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

Example 37 with CertPolicyDaoImpl

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

the class CertPolicyDaoImpl_disassociatePolicyGroupFromDomainTest method testDisassociatePolicyGroupFromDomain_unknownPolicy_assertException.

@Test
public void testDisassociatePolicyGroupFromDomain_unknownPolicy_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 CertPolicyDaoImpl dao = new CertPolicyDaoImpl();
    final Query query = mock(Query.class);
    doThrow(new NoResultException()).when(query).getSingleResult();
    when(mgr.createQuery("SELECT cpg from CertPolicyGroup cpg WHERE cpg.id = ?1")).thenReturn(query);
    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(new Long(1234));
    verify(spyDao, times(1)).getPolicyGroupById(5678);
    verify(mgr, never()).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) NoResultException(javax.persistence.NoResultException) Test(org.junit.Test)

Example 38 with CertPolicyDaoImpl

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

the class CertPolicyDaoImpl_disassociatePolicyGroupFromDomainsTest method testDisassociatePolicyGroupFromDomains_unknownErrorInRemove_assertException.

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

Example 39 with CertPolicyDaoImpl

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

the class CertPolicyDaoImpl_disassociatePolicyGroupsFromDomainTest method testDisassociatePolicyGroupsFromDomain_unknownDomain_assertException.

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

Example 40 with CertPolicyDaoImpl

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

the class CertPolicyDaoImpl_updatePolicyAttributesTest method testUpdatePolicyAttributes_exceptionInQuery_assertException.

@Test
public void testUpdatePolicyAttributes_exceptionInQuery_assertException() throws Exception {
    final EntityManager manager = mock(EntityManager.class);
    doThrow(new RuntimeException("Just Passing Through")).when(manager).createQuery((String) any());
    final CertPolicyDaoImpl dao = new CertPolicyDaoImpl();
    dao.setEntityManager(manager);
    boolean exceptionOccured = false;
    try {
        dao.updatePolicyAttributes(12345, "", null, null);
    } catch (ConfigurationStoreException ex) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : EntityManager(javax.persistence.EntityManager) CertPolicyDaoImpl(org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)44 CertPolicyDaoImpl (org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl)44 EntityManager (javax.persistence.EntityManager)24 DomainDao (org.nhindirect.config.store.dao.DomainDao)10 Query (javax.persistence.Query)8 NoResultException (javax.persistence.NoResultException)3