@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"));
            });
}