use of org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl in project nhin-d by DirectProject.
the class CertPolicyDaoImpl_addPolicyUseToGroupTest method testAddPolicyToGroup_unknownTrustBundle_assertException.
@Test
public void testAddPolicyToGroup_unknownTrustBundle_assertException() {
boolean exceptionOccured = false;
final EntityManager mgr = mock(EntityManager.class);
final CertPolicyDaoImpl certDao = new CertPolicyDaoImpl() {
@Override
public CertPolicyGroup getPolicyGroupById(long id) throws ConfigurationStoreException {
return new CertPolicyGroup();
}
};
final Query query = mock(Query.class);
doThrow(new NoResultException()).when(query).getSingleResult();
when(mgr.createQuery("SELECT cp from CertPolicy cp WHERE cp.id = ?1")).thenReturn(query);
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(1234L);
verify(spyDao, times(1)).getPolicyById(5678L);
verify(mgr, never()).persist((CertPolicyGroupReltn) any());
}
use of org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl in project nhin-d by DirectProject.
the class CertPolicyDaoImpl_associatePolicyGroupToDomainTest method testAssociatePolicyGroupToDomain_unknownPolicyGroup_assertException.
@Test
public void testAssociatePolicyGroupToDomain_unknownPolicyGroup_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.associatePolicyGroupToDomain(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()).persist((CertPolicyGroupDomainReltn) any());
}
use of org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl in project nhin-d by DirectProject.
the class CertPolicyDaoImpl_deletePoliciesTest method testDeletePolicies_noEntityManager_assertException.
@Test
public void testDeletePolicies_noEntityManager_assertException() {
final CertPolicyDaoImpl dao = new CertPolicyDaoImpl();
boolean exceptionOccured = false;
try {
dao.deletePolicies(new long[] { 1234 });
} catch (IllegalStateException ex) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl in project nhin-d by DirectProject.
the class CertPolicyDaoImpl_deletePolicyGroupsTest method testDeletePolicyGroups_noEntityManager_assertException.
@Test
public void testDeletePolicyGroups_noEntityManager_assertException() {
final CertPolicyDaoImpl dao = new CertPolicyDaoImpl();
boolean exceptionOccured = false;
try {
dao.deletePolicyGroups(new long[] { 1234 });
} catch (IllegalStateException ex) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of org.nhindirect.config.store.dao.impl.CertPolicyDaoImpl in project nhin-d by DirectProject.
the class CertPolicyDaoImpl_deletePolicyGroupsTest method testDeletePolicyGroups_exceptionInQuery_assertNoException.
@Test
public void testDeletePolicyGroups_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.deletePolicyGroups(new long[] { 1234 });
} catch (ConfigurationStoreException ex) {
exceptionOccured = true;
}
assertFalse(exceptionOccured);
verify(manager, never()).remove((CertPolicyGroup) any());
verify(manager, never()).flush();
}
Aggregations