@Test public void testMaybeConfigResource_singleton() throws Exception { String configPath = "/apps/install/com.Test"; OakpalPlan.fromJson(key(keys().repoInits(), arr().val(String.format("create path (nt:unstructured) %s", configPath))).get()) .toOakMachineBuilder(null, getClass().getClassLoader()) .build().initAndInspect(session -> { DefaultSlingSimulator.NodeRes nodeRes = new DefaultSlingSimulator.NodeRes( session.getNode(configPath), configPath); OsgiConfigInstallableParams params = DefaultSlingSimulator.maybeConfigResource(nodeRes); assertNotNull("expect nonnull config params", params); assertEquals("expect servicePid", "com.Test", params.getServicePid()); assertNull("expect null factoryPid", params.getFactoryPid()); }); }
static @Nullable OsgiConfigInstallableParams maybeConfigResource(final @NotNull NodeRes resource) { final String lastIdPart = getResourceId(resource.getPath()); final String pid = removeConfigExtension(lastIdPart); final String factoryPid; final String configPid; int n = pid.indexOf('~'); if (n == -1) { n = pid.indexOf('-'); } if (n > 0) { configPid = pid.substring(n + 1); factoryPid = pid.substring(0, n); } else { factoryPid = null; configPid = pid; } return new OsgiConfigInstallableParams(resource.getProps(), configPid, factoryPid, resource.getParseError()); }
DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator { static @Nullable OsgiConfigInstallableParams maybeConfigResource(final @NotNull NodeRes resource) { final String lastIdPart = getResourceId(resource.getPath()); final String pid = removeConfigExtension(lastIdPart); final String factoryPid; final String configPid; int n = pid.indexOf('~'); if (n == -1) { n = pid.indexOf('-'); } if (n > 0) { configPid = pid.substring(n + 1); factoryPid = pid.substring(0, n); } else { factoryPid = null; configPid = pid; } return new OsgiConfigInstallableParams(resource.getProps(), configPid, factoryPid, resource.getParseError()); } }
DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator { static @Nullable OsgiConfigInstallableParams maybeConfigResource(final @NotNull NodeRes resource) { final String lastIdPart = getResourceId(resource.getPath()); final String pid = removeConfigExtension(lastIdPart); final String factoryPid; final String configPid; int n = pid.indexOf('~'); if (n == -1) { n = pid.indexOf('-'); } if (n > 0) { configPid = pid.substring(n + 1); factoryPid = pid.substring(0, n); } else { factoryPid = null; configPid = pid; } return new OsgiConfigInstallableParams(resource.getProps(), configPid, factoryPid, resource.getParseError()); }  }
DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator { static @Nullable OsgiConfigInstallableParams maybeConfigResource(final @NotNull NodeRes resource) { final String lastIdPart = getResourceId(resource.getPath()); final String pid = removeConfigExtension(lastIdPart); final String factoryPid; final String configPid; int n = pid.indexOf('~'); if (n == -1) { n = pid.indexOf('-'); } if (n > 0) { configPid = pid.substring(n + 1); factoryPid = pid.substring(0, n); } else { factoryPid = null; configPid = pid; } return new OsgiConfigInstallableParams(resource.getProps(), configPid, factoryPid, resource.getParseError()); }  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); }
DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator { static @Nullable OsgiConfigInstallableParams maybeConfigResource(final @NotNull NodeRes resource) { final String lastIdPart = getResourceId(resource.getPath()); final String pid = removeConfigExtension(lastIdPart); final String factoryPid; final String configPid; int n = pid.indexOf('~'); if (n == -1) { n = pid.indexOf('-'); } if (n > 0) { configPid = pid.substring(n + 1); factoryPid = pid.substring(0, n); } else { factoryPid = null; configPid = pid; } return new OsgiConfigInstallableParams(resource.getProps(), configPid, factoryPid, resource.getParseError()); }  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);  }