Search in sources :

Example 11 with Domain

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

the class SpringBaseTest method cleanDataStore.

protected void cleanDataStore() throws Exception {
    final ApplicationContext ctx = ConfigServiceRunner.getSpringApplicationContext();
    final AddressDao addressDao = (AddressDao) ctx.getBean("addressDao");
    final TrustBundleDao trustDao = (TrustBundleDao) ctx.getBean("trustBundleDao");
    final DomainDao domainDao = (DomainDao) ctx.getBean("domainDao");
    final AnchorDao anchorDao = (AnchorDao) ctx.getBean("anchorDao");
    final CertificateDao certDao = (CertificateDao) ctx.getBean("certificateDao");
    final DNSDao dnsDao = (DNSDao) ctx.getBean("dnsDao");
    final SettingDao settingDao = (SettingDao) ctx.getBean("settingDao");
    final CertPolicyDao policyDao = (CertPolicyDao) ctx.getBean("certPolicyDao");
    // clean anchors
    final List<Anchor> anchors = anchorDao.listAll();
    if (!anchors.isEmpty()) {
        final List<Long> anchorIds = new ArrayList<Long>();
        for (Anchor anchor : anchors) anchorIds.add(anchor.getId());
        anchorDao.delete(anchorIds);
    }
    // clean domains and the trust bundle domain relationships
    final List<Domain> domains = domainDao.listDomains(null, domainDao.count());
    if (domains != null) {
        for (Domain domain : domains) {
            Collection<Address> addresses = addressDao.getByDomain(domain, null);
            if (addresses != null) {
                for (Address address : addresses) {
                    addressDao.delete(address.getEmailAddress());
                }
            }
            trustDao.disassociateTrustBundlesFromDomain(domain.getId());
            domainDao.delete(domain.getId());
        }
    }
    assertEquals(0, domainDao.count());
    //clean trust bundles
    Collection<TrustBundle> bundles = trustDao.getTrustBundles();
    for (TrustBundle bundle : bundles) trustDao.deleteTrustBundles(new long[] { bundle.getId() });
    bundles = trustDao.getTrustBundles();
    assertEquals(0, bundles.size());
    // clean certificates
    final List<Certificate> certs = certDao.list((String) null);
    if (!certs.isEmpty()) {
        for (Certificate cert : certs) {
            certDao.delete(cert.getOwner());
        }
    }
    // clean DNS records
    final Collection<DNSRecord> records = dnsDao.get(Type.ANY);
    if (!records.isEmpty()) {
        for (DNSRecord record : records) dnsDao.remove(record.getId());
    }
    // clean settings
    final Collection<Setting> settings = settingDao.getAll();
    if (!settings.isEmpty()) {
        for (Setting setting : settings) settingDao.delete(Arrays.asList(setting.getName()));
    }
    // clean policies
    final Collection<CertPolicy> policies = policyDao.getPolicies();
    if (!policies.isEmpty()) {
        for (CertPolicy policy : policies) policyDao.deletePolicies(new long[] { policy.getId() });
    }
    // clean policy groups
    final Collection<CertPolicyGroup> groups = policyDao.getPolicyGroups();
    if (!groups.isEmpty()) {
        for (CertPolicyGroup group : groups) policyDao.deletePolicyGroups(new long[] { group.getId() });
    }
}
Also used : CertificateDao(org.nhindirect.config.store.dao.CertificateDao) Address(org.nhindirect.config.store.Address) ArrayList(java.util.ArrayList) TrustBundleDao(org.nhindirect.config.store.dao.TrustBundleDao) AnchorDao(org.nhindirect.config.store.dao.AnchorDao) ApplicationContext(org.springframework.context.ApplicationContext) SettingDao(org.nhindirect.config.store.dao.SettingDao) DomainDao(org.nhindirect.config.store.dao.DomainDao) TrustBundle(org.nhindirect.config.store.TrustBundle) AddressDao(org.nhindirect.config.store.dao.AddressDao) CertPolicyDao(org.nhindirect.config.store.dao.CertPolicyDao) DNSRecord(org.nhindirect.config.store.DNSRecord) Setting(org.nhindirect.config.store.Setting) DNSDao(org.nhindirect.config.store.dao.DNSDao) Anchor(org.nhindirect.config.store.Anchor) CertPolicy(org.nhindirect.config.store.CertPolicy) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) Domain(org.nhindirect.config.store.Domain) Certificate(org.nhindirect.config.store.Certificate)

Example 12 with Domain

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

the class ConfigurationServiceTest method testUpdateAddress.

/**
     * Test the updateAddress method.
     */
