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() });
}
}
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");
}
}
use of org.nhindirect.config.store.Domain 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");
}
}
use of org.nhindirect.config.store.Domain 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");
}
}
use of org.nhindirect.config.store.Domain in project nhin-d by DirectProject.
the class DomainService_realDataTest method testDeleteDomainById_associatedTrustBundle_assertDomainDeleted.
public void testDeleteDomainById_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.removeDomainById(domain.getId());
assertEquals(0, domainService.getDomainCount());
boolean exceptionOccured = false;
try {
associatedBundel = trustService.getTrustBundlesByDomain(domain.getId(), true);
} catch (ConfigurationStoreException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
Aggregations