use of org.nhindirect.config.store.TrustBundleAnchor in project nhin-d by DirectProject.
the class DefaultBundleCacheUpdateProcessorImpl_springInitTest method testLoadConfigService_addTrustBundle_bundleAnchorsAdded.
public void testLoadConfigService_addTrustBundle_bundleAnchorsAdded() throws Exception {
File bundleLocation = new File("./src/test/resources/bundles/signedbundle.p7b");
final ApplicationContext ctx = ConfigServiceRunner.getSpringApplicationContext();
assertNotNull(ctx);
TrustBundleService trustService = (TrustBundleService) ctx.getBean("trustBundleSvc");
final TrustBundle bundle = new TrustBundle();
bundle.setBundleName("Test Bundle");
bundle.setBundleURL(filePrefix + bundleLocation.getAbsolutePath());
trustService.addTrustBundle(bundle);
final TrustBundle addedBundle = trustService.getTrustBundleByName("Test Bundle");
assertTrue(addedBundle.getTrustBundleAnchors().size() > 0);
for (TrustBundleAnchor anchor : addedBundle.getTrustBundleAnchors()) assertNotNull(anchor.getData());
}
use of org.nhindirect.config.store.TrustBundleAnchor in project nhin-d by DirectProject.
the class DefaultBundleRefreshProcessorImpl_refreshBundleTest method testRefreshBundle_validBundle_unmatchedChecksum_needsRefreshed_assertUpdateCalled.
@SuppressWarnings("unchecked")
public void testRefreshBundle_validBundle_unmatchedChecksum_needsRefreshed_assertUpdateCalled() throws Exception {
DefaultBundleRefreshProcessorImpl processor = new DefaultBundleRefreshProcessorImpl();
processor.setDao(dao);
final TrustBundle bundle = new TrustBundle();
bundle.setBundleName("Junit Bundle");
File fl = new File("src/test/resources/bundles/signedbundle.p7b");
bundle.setBundleURL(filePrefix + fl.getAbsolutePath());
bundle.setCheckSum("12345");
processor.refreshBundle(bundle);
verify(dao, times(1)).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
}
use of org.nhindirect.config.store.TrustBundleAnchor in project nhin-d by DirectProject.
the class DefaultBundleRefreshProcessorImpl_refreshBundleTest method testRefreshBundle_checkSumsMatch_assertUpdateNotCalled.
@SuppressWarnings("unchecked")
public void testRefreshBundle_checkSumsMatch_assertUpdateNotCalled() throws Exception {
DefaultBundleRefreshProcessorImpl processor = new DefaultBundleRefreshProcessorImpl();
processor.setDao(dao);
final TrustBundle bundle = new TrustBundle();
File fl = new File("src/test/resources/bundles/signedbundle.p7b");
byte[] rawBundleByte = FileUtils.readFileToByteArray(fl);
bundle.setBundleName("Junit Bundle");
bundle.setBundleURL(filePrefix + fl.getAbsolutePath());
bundle.setCheckSum(BundleThumbprint.toThumbprint(rawBundleByte).toString());
processor.refreshBundle(bundle);
verify(dao, times(0)).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
}
use of org.nhindirect.config.store.TrustBundleAnchor in project nhin-d by DirectProject.
the class DefaultBundleRefreshProcessorImpl_refreshBundleTest method testRefreshBundle_errorOnUpdate.
@SuppressWarnings("unchecked")
public void testRefreshBundle_errorOnUpdate() throws Exception {
DefaultBundleRefreshProcessorImpl processor = new DefaultBundleRefreshProcessorImpl();
processor.setDao(dao);
final TrustBundle bundle = new TrustBundle();
bundle.setBundleName("Junit Bundle");
File fl = new File("src/test/resources/bundles/signedbundle.p7b");
bundle.setBundleURL(filePrefix + fl.getAbsolutePath());
doThrow(new ConfigurationStoreException("Just Passing Through")).when(dao).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
processor.refreshBundle(bundle);
verify(dao, times(1)).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
}
use of org.nhindirect.config.store.TrustBundleAnchor 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;
}
Aggregations