OakpalPlan implements JsonObjectConvertible { InitStage toInitStage() { LOGGER.debug("[Plan#toInitStage] json={}", this.toJson()); InitStage.Builder builder = new InitStage.Builder(); for (JcrNs ns : jcrNamespaces) { builder = builder.withNs(ns.getPrefix(), ns.getUri()); } builder.withQNodeTypes(jcrNodetypes); for (PrivilegeDefinition privilege : jcrPrivileges) { builder = builder.withPrivilegeDefinition(privilege); } for (ForcedRoot forcedRoot : forcedRoots) { builder = builder.withForcedRoot(forcedRoot); } builder.withRepoInitUrls(repoInitUrls); builder.withRepoInits(repoInits); return builder.build(); } private  OakpalPlan(final @Nullable URL base,
                       final @Nullable JsonObject originalJson,
                       final @NotNull String name,
                       final @NotNull List<String> runModes,
                       final @NotNull List<String> checklists,
                       final @NotNull List<URL> preInstallUrls,
                       final @NotNull List<JcrNs> jcrNamespaces,
                       final @NotNull List<QNodeTypeDefinition> jcrNodetypes,
                       final @NotNull List<PrivilegeDefinition> jcrPrivileges,
                       final @NotNull List<ForcedRoot> forcedRoots,
                       final @NotNull List<CheckSpec> checks,
                       final boolean enablePreInstallHooks,
                       final @Nullable InstallHookPolicy installHookPolicy,
                       final @NotNull List<URL> repoInitUrls,
                       final @NotNull List<String> repoInits); @NotNull static JsonKeys keys(); URL getBase(); String getName(); JsonObject getOriginalJson(); List<String> getRunModes(); List<String> getChecklists(); List<URL> getPreInstallUrls(); List<JcrNs> getJcrNamespaces(); List<QNodeTypeDefinition> getJcrNodetypes(); List<PrivilegeDefinition> getJcrPrivileges(); List<ForcedRoot> getForcedRoots(); List<CheckSpec> getChecks(); boolean isEnablePreInstallHooks(); InstallHookPolicy getInstallHookPolicy(); List<URL> getRepoInitUrls(); List<String> getRepoInits(); @Override JsonObject toJson(); @Override String toString(); OakMachine.Builder toOakMachineBuilder(final @Nullable ErrorListener errorListener,
                                                  final @NotNull ClassLoader classLoader); static OakpalPlan fromJson(final @NotNull JsonObject json); static Result<OakpalPlan> fromJson(final @NotNull URL jsonUrl); static final URL EMPTY_PLAN_URL; static final URL BASIC_PLAN_URL; static final String DEFAULT_PLAN_NAME; }
@Test public void testToInitStage() throws Exception { final URL expectBaseUrl = new URL(baseUrl, "fullPlan.json"); final Result<OakpalPlan> fullPlan = OakpalPlan.fromJson(expectBaseUrl); assertTrue("full plan is successful", fullPlan.isSuccess()); final OakpalPlan derived = fullPlan.getOrDefault(null); assertNotNull("not null full plan", derived); final ErrorListener errorListener = mock(ErrorListener.class); doAnswer(call -> { LOGGER.error("call: " + call.getArgument(1, String.class), call.getArgument(0, Throwable.class)); return true; }).when(errorListener).onJcrPrivilegeRegistrationError(any(Throwable.class), anyString()); new OakMachine.Builder() .withErrorListener(errorListener) .withInitStage(derived.toInitStage()) .build() .adminInitAndInspect(session -> { assertEquals("foo ns uri is defined", NS_FOO_URI, session.getNamespaceURI(NS_FOO_PREFIX)); assertEquals("bar ns uri is defined", NS_BAR_URI, session.getNamespaceURI(NS_BAR_PREFIX)); final NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); assertTrue("nt:foo1 is mixin", manager.getNodeType("nt:foo1").isMixin()); assertTrue("nt:foo2 is mixin", manager.getNodeType("nt:foo2").isMixin()); assertTrue("/root1 exists", session.nodeExists("/root1")); assertTrue("/root2 exists", session.nodeExists("/root2")); assertFalse("/root3 does not exist", session.nodeExists("/root3")); final PrivilegeManager privilegeManager = ((JackrabbitWorkspace) session.getWorkspace()) .getPrivilegeManager(); assertNotNull("privilege1 is defined", privilegeManager.getPrivilege("foo:priv1")); assertNotNull("privilege1 is defined", privilegeManager.getPrivilege("foo:priv2")); }); }