AuthorizationInitializer implements WorkspaceInitializer, AccessControlConstants, PermissionConstants { @Override public void initialize(NodeBuilder builder, String workspaceName) { NodeBuilder index = IndexUtils.getOrCreateOakIndex(builder); if (!index.hasChildNode("acPrincipalName")) { NodeBuilder acPrincipalName = IndexUtils.createIndexDefinition(index, "acPrincipalName", true, false, ImmutableList.<String>of(REP_PRINCIPAL_NAME), ImmutableList.<String>of(NT_REP_DENY_ACE, NT_REP_GRANT_ACE, NT_REP_ACE)); acPrincipalName.setProperty("info", "Oak index used by authorization to quickly search a principal by name."); } NodeBuilder permissionStore = builder.child(JCR_SYSTEM).child(REP_PERMISSION_STORE); if (!permissionStore.hasProperty(JCR_PRIMARYTYPE)) { permissionStore.setProperty(JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } if (!permissionStore.hasChildNode(workspaceName)) { permissionStore.child(workspaceName).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } for (Mount m : mountInfoProvider.getNonDefaultMounts()) { String permissionRootName = MountPermissionProvider.getPermissionRootName(m, workspaceName); if (!permissionStore.hasChildNode(permissionRootName)) { permissionStore.child(permissionRootName).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } } } AuthorizationInitializer(@NotNull MountInfoProvider mountInfoProvider); @Override void initialize(NodeBuilder builder, String workspaceName);  }
@Test public void testFirstInit() { when(builder.hasChildNode(anyString())).thenReturn(false); when(builder.hasProperty(anyString())).thenReturn(false); initializer.initialize(builder, "wspName"); verify(builder, times(4)).hasChildNode(anyString()); verify(builder, times(6)).child(anyString()); verify(builder, times(1)).hasProperty(anyString()); verify(builder, times(2)).setProperty(any(PropertyState.class)); verify(builder, times(3)).setProperty(anyString(), any(Object.class)); verify(builder, times(5)).setProperty(anyString(), any(Object.class), any(Type.class)); }
@Test public void testSecondInit() { when(builder.hasChildNode(anyString())).thenReturn(true); when(builder.hasProperty(anyString())).thenReturn(true); initializer.initialize(builder, "wspName"); verify(builder, times(4)).hasChildNode(anyString()); verify(builder, times(3)).child(anyString()); verify(builder, times(1)).hasProperty(anyString()); verify(builder, never()).setProperty(any(PropertyState.class)); verify(builder, never()).setProperty(anyString(), any(Object.class)); verify(builder, never()).setProperty(anyString(), any(Object.class), any(Type.class)); }