Search in sources :

Example 26 with CertPolicyDaoImpl

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

the class CertPolicyDaoImpl_associatePolicyGroupToDomainTest method testAssociatePolicyGroupToDomain_errorInAdd_assertException.

@Test
public void testAssociatePolicyGroupToDomain_errorInAdd_assertException() {
    boolean exceptionOccured = false;
    final EntityManager mgr = mock(EntityManager.class);
    doThrow(new RuntimeException("Just Passing Through")).when(mgr).persist((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 CertPolicyDaoImpl dao = new CertPolicyDaoImpl();
    dao.setDomainDao(domainDao);
    dao.setEntityManager(mgr);
    final CertPolicyDaoImpl spyDao = spy(dao);
    try {
        spyDao.associatePolicyGroupToDomain(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)).persist((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 27 with CertPolicyDaoImpl

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

the class CertPolicyDaoImpl_associatePolicyGroupToDomainTest method testAssociatePolicyGroupToDomain_noEntityManager_assertException.

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

Example 28 with CertPolicyDaoImpl

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

the class CertPolicyDaoImpl_deletePoliciesTest method testDeletePolicies_exceptionInQuery_assertNoException.

@Test
public void testDeletePolicies_exceptionInQuery_assertNoException() {
    final EntityManager manager = mock(EntityManager.class);
    doThrow(new RuntimeException("Just Passing Through")).when(manager).remove((TrustBundle) any());
    final CertPolicyDaoImpl dao = new CertPolicyDaoImpl();
    dao.setEntityManager(manager);
    boolean exceptionOccured = false;
    try {
        dao.deletePolicies(new long[] { 1234 });
    } catch (ConfigurationStoreException ex) {
        exceptionOccured = true;
    }
    assertFalse(exceptionOccured);
    verify(manager, never()).remove((CertPolicy) any());
    verify(manager, never()).flush();
}
Also used : EntityManager(javax.persistence.EntityManager) CertPolicyDaoImpl(org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl) Test(org.junit.Test)

Example 29 with CertPolicyDaoImpl

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

the class CertPolicyDaoImpl_updatePolicyAttributesTest method ttestUpdatePolicyAttributes_noEntityManager_assertException.

@Test
public void ttestUpdatePolicyAttributes_noEntityManager_assertException() throws Exception {
    final CertPolicyDaoImpl dao = new CertPolicyDaoImpl();
    boolean exceptionOccured = false;
    try {
        dao.updatePolicyAttributes(12345, "", null, null);
    } catch (IllegalStateException ex) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : CertPolicyDaoImpl(org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl) Test(org.junit.Test)

Example 30 with CertPolicyDaoImpl

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

the class CertPolicyDaoBase_getPolicyGroupsByDomainTest method testGetPolicyGroupsByDomain_errorInGet_assertException.

@Test
public void testGetPolicyGroupsByDomain_errorInGet_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 CertPolicyGroupDomainReltn reltn = mock(CertPolicyGroupDomainReltn.class);
    final Query findReltnQeury = mock(Query.class);
    when(findReltnQeury.getSingleResult()).thenReturn(reltn);
    doThrow(new RuntimeException("Just Passing Through")).when(findReltnQeury).getResultList();
    when(mgr.createQuery("SELECT cpr from CertPolicyGroupDomainReltn cpr where cpr.domain = ?1")).thenReturn(findReltnQeury);
    final CertPolicyDaoImpl dao = new CertPolicyDaoImpl();
    dao.setDomainDao(domainDao);
    dao.setEntityManager(mgr);
    final CertPolicyDaoImpl spyDao = spy(dao);
    try {
        spyDao.getPolicyGroupsByDomain(1234);
    } catch (ConfigurationStoreException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
    verify(domainDao, times(1)).getDomain(new Long(1234));
    verify(findReltnQeury, times(1)).getResultList();
}
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)

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