Search in sources :

Example 1 with TrustBundleService

use of org.nhindirect.config.service.TrustBundleService 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 2 with TrustBundleService

use of org.nhindirect.config.service.TrustBundleService 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 3 with TrustBundleService

use of org.nhindirect.config.service.TrustBundleService in project nhin-d by DirectProject.

the class DefaultBundleCacheUpdateProcessorImpl_springInitTest method testLoadConfigService_refreshBundle_assertBundleRefreshed.

public void testLoadConfigService_refreshBundle_assertBundleRefreshed() 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);
    final Calendar lastRefreshAttemp = addedBundle.getLastRefreshAttempt();
    final Calendar lastSuccessfulRefresh = addedBundle.getLastSuccessfulRefresh();
    // now refresh
    trustService.refreshTrustBundle(addedBundle.getId());
    final TrustBundle refreshedBundle = trustService.getTrustBundleByName("Test Bundle");
    assertEquals(lastSuccessfulRefresh.getTimeInMillis(), refreshedBundle.getLastSuccessfulRefresh().getTimeInMillis());
    assertTrue(refreshedBundle.getLastRefreshAttempt().getTimeInMillis() > lastRefreshAttemp.getTimeInMillis());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TrustBundleService(org.nhindirect.config.service.TrustBundleService) Calendar(java.util.Calendar) TrustBundle(org.nhindirect.config.store.TrustBundle) File(java.io.File)

Aggregations

File (java.io.File)3 TrustBundleService (org.nhindirect.config.service.TrustBundleService)3 TrustBundle (org.nhindirect.config.store.TrustBundle)3 ApplicationContext (org.springframework.context.ApplicationContext)3 Calendar (java.util.Calendar)1 TrustBundleAnchor (org.nhindirect.config.store.TrustBundleAnchor)1