DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator { @NotNull Result<Optional<SlingInstallableParams<?>>> readInstallableParamsFromNode(final @NotNull Node node) { return result0(() -> { final String path = node.getPath(); NodeRes nodeRes = new NodeRes(node, path); if (Arrays.asList(node.getSession().getWorkspace().getNamespaceRegistry().getURIs()).contains(SLING_NS) && node.isNodeType(SLING_OSGI_CONFIG)) { loadJcrProperties(nodeRes.getProps(), node); return maybeConfigResource(nodeRes); } else if (node.hasProperty(JCR_CONTENT_DATA)) { nodeRes.getProps().put(InstallableResource.INSTALLATION_HINT, node.getParent().getName()); EmbeddedPackageInstallableParams packageInstallableParams = maybePackageResource(nodeRes); if (packageInstallableParams != null) { return packageInstallableParams; } if (isConfigExtension(path)) { try (InputStream is = node.getProperty(JCR_CONTENT_DATA).getBinary().getStream()) { nodeRes.getProps().putAll(readDictionary(is, nodeRes.getPath())); } catch (Exception e) { nodeRes.setParseError(e); } return maybeConfigResource(nodeRes); } } return null; }).get().map(Optional::ofNullable); }  static SlingSimulatorBackend instance(); @Override void startedScan(); @Override void setSession(final Session session); @Override void setPackageManager(final JcrPackageManager packageManager); @Override void setErrorListener(final ErrorListener errorListener); @Override @Nullable SlingInstallable dequeueInstallable(); @SuppressWarnings("unchecked") @Override @NotNull Fun.ThrowingSupplier<ResourceType> open(@NotNull final SlingOpenable<ResourceType> installable); @NotNull JcrPackage openEmbeddedPackage(@NotNull final EmbeddedPackageInstallable installable); @Override @Nullable SlingInstallable addInstallableNode(final @NotNull PackageId parentPackageId,
                                                         final @NotNull Node node);  }
@Test public void testReadInstallableResourceFromNode_noRepositoryException() throws Exception { OakpalPlan.fromJson(key(keys().repoInits(), arr().val("create path (nt:unstructured) /apps/config/Test")).get()) .toOakMachineBuilder(null, getClass().getClassLoader()) .build().initAndInspect(session -> { Result<Optional<SlingInstallableParams<?>>> result = slingSimulator .readInstallableParamsFromNode(session.getNode("/apps/config/Test")); assertTrue("expect null config", result.isSuccess() && !result.getOrDefault(null).isPresent()); }); }
@Test public void testReadInstallableResourceFromNode_slingOsgiConfig() throws Exception { OakpalPlan.fromJson(key(keys().repoInits(), arr() .val("register nodetypes") .val("<<===") .val("<'sling'='http: .val("[sling:OsgiConfig] > nt:unstructured, nt:hierarchyNode") .val("===>>") .val("create path (nt:folder) /apps/config/Test(sling:OsgiConfig)")) .get()).toOakMachineBuilder(null, getClass().getClassLoader()) .build().initAndInspect(session -> { SlingInstallableParams<?> resource = slingSimulator .readInstallableParamsFromNode(session.getNode("/apps/config/Test")).toOptional() .flatMap(Function.identity()) .orElse(null); assertNotNull("expect not null resource", resource); assertTrue("expect instance of OsgiConfigInstallableParams", resource instanceof OsgiConfigInstallableParams); OsgiConfigInstallableParams params = (OsgiConfigInstallableParams) resource; assertNotNull("expect not null properties", params.getProperties()); assertEquals("expect servicePid is Test", "Test", params.getServicePid()); PackageId base = new PackageId("com.test", "base", "1.0.0"); OsgiConfigInstallable installable = params.createInstallable(base, "/apps/config/Test"); }); }