Search in sources :

Example 1 with TrustBundleDomainReltn

use of org.nhindirect.config.store.TrustBundleDomainReltn 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);
}
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)

Example 2 with TrustBundleDomainReltn

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

the class TrustBundleDaoImpl method getTrustBundlesByDomain.

/**
	 * {@inheritDoc}
	 */
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public Collection<TrustBundleDomainReltn> getTrustBundlesByDomain(long domainId) throws ConfigurationStoreException {
    validateState();
    // make sure the domain exists
    final Domain domain = domainDao.getDomain(domainId);
    if (domain == null)
        throw new ConfigurationStoreException("Domain with id " + domainId + " does not exist");
    Collection<TrustBundleDomainReltn> retVal = null;
    try {
        final Query select = entityManager.createQuery("SELECT tbd from TrustBundleDomainReltn tbd where tbd.domain = ?1");
        select.setParameter(1, domain);
        retVal = (Collection<TrustBundleDomainReltn>) select.getResultList();
        if (retVal.size() == 0)
            return Collections.emptyList();
        for (TrustBundleDomainReltn reltn : retVal) {
            if (!reltn.getTrustBundle().getTrustBundleAnchors().isEmpty())
                for (TrustBundleAnchor anchor : reltn.getTrustBundle().getTrustBundleAnchors()) anchor.getData();
        }
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to execute trust bundle relation DAO query.", e);
    }
    return retVal;
}
Also used : Query(javax.persistence.Query) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Domain(org.nhindirect.config.store.Domain) TrustBundleAnchor(org.nhindirect.config.store.TrustBundleAnchor) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with TrustBundleDomainReltn

use of org.nhindirect.config.store.TrustBundleDomainReltn 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)

Example 4 with TrustBundleDomainReltn

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

the class TrustBundleService_realDataTest method testAssociateDomainToBundle_incomingTrueOutgoingFalse_assertIncomingAndOutgoingFlags.

public void testAssociateDomainToBundle_incomingTrueOutgoingFalse_assertIncomingAndOutgoingFlags() 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, false);
    // assert the association
    Collection<TrustBundleDomainReltn> associatedBundel = trustService.getTrustBundlesByDomain(domain.getId(), true);
    assertEquals(1, associatedBundel.size());
    TrustBundleDomainReltn reltn = associatedBundel.iterator().next();
    assertTrue(reltn.isIncoming());
    assertFalse(reltn.isOutgoing());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TrustBundle(org.nhindirect.config.store.TrustBundle) Domain(org.nhindirect.config.store.Domain) File(java.io.File) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn)

Example 5 with TrustBundleDomainReltn

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

the class TrustBundleService_realDataTest method testAssociateDomainToBundle_incomingAndOutgoingTrue_assertIncomingAndOutgoingFlags.

public void testAssociateDomainToBundle_incomingAndOutgoingTrue_assertIncomingAndOutgoingFlags() 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());
    TrustBundleDomainReltn reltn = associatedBundel.iterator().next();
    assertTrue(reltn.isIncoming());
    assertTrue(reltn.isOutgoing());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TrustBundle(org.nhindirect.config.store.TrustBundle) Domain(org.nhindirect.config.store.Domain) File(java.io.File) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn)

Aggregations

Domain (org.nhindirect.config.store.Domain)8 TrustBundleDomainReltn (org.nhindirect.config.store.TrustBundleDomainReltn)8 TrustBundle (org.nhindirect.config.store.TrustBundle)7 File (java.io.File)5 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)5 ApplicationContext (org.springframework.context.ApplicationContext)5 NoResultException (javax.persistence.NoResultException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Query (javax.persistence.Query)2 TrustBundleAnchor (org.nhindirect.config.store.TrustBundleAnchor)1