Search in sources :

Example 6 with Anchor

use of org.nhindirect.config.store.Anchor 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 7 with Anchor

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

the class AnchorServiceTest method testAddAnchors.

/**
     * Test the addAnchors method.
     */
public void testAddAnchors() {
    final AnchorDao anchorDao = context.mock(AnchorDao.class);
    final Collection<Anchor> anchors = Arrays.asList(new Anchor());
    context.checking(new Expectations() {

        {
            for (Anchor anchor : anchors) oneOf(anchorDao).add(anchor);
        }
    });
    AnchorServiceImpl service = new AnchorServiceImpl();
    service.setDao(anchorDao);
    try {
        service.addAnchors(anchors);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) Anchor(org.nhindirect.config.store.Anchor) AnchorServiceImpl(org.nhindirect.config.service.impl.AnchorServiceImpl) AnchorDao(org.nhindirect.config.store.dao.AnchorDao)

Example 8 with Anchor

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

the class AnchorServiceTest method testListAnchors.

/**
     * Test the listAnchors method.
     */
public void testListAnchors() {
    final AnchorDao anchorDao = context.mock(AnchorDao.class);
    final Long anchorId = 7L;
    final int maxResults = 7;
    final CertificateGetOptions certificateOptions = CertificateGetOptions.DEFAULT;
    context.checking(new Expectations() {

        {
            oneOf(anchorDao).listAll();
            will(returnValue(Collections.<Anchor>emptyList()));
        }
    });
    AnchorServiceImpl service = new AnchorServiceImpl();
    service.setDao(anchorDao);
    try {
        Collection<Anchor> output = service.listAnchors(anchorId, maxResults, certificateOptions);
        assertNotNull("Output is null when passing valid params", output);
        assertEquals("Output does not match mocked return value when using valid params", Collections.<Anchor>emptyList(), output);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) CertificateGetOptions(org.nhindirect.config.service.impl.CertificateGetOptions) AnchorServiceImpl(org.nhindirect.config.service.impl.AnchorServiceImpl) Anchor(org.nhindirect.config.store.Anchor) AnchorDao(org.nhindirect.config.store.dao.AnchorDao)

Example 9 with Anchor

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

the class AnchorServiceTest method testGetAnchors.

/**
     * Test the getAnchors method.
     */
public void testGetAnchors() {
    final AnchorDao anchorDao = context.mock(AnchorDao.class);
    final List<Long> anchorIds = Arrays.asList(7L, 8L);
    final CertificateGetOptions certificateOptions = CertificateGetOptions.DEFAULT;
    context.checking(new Expectations() {

        {
            oneOf(anchorDao).listByIds(anchorIds);
            will(returnValue(Collections.<Long>emptyList()));
        }
    });
    AnchorServiceImpl service = new AnchorServiceImpl();
    service.setDao(anchorDao);
    try {
        Collection<Anchor> output = service.getAnchors(null, certificateOptions);
        assertNotNull("Output is null when passing a null param", output);
        assertEquals("Output does not match expected return value for a null param", Collections.emptyList(), output);
    } catch (Exception e) {
        fail("Exception thrown");
    }
    try {
        Collection<Anchor> output = service.getAnchors(Collections.<Long>emptyList(), certificateOptions);
        assertNotNull("Output is null when passing an empty collection", output);
        assertEquals("Output does not match expected return value for an empty collection", Collections.emptyList(), output);
    } catch (Exception e) {
        fail("Exception thrown");
    }
    try {
        Collection<Anchor> output = service.getAnchors(anchorIds, certificateOptions);
        assertNotNull("Output is null when using valid params", output);
        assertEquals("Output does not match mocked return value when using valid params", Collections.<Long>emptyList(), output);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) CertificateGetOptions(org.nhindirect.config.service.impl.CertificateGetOptions) AnchorServiceImpl(org.nhindirect.config.service.impl.AnchorServiceImpl) Anchor(org.nhindirect.config.store.Anchor) AnchorDao(org.nhindirect.config.store.dao.AnchorDao)

Example 10 with Anchor

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

the class AnchorServiceTest method testGetIncomingAnchors.

/**
     * Test the getIncomingAnchors method.
     */
public void testGetIncomingAnchors() {
    final AnchorDao anchorDao = context.mock(AnchorDao.class);
    final String owner = "beau";
    final CertificateGetOptions certificateOptions = CertificateGetOptions.DEFAULT;
    final List<String> owners = Arrays.asList(owner);
    context.checking(new Expectations() {

        {
            oneOf(anchorDao).list(owners);
        }
    });
    AnchorServiceImpl service = new AnchorServiceImpl();
    service.setDao(anchorDao);
    try {
        Collection<Anchor> output = service.getIncomingAnchors(owner, certificateOptions);
        assertEquals("Output does not match expected", Collections.emptyList(), output);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) CertificateGetOptions(org.nhindirect.config.service.impl.CertificateGetOptions) AnchorServiceImpl(org.nhindirect.config.service.impl.AnchorServiceImpl) Anchor(org.nhindirect.config.store.Anchor) AnchorDao(org.nhindirect.config.store.dao.AnchorDao)

Aggregations

Anchor (org.nhindirect.config.store.Anchor)19 AnchorDao (org.nhindirect.config.store.dao.AnchorDao)10 ArrayList (java.util.ArrayList)9 Expectations (org.jmock.Expectations)9 AnchorServiceImpl (org.nhindirect.config.service.impl.AnchorServiceImpl)8 CertificateGetOptions (org.nhindirect.config.service.impl.CertificateGetOptions)6 Transactional (org.springframework.transaction.annotation.Transactional)5 List (java.util.List)3 Query (javax.persistence.Query)3 Address (org.nhindirect.config.store.Address)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 Domain (org.nhindirect.config.store.Domain)2 Setting (org.nhindirect.config.store.Setting)2 TrustBundle (org.nhindirect.config.store.TrustBundle)2 AddressDao (org.nhindirect.config.store.dao.AddressDao)2 CertPolicyDao (org.nhindirect.config.store.dao.CertPolicyDao)2 CertificateDao (org.nhindirect.config.store.dao.CertificateDao)2