Search in sources :

Example 16 with TrustBundle

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

the class DefaultBundleCacheUpdateProcessorImpl_springInitTest method testLoadConfigService_refreshBundle_newBundleData_assertBundleRefreshed.

public void testLoadConfigService_refreshBundle_newBundleData_assertBundleRefreshed() throws Exception {
    final File originalBundleLocation = new File("./src/test/resources/bundles/signedbundle.p7b");
    final File updatedBundleLocation = new File("./src/test/resources/bundles/providerTestBundle.p7b");
    final File targetTempFileLocation = new File("./target/tempFiles/bundle.p7b");
    // copy the original bundle to the target location
    FileUtils.copyFile(originalBundleLocation, targetTempFileLocation);
    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 + targetTempFileLocation.getAbsolutePath());
    trustService.addTrustBundle(bundle);
    final TrustBundle addedBundle = trustService.getTrustBundleByName("Test Bundle");
    assertTrue(addedBundle.getTrustBundleAnchors().size() > 0);
    // validate the contents of the bundle
    final TrustBundle firstBundleInsert = trustService.getTrustBundleByName("Test Bundle");
    assertEquals(1, firstBundleInsert.getTrustBundleAnchors().size());
    // copy in the new bundle
    FileUtils.copyFile(updatedBundleLocation, targetTempFileLocation);
    // now refresh
    trustService.refreshTrustBundle(addedBundle.getId());
    final TrustBundle refreshedBundle = trustService.getTrustBundleByName("Test Bundle");
    assertEquals(6, refreshedBundle.getTrustBundleAnchors().size());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TrustBundleService(org.nhindirect.config.service.TrustBundleService) TrustBundle(org.nhindirect.config.store.TrustBundle) File(java.io.File)

Example 17 with TrustBundle

use of org.nhindirect.config.store.TrustBundle 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());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TrustBundleService(org.nhindirect.config.service.TrustBundleService) TrustBundle(org.nhindirect.config.store.TrustBundle) File(java.io.File) TrustBundleAnchor(org.nhindirect.config.store.TrustBundleAnchor)

Example 18 with TrustBundle

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

the class DefaultBundleCacheUpdateProcessorImpl_updateBundleCacheTest method testUpdateBundleCache_updateCache_refreshIntervalNotExpired_assertBundleRefreshNotCalled.

public void testUpdateBundleCache_updateCache_refreshIntervalNotExpired_assertBundleRefreshNotCalled() throws Exception {
    final DefaultBundleCacheUpdateProcessorImpl cacheUpdate = new DefaultBundleCacheUpdateProcessorImpl();
    cacheUpdate.setDao(dao);
    cacheUpdate.setRefreshProcessor(processor);
    final TrustBundle bundle = new TrustBundle();
    bundle.setRefreshInterval(1000);
    bundle.setLastSuccessfulRefresh(Calendar.getInstance(Locale.getDefault()));
    final Collection<TrustBundle> bundles = Arrays.asList(bundle);
    when(dao.getTrustBundles()).thenReturn(bundles);
    cacheUpdate.updateBundleCache();
    verify(dao, times(1)).getTrustBundles();
    verify(processor, never()).refreshBundle(bundle);
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle)

Example 19 with TrustBundle

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

the class DefaultBundleCacheUpdateProcessorImpl_updateBundleCacheTest method testUpdateBundleCache_updateCache_errorInUpdate_assertBundleRefreshCalled.

public void testUpdateBundleCache_updateCache_errorInUpdate_assertBundleRefreshCalled() throws Exception {
    final DefaultBundleCacheUpdateProcessorImpl cacheUpdate = new DefaultBundleCacheUpdateProcessorImpl();
    cacheUpdate.setDao(dao);
    cacheUpdate.setRefreshProcessor(processor);
    final TrustBundle bundle = new TrustBundle();
    bundle.setRefreshInterval(1);
    final Collection<TrustBundle> bundles = Arrays.asList(bundle);
    when(dao.getTrustBundles()).thenReturn(bundles);
    doThrow(new RuntimeException("Just Passing Through")).when(processor).refreshBundle(bundle);
    cacheUpdate.updateBundleCache();
    verify(dao, times(1)).getTrustBundles();
    verify(processor, times(1)).refreshBundle(bundle);
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle)

Example 20 with TrustBundle

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

the class DefaultBundleCacheUpdateProcessorImpl_updateBundleCacheTest method testUpdateBundleCache_updateCache_bundleNeverUpdated_assertBundleRefreshCalled.

public void testUpdateBundleCache_updateCache_bundleNeverUpdated_assertBundleRefreshCalled() throws Exception {
    final DefaultBundleCacheUpdateProcessorImpl cacheUpdate = new DefaultBundleCacheUpdateProcessorImpl();
    cacheUpdate.setDao(dao);
    cacheUpdate.setRefreshProcessor(processor);
    final TrustBundle bundle = new TrustBundle();
    bundle.setRefreshInterval(1);
    final Collection<TrustBundle> bundles = Arrays.asList(bundle);
    when(dao.getTrustBundles()).thenReturn(bundles);
    cacheUpdate.updateBundleCache();
    verify(dao, times(1)).getTrustBundles();
    verify(processor, times(1)).refreshBundle(bundle);
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle)

Aggregations

TrustBundle (org.nhindirect.config.store.TrustBundle)44 File (java.io.File)16 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)15 ApplicationContext (org.springframework.context.ApplicationContext)12 Transactional (org.springframework.transaction.annotation.Transactional)12 NoResultException (javax.persistence.NoResultException)11 TrustBundleAnchor (org.nhindirect.config.store.TrustBundleAnchor)10 Domain (org.nhindirect.config.store.Domain)9 Calendar (java.util.Calendar)8 TrustBundleDomainReltn (org.nhindirect.config.store.TrustBundleDomainReltn)7 X509Certificate (java.security.cert.X509Certificate)6 Query (javax.persistence.Query)6 TrustBundleDao (org.nhindirect.config.store.dao.TrustBundleDao)4 TrustBundleService (org.nhindirect.config.service.TrustBundleService)3 ArrayList (java.util.ArrayList)2 Address (org.nhindirect.config.store.Address)2 Anchor (org.nhindirect.config.store.Anchor)2 CertPolicy (org.nhindirect.config.store.CertPolicy)2 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)2 Certificate (org.nhindirect.config.store.Certificate)2