@Test public void testAlreadyInitialized() { NodeBuilder nb = when(mock(NodeBuilder.class).hasChildNode(JCR_SYSTEM)).thenReturn(true).getMock(); when(nb.getChildNode(JCR_SYSTEM)).thenReturn(nb); when(nb.hasChildNode(REP_PRIVILEGES)).thenReturn(true); initializer.initialize(nb); verify(nb, never()).child(anyString()); }
@Override public void initialize(@NotNull NodeBuilder builder) { if (!builder.hasChildNode(JcrConstants.JCR_SYSTEM)) { throw new IllegalStateException("Missing " + JcrConstants.JCR_SYSTEM + " node, NodeStore not initialized."); } NodeBuilder system = builder.getChildNode(JcrConstants.JCR_SYSTEM); if (!system.hasChildNode(REP_PRIVILEGES)) { NodeBuilder privileges = system.child(REP_PRIVILEGES); privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME); NodeState base = squeeze(builder.getNodeState()); NodeStore store = new MemoryNodeStore(base); try { Root systemRoot = rootProvider.createSystemRoot(store, null); new PrivilegeDefinitionWriter(systemRoot).writeBuiltInDefinitions(); } catch (RepositoryException e) { log.error("Failed to register built-in privileges", e); throw new RuntimeException(e); } NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); } }
PrivilegeInitializer implements RepositoryInitializer, PrivilegeConstants { @Override public void initialize(@NotNull NodeBuilder builder) { if (!builder.hasChildNode(JcrConstants.JCR_SYSTEM)) { throw new IllegalStateException("Missing " + JcrConstants.JCR_SYSTEM + " node, NodeStore not initialized."); } NodeBuilder system = builder.getChildNode(JcrConstants.JCR_SYSTEM); if (!system.hasChildNode(REP_PRIVILEGES)) { NodeBuilder privileges = system.child(REP_PRIVILEGES); privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME); NodeState base = squeeze(builder.getNodeState()); NodeStore store = new MemoryNodeStore(base); try { Root systemRoot = rootProvider.createSystemRoot(store, null); new PrivilegeDefinitionWriter(systemRoot).writeBuiltInDefinitions(); } catch (RepositoryException e) { log.error("Failed to register built-in privileges", e); throw new RuntimeException(e); } NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); } } }
PrivilegeInitializer implements RepositoryInitializer, PrivilegeConstants { @Override public void initialize(@NotNull NodeBuilder builder) { if (!builder.hasChildNode(JcrConstants.JCR_SYSTEM)) { throw new IllegalStateException("Missing " + JcrConstants.JCR_SYSTEM + " node, NodeStore not initialized."); } NodeBuilder system = builder.getChildNode(JcrConstants.JCR_SYSTEM); if (!system.hasChildNode(REP_PRIVILEGES)) { NodeBuilder privileges = system.child(REP_PRIVILEGES); privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME); NodeState base = squeeze(builder.getNodeState()); NodeStore store = new MemoryNodeStore(base); try { Root systemRoot = rootProvider.createSystemRoot(store, null); new PrivilegeDefinitionWriter(systemRoot).writeBuiltInDefinitions(); } catch (RepositoryException e) { log.error("Failed to register built-in privileges", e); throw new RuntimeException(e); } NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); } } PrivilegeInitializer(@NotNull RootProvider rootProvider); }
PrivilegeInitializer implements RepositoryInitializer, PrivilegeConstants { @Override public void initialize(@NotNull NodeBuilder builder) { if (!builder.hasChildNode(JcrConstants.JCR_SYSTEM)) { throw new IllegalStateException("Missing " + JcrConstants.JCR_SYSTEM + " node, NodeStore not initialized."); } NodeBuilder system = builder.getChildNode(JcrConstants.JCR_SYSTEM); if (!system.hasChildNode(REP_PRIVILEGES)) { NodeBuilder privileges = system.child(REP_PRIVILEGES); privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME); NodeState base = squeeze(builder.getNodeState()); NodeStore store = new MemoryNodeStore(base); try { Root systemRoot = rootProvider.createSystemRoot(store, null); new PrivilegeDefinitionWriter(systemRoot).writeBuiltInDefinitions(); } catch (RepositoryException e) { log.error("Failed to register built-in privileges", e); throw new RuntimeException(e); } NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); } } PrivilegeInitializer(@NotNull RootProvider rootProvider); @Override void initialize(@NotNull NodeBuilder builder); }
PrivilegeInitializer implements RepositoryInitializer, PrivilegeConstants { @Override public void initialize(@NotNull NodeBuilder builder) { if (!builder.hasChildNode(JcrConstants.JCR_SYSTEM)) { throw new IllegalStateException("Missing " + JcrConstants.JCR_SYSTEM + " node, NodeStore not initialized."); } NodeBuilder system = builder.getChildNode(JcrConstants.JCR_SYSTEM); if (!system.hasChildNode(REP_PRIVILEGES)) { NodeBuilder privileges = system.child(REP_PRIVILEGES); privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME); NodeState base = squeeze(builder.getNodeState()); NodeStore store = new MemoryNodeStore(base); try { Root systemRoot = rootProvider.createSystemRoot(store, null); new PrivilegeDefinitionWriter(systemRoot).writeBuiltInDefinitions(); } catch (RepositoryException e) { log.error("Failed to register built-in privileges", e); throw new RuntimeException(e); } NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); } } PrivilegeInitializer(@NotNull RootProvider rootProvider); @Override void initialize(@NotNull NodeBuilder builder);  }