OakMachine { final void processSubpackage(final @NotNull Session admin, final @NotNull JcrPackageManager manager, final @NotNull PackageId packageId, final @NotNull PackageId parentId, final boolean preInstall) throws RepositoryException { internalProcessSubpackage(admin, manager, packageId, preInstall, () -> manager.open(packageId), check -> check.identifySubpackage(packageId, parentId), error -> getErrorListener().onSubpackageException(error, packageId)); } private  OakMachine(final Packaging packagingService,
                       final List<ProgressCheck> progressChecks,
                       final ErrorListener errorListener,
                       final List<URL> preInstallUrls,
                       final List<InitStage> initStages,
                       final JcrCustomizer jcrCustomizer,
                       final InstallHookProcessorFactory installHookProcessorFactory,
                       final ClassLoader installHookClassLoader,
                       final boolean enablePreInstallHooks,
                       final InstallHookPolicy scanInstallHookPolicy,
                       final Supplier<NodeStore> nodeStoreSupplier,
                       final SubpackageSilencer subpackageSilencer,
                       final RepoInitProcessor repoInitProcessor,
                       final SlingSimulatorBackend slingSimulator,
                       final Set<String> runModes); List<ProgressCheck> getProgressChecks(); ErrorListener getErrorListener(); @Deprecated List<File> getPreInstallFiles(); List<URL> getPreInstallUrls(); @SuppressWarnings("WeakerAccess") void initAndInspect(final InspectBody<E> inspectBody); void adminInitAndInspect(final InspectBody<E> inspectBody); List<CheckReport> scanPackage(final @NotNull File... file); List<CheckReport> scanPackages(final List<File> files); static Packaging newOakpalPackagingService(); static Packaging newOakpalPackagingService(final @NotNull ClassLoader classLoader); static final String NS_URI_OAKPAL; static final String NS_PREFIX_OAKPAL; static final String LN_UNDECLARED; static final String NT_UNDECLARED; }
@Test public void testProcessSubpackage_onSubpackageException() throws Exception { final JcrPackageManager manager = mock(JcrPackageManager.class); doThrow(RepositoryException.class).when(manager).open(any(PackageId.class)); final PackageId root = PackageId.fromString("my_packages:subsubtest"); final PackageId sub1 = PackageId.fromString("my_packages:subtest"); final Session session = mock(Session.class); final CompletableFuture<Exception> eLatch = new CompletableFuture<>(); final CompletableFuture<PackageId> idLatch = new CompletableFuture<>(); final ErrorListener errorListener = mock(ErrorListener.class); doAnswer(call -> { eLatch.complete(call.getArgument(0, Exception.class)); idLatch.complete(call.getArgument(1, PackageId.class)); return true; }).when(errorListener).onSubpackageException(any(Exception.class), any(PackageId.class)); builder().withErrorListener(errorListener).build() .processSubpackage(session, manager, sub1, root, false); assertTrue("error is of type", eLatch.getNow(null) instanceof RepositoryException); assertEquals("package id is", sub1, idLatch.getNow(null)); }
@Test(expected = RepositoryException.class) public void testProcessSubpackage_bubbledRepositoryException() throws Exception { final JcrPackageManager manager = mock(JcrPackageManager.class); doThrow(RepositoryException.class).when(manager).open(any(PackageId.class)); final PackageId root = PackageId.fromString("my_packages:subsubtest"); final PackageId sub1 = PackageId.fromString("my_packages:subtest"); final Session session = mock(Session.class); doThrow(RepositoryException.class).when(session).refresh(anyBoolean()); final CompletableFuture<Exception> eLatch = new CompletableFuture<>(); final CompletableFuture<PackageId> idLatch = new CompletableFuture<>(); final ErrorListener errorListener = mock(ErrorListener.class); doAnswer(call -> { eLatch.complete(call.getArgument(0, Exception.class)); idLatch.complete(call.getArgument(1, PackageId.class)); return true; }).when(errorListener).onSubpackageException(any(Exception.class), any(PackageId.class)); builder().withErrorListener(errorListener).build() .processSubpackage(session, manager, sub1, root, false); }