Search in sources :

Example 21 with CertPolicyDaoImpl

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

the class CertPolicyDaoImpl_disassociatePolicyGroupsFromDomainTest method testDisassociatePolicyGroupsFromDomain_noEntityManager_assertException.

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

Example 22 with CertPolicyDaoImpl

use of org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl 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 23 with CertPolicyDaoImpl

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

the class CertPolicyDaoImpl_addPolicyUseToGroupTest method testAddPolicyToGroup_noEntityManager_assertException.

@Test
public void testAddPolicyToGroup_noEntityManager_assertException() {
    final CertPolicyDaoImpl dao = new CertPolicyDaoImpl();
    boolean exceptionOccured = false;
    try {
        dao.addPolicyUseToGroup(1234L, 5678L, CertPolicyUse.PRIVATE_RESOLVER, true, true);
    } catch (IllegalStateException ex) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : CertPolicyDaoImpl(org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl) Test(org.junit.Test)

Example 24 with CertPolicyDaoImpl

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

the class CertPolicyDaoImpl_addPolicyUseToGroupTest method testAddPolicyToGroup_errorInAdd_assertException.

@Test
public void testAddPolicyToGroup_errorInAdd_assertException() {
    boolean exceptionOccured = false;
    final EntityManager mgr = mock(EntityManager.class);
    doThrow(new RuntimeException("Just Passing Through")).when(mgr).persist((CertPolicyGroupReltn) any());
    final CertPolicyDaoImpl certDao = new CertPolicyDaoImpl() {

        @Override
        public CertPolicy getPolicyById(long id) throws ConfigurationStoreException {
            return new CertPolicy();
        }

        @Override
        public CertPolicyGroup getPolicyGroupById(long id) throws ConfigurationStoreException {
            return new CertPolicyGroup();
        }
    };
    certDao.setEntityManager(mgr);
    final CertPolicyDaoImpl spyDao = spy(certDao);
    try {
        spyDao.addPolicyUseToGroup(1234L, 5678L, CertPolicyUse.PRIVATE_RESOLVER, true, true);
    } catch (ConfigurationStoreException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
    verify(spyDao, times(1)).getPolicyGroupById(1234);
    verify(spyDao, times(1)).getPolicyById(5678);
    verify(mgr, times(1)).persist((CertPolicyGroupReltn) any());
}
Also used : EntityManager(javax.persistence.EntityManager) CertPolicyDaoImpl(org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl) Test(org.junit.Test)

Example 25 with CertPolicyDaoImpl

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

the class CertPolicyDaoImpl_associatePolicyGroupToDomainTest method testAssociatePolicyGroupToDomain_unknownDomain_assertException.

@Test
public void testAssociatePolicyGroupToDomain_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.associatePolicyGroupToDomain(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)

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