Search in sources :

Example 1 with DomainDao

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

the class DomainServiceTest method testUpdateDomain.

/**
     * Test the updateDomain method.
     */
public void testUpdateDomain() {
    final DomainDao domainDao = context.mock(DomainDao.class);
    final Domain domain = new Domain();
    context.checking(new Expectations() {

        {
            oneOf(domainDao).update(domain);
        }
    });
    DomainServiceImpl service = new DomainServiceImpl();
    service.setDao(domainDao);
    try {
        service.updateDomain(domain);
        service.updateDomain(null);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) DomainDao(org.nhindirect.config.store.dao.DomainDao) DomainServiceImpl(org.nhindirect.config.service.impl.DomainServiceImpl) Domain(org.nhindirect.config.store.Domain)

Example 2 with DomainDao

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

the class DomainServiceTest method testGetDomain.

/**
     * Test the getDomain method.
     */
public void testGetDomain() {
    final DomainDao domainDao = context.mock(DomainDao.class);
    final long id = 7;
    final Domain expected = new Domain();
    final Domain expectedNull = null;
    context.checking(new Expectations() {

        {
            oneOf(domainDao).getDomain(id);
            will(returnValue(expected));
            oneOf(domainDao).getDomain(id);
            will(returnValue(expectedNull));
        }
    });
    DomainServiceImpl service = new DomainServiceImpl();
    service.setDao(domainDao);
    try {
        service.getDomain(id);
        service.getDomain(id);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) DomainDao(org.nhindirect.config.store.dao.DomainDao) DomainServiceImpl(org.nhindirect.config.service.impl.DomainServiceImpl) Domain(org.nhindirect.config.store.Domain)

Example 3 with DomainDao

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

the class DomainServiceTest method testListDomains.

/**
     * Test the listDomains method.
     */
public void testListDomains() {
    final DomainDao domainDao = context.mock(DomainDao.class);
    final String lastDomainName = "lastDomainName.com";
    final int maxResults = 7;
    final List<Domain> expected = Arrays.asList(new Domain());
    final List<Domain> expectedNull = null;
    context.checking(new Expectations() {

        {
            oneOf(domainDao).listDomains(lastDomainName, maxResults);
            will(returnValue(expected));
            oneOf(domainDao).listDomains(lastDomainName, maxResults);
            will(returnValue(expectedNull));
        }
    });
    DomainServiceImpl service = new DomainServiceImpl();
    service.setDao(domainDao);
    try {
        service.listDomains(lastDomainName, maxResults);
        service.listDomains(lastDomainName, maxResults);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) DomainDao(org.nhindirect.config.store.dao.DomainDao) DomainServiceImpl(org.nhindirect.config.service.impl.DomainServiceImpl) Domain(org.nhindirect.config.store.Domain)

Example 4 with DomainDao

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

the class TrustBundleDaoImpl_disassociateTrustBundlesFromDomainTest method testDisassociateTrustBundlesFromDomain_unknownErrorInRemove_assertException.

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

Example 5 with DomainDao

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

the class TrustBundleDaoImpl_disassociateTrustBundlesFromDomainTest method testDisassociateTrustBundlesFromDomain_unknownDomain_assertException.

@Test
public void testDisassociateTrustBundlesFromDomain_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.disassociateTrustBundlesFromDomain(1234);
    } catch (ConfigurationStoreException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
    verify(domainDao, times(1)).getDomain(new Long(1234));
}
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)

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