Start AssertJ Migration
Issue gh-3175
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package org.springframework.security.ldap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
@@ -21,8 +21,8 @@ public class DefaultSpringSecurityContextSourceTests extends AbstractLdapIntegra
|
||||
public void instantiationSucceedsWithExpectedProperties() {
|
||||
DefaultSpringSecurityContextSource ctxSrc = new DefaultSpringSecurityContextSource(
|
||||
"ldap://blah:789/dc=springframework,dc=org");
|
||||
assertFalse(ctxSrc.isAnonymousReadOnly());
|
||||
assertTrue(ctxSrc.isPooled());
|
||||
assertThat(ctxSrc.isAnonymousReadOnly()).isFalse();
|
||||
assertThat(ctxSrc.isPooled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -39,7 +39,7 @@ public class DefaultSpringSecurityContextSourceTests extends AbstractLdapIntegra
|
||||
ctxSrc.setUserDn("manager");
|
||||
ctxSrc.setPassword("password");
|
||||
ctxSrc.afterPropertiesSet();
|
||||
assertTrue(ctxSrc.getAuthenticatedEnvForTest("manager", "password").containsKey(
|
||||
assertThat(ctxSrc.getAuthenticatedEnvForTest("manager", "password").isTrue().containsKey(
|
||||
AbstractContextSource.SUN_LDAP_POOLING_FLAG));
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class DefaultSpringSecurityContextSourceTests extends AbstractLdapIntegra
|
||||
ctxSrc.setUserDn("manager");
|
||||
ctxSrc.setPassword("password");
|
||||
ctxSrc.afterPropertiesSet();
|
||||
assertFalse(ctxSrc.getAuthenticatedEnvForTest("user", "password").containsKey(
|
||||
assertThat(ctxSrc.getAuthenticatedEnvForTest("user", "password").isFalse().containsKey(
|
||||
AbstractContextSource.SUN_LDAP_POOLING_FLAG));
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class DefaultSpringSecurityContextSourceTests extends AbstractLdapIntegra
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
assertNotNull(ctx);
|
||||
assertThat(ctx).isNotNull();
|
||||
// com.sun.jndi.ldap.LdapPoolManager.showStats(System.out);
|
||||
ctx.close();
|
||||
// com.sun.jndi.ldap.LdapPoolManager.showStats(System.out);
|
||||
@@ -104,8 +104,8 @@ public class DefaultSpringSecurityContextSourceTests extends AbstractLdapIntegra
|
||||
DefaultSpringSecurityContextSource ctxSrc = new DefaultSpringSecurityContextSource(
|
||||
serverUrls, "dc=springframework,dc=org");
|
||||
|
||||
assertFalse(ctxSrc.isAnonymousReadOnly());
|
||||
assertTrue(ctxSrc.isPooled());
|
||||
assertThat(ctxSrc.isAnonymousReadOnly()).isFalse();
|
||||
assertThat(ctxSrc.isPooled()).isTrue();
|
||||
}
|
||||
|
||||
// SEC-2308
|
||||
@@ -119,8 +119,8 @@ public class DefaultSpringSecurityContextSourceTests extends AbstractLdapIntegra
|
||||
DefaultSpringSecurityContextSource ctxSrc = new DefaultSpringSecurityContextSource(
|
||||
serverUrls, baseDn);
|
||||
|
||||
assertFalse(ctxSrc.isAnonymousReadOnly());
|
||||
assertTrue(ctxSrc.isPooled());
|
||||
assertThat(ctxSrc.isAnonymousReadOnly()).isFalse();
|
||||
assertThat(ctxSrc.isPooled()).isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.ldap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -51,7 +51,7 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
|
||||
|
||||
@Test
|
||||
public void compareOfCorrectValueSucceeds() {
|
||||
assertTrue(template.compare("uid=bob,ou=people", "uid", "bob"));
|
||||
assertThat(template.compare("uid=bob,ou=people", "uid", "bob")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,17 +68,17 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
|
||||
|
||||
@Test
|
||||
public void compareOfWrongValueFails() {
|
||||
assertFalse(template.compare("uid=bob,ou=people", "uid", "wrongvalue"));
|
||||
assertThat(template.compare("uid=bob,ou=people", "uid", "wrongvalue")).isFalse();
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testNameExistsForInValidNameFails() {
|
||||
// assertFalse(template.nameExists("ou=doesntexist,dc=springframework,dc=org"));
|
||||
// assertThat(template.nameExists("ou=doesntexist,dc=springframework,dc=org")).isFalse();
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testNameExistsForValidNameSucceeds() {
|
||||
// assertTrue(template.nameExists("ou=groups,dc=springframework,dc=org"));
|
||||
// assertThat(template.nameExists("ou=groups,dc=springframework,dc=org")).isTrue();
|
||||
// }
|
||||
|
||||
@Test
|
||||
@@ -103,10 +103,10 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
|
||||
Set<String> values = template.searchForSingleAttributeValues("ou=groups",
|
||||
"(member={0})", new String[] { param }, "ou");
|
||||
|
||||
assertEquals("Expected 3 results from search", 3, values.size());
|
||||
assertTrue(values.contains("developer"));
|
||||
assertTrue(values.contains("manager"));
|
||||
assertTrue(values.contains("submanager"));
|
||||
assertThat(values).as("Expected 3 results from search").hasSize(3);
|
||||
assertThat(values.contains("developer")).isTrue();
|
||||
assertThat(values.contains("manager")).isTrue();
|
||||
assertThat(values.contains("submanager")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,14 +114,14 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
|
||||
Set<Map<String, List<String>>> values = template
|
||||
.searchForMultipleAttributeValues("ou=people", "(uid={0})",
|
||||
new String[] { "bob" }, null);
|
||||
assertEquals(1, values.size());
|
||||
assertThat(values).hasSize(1);
|
||||
Map<String, List<String>> record = values.iterator().next();
|
||||
assertAttributeValue(record, "uid", "bob");
|
||||
assertAttributeValue(record, "objectclass", "top", "person",
|
||||
"organizationalPerson", "inetOrgPerson");
|
||||
assertAttributeValue(record, "cn", "Bob Hamilton");
|
||||
assertAttributeValue(record, "sn", "Hamilton");
|
||||
assertFalse(record.containsKey("userPassword"));
|
||||
assertThat(record.containsKey("userPassword")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,14 +129,14 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
|
||||
Set<Map<String, List<String>>> values = template
|
||||
.searchForMultipleAttributeValues("ou=people", "(uid={0})",
|
||||
new String[] { "bob" }, new String[0]);
|
||||
assertEquals(1, values.size());
|
||||
assertThat(values).hasSize(1);
|
||||
Map<String, List<String>> record = values.iterator().next();
|
||||
assertAttributeValue(record, "uid", "bob");
|
||||
assertAttributeValue(record, "objectclass", "top", "person",
|
||||
"organizationalPerson", "inetOrgPerson");
|
||||
assertAttributeValue(record, "cn", "Bob Hamilton");
|
||||
assertAttributeValue(record, "sn", "Hamilton");
|
||||
assertFalse(record.containsKey("userPassword"));
|
||||
assertThat(record.containsKey("userPassword")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -144,21 +144,21 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
|
||||
Set<Map<String, List<String>>> values = template
|
||||
.searchForMultipleAttributeValues("ou=people", "(uid={0})",
|
||||
new String[] { "bob" }, new String[] { "uid", "cn", "sn" });
|
||||
assertEquals(1, values.size());
|
||||
assertThat(values).hasSize(1);
|
||||
Map<String, List<String>> record = values.iterator().next();
|
||||
assertAttributeValue(record, "uid", "bob");
|
||||
assertAttributeValue(record, "cn", "Bob Hamilton");
|
||||
assertAttributeValue(record, "sn", "Hamilton");
|
||||
assertFalse(record.containsKey("userPassword"));
|
||||
assertFalse(record.containsKey("objectclass"));
|
||||
assertThat(record.containsKey("userPassword")).isFalse();
|
||||
assertThat(record.containsKey("objectclass")).isFalse();
|
||||
}
|
||||
|
||||
protected void assertAttributeValue(Map<String, List<String>> record,
|
||||
String attributeName, String... values) {
|
||||
assertTrue(record.containsKey(attributeName));
|
||||
assertEquals(values.length, record.get(attributeName).size());
|
||||
assertThat(record.containsKey(attributeName)).isTrue();
|
||||
assertThat(record.get(attributeName).size()).isEqualTo(values.length);
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
assertEquals(values[i], record.get(attributeName).get(i));
|
||||
assertThat(record.get(attributeName).get(i)).isEqualTo(values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
|
||||
Set<String> values = template.searchForSingleAttributeValues("ou=groups",
|
||||
"(member={0})", new String[] { param }, "mail");
|
||||
|
||||
assertEquals(0, values.size());
|
||||
assertThat(values).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -179,7 +179,7 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
|
||||
Set<String> values = template.searchForSingleAttributeValues("ou=groups",
|
||||
"(member={0})", new String[] { param }, "cn");
|
||||
|
||||
assertEquals(1, values.size());
|
||||
assertThat(values).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -202,7 +202,7 @@ public class SpringSecurityLdapTemplateITests extends AbstractLdapIntegrationTes
|
||||
"ou=groups,dc=springframework,dc=org", "(member={0})",
|
||||
new String[] { param }, controls);
|
||||
|
||||
assertTrue("Expected a result", results.hasMore());
|
||||
assertThat(results.hasMore()).as("Expected a result").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.ldap.authentication;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.*;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
@@ -60,7 +60,7 @@ public class BindAuthenticatorTests extends AbstractLdapIntegrationTests {
|
||||
"cn={0},ou=people" });
|
||||
|
||||
DirContextOperations user = authenticator.authenticate(bob);
|
||||
assertEquals("bob", user.getStringAttribute("uid"));
|
||||
assertThat(user.getStringAttribute("uid")).isEqualTo("bob");
|
||||
authenticator.authenticate(new UsernamePasswordAuthenticationToken(
|
||||
"mouse, jerry", "jerryspassword"));
|
||||
}
|
||||
@@ -141,6 +141,6 @@ public class BindAuthenticatorTests extends AbstractLdapIntegrationTests {
|
||||
@Test
|
||||
public void testUserDnPatternReturnsCorrectDn() {
|
||||
authenticator.setUserDnPatterns(new String[] { "cn={0},ou=people" });
|
||||
assertEquals("cn=Joe,ou=people", authenticator.getUserDns("Joe").get(0));
|
||||
assertThat(authenticator.getUserDns("Joe").get(0)).isEqualTo("cn=Joe,ou=people");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.security.ldap.AbstractLdapIntegrationTests;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Tests for {@link PasswordComparisonAuthenticator}.
|
||||
@@ -59,7 +59,7 @@ public class PasswordComparisonAuthenticatorTests extends AbstractLdapIntegratio
|
||||
public void testAllAttributesAreRetrievedByDefault() {
|
||||
DirContextAdapter user = (DirContextAdapter) authenticator.authenticate(bob);
|
||||
// System.out.println(user.getAttributes().toString());
|
||||
assertEquals("User should have 5 attributes", 5, user.getAttributes().size());
|
||||
assertThat(user.getAttributes()).as("User should have 5 attributes").hasSize(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,7 +99,7 @@ public class PasswordComparisonAuthenticatorTests extends AbstractLdapIntegratio
|
||||
authenticator.setUserAttributes(new String[] { "uid", "userPassword" });
|
||||
|
||||
DirContextAdapter user = (DirContextAdapter) authenticator.authenticate(bob);
|
||||
assertEquals("Should have retrieved 2 attribute (uid, userPassword)", 2, user
|
||||
assertThat(userPassword).isEqualTo("Should have retrieved 2 attribute (uid)", 2, user
|
||||
.getAttributes().size());
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.ldap.search;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import javax.naming.ldap.LdapName;
|
||||
|
||||
@@ -41,9 +41,9 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
|
||||
locator.setDerefLinkFlag(false);
|
||||
|
||||
DirContextOperations bob = locator.searchForUser("bob");
|
||||
assertEquals("bob", bob.getStringAttribute("uid"));
|
||||
assertThat(bob.getStringAttribute("uid")).isEqualTo("bob");
|
||||
|
||||
assertEquals(new LdapName("uid=bob,ou=people"), bob.getDn());
|
||||
assertThat(bob.getDn()).isEqualTo(new LdapName("uid=bob,ou=people"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,9 +53,9 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
|
||||
locator.setSearchSubtree(false);
|
||||
|
||||
DirContextOperations jerry = locator.searchForUser("jerry");
|
||||
assertEquals("jerry", jerry.getStringAttribute("uid"));
|
||||
assertThat(jerry.getStringAttribute("uid")).isEqualTo("jerry");
|
||||
|
||||
assertEquals(new LdapName("cn=mouse\\, jerry,ou=people"), jerry.getDn());
|
||||
assertThat(jerry.getDn()).isEqualTo(new LdapName("cn=mouse\\, jerry,ou=people"));
|
||||
}
|
||||
|
||||
// Try some funny business with filters.
|
||||
@@ -68,7 +68,7 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
|
||||
|
||||
// Search for bob, get back ben...
|
||||
DirContextOperations ben = locator.searchForUser("bob");
|
||||
assertEquals("Ben Alex", ben.getStringAttribute("cn"));
|
||||
assertThat(ben.getStringAttribute("cn")).isEqualTo("Ben Alex");
|
||||
}
|
||||
|
||||
@Test(expected = IncorrectResultSizeDataAccessException.class)
|
||||
@@ -93,9 +93,9 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
|
||||
locator.setSearchSubtree(true);
|
||||
|
||||
DirContextOperations ben = locator.searchForUser("Ben Alex");
|
||||
assertEquals("ben", ben.getStringAttribute("uid"));
|
||||
assertThat(ben.getStringAttribute("uid")).isEqualTo("ben");
|
||||
|
||||
assertEquals(new LdapName("uid=ben,ou=people"), ben.getDn());
|
||||
assertThat(ben.getDn()).isEqualTo(new LdapName("uid=ben,ou=people"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,7 +103,7 @@ public class FilterBasedLdapUserSearchTests extends AbstractLdapIntegrationTests
|
||||
FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch(
|
||||
"ou=otherpeople", "(cn={0})", getContextSource());
|
||||
DirContextOperations joe = locator.searchForUser("Joe Smeth");
|
||||
assertEquals("Joe Smeth", joe.getStringAttribute("cn"));
|
||||
assertThat(joe.getStringAttribute("cn")).isEqualTo("Joe Smeth");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.ldap.userdetails;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.*;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
@@ -47,15 +47,15 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
|
||||
@Test
|
||||
public void defaultRoleIsAssignedWhenSet() {
|
||||
populator.setDefaultRole("ROLE_USER");
|
||||
assertSame(getContextSource(), populator.getContextSource());
|
||||
assertThat(populator.getContextSource()).isSameAs(getContextSource());
|
||||
|
||||
DirContextAdapter ctx = new DirContextAdapter(
|
||||
new DistinguishedName("cn=notfound"));
|
||||
|
||||
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx,
|
||||
"notfound");
|
||||
assertEquals(1, authorities.size());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER"));
|
||||
assertThat(authorities).hasSize(1);
|
||||
assertThat(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,8 +65,8 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
|
||||
|
||||
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(
|
||||
new DirContextAdapter(new DistinguishedName("cn=notused")), "notused");
|
||||
assertEquals(1, authorities.size());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER"));
|
||||
assertThat(authorities).hasSize(1);
|
||||
assertThat(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,10 +84,10 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
|
||||
Set<String> authorities = AuthorityUtils.authorityListToSet(populator
|
||||
.getGrantedAuthorities(ctx, "ben"));
|
||||
|
||||
assertEquals("Should have 2 roles", 2, authorities.size());
|
||||
assertThat(authorities).as("Should have 2 roles").hasSize(2);
|
||||
|
||||
assertTrue(authorities.contains("ROLE_DEVELOPER"));
|
||||
assertTrue(authorities.contains("ROLE_MANAGER"));
|
||||
assertThat(authorities.contains("ROLE_DEVELOPER")).isTrue();
|
||||
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,8 +102,8 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
|
||||
Set<String> authorities = AuthorityUtils.authorityListToSet(populator
|
||||
.getGrantedAuthorities(ctx, "manager"));
|
||||
|
||||
assertEquals("Should have 1 role", 1, authorities.size());
|
||||
assertTrue(authorities.contains("ROLE_MANAGER"));
|
||||
assertThat(authorities).as("Should have 1 role").hasSize(1);
|
||||
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,9 +117,9 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
|
||||
Set<String> authorities = AuthorityUtils.authorityListToSet(populator
|
||||
.getGrantedAuthorities(ctx, "manager"));
|
||||
|
||||
assertEquals("Should have 2 roles", 2, authorities.size());
|
||||
assertTrue(authorities.contains("ROLE_MANAGER"));
|
||||
assertTrue(authorities.contains("ROLE_DEVELOPER"));
|
||||
assertThat(authorities).as("Should have 2 roles").hasSize(2);
|
||||
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
|
||||
assertThat(authorities.contains("ROLE_DEVELOPER")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,10 +134,10 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
|
||||
Set<String> authorities = AuthorityUtils.authorityListToSet(populator
|
||||
.getGrantedAuthorities(ctx, "manager"));
|
||||
|
||||
assertEquals("Should have 3 roles", 3, authorities.size());
|
||||
assertTrue(authorities.contains("ROLE_MANAGER"));
|
||||
assertTrue(authorities.contains("ROLE_SUBMANAGER"));
|
||||
assertTrue(authorities.contains("ROLE_DEVELOPER"));
|
||||
assertThat(authorities).as("Should have 3 roles").hasSize(3);
|
||||
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
|
||||
assertThat(authorities.contains("ROLE_SUBMANAGER")).isTrue();
|
||||
assertThat(authorities.contains("ROLE_DEVELOPER")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -153,8 +153,8 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
|
||||
|
||||
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(
|
||||
new DirContextAdapter(new DistinguishedName("cn=notused")), "notused");
|
||||
assertEquals(1, authorities.size());
|
||||
assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_EXTRA"));
|
||||
assertThat(authorities).hasSize(1);
|
||||
assertThat(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_EXTRA")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,7 +169,7 @@ public class DefaultLdapAuthoritiesPopulatorTests extends AbstractLdapIntegratio
|
||||
Set<String> authorities = AuthorityUtils.authorityListToSet(populator
|
||||
.getGrantedAuthorities(ctx, "notused"));
|
||||
|
||||
assertEquals("Should have 1 role", 1, authorities.size());
|
||||
assertTrue(authorities.contains("ROLE_MANAGER"));
|
||||
assertThat(authorities).as("Should have 1 role").hasSize(1);
|
||||
assertThat(authorities.contains("ROLE_MANAGER")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
*/
|
||||
package org.springframework.security.ldap.userdetails;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -100,11 +100,11 @@ public class LdapUserDetailsManagerTests extends AbstractLdapIntegrationTests {
|
||||
mgr.setUsernameMapper(new DefaultLdapUsernameToDnMapper("ou=people", "uid"));
|
||||
mgr.setGroupSearchBase("ou=groups");
|
||||
LdapUserDetails bob = (LdapUserDetails) mgr.loadUserByUsername("bob");
|
||||
assertEquals("bob", bob.getUsername());
|
||||
assertEquals("uid=bob,ou=people,dc=springframework,dc=org", bob.getDn());
|
||||
assertEquals("bobspassword", bob.getPassword());
|
||||
assertThat(bob.getUsername()).isEqualTo("bob");
|
||||
assertThat(bob.getDn()).isEqualTo("uid=bob,ou=people,dc=springframework,dc=org");
|
||||
assertThat(bob.getPassword()).isEqualTo("bobspassword");
|
||||
|
||||
assertEquals(1, bob.getAuthorities().size());
|
||||
assertThat(bob.getAuthorities()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test(expected = UsernameNotFoundException.class)
|
||||
@@ -115,12 +115,12 @@ public class LdapUserDetailsManagerTests extends AbstractLdapIntegrationTests {
|
||||
@Test
|
||||
public void testUserExistsReturnsTrueForValidUser() {
|
||||
mgr.setUsernameMapper(new DefaultLdapUsernameToDnMapper("ou=people", "uid"));
|
||||
assertTrue(mgr.userExists("bob"));
|
||||
assertThat(mgr.userExists("bob")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserExistsReturnsFalseForInValidUser() {
|
||||
assertFalse(mgr.userExists("jim"));
|
||||
assertThat(mgr.userExists("jim")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -160,7 +160,7 @@ public class LdapUserDetailsManagerTests extends AbstractLdapIntegrationTests {
|
||||
|
||||
InetOrgPerson don = (InetOrgPerson) mgr.loadUserByUsername("don");
|
||||
|
||||
assertEquals(2, don.getAuthorities().size());
|
||||
assertThat(don.getAuthorities()).hasSize(2);
|
||||
|
||||
mgr.deleteUser("don");
|
||||
|
||||
@@ -173,7 +173,7 @@ public class LdapUserDetailsManagerTests extends AbstractLdapIntegrationTests {
|
||||
}
|
||||
|
||||
// Check that no authorities are left
|
||||
assertEquals(0, mgr.getUserAuthorities(mgr.usernameMapper.buildDn("don"), "don")
|
||||
assertThat("don").isEqualTo(0, mgr.getUserAuthorities(mgr.usernameMapper.buildDn("don"))
|
||||
.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* @author Filip Hanik
|
||||
@@ -71,7 +71,7 @@ public class NestedLdapAuthoritiesPopulatorTests extends AbstractLdapIntegration
|
||||
"uid=scaladude,ou=people,dc=springframework,dc=org");
|
||||
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx,
|
||||
"scaladude");
|
||||
assertEquals(5, authorities.size());
|
||||
assertThat(authorities).hasSize(5);
|
||||
assertEquals(Arrays.asList(javaDevelopers, scalaDevelopers,
|
||||
circularJavaDevelopers, jDevelopers, groovyDevelopers), authorities);
|
||||
}
|
||||
@@ -82,8 +82,8 @@ public class NestedLdapAuthoritiesPopulatorTests extends AbstractLdapIntegration
|
||||
"uid=javadude,ou=people,dc=springframework,dc=org");
|
||||
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx,
|
||||
"javadude");
|
||||
assertEquals(3, authorities.size());
|
||||
assertEquals(Arrays.asList(javaDevelopers, circularJavaDevelopers, jDevelopers),
|
||||
assertThat(authorities).hasSize(3);
|
||||
assertThat(circularJavaDevelopers).isCloseTo(Arrays.asList(javaDevelopers, within(jDevelopers)),
|
||||
authorities);
|
||||
}
|
||||
|
||||
@@ -94,8 +94,8 @@ public class NestedLdapAuthoritiesPopulatorTests extends AbstractLdapIntegration
|
||||
"uid=scaladude,ou=people,dc=springframework,dc=org");
|
||||
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx,
|
||||
"scaladude");
|
||||
assertEquals(1, authorities.size());
|
||||
assertEquals(Arrays.asList(scalaDevelopers), authorities);
|
||||
assertThat(authorities).hasSize(1);
|
||||
assertThat(authorities).isEqualTo(Arrays.asList(scalaDevelopers));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -104,7 +104,7 @@ public class NestedLdapAuthoritiesPopulatorTests extends AbstractLdapIntegration
|
||||
"uid=groovydude,ou=people,dc=springframework,dc=org");
|
||||
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx,
|
||||
"groovydude");
|
||||
assertEquals(4, authorities.size());
|
||||
assertThat(authorities).hasSize(4);
|
||||
assertEquals(Arrays.asList(javaDevelopers, circularJavaDevelopers, jDevelopers,
|
||||
groovyDevelopers), authorities);
|
||||
}
|
||||
@@ -117,34 +117,34 @@ public class NestedLdapAuthoritiesPopulatorTests extends AbstractLdapIntegration
|
||||
"uid=closuredude,ou=people,dc=springframework,dc=org");
|
||||
Collection<GrantedAuthority> authorities = populator.getGrantedAuthorities(ctx,
|
||||
"closuredude");
|
||||
assertEquals(5, authorities.size());
|
||||
assertThat(authorities).hasSize(5);
|
||||
assertEquals(Arrays.asList(closureDevelopers, javaDevelopers,
|
||||
circularJavaDevelopers, jDevelopers, groovyDevelopers), authorities);
|
||||
|
||||
LdapAuthority[] ldapAuthorities = authorities.toArray(new LdapAuthority[0]);
|
||||
assertEquals(5, ldapAuthorities.length);
|
||||
assertThat(ldapAuthorities.length).isEqualTo(5);
|
||||
// closure group
|
||||
assertTrue(ldapAuthorities[0].getAttributes().containsKey("member"));
|
||||
assertNotNull(ldapAuthorities[0].getAttributes().get("member"));
|
||||
assertEquals(1, ldapAuthorities[0].getAttributes().get("member").size());
|
||||
assertThat(ldapAuthorities[0].getAttributes().containsKey("member")).isTrue();
|
||||
assertThat(ldapAuthorities[0].getAttributes().get("member")).isNotNull();
|
||||
assertThat(ldapAuthorities[0].getAttributes().get("member")).hasSize(1);
|
||||
assertEquals("uid=closuredude,ou=people,dc=springframework,dc=org",
|
||||
ldapAuthorities[0].getFirstAttributeValue("member"));
|
||||
|
||||
// java group
|
||||
assertTrue(ldapAuthorities[1].getAttributes().containsKey("member"));
|
||||
assertNotNull(ldapAuthorities[1].getAttributes().get("member"));
|
||||
assertEquals(3, ldapAuthorities[1].getAttributes().get("member").size());
|
||||
assertThat(ldapAuthorities[1].getAttributes().containsKey("member")).isTrue();
|
||||
assertThat(ldapAuthorities[1].getAttributes().get("member")).isNotNull();
|
||||
assertThat(ldapAuthorities[1].getAttributes().get("member")).hasSize(3);
|
||||
assertEquals(groovyDevelopers.getDn(),
|
||||
ldapAuthorities[1].getFirstAttributeValue("member"));
|
||||
assertEquals(new String[] { groovyDevelopers.getDn(), scalaDevelopers.getDn(),
|
||||
assertThat(scalaDevelopers.getDn().isEqualTo(new String[] { groovyDevelopers.getDn()),
|
||||
"uid=javadude,ou=people,dc=springframework,dc=org" }, ldapAuthorities[1]
|
||||
.getAttributes().get("member"));
|
||||
|
||||
// test non existent attribute
|
||||
assertNull(ldapAuthorities[2].getFirstAttributeValue("test"));
|
||||
assertNotNull(ldapAuthorities[2].getAttributeValues("test"));
|
||||
assertEquals(0, ldapAuthorities[2].getAttributeValues("test").size());
|
||||
assertThat(ldapAuthorities[2].getFirstAttributeValue("test")).isNull();
|
||||
assertThat(ldapAuthorities[2].getAttributeValues("test")).isNotNull();
|
||||
assertThat(ldapAuthorities[2].getAttributeValues("test")).isEmpty();
|
||||
// test role name
|
||||
assertEquals(jDevelopers.getAuthority(), ldapAuthorities[3].getAuthority());
|
||||
assertThat(ldapAuthorities[3].getAuthority()).isEqualTo(jDevelopers.getAuthority());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user