OakMachine { final void processEmbeddedPackage(final @NotNull Session admin, final @NotNull JcrPackageManager manager, final @NotNull EmbeddedPackageInstallable installable, final boolean preInstall) throws RepositoryException { final Consumer<Exception> onError = error -> getErrorListener().onSlingEmbeddedPackageError(error, installable); Fun.ThrowingSupplier<JcrPackage> supplier = slingSimulator.open(installable); internalProcessSubpackage(admin, manager, installable.getEmbeddedId(), preInstall, supplier, check -> check.identifyEmbeddedPackage( installable.getEmbeddedId(), installable.getParentId(), installable), onError); } 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 testProcessSubpackageInstallable_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 String jcrPath = "/some/path"; final EmbeddedPackageInstallable installable = new EmbeddedPackageInstallable(root, jcrPath, sub1); final Session session = mock(Session.class); final CompletableFuture<Exception> eLatch = new CompletableFuture<>(); final CompletableFuture<EmbeddedPackageInstallable> installableLatch = new CompletableFuture<>(); final ErrorListener errorListener = mock(ErrorListener.class); doAnswer(call -> { eLatch.complete(call.getArgument(0, Exception.class)); installableLatch.complete(call.getArgument(1, EmbeddedPackageInstallable.class)); return true; }).when(errorListener).onSlingEmbeddedPackageError(any(Exception.class), any(EmbeddedPackageInstallable.class)); final SlingSimulatorBackend installWatcher = mock(SlingSimulatorBackend.class); when(installWatcher.open(installable)) .thenReturn(() -> manager.open(sub1)); builder() .withSlingSimulator(installWatcher) .withErrorListener(errorListener).build() .processEmbeddedPackage(session, manager, installable, false); assertTrue("error is of type", eLatch.getNow(null) instanceof RepositoryException); assertSame("expect same installable", installable, installableLatch.getNow(null)); }
@Test(expected = RepositoryException.class) public void testProcessSubpackageInstallable_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 String jcrPath = "/some/path"; final EmbeddedPackageInstallable installable = new EmbeddedPackageInstallable(root, jcrPath, sub1); 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 CompletableFuture<EmbeddedPackageInstallable> installableLatch = new CompletableFuture<>(); final ErrorListener errorListener = mock(ErrorListener.class); doAnswer(call -> { eLatch.complete(call.getArgument(0, Exception.class)); installableLatch.complete(call.getArgument(1, EmbeddedPackageInstallable.class)); return true; }).when(errorListener).onSlingEmbeddedPackageError(any(Exception.class), any(EmbeddedPackageInstallable.class)); final SlingSimulatorBackend installWatcher = mock(SlingSimulatorBackend.class); when(installWatcher.open(installable)) .thenReturn(() -> manager.open(sub1)); builder() .withSlingSimulator(installWatcher) .withErrorListener(errorListener).build() .processEmbeddedPackage(session, manager, installable, false); }