ExternalIdentityRepositoryInitializer implements RepositoryInitializer { @Override public void initialize(@NotNull NodeBuilder builder) { NodeBuilder index = IndexUtils.getOrCreateOakIndex(builder); if (enforceUniqueIds && !index.hasChildNode("externalId")) { NodeBuilder definition = IndexUtils.createIndexDefinition(index, "externalId", true, true, ImmutableList.of(ExternalIdentityConstants.REP_EXTERNAL_ID), null); definition.setProperty("info", "Oak index assuring uniqueness of rep:externalId properties."); } if (!index.hasChildNode("externalPrincipalNames")) { NodeBuilder definition = IndexUtils.createIndexDefinition(index, "externalPrincipalNames", true, false, ImmutableList.of(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES), null); definition.setProperty("info", "Oak index used by the principal management provided by the external authentication module."); } } ExternalIdentityRepositoryInitializer(boolean enforceUniqueIds); @Override void initialize(@NotNull NodeBuilder builder);  }
@Test public void testInitializeNotEnforced() { NodeBuilder builder = mock(NodeBuilder.class); when(builder.hasChildNode(INDEX_DEFINITIONS_NAME)).thenReturn(true); when(builder.child(INDEX_DEFINITIONS_NAME)).thenReturn(builder); when(builder.hasChildNode("externalPrincipalNames")).thenReturn(true); ExternalIdentityRepositoryInitializer initializer = new ExternalIdentityRepositoryInitializer(false); initializer.initialize(builder); verify(builder, never()).child("externalId"); verify(builder, never()).setProperty(anyString(), any()); }
@Test public void testInitializeIndicesExist() { NodeBuilder builder = spy(getTreeProvider().asNodeState(root.getTree(PathUtils.ROOT_PATH)).builder()); ExternalIdentityRepositoryInitializer initializer = new ExternalIdentityRepositoryInitializer(true); initializer.initialize(builder); verify(builder, never()).child("externalId"); verify(builder, never()).child("externalPrincipalNames"); verify(builder, never()).setProperty(anyString(), any()); }