Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK-11328: Remove usage of Guava ImmutableList (test classes) #1920

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
package org.apache.jackrabbit.oak.spi.security.authentication.external;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Test;
Expand Down Expand Up @@ -169,7 +168,7 @@ public Iterable<ExternalIdentityRef> getDeclaredGroups() {

@Test
public void testToString() {
for (ExternalIdentityRef r : ImmutableList.of(ref, refEmptyProvider, refEmptyProvider)) {
for (ExternalIdentityRef r : List.of(ref, refEmptyProvider, refEmptyProvider)) {
assertEquals("ExternalIdentityRef{" + "id='" + r.getId() + '\'' + ", providerName='" + r.getProviderName() + '\'' + '}', r.toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
Expand All @@ -29,8 +30,7 @@
import javax.jcr.SimpleCredentials;
import javax.security.auth.login.LoginException;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;

import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
import org.jetbrains.annotations.NotNull;

public class TestIdentityProvider implements ExternalIdentityProvider {
Expand Down Expand Up @@ -75,7 +75,7 @@ public TestIdentityProvider(@NotNull String idpName) {
addUser(new TestUser(ID_SECOND_USER, getName())
.withProperty("profile/name", "Second User")
.withProperty("age", 24)
.withProperty("col", ImmutableList.of("v1", "v2", "v3"))
.withProperty("col", List.of("v1", "v2", "v3"))
.withProperty("boolArr", new Boolean[]{true, false})
.withProperty("charArr", new char[]{'t', 'o', 'b'})
.withProperty("byteArr", new byte[0])
Expand Down Expand Up @@ -237,7 +237,7 @@ public TestIdentity withGroups(@NotNull String ... grps) {

@NotNull
public TestIdentity withGroups(@NotNull ExternalIdentityRef... groups) {
this.groups.addAll(Set.of(groups));
this.groups.addAll(ImmutableSet.copyOf(groups));
return this;
}
}
Expand Down Expand Up @@ -283,7 +283,7 @@ public ForeignExternalGroup() {
@NotNull
@Override
public Iterable<ExternalIdentityRef> getDeclaredMembers() {
return ImmutableList.of();
return List.of();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package org.apache.jackrabbit.oak.spi.security.authentication.external.basic;

import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.User;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -158,9 +158,9 @@ public void testAutoMembership() {
// only global ids for getAutoMembership(Authorizable) as no specific config for 'gr'
assertEquals(globalGroupIds, dscA.getAutoMembership(gr));
// for 'user' the combine set of global and conditional config is returned
Set<String> expected = new HashSet<>();
expected.addAll(globalGroupIds);
expected.addAll(configGroupIds);
Set<String> expected = ImmutableSet.<String>builder()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is class is doing the opposite.

.addAll(globalGroupIds)
.addAll(configGroupIds).build();
assertEquals(expected, dscA.getAutoMembership(user));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.spi.security.authentication.external.basic;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
Expand Down Expand Up @@ -1451,7 +1450,7 @@ public void testCreateValueFromInputStream() throws Exception {

@Test
public void testCreateValuesEmptyCollection() throws Exception {
Value[] vs = syncCtx.createValues(ImmutableList.of());
Value[] vs = syncCtx.createValues(List.of());
assertNotNull(vs);
assertEquals(0, vs.length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
*/
package org.apache.jackrabbit.oak.spi.security.authentication.external.impl;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser;
Expand All @@ -36,6 +35,7 @@
import java.security.Principal;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.Assert.assertSame;

Expand Down Expand Up @@ -116,17 +116,17 @@ protected void sync(@NotNull ExternalIdentity externalIdentity, @NotNull SyncRes

@NotNull
static List<String> getIds(@NotNull Iterator<? extends Authorizable> authorizables) {
return ImmutableList.copyOf(Iterators.transform(authorizables, authorizable -> {
return CollectionUtils.toStream(authorizables).map(authorizable -> {
try {
return authorizable.getID();
} catch (RepositoryException repositoryException) {
throw new RuntimeException();
}
}));
}).collect(Collectors.toList());
}

@NotNull
static List<String> getPrincipalNames(@NotNull Iterator<Principal> groupPrincipals) {
return ImmutableList.copyOf(Iterators.transform(groupPrincipals, Principal::getName));
return CollectionUtils.toStream(groupPrincipals).map(Principal::getName).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import javax.jcr.SimpleCredentials;
import javax.security.auth.login.LoginException;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.oak.api.AuthInfo;
import org.apache.jackrabbit.oak.api.ContentSession;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup;
Expand Down Expand Up @@ -71,7 +70,7 @@ public void testLogin() throws Exception {

@Test
public void testLoginWithUnsupportedCredentials() throws Exception {
List<Credentials> creds = ImmutableList.of(
List<Credentials> creds = List.of(
new SimpleCredentials("testUser", new char[0]),
new GuestCredentials());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
*/
package org.apache.jackrabbit.oak.spi.security.authentication.external.impl;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal;
import org.apache.jackrabbit.api.security.principal.PrincipalManager;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityProvider;
Expand Down Expand Up @@ -294,7 +292,7 @@ public void testCrossIDPMembership() throws Exception {
UserManager um = getUserManager(r);
PrincipalManager pm = getPrincipalManager(r);

List<ExternalIdentityRef> declaredGroupRefs = ImmutableList.copyOf(previouslySyncedUser.getDeclaredGroups());
List<ExternalIdentityRef> declaredGroupRefs = CollectionUtils.toList(previouslySyncedUser.getDeclaredGroups());
assertTrue(declaredGroupRefs.size() > 1);

String groupId = declaredGroupRefs.get(0).getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.spi.security.authentication.external.impl;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.jackrabbit.api.security.user.Authorizable;
Expand Down Expand Up @@ -47,6 +46,7 @@

import javax.jcr.RepositoryException;
import javax.jcr.Value;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -119,7 +119,7 @@ protected void assertDynamicMembership(@NotNull ExternalIdentity externalIdentit

private void assertDynamicMembership(@NotNull Authorizable a, @NotNull ExternalIdentity externalIdentity, long depth) throws Exception {
Value[] vs = a.getProperty(REP_EXTERNAL_PRINCIPAL_NAMES);
Set<String> pNames = ImmutableList.copyOf(vs).stream().map(value -> {
Set<String> pNames = Arrays.stream(vs).map(value -> {
try {
return value.getString();
} catch (RepositoryException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.ValueFactory;

import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.User;
Expand Down Expand Up @@ -636,7 +637,7 @@ public void testListOrphanedUsers() throws Exception {

result = syncMBean.listOrphanedUsers();
assertEquals(2, result.length);
assertEquals(Set.of("thirdUser", "g"), Set.of(result));
assertEquals(Set.of("thirdUser", "g"), ImmutableSet.copyOf(result));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing the opposite here too.

}

@Test
Expand Down Expand Up @@ -668,7 +669,7 @@ public void testListOrphanedUsersThrowingHandler() throws Exception {

result = createThrowingSyncMBean(true).listOrphanedUsers();
assertEquals(2, result.length);
assertEquals(Set.of("thirdUser", "g"), Set.of(result));
assertEquals(Set.of("thirdUser", "g"), ImmutableSet.copyOf(result));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal;

import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.jackrabbit.api.security.principal.GroupPrincipal;
import org.apache.jackrabbit.api.security.user.Authorizable;
Expand Down Expand Up @@ -116,7 +117,7 @@ public void testGetPrincipalsMultipleGroups() throws Exception {
public void testGetPrincipalsMixed() throws Exception {
Collection<Principal> principals = getAutoMembership(IDP_MIXED_AM, authorizable, false);
assertFalse(principals.isEmpty());
assertEquals(Set.of(automembershipGroup1.getPrincipal()), Set.copyOf(principals));
assertEquals(Set.of(automembershipGroup1.getPrincipal()), ImmutableSet.copyOf(principals));
verifyNoInteractions(authorizable, amConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
*/
package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal;

import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.jackrabbit.oak.api.QueryEngine;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef;
import org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncConfig;
import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal;
Expand Down Expand Up @@ -107,14 +107,14 @@ private AutoMembershipProvider createAutoMembershipProvider(@NotNull Root root,
}

private static void assertMatchingEntries(@NotNull Iterator<Authorizable> it, @NotNull String... expectedIds) {
Set<String> ids = CollectionUtils.toSet(Iterators.transform(it, authorizable -> {
Set<String> ids = ImmutableSet.copyOf(Iterators.transform(it, authorizable -> {
try {
return authorizable.getID();
} catch (RepositoryException repositoryException) {
return "";
}
}));
assertEquals(Set.of(expectedIds), ids);
assertEquals(ImmutableSet.copyOf(expectedIds), ids);
}

@Test
Expand Down Expand Up @@ -378,7 +378,7 @@ public void testGetMembershipSelf() throws Exception {
public void testGetMembershipExternalUser() throws Exception {
setExternalId(getTestUser().getID(), IDP_VALID_AM);

Set<Group> groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), false));
Set<Group> groups = ImmutableSet.copyOf(provider.getMembership(getTestUser(), false));
assertEquals(2, groups.size());
assertTrue(groups.contains(automembershipGroup1));
assertTrue(groups.contains(automembershipGroup2));
Expand All @@ -388,7 +388,7 @@ public void testGetMembershipExternalUser() throws Exception {
public void testGetMembershipExternalUserInherited() throws Exception {
setExternalId(getTestUser().getID(), IDP_VALID_AM);

Set<Group> groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), true));
Set<Group> groups = ImmutableSet.copyOf(provider.getMembership(getTestUser(), true));
assertEquals(2, groups.size());
assertTrue(groups.contains(automembershipGroup1));
}
Expand All @@ -399,12 +399,12 @@ public void testGetMembershipExternalUserNestedGroups() throws Exception {

Group baseGroup = getTestGroup(automembershipGroup1);

Set<Group> groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), false));
Set<Group> groups = ImmutableSet.copyOf(provider.getMembership(getTestUser(), false));
assertEquals(2, groups.size());
assertTrue(groups.contains(automembershipGroup1));
assertTrue(groups.contains(automembershipGroup2));

groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), true));
groups = ImmutableSet.copyOf(provider.getMembership(getTestUser(), true));
assertEquals(3, groups.size());
assertTrue(groups.contains(automembershipGroup1));
assertTrue(groups.contains(automembershipGroup2));
Expand All @@ -421,12 +421,12 @@ public void testGetMembershipExternalUserEveryoneGroupExists() throws Exception
automembershipGroup2.addMember(automembershipGroup1);
root.commit();

Set<Group> groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), false));
Set<Group> groups = ImmutableSet.copyOf(provider.getMembership(getTestUser(), false));
assertEquals(2, groups.size());
assertTrue(groups.contains(automembershipGroup1));
assertTrue(groups.contains(automembershipGroup2));

groups = CollectionUtils.toSet(provider.getMembership(getTestUser(), true));
groups = ImmutableSet.copyOf(provider.getMembership(getTestUser(), true));
assertEquals(2, groups.size()); // all duplicates must be properly filtered and everyone must be omitted
assertTrue(groups.contains(automembershipGroup1));
assertTrue(groups.contains(automembershipGroup2));
Expand Down Expand Up @@ -512,7 +512,7 @@ public void testGetMembershipAutogroupGroupMemberOfFails() throws Exception {
setExternalId(getTestUser().getID(), IDP_VALID_AM);

AutoMembershipProvider amp = createAutoMembershipProvider(root, um);
Set<Group> membership = CollectionUtils.toSet(amp.getMembership(getTestUser(), true));
Set<Group> membership = ImmutableSet.copyOf(amp.getMembership(getTestUser(), true));
assertEquals(2, membership.size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal;

import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.User;
Expand Down Expand Up @@ -141,7 +140,7 @@ public void testAddMembersProperty() throws Exception {
assertFalse(groupTree.hasProperty(REP_MEMBERS));

String uuid = r.getTree(userManager.getAuthorizable(USER_ID).getPath()).getProperty(JCR_UUID).getValue(Type.STRING);
groupTree.setProperty(REP_MEMBERS, ImmutableList.of(uuid), Type.WEAKREFERENCES);
groupTree.setProperty(REP_MEMBERS, List.of(uuid), Type.WEAKREFERENCES);
try {
r.commit();
fail("CommitFailedException 77 expected.");
Expand Down
Loading
Loading