public void testUpdateAddress() throws Exception {
    final AddressService addressService = context.mock(AddressService.class);
    final Address address = new Address(new Domain("domain"), "address");
    context.checking(new Expectations() {

        {
            oneOf(addressService).updateAddress(address);
        }
    });
    ConfigurationServiceImpl service = new ConfigurationServiceImpl();
    service.setAddressSvc(addressService);
    try {
        service.updateAddress(address);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) Address(org.nhindirect.config.store.Address) Domain(org.nhindirect.config.store.Domain) ConfigurationServiceImpl(org.nhindirect.config.service.impl.ConfigurationServiceImpl)

Example 13 with Domain

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

the class AddressServiceTest method testAddAddress.

/**
     * Test the addAddress method.
     */
public void testAddAddress() {
    final AddressDao addressDao = context.mock(AddressDao.class);
    final Collection<Address> addresses = Arrays.asList(new Address(new Domain("healthdomain.com"), "beau@healthdomain.com"), new Address(new Domain("healthdomain2.com"), "beau@healthdomain2.com"));
    context.checking(new Expectations() {

        {
        // TODO
        }
    });
    AddressServiceImpl service = new AddressServiceImpl();
    service.setDao(addressDao);
    try {
        service.addAddress(addresses);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) AddressServiceImpl(org.nhindirect.config.service.impl.AddressServiceImpl) Address(org.nhindirect.config.store.Address) Domain(org.nhindirect.config.store.Domain) AddressDao(org.nhindirect.config.store.dao.AddressDao)

Example 14 with Domain

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

the class DomainServiceTest method testSearchDomain.

/**
     * Test the searchDomain method.
     */
public void testSearchDomain() {
    final DomainDao domainDao = context.mock(DomainDao.class);
    final String domainName = "domain.com";
    final EntityStatus status = EntityStatus.ENABLED;
    final List<Domain> expected = Arrays.asList(new Domain());
    final List<Domain> expectedNull = null;
    context.checking(new Expectations() {

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

Example 15 with Domain

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

the class DomainService_realDataTest method testDeleteDomainByName_associatedTrustBundle_assertDomainDeleted.

@SuppressWarnings("deprecation")
public void testDeleteDomainByName_associatedTrustBundle_assertDomainDeleted() throws Exception {
    File bundleLocation = new File("./src/test/resources/bundles/signedbundle.p7b");
    final ApplicationContext ctx = ConfigServiceRunner.getSpringApplicationContext();
    // add a bundle
    TrustBundleService trustService = (TrustBundleService) ctx.getBean("trustBundleSvc");
    final TrustBundle bundle = new TrustBundle();
    bundle.setBundleName("Test Bundle");
    bundle.setBundleURL(filePrefix + bundleLocation.getAbsolutePath());
    trustService.addTrustBundle(bundle);
    // add a domain
    DomainService domainService = (DomainService) ctx.getBean("domainSvc");
    Domain domain = new Domain();
    domain.setDomainName("Test Domain");
    domain.setStatus(EntityStatus.ENABLED);
    domainService.addDomain(domain);
    //associate domain to bundle
    trustService.associateTrustBundleToDomain(domain.getId(), bundle.getId(), true, true);
    // assert the association
    Collection<TrustBundleDomainReltn> associatedBundel = trustService.getTrustBundlesByDomain(domain.getId(), true);
    assertEquals(1, associatedBundel.size());
    // now delete the domain
    domainService.removeDomain(domain.getDomainName());
    assertEquals(0, domainService.getDomainCount());
    boolean exceptionOccured = false;
    try {
        associatedBundel = trustService.getTrustBundlesByDomain(domain.getId(), true);
    } catch (ConfigurationStoreException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Domain(org.nhindirect.config.store.Domain) File(java.io.File) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn)

Aggregations

Domain (org.nhindirect.config.store.Domain)32 Transactional (org.springframework.transaction.annotation.Transactional)14 Query (javax.persistence.Query)10 Expectations (org.jmock.Expectations)10 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)10 TrustBundle (org.nhindirect.config.store.TrustBundle)9 NoResultException (javax.persistence.NoResultException)8 TrustBundleDomainReltn (org.nhindirect.config.store.TrustBundleDomainReltn)8 DomainDao (org.nhindirect.config.store.dao.DomainDao)7 ApplicationContext (org.springframework.context.ApplicationContext)7 File (java.io.File)5 DomainServiceImpl (org.nhindirect.config.service.impl.DomainServiceImpl)5 Address (org.nhindirect.config.store.Address)5 ArrayList (java.util.ArrayList)4 ConfigurationServiceImpl (org.nhindirect.config.service.impl.ConfigurationServiceImpl)4 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)4 CertPolicyGroupDomainReltn (org.nhindirect.config.store.CertPolicyGroupDomainReltn)3 AddressDao (org.nhindirect.config.store.dao.AddressDao)3 List (java.util.List)2 Anchor (org.nhindirect.config.store.Anchor)2