Move test to assertj (#401)

This commit is contained in:
Eddú Meléndez Gonzales
2016-04-16 03:56:31 +10:00
committed by Rob Winch
parent 2a7e3eba0e
commit 64208a34ed
156 changed files with 3606 additions and 3570 deletions

View File

@@ -4,5 +4,6 @@ dependencies {
"org.springframework:spring-tx:$springVersion"
testCompile "junit:junit:$junitVersion",
"org.easymock:easymock:2.5.1"
}
"org.easymock:easymock:2.5.1",
"org.assertj:assertj-core:$assertjVersion"
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,12 +28,12 @@ import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for the {@link ContextMapperCallbackHandlerWithControlsTest}
* class.
*
*
* @author Ulrik Sandberg
*/
public class ContextMapperCallbackHandlerWithControlsTest {
@@ -78,7 +78,7 @@ public class ContextMapperCallbackHandlerWithControlsTest {
Object actualResult = tested.getObjectFromNameClassPair(expectedBinding);
verify(mapperMock);
assertEquals(expectedResult, actualResult);
assertThat(actualResult).isEqualTo(expectedResult);
}
@Test
@@ -93,7 +93,7 @@ public class ContextMapperCallbackHandlerWithControlsTest {
Object actualResult = tested.getObjectFromNameClassPair(expectedBinding);
verify(mapperMock);
assertEquals(expectedResult, actualResult);
assertThat(actualResult).isEqualTo(expectedResult);
}
@Test(expected = ObjectRetrievalException.class)

View File

@@ -30,5 +30,6 @@ dependencies {
"org.mockito:mockito-core:$mockitoVersion",
"org.slf4j:slf4j-log4j12:$slf4jVersion",
"org.springframework:spring-test:$springVersion",
"org.assertj:assertj-core:$assertjVersion",
powerMockDependencies
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,8 +49,8 @@ public class LdapTemplateLookupOpenLdapITest extends
DirContextAdapter result = (DirContextAdapter) tested
.lookup("cn=Some Person2, ou=company1,c=Sweden");
assertEquals("Some Person2", result.getStringAttribute("cn"));
assertEquals("Person2", result.getStringAttribute("sn"));
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2");
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
assertEquals("Sweden, Company1, Some Person2", result
.getStringAttribute("description"));
}
@@ -60,9 +60,9 @@ public class LdapTemplateLookupOpenLdapITest extends
Person person = (Person) tested.lookup(
"cn=Some Person2, ou=company1,c=Sweden", mapper);
assertEquals("Some Person2", person.getFullname());
assertEquals("Person2", person.getLastname());
assertEquals("Sweden, Company1, Some Person2", person.getDescription());
assertThat(person.getFullname()).isEqualTo("Some Person2");
assertThat(person.getLastname()).isEqualTo("Person2");
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
}
public void testLookup_AttributesMapper_DistinguishedName() {
@@ -70,9 +70,9 @@ public class LdapTemplateLookupOpenLdapITest extends
Person person = (Person) tested.lookup(new DistinguishedName(
"cn=Some Person2, ou=company1,c=Sweden"), mapper);
assertEquals("Some Person2", person.getFullname());
assertEquals("Person2", person.getLastname());
assertEquals("Sweden, Company1, Some Person2", person.getDescription());
assertThat(person.getFullname()).isEqualTo("Some Person2");
assertThat(person.getLastname()).isEqualTo("Person2");
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
}
/**
@@ -94,7 +94,7 @@ public class LdapTemplateLookupOpenLdapITest extends
throws NamingException {
Person person = new Person();
person.setFullname((String) attributes.get("cn").get());
assertNull("sn should be null", attributes.get("sn"));
assertThat(attributes.get("sn")).as("sn should be null").isNull();
assertNull("description should be null", attributes
.get("description"));
return person;
@@ -112,9 +112,9 @@ public class LdapTemplateLookupOpenLdapITest extends
"cn=Some Person2, ou=company1,c=Sweden", new String[] { "cn" },
mapper);
assertEquals("Some Person2", person.getFullname());
assertNull("lastName should not be set", person.getLastname());
assertNull("description should not be set", person.getDescription());
assertThat(person.getFullname()).isEqualTo("Some Person2");
assertThat(person.getLastname()).as("lastName should not be set").isNull();
assertThat(person.getDescription()).as("description should not be set").isNull();
}
/**
@@ -128,9 +128,9 @@ public class LdapTemplateLookupOpenLdapITest extends
"cn=Some Person2, ou=company1,c=Sweden"),
new String[] { "cn" }, mapper);
assertEquals("Some Person2", person.getFullname());
assertNull("lastName should not be set", person.getLastname());
assertNull("description should not be set", person.getDescription());
assertThat(person.getFullname()).isEqualTo("Some Person2");
assertThat(person.getLastname()).as("lastName should not be set").isNull();
assertThat(person.getDescription()).as("description should not be set").isNull();
}
/**
@@ -142,9 +142,9 @@ public class LdapTemplateLookupOpenLdapITest extends
Person person = (Person) tested.lookup(
"cn=Some Person2, ou=company1,c=Sweden", mapper);
assertEquals("Some Person2", person.getFullname());
assertEquals("Person2", person.getLastname());
assertEquals("Sweden, Company1, Some Person2", person.getDescription());
assertThat(person.getFullname()).isEqualTo("Some Person2");
assertThat(person.getLastname()).isEqualTo("Person2");
assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2");
}
/**
@@ -158,9 +158,9 @@ public class LdapTemplateLookupOpenLdapITest extends
"cn=Some Person2, ou=company1,c=Sweden", new String[] { "cn" },
mapper);
assertEquals("Some Person2", person.getFullname());
assertNull("lastName should not be set", person.getLastname());
assertNull("description should not be set", person.getDescription());
assertThat(person.getFullname()).isEqualTo("Some Person2");
assertThat(person.getLastname()).as("lastName should not be set").isNull();
assertThat(person.getDescription()).as("description should not be set").isNull();
}
/**
@@ -172,8 +172,8 @@ public class LdapTemplateLookupOpenLdapITest extends
Person person = (Person) tested.lookup(
"cn=Some Person+sn=Person, ou=company1,c=Norway", mapper);
assertEquals("Some Person", person.getFullname());
assertEquals("Person", person.getLastname());
assertThat(person.getFullname()).isEqualTo("Some Person");
assertThat(person.getLastname()).isEqualTo("Person");
assertEquals("Norway, Company1, Some Person+Person", person
.getDescription());
}
@@ -186,8 +186,8 @@ public class LdapTemplateLookupOpenLdapITest extends
DirContextAdapter result = (DirContextAdapter) tested
.lookup("cn=Some Person+sn=Person, ou=company1,c=Norway");
assertEquals("Some Person", result.getStringAttribute("cn"));
assertEquals("Person", result.getStringAttribute("sn"));
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person");
assertThat(result.getStringAttribute("sn")).isEqualTo("Person");
assertEquals("Norway, Company1, Some Person+Person", result
.getStringAttribute("description"));
}
@@ -196,7 +196,7 @@ public class LdapTemplateLookupOpenLdapITest extends
DirContextAdapter result = (DirContextAdapter) tested
.lookup("cn=Some Person2, ou=company1,c=Sweden");
assertEquals("cn=Some Person2, ou=company1, c=Sweden", result.getDn()
assertThat(result.getDn().isEqualTo("cn=Some Person2, ou=company1, c=Sweden")
.toString());
assertEquals(
"cn=Some Person2, ou=company1, c=Sweden, dc=jayway, dc=se",

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -90,31 +90,31 @@ public class LdapTemplatePagedSearchITest extends
requestControl = new PagedResultsRequestControl(3);
tested.search(searchExecutor, callbackHandler, requestControl);
cookie = requestControl.getCookie();
assertNotNull("Cookie should not be null yet", cookie.getCookie());
assertThat(cookie.getCookie()).as("Cookie should not be null yet").isNotNull();
list = callbackHandler.getList();
assertEquals(3, list.size());
assertThat(list).hasSize(3);
person = (Person) list.get(0);
assertEquals("Some Person", person.getFullname());
assertEquals("+46 555-123456", person.getPhone());
assertThat(person.getFullname()).isEqualTo("Some Person");
assertThat(person.getPhone()).isEqualTo("+46 555-123456");
person = (Person) list.get(1);
assertEquals("Some Person2", person.getFullname());
assertEquals("+46 555-654321", person.getPhone());
assertThat(person.getFullname()).isEqualTo("Some Person2");
assertThat(person.getPhone()).isEqualTo("+46 555-654321");
person = (Person) list.get(2);
assertEquals("Some Person3", person.getFullname());
assertEquals("+46 555-123654", person.getPhone());
assertThat(person.getFullname()).isEqualTo("Some Person3");
assertThat(person.getPhone()).isEqualTo("+46 555-123654");
// Prepare for second and last search
requestControl = new PagedResultsRequestControl(3, cookie);
tested.search(searchExecutor, callbackHandler, requestControl);
cookie = requestControl.getCookie();
assertNull("Cookie should be null now", cookie.getCookie());
assertEquals(5, list.size());
assertThat(cookie.getCookie()).as("Cookie should be null now").isNull();
assertThat(list).hasSize(5);
person = (Person) list.get(3);
assertEquals("Some Person", person.getFullname());
assertEquals("+46 555-456321", person.getPhone());
assertThat(person.getFullname()).isEqualTo("Some Person");
assertThat(person.getPhone()).isEqualTo("+46 555-456321");
person = (Person) list.get(4);
assertEquals("Some Person", person.getFullname());
assertEquals("+45 555-654123", person.getPhone());
assertThat(person.getFullname()).isEqualTo("Some Person");
assertThat(person.getPhone()).isEqualTo("+45 555-654123");
}
public void testSearch_PagedResult_ConvenienceMethod() {
@@ -128,27 +128,27 @@ public class LdapTemplatePagedSearchITest extends
tested.search(BASE, FILTER_STRING, searchControls,
callbackHandler, requestControl);
cookie = requestControl.getCookie();
assertNotNull("Cookie should not be null yet", cookie.getCookie());
assertThat(cookie.getCookie()).as("Cookie should not be null yet").isNotNull();
list = callbackHandler.getList();
assertEquals(3, list.size());
assertThat(list).hasSize(3);
person = (Person) list.get(0);
assertEquals("Some Person", person.getFullname());
assertThat(person.getFullname()).isEqualTo("Some Person");
person = (Person) list.get(1);
assertEquals("Some Person2", person.getFullname());
assertThat(person.getFullname()).isEqualTo("Some Person2");
person = (Person) list.get(2);
assertEquals("Some Person3", person.getFullname());
assertThat(person.getFullname()).isEqualTo("Some Person3");
// Prepare for second and last search
requestControl = new PagedResultsRequestControl(3, cookie);
tested.search(BASE, FILTER_STRING, searchControls,
callbackHandler, requestControl);
cookie = requestControl.getCookie();
assertNull("Cookie should be null now", cookie.getCookie());
assertEquals(5, list.size());
assertThat(cookie.getCookie()).as("Cookie should be null now").isNull();
assertThat(list).hasSize(5);
person = (Person) list.get(3);
assertEquals("Some Person", person.getFullname());
assertThat(person.getFullname()).isEqualTo("Some Person");
person = (Person) list.get(4);
assertEquals("Some Person", person.getFullname());
assertThat(person.getFullname()).isEqualTo("Some Person");
}
public void setTested(LdapTemplate tested) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,7 +84,7 @@ public class LdapTemplateSortedSearchITest extends
tested.search(searchExecutor, callbackHandler, requestControl);
int resultCode = requestControl.getResultCode();
boolean sorted = requestControl.isSorted();
assertTrue("Search result should have been sorted: " + resultCode, sorted);
assertThat("Search result should have been sorted: " + resultCode, sorted).isTrue();
List list = callbackHandler.getList();
assertSortedList(list);
}
@@ -98,26 +98,26 @@ public class LdapTemplateSortedSearchITest extends
requestControl);
int resultCode = requestControl.getResultCode();
boolean sorted = requestControl.isSorted();
assertTrue("Search result should have been sorted: " + resultCode, sorted);
assertThat("Search result should have been sorted: " + resultCode, sorted).isTrue();
List list = callbackHandler.getList();
assertSortedList(list);
}
private void assertSortedList(List list) {
Person person;
assertEquals(6, list.size());
assertThat(list).hasSize(6);
person = (Person) list.get(0);
assertEquals("Goran Milenkovic", person.getFullname());
assertThat(person.getFullname()).isEqualTo("Goran Milenkovic");
person = (Person) list.get(1);
assertEquals("Goran Sundberg", person.getFullname());
assertThat(person.getFullname()).isEqualTo("Goran Sundberg");
person = (Person) list.get(2);
assertEquals("Goran Westerberg", person.getFullname());
assertThat(person.getFullname()).isEqualTo("Goran Westerberg");
person = (Person) list.get(3);
assertEquals("Gorana Milicevic", person.getFullname());
assertThat(person.getFullname()).isEqualTo("Gorana Milicevic");
person = (Person) list.get(4);
assertEquals("Gordana Canic", person.getFullname());
assertThat(person.getFullname()).isEqualTo("Gordana Canic");
person = (Person) list.get(5);
assertEquals("Gordana Russ", person.getFullname());
assertThat(person.getFullname()).isEqualTo("Gordana Russ");
}
public void setTested(LdapTemplate tested) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,9 +19,8 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.ldap.core.AuthenticationSource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -49,7 +48,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest {
when(authenticationSourceMock.getPrincipal()).thenReturn("cn=someUser");
String principal = tested.getPrincipal();
assertEquals("cn=someUser", principal);
assertThat(principal).isEqualTo("cn=someUser");
}
@Test
@@ -58,7 +57,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest {
String principal = tested.getPrincipal();
assertEquals(DEFAULT_USER, principal);
assertThat(principal).isEqualTo(DEFAULT_USER);
}
@Test
@@ -68,7 +67,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest {
String credentials = tested.getCredentials();
assertEquals("somepassword", credentials);
assertThat(credentials).isEqualTo("somepassword");
}
@Test
@@ -78,7 +77,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest {
String credentials = tested.getCredentials();
assertEquals(DEFAULT_PASSWORD, credentials);
assertThat(credentials).isEqualTo(DEFAULT_PASSWORD);
}
@Test
@@ -88,7 +87,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest {
tested.afterPropertiesSet();
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -99,7 +98,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest {
tested.afterPropertiesSet();
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -110,7 +109,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest {
tested.afterPropertiesSet();
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2015 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,11 +47,7 @@ import java.lang.management.ManagementFactory;
import java.util.Set;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.internal.util.reflection.Whitebox.getInternalState;
/**
@@ -65,26 +61,26 @@ public class LdapTemplateNamespaceHandlerTest {
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
LdapTemplate ldapTemplate = ctx.getBean(LdapTemplate.class);
assertNotNull(outerContextSource);
assertNotNull(ldapTemplate);
assertThat(outerContextSource).isNotNull();
assertThat(ldapTemplate).isNotNull();
assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy);
assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();
ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertEquals(LdapUtils.emptyLdapName(), getInternalState(contextSource, "base"));
assertEquals("uid=admin", getInternalState(contextSource, "userDn"));
assertEquals("apassword", getInternalState(contextSource, "password"));
assertArrayEquals(new String[]{"ldap://localhost:389"}, (Object[]) getInternalState(contextSource, "urls"));
assertEquals(Boolean.FALSE, getInternalState(contextSource, "pooled"));
assertEquals(Boolean.FALSE, getInternalState(contextSource, "anonymousReadOnly"));
assertNull(getInternalState(contextSource, "referral"));
assertThat(LdapUtils.emptyLdapName()).isEqualTo(getInternalState(contextSource, "base"));
assertThat("uid=admin").isEqualTo(getInternalState(contextSource, "userDn"));
assertThat("apassword").isEqualTo(getInternalState(contextSource, "password"));
assertThat(new String[]{"ldap://localhost:389"}).isEqualTo((Object[]) getInternalState(contextSource, "urls"));
assertThat(Boolean.FALSE).isEqualTo(getInternalState(contextSource, "pooled"));
assertThat(Boolean.FALSE).isEqualTo(getInternalState(contextSource, "anonymousReadOnly"));
assertThat(getInternalState(contextSource, "referral")).isNull();
assertSame(outerContextSource, getInternalState(ldapTemplate, "contextSource"));
assertEquals(Boolean.FALSE, getInternalState(ldapTemplate, "ignorePartialResultException"));
assertEquals(Boolean.FALSE, getInternalState(ldapTemplate, "ignoreNameNotFoundException"));
assertEquals(0, getInternalState(ldapTemplate, "defaultCountLimit"));
assertEquals(0, getInternalState(ldapTemplate, "defaultTimeLimit"));
assertEquals(SearchControls.SUBTREE_SCOPE, getInternalState(ldapTemplate, "defaultSearchScope"));
assertThat(outerContextSource).isSameAs(getInternalState(ldapTemplate, "contextSource"));
assertThat(Boolean.FALSE).isEqualTo(getInternalState(ldapTemplate, "ignorePartialResultException"));
assertThat(Boolean.FALSE).isEqualTo(getInternalState(ldapTemplate, "ignoreNameNotFoundException"));
assertThat(0).isEqualTo(getInternalState(ldapTemplate, "defaultCountLimit"));
assertThat(0).isEqualTo(getInternalState(ldapTemplate, "defaultTimeLimit"));
assertThat(SearchControls.SUBTREE_SCOPE).isEqualTo(getInternalState(ldapTemplate, "defaultSearchScope"));
}
@Test
@@ -92,9 +88,9 @@ public class LdapTemplateNamespaceHandlerTest {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-anonymous-read-only.xml");
ContextSource contextSource = ctx.getBean(ContextSource.class);
assertNotNull(contextSource);
assertTrue(contextSource instanceof LdapContextSource);
assertEquals(Boolean.TRUE, getInternalState(contextSource, "anonymousReadOnly"));
assertThat(contextSource).isNotNull();
assertThat(contextSource instanceof LdapContextSource).isTrue();
assertThat(Boolean.TRUE).isEqualTo(getInternalState(contextSource, "anonymousReadOnly"));
}
@Test(expected = BeansException.class)
@@ -120,14 +116,14 @@ public class LdapTemplateNamespaceHandlerTest {
DirContextAuthenticationStrategy authenticationStrategy = ctx.getBean(DirContextAuthenticationStrategy.class);
Object baseEnv = ctx.getBean("baseEnvProps");
assertNotNull(outerContextSource);
assertThat(outerContextSource).isNotNull();
assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy);
assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();
ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertSame(authenticationSource, getInternalState(contextSource, "authenticationSource"));
assertSame(authenticationStrategy, getInternalState(contextSource, "authenticationStrategy"));
assertEquals(baseEnv, getInternalState(contextSource, "baseEnv"));
assertThat(authenticationSource).isSameAs(getInternalState(contextSource, "authenticationSource"));
assertThat(authenticationStrategy).isSameAs(getInternalState(contextSource, "authenticationStrategy"));
assertThat(baseEnv).isEqualTo(getInternalState(contextSource, "baseEnv"));
}
@Test
@@ -137,27 +133,27 @@ public class LdapTemplateNamespaceHandlerTest {
LdapTemplate ldapTemplate = ctx.getBean(LdapTemplate.class);
DirContextAuthenticationStrategy authenticationStrategy = ctx.getBean(DirContextAuthenticationStrategy.class);
assertNotNull(outerContextSource);
assertNotNull(ldapTemplate);
assertThat(outerContextSource).isNotNull();
assertThat(ldapTemplate).isNotNull();
assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy);
assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();
ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertEquals(LdapUtils.newLdapName("dc=261consulting,dc=com"), getInternalState(contextSource, "base"));
assertEquals("uid=admin", getInternalState(contextSource, "userDn"));
assertEquals("apassword", getInternalState(contextSource, "password"));
assertArrayEquals(new String[]{"ldap://localhost:389"}, (Object[]) getInternalState(contextSource, "urls"));
assertEquals(Boolean.TRUE, getInternalState(contextSource, "pooled"));
assertEquals(Boolean.FALSE, getInternalState(contextSource, "anonymousReadOnly"));
assertEquals("follow", getInternalState(contextSource, "referral"));
assertSame(authenticationStrategy, getInternalState(contextSource, "authenticationStrategy"));
assertThat(LdapUtils.newLdapName("dc=261consulting,dc=com")).isEqualTo(getInternalState(contextSource, "base"));
assertThat("uid=admin").isEqualTo(getInternalState(contextSource, "userDn"));
assertThat("apassword").isEqualTo(getInternalState(contextSource, "password"));
assertThat(new String[]{"ldap://localhost:389"}).isEqualTo((Object[]) getInternalState(contextSource, "urls"));
assertThat(Boolean.TRUE).isEqualTo(getInternalState(contextSource, "pooled"));
assertThat(Boolean.FALSE).isEqualTo(getInternalState(contextSource, "anonymousReadOnly"));
assertThat("follow").isEqualTo(getInternalState(contextSource, "referral"));
assertThat(authenticationStrategy).isSameAs(getInternalState(contextSource, "authenticationStrategy"));
assertSame(outerContextSource, getInternalState(ldapTemplate, "contextSource"));
assertEquals(Boolean.TRUE, getInternalState(ldapTemplate, "ignorePartialResultException"));
assertEquals(Boolean.TRUE, getInternalState(ldapTemplate, "ignoreNameNotFoundException"));
assertEquals(100, getInternalState(ldapTemplate, "defaultCountLimit"));
assertEquals(200, getInternalState(ldapTemplate, "defaultTimeLimit"));
assertEquals(SearchControls.OBJECT_SCOPE, getInternalState(ldapTemplate, "defaultSearchScope"));
assertThat(outerContextSource).isSameAs(getInternalState(ldapTemplate, "contextSource"));
assertThat(Boolean.TRUE).isEqualTo(getInternalState(ldapTemplate, "ignorePartialResultException"));
assertThat(Boolean.TRUE).isEqualTo(getInternalState(ldapTemplate, "ignoreNameNotFoundException"));
assertThat(100).isEqualTo(getInternalState(ldapTemplate, "defaultCountLimit"));
assertThat(200).isEqualTo(getInternalState(ldapTemplate, "defaultTimeLimit"));
assertThat(SearchControls.OBJECT_SCOPE).isEqualTo(getInternalState(ldapTemplate, "defaultSearchScope"));
}
@Test
@@ -165,15 +161,15 @@ public class LdapTemplateNamespaceHandlerTest {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-spel.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
assertThat(outerContextSource).isNotNull();
assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy);
assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();
ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertEquals(LdapUtils.newLdapName("dc=261consulting,dc=com"), getInternalState(contextSource, "base"));
assertEquals("uid=admin", getInternalState(contextSource, "userDn"));
assertEquals("apassword", getInternalState(contextSource, "password"));
assertArrayEquals(new String[]{"ldap://localhost:389"}, (Object[]) getInternalState(contextSource, "urls"));
assertThat(LdapUtils.newLdapName("dc=261consulting,dc=com")).isEqualTo(getInternalState(contextSource, "base"));
assertThat("uid=admin").isEqualTo(getInternalState(contextSource, "userDn"));
assertThat("apassword").isEqualTo(getInternalState(contextSource, "password"));
assertThat(new String[]{"ldap://localhost:389"}).isEqualTo((Object[]) getInternalState(contextSource, "urls"));
}
@@ -182,9 +178,9 @@ public class LdapTemplateNamespaceHandlerTest {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-spel-multiurls.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
assertThat(outerContextSource).isNotNull();
assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy);
assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();
ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertArrayEquals(new String[] { "ldap://a.localhost:389", "ldap://b.localhost:389" },
@@ -197,9 +193,9 @@ public class LdapTemplateNamespaceHandlerTest {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-multiurls.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
assertThat(outerContextSource).isNotNull();
assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy);
assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();
ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertArrayEquals(new String[] { "ldap://a.localhost:389", "ldap://b.localhost:389" },
@@ -214,21 +210,21 @@ public class LdapTemplateNamespaceHandlerTest {
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
PlatformTransactionManager transactionManager = ctx.getBean(PlatformTransactionManager.class);
assertNotNull(outerContextSource);
assertNotNull(transactionManager);
assertThat(outerContextSource).isNotNull();
assertThat(transactionManager).isNotNull();
assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy);
assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();
ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertTrue(transactionManager instanceof ContextSourceTransactionManager);
assertThat(transactionManager instanceof ContextSourceTransactionManager).isTrue();
Object delegate = getInternalState(transactionManager, "delegate");
assertSame(contextSource, getInternalState(delegate, "contextSource"));
assertThat(contextSource).isSameAs(getInternalState(delegate, "contextSource"));
TempEntryRenamingStrategy renamingStrategy =
(TempEntryRenamingStrategy) getInternalState(delegate, "renamingStrategy");
assertTrue(renamingStrategy instanceof DefaultTempEntryRenamingStrategy);
assertEquals("_temp", getInternalState(renamingStrategy, "tempSuffix"));
assertThat(renamingStrategy instanceof DefaultTempEntryRenamingStrategy).isTrue();
assertThat("_temp").isEqualTo(getInternalState(renamingStrategy, "tempSuffix"));
}
@Test
@@ -236,7 +232,7 @@ public class LdapTemplateNamespaceHandlerTest {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-transactional-datasource.xml");
PlatformTransactionManager transactionManager = ctx.getBean(PlatformTransactionManager.class);
assertTrue(transactionManager instanceof ContextSourceAndDataSourceTransactionManager);
assertThat(transactionManager instanceof ContextSourceAndDataSourceTransactionManager).isTrue();
}
@Test
@@ -245,15 +241,15 @@ public class LdapTemplateNamespaceHandlerTest {
PlatformTransactionManager transactionManager = ctx.getBean(PlatformTransactionManager.class);
assertNotNull(transactionManager);
assertTrue(transactionManager instanceof ContextSourceTransactionManager);
assertThat(transactionManager).isNotNull();
assertThat(transactionManager instanceof ContextSourceTransactionManager).isTrue();
Object delegate = getInternalState(transactionManager, "delegate");
TempEntryRenamingStrategy renamingStrategy =
(TempEntryRenamingStrategy) getInternalState(delegate, "renamingStrategy");
assertTrue(renamingStrategy instanceof DefaultTempEntryRenamingStrategy);
assertEquals("_thisisthesuffix", getInternalState(renamingStrategy, "tempSuffix"));
assertThat(renamingStrategy instanceof DefaultTempEntryRenamingStrategy).isTrue();
assertThat("_thisisthesuffix").isEqualTo(getInternalState(renamingStrategy, "tempSuffix"));
}
@Test
@@ -262,15 +258,15 @@ public class LdapTemplateNamespaceHandlerTest {
PlatformTransactionManager transactionManager = ctx.getBean(PlatformTransactionManager.class);
assertNotNull(transactionManager);
assertTrue(transactionManager instanceof ContextSourceTransactionManager);
assertThat(transactionManager).isNotNull();
assertThat(transactionManager instanceof ContextSourceTransactionManager).isTrue();
Object delegate = getInternalState(transactionManager, "delegate");
TempEntryRenamingStrategy renamingStrategy =
(TempEntryRenamingStrategy) getInternalState(delegate, "renamingStrategy");
assertTrue(renamingStrategy instanceof DifferentSubtreeTempEntryRenamingStrategy);
assertEquals(LdapUtils.newLdapName("ou=temp"), getInternalState(renamingStrategy, "subtreeNode"));
assertThat(renamingStrategy instanceof DifferentSubtreeTempEntryRenamingStrategy).isTrue();
assertThat(LdapUtils.newLdapName("ou=temp")).isEqualTo(getInternalState(renamingStrategy, "subtreeNode"));
}
@Test
@@ -279,28 +275,28 @@ public class LdapTemplateNamespaceHandlerTest {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-defaults.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy);
assertThat(outerContextSource).isNotNull();
assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();
ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertNotNull(pooledContextSource);
assertTrue(pooledContextSource instanceof PoolingContextSource);
assertThat(pooledContextSource).isNotNull();
assertThat(pooledContextSource instanceof PoolingContextSource).isTrue();
Object objectFactory = getInternalState(pooledContextSource, "dirContextPoolableObjectFactory");
assertNotNull(getInternalState(objectFactory, "contextSource"));
assertNull(getInternalState(objectFactory, "dirContextValidator"));
assertThat(getInternalState(objectFactory, "contextSource")).isNotNull();
assertThat(getInternalState(objectFactory, "dirContextValidator")).isNull();
Set<Class<? extends Throwable>> nonTransientExceptions =
(Set<Class<? extends Throwable>>) getInternalState(objectFactory, "nonTransientExceptions");
assertEquals(1, nonTransientExceptions.size());
assertTrue(nonTransientExceptions.contains(CommunicationException.class));
assertThat(nonTransientExceptions).hasSize(1);
assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue();
GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
assertEquals(8, objectPool.getMaxActive());
assertEquals(-1, objectPool.getMaxTotal());
assertEquals(8, objectPool.getMaxIdle());
assertEquals(-1, objectPool.getMaxWait());
assertEquals(0, objectPool.getMinIdle());
assertEquals(1, objectPool.getWhenExhaustedAction());
assertThat(objectPool.getMaxActive()).isEqualTo(8);
assertThat(objectPool.getMaxTotal()).isEqualTo(-1);
assertThat(objectPool.getMaxIdle()).isEqualTo(8);
assertThat(objectPool.getMaxWait()).isEqualTo(-1);
assertThat(objectPool.getMinIdle()).isEqualTo(0);
assertThat(objectPool.getWhenExhaustedAction()).isEqualTo((byte)1);
}
@Test
@@ -308,18 +304,18 @@ public class LdapTemplateNamespaceHandlerTest {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-configured-poolsize.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
assertThat(outerContextSource).isNotNull();
ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertNotNull(pooledContextSource);
assertThat(pooledContextSource).isNotNull();
GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
assertEquals(10, objectPool.getMaxActive());
assertEquals(12, objectPool.getMaxTotal());
assertEquals(11, objectPool.getMaxIdle());
assertEquals(13, objectPool.getMaxWait());
assertEquals(14, objectPool.getMinIdle());
assertEquals(0, objectPool.getWhenExhaustedAction());
assertThat(objectPool.getMaxActive()).isEqualTo(10);
assertThat(objectPool.getMaxTotal()).isEqualTo(12);
assertThat(objectPool.getMaxIdle()).isEqualTo(11);
assertThat(objectPool.getMaxWait()).isEqualTo(13);
assertThat(objectPool.getMinIdle()).isEqualTo(14);
assertThat(objectPool.getWhenExhaustedAction()).isEqualTo((byte)0);
}
@Test
@@ -328,30 +324,30 @@ public class LdapTemplateNamespaceHandlerTest {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-test-specified.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
assertThat(outerContextSource).isNotNull();
ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertNotNull(pooledContextSource);
assertThat(pooledContextSource).isNotNull();
GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
assertEquals(123, objectPool.getMinEvictableIdleTimeMillis());
assertEquals(321, objectPool.getTimeBetweenEvictionRunsMillis());
assertEquals(22, objectPool.getNumTestsPerEvictionRun());
assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(123);
assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(321);
assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(22);
Object objectFactory = getInternalState(pooledContextSource, "dirContextPoolableObjectFactory");
DefaultDirContextValidator validator = (DefaultDirContextValidator) getInternalState(objectFactory, "dirContextValidator");
assertEquals("ou=test", validator.getBase());
assertEquals("objectclass=person", validator.getFilter());
assertThat(validator.getBase()).isEqualTo("ou=test");
assertThat(validator.getFilter()).isEqualTo("objectclass=person");
SearchControls searchControls = ctx.getBean(SearchControls.class);
assertEquals("objectclass=person", validator.getFilter());
assertSame(searchControls, validator.getSearchControls());
assertThat(validator.getFilter()).isEqualTo("objectclass=person");
assertThat(validator.getSearchControls()).isSameAs(searchControls);
Set<Class<? extends Throwable>> nonTransientExceptions =
(Set<Class<? extends Throwable>>) getInternalState(objectFactory, "nonTransientExceptions");
assertEquals(2, nonTransientExceptions.size());
assertTrue(nonTransientExceptions.contains(CommunicationException.class));
assertTrue(nonTransientExceptions.contains(CannotProceedException.class));
assertThat(nonTransientExceptions).hasSize(2);
assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue();
assertThat(nonTransientExceptions.contains(CannotProceedException.class)).isTrue();
}
@Test(expected = BeansException.class)
@@ -364,7 +360,7 @@ public class LdapTemplateNamespaceHandlerTest {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-with-repositories.xml");
DummyLdapRepository repository = ctx.getBean(DummyLdapRepository.class);
assertNotNull(repository);
assertThat(repository).isNotNull();
}
@Test
@@ -372,48 +368,48 @@ public class LdapTemplateNamespaceHandlerTest {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling2-defaults.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy);
assertThat(outerContextSource).isNotNull();
assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();
ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertNotNull(pooledContextSource);
assertTrue(pooledContextSource instanceof PooledContextSource);
assertNotNull(getInternalState(pooledContextSource, "poolConfig"));
assertThat(pooledContextSource).isNotNull();
assertThat(pooledContextSource instanceof PooledContextSource).isTrue();
assertThat(getInternalState(pooledContextSource, "poolConfig")).isNotNull();
Object objectFactory = getInternalState(pooledContextSource, "dirContextPooledObjectFactory");
assertNotNull(getInternalState(objectFactory, "contextSource"));
assertNull(getInternalState(objectFactory, "dirContextValidator"));
assertThat(getInternalState(objectFactory, "contextSource")).isNotNull();
assertThat(getInternalState(objectFactory, "dirContextValidator")).isNull();
Set<Class<? extends Throwable>> nonTransientExceptions =
(Set<Class<? extends Throwable>>) getInternalState(objectFactory, "nonTransientExceptions");
assertEquals(1, nonTransientExceptions.size());
assertTrue(nonTransientExceptions.contains(CommunicationException.class));
assertThat(nonTransientExceptions).hasSize(1);
assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue();
org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool =
(org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
assertEquals(8, objectPool.getMaxIdlePerKey());
assertEquals(-1, objectPool.getMaxTotal());
assertEquals(8, objectPool.getMaxTotalPerKey());
assertEquals(0, objectPool.getMinIdlePerKey());
assertEquals(true, objectPool.getBlockWhenExhausted());
assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME, objectPool.getEvictionPolicyClassName());
assertEquals(false, objectPool.getFairness());
assertThat(objectPool.getMaxIdlePerKey()).isEqualTo(8);
assertThat(objectPool.getMaxTotal()).isEqualTo(-1);
assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(8);
assertThat(objectPool.getMinIdlePerKey()).isEqualTo(0);
assertThat(objectPool.getBlockWhenExhausted()).isEqualTo(true);
assertThat(objectPool.getEvictionPolicyClassName()).isEqualTo(GenericKeyedObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME);
assertThat(objectPool.getFairness()).isEqualTo(false);
// ensures the pool is registered
ObjectName oname = objectPool.getJmxName();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> result = mbs.queryNames(oname, null);
assertEquals(1, result.size());
assertThat(result).hasSize(1);
assertEquals(true, objectPool.getLifo());
assertEquals(-1L, objectPool.getMaxWaitMillis());
assertEquals(1000L*60L*30L, objectPool.getMinEvictableIdleTimeMillis());
assertEquals(3, objectPool.getNumTestsPerEvictionRun());
assertEquals(-1L, objectPool.getSoftMinEvictableIdleTimeMillis());
assertEquals(-1L, objectPool.getTimeBetweenEvictionRunsMillis());
assertEquals(false, objectPool.getTestOnBorrow());
assertEquals(false, objectPool.getTestOnCreate());
assertEquals(false, objectPool.getTestOnReturn());
assertEquals(false, objectPool.getTestWhileIdle());
assertThat(objectPool.getLifo()).isEqualTo(true);
assertThat(objectPool.getMaxWaitMillis()).isEqualTo(-1L);
assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(1000L*60L*30L);
assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(3);
assertThat(objectPool.getSoftMinEvictableIdleTimeMillis()).isEqualTo(-1L);
assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(-1L);
assertThat(objectPool.getTestOnBorrow()).isEqualTo(false);
assertThat(objectPool.getTestOnCreate()).isEqualTo(false);
assertThat(objectPool.getTestOnReturn()).isEqualTo(false);
assertThat(objectPool.getTestWhileIdle()).isEqualTo(false);
}
@Test
@@ -421,29 +417,29 @@ public class LdapTemplateNamespaceHandlerTest {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-configured-poolsize.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
assertThat(outerContextSource).isNotNull();
ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertNotNull(pooledContextSource);
assertThat(pooledContextSource).isNotNull();
org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool =
(org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
assertEquals(12, objectPool.getMaxTotal());
assertEquals(20, objectPool.getMaxIdlePerKey());
assertEquals(10, objectPool.getMaxTotalPerKey());
assertEquals(13, objectPool.getMaxWaitMillis());
assertEquals(14, objectPool.getMinIdlePerKey());
assertEquals(true, objectPool.getBlockWhenExhausted());
assertEquals("org.springframework.ldap.pool2.DummyEvictionPolicy", objectPool.getEvictionPolicyClassName());
assertEquals(true, objectPool.getFairness());
assertEquals(false, objectPool.getLifo());
assertThat(objectPool.getMaxTotal()).isEqualTo(12);
assertThat(objectPool.getMaxIdlePerKey()).isEqualTo(20);
assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(10);
assertThat(objectPool.getMaxWaitMillis()).isEqualTo(13);
assertThat(objectPool.getMinIdlePerKey()).isEqualTo(14);
assertThat(objectPool.getBlockWhenExhausted()).isEqualTo(true);
assertThat(objectPool.getEvictionPolicyClassName()).isEqualTo("org.springframework.ldap.pool2.DummyEvictionPolicy");
assertThat(objectPool.getFairness()).isEqualTo(true);
assertThat(objectPool.getLifo()).isEqualTo(false);
// ensures the pool is registered
ObjectName oname = objectPool.getJmxName();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> result = mbs.queryNames(oname, null);
assertEquals(1, result.size());
assertEquals("org.springframework.ldap.pool2:type=ldap-pool,name=test-pool", oname.toString());
assertThat(result).hasSize(1);
assertThat(oname.toString()).isEqualTo("org.springframework.ldap.pool2:type=ldap-pool,name=test-pool");
}
@Test
@@ -451,38 +447,38 @@ public class LdapTemplateNamespaceHandlerTest {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-test-specified.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
assertThat(outerContextSource).isNotNull();
ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertNotNull(pooledContextSource);
assertThat(pooledContextSource).isNotNull();
org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool =
(org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
assertEquals(123, objectPool.getMinEvictableIdleTimeMillis());
assertEquals(321, objectPool.getTimeBetweenEvictionRunsMillis());
assertEquals(22, objectPool.getNumTestsPerEvictionRun());
assertEquals(12, objectPool.getSoftMinEvictableIdleTimeMillis());
assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(123);
assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(321);
assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(22);
assertThat(objectPool.getSoftMinEvictableIdleTimeMillis()).isEqualTo(12);
assertEquals(true, objectPool.getTestOnBorrow());
assertEquals(true, objectPool.getTestOnReturn());
assertEquals(true, objectPool.getTestOnCreate());
assertEquals(true, objectPool.getTestWhileIdle());
assertThat(objectPool.getTestOnBorrow()).isEqualTo(true);
assertThat(objectPool.getTestOnReturn()).isEqualTo(true);
assertThat(objectPool.getTestOnCreate()).isEqualTo(true);
assertThat(objectPool.getTestWhileIdle()).isEqualTo(true);
Object objectFactory = getInternalState(pooledContextSource, "dirContextPooledObjectFactory");
org.springframework.ldap.pool2.validation.DefaultDirContextValidator validator =
(org.springframework.ldap.pool2.validation.DefaultDirContextValidator) getInternalState(objectFactory, "dirContextValidator");
assertEquals("ou=test", validator.getBase());
assertEquals("objectclass=person", validator.getFilter());
assertThat(validator.getBase()).isEqualTo("ou=test");
assertThat(validator.getFilter()).isEqualTo("objectclass=person");
SearchControls searchControls = ctx.getBean(SearchControls.class);
assertEquals("objectclass=person", validator.getFilter());
assertSame(searchControls, validator.getSearchControls());
assertThat(validator.getFilter()).isEqualTo("objectclass=person");
assertThat(validator.getSearchControls()).isSameAs(searchControls);
Set<Class<? extends Throwable>> nonTransientExceptions =
(Set<Class<? extends Throwable>>) getInternalState(objectFactory, "nonTransientExceptions");
assertEquals(2, nonTransientExceptions.size());
assertTrue(nonTransientExceptions.contains(CommunicationException.class));
assertTrue(nonTransientExceptions.contains(CannotProceedException.class));
assertThat(nonTransientExceptions).hasSize(2);
assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue();
assertThat(nonTransientExceptions.contains(CannotProceedException.class)).isTrue();
}
@Test(expected = BeansException.class)
@@ -499,40 +495,40 @@ public class LdapTemplateNamespaceHandlerTest {
public void verifyParsePoolWithPlaceholders() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-config-with-placeholders.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
assertThat(outerContextSource).isNotNull();
ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertNotNull(pooledContextSource);
assertThat(pooledContextSource).isNotNull();
GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
assertEquals(10, objectPool.getTimeBetweenEvictionRunsMillis());
assertEquals(20, objectPool.getMinEvictableIdleTimeMillis());
assertEquals(10, objectPool.getMaxWait());
assertEquals(11, objectPool.getMaxTotal());
assertEquals(15, objectPool.getMaxActive());
assertEquals(16, objectPool.getMinIdle());
assertEquals(17, objectPool.getMaxIdle());
assertEquals(18, objectPool.getNumTestsPerEvictionRun());
assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(10);
assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(20);
assertThat(objectPool.getMaxWait()).isEqualTo(10);
assertThat(objectPool.getMaxTotal()).isEqualTo(11);
assertThat(objectPool.getMaxActive()).isEqualTo(15);
assertThat(objectPool.getMinIdle()).isEqualTo(16);
assertThat(objectPool.getMaxIdle()).isEqualTo(17);
assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(18);
}
@Test
public void verifyParsePool2WithPlaceholders() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling2-config-with-placeholders.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
assertThat(outerContextSource).isNotNull();
ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertNotNull(pooledContextSource);
assertThat(pooledContextSource).isNotNull();
org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool =
(org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
assertEquals(10, objectPool.getTimeBetweenEvictionRunsMillis());
assertEquals(20, objectPool.getMinEvictableIdleTimeMillis());
assertEquals(10, objectPool.getMaxWaitMillis());
assertEquals(11, objectPool.getMaxTotal());
assertEquals(12, objectPool.getMinIdlePerKey());
assertEquals(13, objectPool.getMaxIdlePerKey());
assertEquals(14, objectPool.getMaxTotalPerKey());
assertEquals(18, objectPool.getNumTestsPerEvictionRun());
assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(10);
assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(20);
assertThat(objectPool.getMaxWaitMillis()).isEqualTo(10);
assertThat(objectPool.getMaxTotal()).isEqualTo(11);
assertThat(objectPool.getMinIdlePerKey()).isEqualTo(12);
assertThat(objectPool.getMaxIdlePerKey()).isEqualTo(13);
assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(14);
assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(18);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,9 +29,7 @@ import javax.naming.ldap.PagedResultsControl;
import javax.naming.ldap.PagedResultsResponseControl;
import java.io.IOException;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -61,7 +59,7 @@ public class PagedResultsDirContextProcessorTest {
public void testCreateRequestControl() throws Exception {
PagedResultsControl control = (PagedResultsControl) tested
.createRequestControl();
assertNotNull(control);
assertThat(control).isNotNull();
}
@Test
@@ -72,7 +70,7 @@ public class PagedResultsDirContextProcessorTest {
PagedResultsControl control = (PagedResultsControl) tested
.createRequestControl();
assertNotNull(control);
assertThat(control).isNotNull();
}
@Test
@@ -90,9 +88,9 @@ public class PagedResultsDirContextProcessorTest {
tested.postProcess(ldapContextMock);
PagedResultsCookie returnedCookie = tested.getCookie();
assertEquals(8, returnedCookie.getCookie()[0]);
assertEquals(20, tested.getPageSize());
assertEquals(50, tested.getResultSize());
assertThat(returnedCookie.getCookie()[0]).isEqualTo((byte)8);
assertThat(tested.getPageSize()).isEqualTo(20);
assertThat(tested.getResultSize()).isEqualTo(50);
}
@Test
@@ -112,9 +110,9 @@ public class PagedResultsDirContextProcessorTest {
when(ldapContextMock.getResponseControls()).thenReturn(new Control[]{control});
tested.postProcess(ldapContextMock);
assertNull(tested.getCookie());
assertEquals(20, tested.getPageSize());
assertEquals(0, tested.getResultSize());
assertThat(tested.getCookie()).isNull();
assertThat(tested.getPageSize()).isEqualTo(20);
assertThat(tested.getResultSize()).isEqualTo(0);
}
@Test
@@ -123,9 +121,9 @@ public class PagedResultsDirContextProcessorTest {
tested.postProcess(ldapContextMock);
assertNull(tested.getCookie());
assertEquals(20, tested.getPageSize());
assertEquals(0, tested.getResultSize());
assertThat(tested.getCookie()).isNull();
assertThat(tested.getPageSize()).isEqualTo(20);
assertThat(tested.getResultSize()).isEqualTo(0);
}
@Test
@@ -141,10 +139,10 @@ public class PagedResultsDirContextProcessorTest {
int actualPageSize = ber.parseInt();
byte[] actualValue = ber.parseOctetString(Ber.ASN_OCTET_STR, null);
assertEquals("pageSize,", 20, actualPageSize);
assertEquals("value length", value.length, actualValue.length);
assertThat(actualPageSize).as("pageSize,").isEqualTo(20);
assertThat(actualValue.length).as("value length").isEqualTo(value.length);
for (int i = 0; i < value.length; i++) {
assertEquals("value (index " + i + "),", value[i], actualValue[i]);
assertThat(actualValue[i]).as("value (index " + i + "),").isEqualTo(value[i]);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,8 +28,7 @@ import javax.naming.ldap.SortControl;
import javax.naming.ldap.SortResponseControl;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -55,9 +54,9 @@ public class SortControlDirContextProcessorTest {
@Test
public void testCreateRequestControl() throws Exception {
SortControl result = (SortControl) tested.createRequestControl();
assertNotNull(result);
assertEquals("1.2.840.113556.1.4.473", result.getID());
assertEquals(9, result.getEncodedValue().length);
assertThat(result).isNotNull();
assertThat(result.getID()).isEqualTo("1.2.840.113556.1.4.473");
assertThat(result.getEncodedValue().length).isEqualTo(9);
}
@Test
@@ -72,8 +71,8 @@ public class SortControlDirContextProcessorTest {
tested.postProcess(ldapContextMock);
assertEquals(true, tested.isSorted());
assertEquals(0, tested.getResultCode());
assertThat(tested.isSorted()).isEqualTo(true);
assertThat(tested.getResultCode()).isEqualTo(0);
}
@Test
@@ -88,8 +87,8 @@ public class SortControlDirContextProcessorTest {
tested.postProcess(ldapContextMock);
assertEquals(false, tested.isSorted());
assertEquals(1, tested.getResultCode());
assertThat(tested.isSorted()).isEqualTo(false);
assertThat(tested.getResultCode()).isEqualTo(1);
}
@Test
@@ -109,7 +108,7 @@ public class SortControlDirContextProcessorTest {
tested.postProcess(ldapContextMock);
assertEquals(false, tested.isSorted());
assertThat(tested.isSorted()).isEqualTo(false);
}
@Test
@@ -122,7 +121,7 @@ public class SortControlDirContextProcessorTest {
ber.parseSeq(null);
int actualSortResult = ber.parseEnumeration();
assertEquals("sortResult,", 53, actualSortResult);
assertThat(actualSortResult).as("sortResult,").isEqualTo(53);
}
private byte[] encodeValue(int sortResult) throws IOException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@ import javax.naming.NameClassPair;
import javax.naming.NamingException;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertSame;
public class CollectingNameClassPairCallbackHandlerTest {
@@ -40,7 +40,7 @@ public class CollectingNameClassPairCallbackHandlerTest {
expectedNameClassPair = new NameClassPair(null, null);
tested = new CollectingNameClassPairCallbackHandler() {
public Object getObjectFromNameClassPair(NameClassPair nameClassPair) {
assertSame(expectedNameClassPair, nameClassPair);
assertThat(nameClassPair).isSameAs(expectedNameClassPair);
return expectedResult;
}
};
@@ -50,8 +50,8 @@ public class CollectingNameClassPairCallbackHandlerTest {
public void testHandleNameClassPair() throws NamingException {
tested.handleNameClassPair(expectedNameClassPair);
List result = tested.getList();
assertEquals(1, result.size());
assertSame(expectedResult, result.get(0));
assertThat(result).hasSize(1);
assertThat(result.get(0)).isSameAs(expectedResult);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import org.junit.Test;
import javax.naming.Binding;
import javax.naming.NamingException;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -51,7 +51,7 @@ public class ContextMapperCallbackHandlerTest {
when(mapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult);
Object actualResult = tested
.getObjectFromNameClassPair(expectedBinding);
assertEquals(expectedResult, actualResult);
assertThat(actualResult).isEqualTo(expectedResult);
}
@Test(expected = ObjectRetrievalException.class)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,8 +22,7 @@ import javax.naming.Name;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests that serve as regression tests for bugs that have been fixed.
@@ -42,7 +41,7 @@ public class DirContextAdapterBugTest {
ctx.setAttributeValues("myattr", new String[] { "a", "b" });
ctx.setAttributeValues("myattr", new String[] { "a", "b", "c" });
assertEquals(0, ctx.getModificationItems().length);
assertThat(ctx.getModificationItems().length).isEqualTo(0);
}
@Test
@@ -55,7 +54,7 @@ public class DirContextAdapterBugTest {
ctx.setAttributeValues("myattr", new String[] { "a", "b", "d" });
ctx.setAttributeValues("myattr", new String[] { "a", "b", "c" });
assertEquals(0, ctx.getModificationItems().length);
assertThat(ctx.getModificationItems().length).isEqualTo(0);
}
/**
@@ -74,7 +73,7 @@ public class DirContextAdapterBugTest {
ctx.setAttributeValues("myattr", new String[] { "a" });
ctx.setAttributeValues("myattr", null);
assertEquals(1, ctx.getModificationItems().length);
assertThat(ctx.getModificationItems().length).isEqualTo(1);
}
@Test
@@ -85,7 +84,7 @@ public class DirContextAdapterBugTest {
ctx.setAttributeValue("myattr", "a");
ctx.setAttributeValue("myattr", "b");
assertEquals(0, ctx.getModificationItems().length);
assertThat(ctx.getModificationItems().length).isEqualTo(0);
}
private static class UpdateAdapter extends DirContextAdapter {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,10 +18,8 @@ package org.springframework.ldap.core;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
/**
* Unit tests for {@link DistinguishedNameEditor}.
@@ -43,14 +41,14 @@ public class DistinguishedNameEditorTest {
tested.setAsText(expectedDn);
DistinguishedName result = (DistinguishedName) tested.getValue();
assertEquals(new DistinguishedName(expectedDn), result);
assertThat(result).isEqualTo(new DistinguishedName(expectedDn));
try {
result.getNames().add(new LdapRdn("cn", "john doe"));
fail("UnsupportedOperationException expected");
}
catch (UnsupportedOperationException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -58,7 +56,7 @@ public class DistinguishedNameEditorTest {
public void testSetAsTextNullValue() throws Exception {
tested.setAsText(null);
Object result = tested.getValue();
assertNull(result);
assertThat(result).isNull();
}
@Test
@@ -66,13 +64,13 @@ public class DistinguishedNameEditorTest {
String expectedDn = "dc=jayway,dc=se";
tested.setValue(new DistinguishedName(expectedDn));
String text = tested.getAsText();
assertEquals(expectedDn, text);
assertThat(text).isEqualTo(expectedDn);
}
@Test
public void testGetAsTextNullValue() throws Exception {
tested.setValue(null);
String text = tested.getAsText();
assertNull(text);
assertThat(text).isNull();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,11 +25,8 @@ import javax.naming.InvalidNameException;
import javax.naming.Name;
import java.util.Enumeration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
/**
* Unit tests for the {@link DistinguishedName} class.
@@ -43,20 +40,20 @@ public class DistinguishedNameTest {
public void testDistinguishedName_CompositeWithSlash() throws Exception {
Name testPath = new CompositeName("cn=foo\\/bar");
DistinguishedName path = new DistinguishedName(testPath);
assertEquals("cn=foo/bar", path.toString());
assertThat(path.toString()).isEqualTo("cn=foo/bar");
}
@Test
public void testDistinguishedName_CompositeWithSlashAsString() throws Exception {
Name testPath = new CompositeName("cn=foo\\/bar");
DistinguishedName path = new DistinguishedName(testPath.toString());
assertEquals("cn=foo/bar", path.toString());
assertThat(path.toString()).isEqualTo("cn=foo/bar");
}
@Test
public void testDistinguishedName_Ldap237_NotDestroyedByCompositeName() throws InvalidNameException {
DistinguishedName path = new DistinguishedName("ou=Roger \\\"Bunny\\\" Rabbit,dc=somecompany,dc=com");
assertEquals("ou=Roger \\\"Bunny\\\" Rabbit,dc=somecompany,dc=com", path.toString());
assertThat(path.toString()).isEqualTo("ou=Roger \\\"Bunny\\\" Rabbit,dc=somecompany,dc=com");
}
/**
@@ -67,7 +64,7 @@ public class DistinguishedNameTest {
@Test
public void testDistinguishedName_Ldap237_DestroyedByCompositeName() throws InvalidNameException {
DistinguishedName path = new DistinguishedName("ou=Roger \\\\\"Bunny\\\\\" Rabbit,dc=somecompany,dc=com");
assertEquals("ou=Roger \\\"Bunny\\\" Rabbit,dc=somecompany,dc=com", path.toString());
assertThat(path.toString()).isEqualTo("ou=Roger \\\"Bunny\\\" Rabbit,dc=somecompany,dc=com");
}
@Test
@@ -78,7 +75,7 @@ public class DistinguishedNameTest {
fail("UnsupportedOperationException expected");
}
catch (UnsupportedOperationException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -91,24 +88,24 @@ public class DistinguishedNameTest {
DistinguishedName path = new DistinguishedName(testPath);
assertEquals("cn", path.getLdapRdn(8).getComponent().getKey());
assertEquals("foo,bar", path.getLdapRdn(8).getComponent().getValue());
assertEquals("ou", path.getLdapRdn(7).getComponent().getKey());
assertEquals("FOO,bar", path.getLdapRdn(7).getComponent().getValue());
assertEquals("ou", path.getLdapRdn(6).getComponent().getKey());
assertEquals("foo;bar", path.getLdapRdn(6).getComponent().getValue());
assertEquals("ou", path.getLdapRdn(5).getComponent().getKey());
assertEquals("foo;bar", path.getLdapRdn(5).getComponent().getValue());
assertEquals("ou", path.getLdapRdn(4).getComponent().getKey());
assertEquals("foo,", path.getLdapRdn(4).getComponent().getValue());
assertEquals("ou", path.getLdapRdn(3).getComponent().getKey());
assertEquals("foo,", path.getLdapRdn(3).getComponent().getValue());
assertEquals("ou", path.getLdapRdn(2).getComponent().getKey());
assertEquals("foo;", path.getLdapRdn(2).getComponent().getValue());
assertEquals("ou", path.getLdapRdn(1).getComponent().getKey());
assertEquals("foo,", path.getLdapRdn(1).getComponent().getValue());
assertEquals("ou", path.getLdapRdn(0).getComponent().getKey());
assertEquals("bar,", path.getLdapRdn(0).getComponent().getValue());
assertThat(path.getLdapRdn(8).getComponent().getKey()).isEqualTo("cn");
assertThat(path.getLdapRdn(8).getComponent().getValue()).isEqualTo("foo,bar");
assertThat(path.getLdapRdn(7).getComponent().getKey()).isEqualTo("ou");
assertThat(path.getLdapRdn(7).getComponent().getValue()).isEqualTo("FOO,bar");
assertThat(path.getLdapRdn(6).getComponent().getKey()).isEqualTo("ou");
assertThat(path.getLdapRdn(6).getComponent().getValue()).isEqualTo("foo;bar");
assertThat(path.getLdapRdn(5).getComponent().getKey()).isEqualTo("ou");
assertThat(path.getLdapRdn(5).getComponent().getValue()).isEqualTo("foo;bar");
assertThat(path.getLdapRdn(4).getComponent().getKey()).isEqualTo("ou");
assertThat(path.getLdapRdn(4).getComponent().getValue()).isEqualTo("foo,");
assertThat(path.getLdapRdn(3).getComponent().getKey()).isEqualTo("ou");
assertThat(path.getLdapRdn(3).getComponent().getValue()).isEqualTo("foo,");
assertThat(path.getLdapRdn(2).getComponent().getKey()).isEqualTo("ou");
assertThat(path.getLdapRdn(2).getComponent().getValue()).isEqualTo("foo;");
assertThat(path.getLdapRdn(1).getComponent().getKey()).isEqualTo("ou");
assertThat(path.getLdapRdn(1).getComponent().getValue()).isEqualTo("foo,");
assertThat(path.getLdapRdn(0).getComponent().getKey()).isEqualTo("ou");
assertThat(path.getLdapRdn(0).getComponent().getValue()).isEqualTo("bar,");
}
@Test
@@ -120,7 +117,7 @@ public class DistinguishedNameTest {
path.remove(1);
path.remove(3);
assertEquals("cn=john.doe,ou=Some Company,ou=G,ou=M", path.toString());
assertThat(path.toString()).isEqualTo("cn=john.doe,ou=Some Company,ou=G,ou=M");
}
/**
@@ -138,13 +135,13 @@ public class DistinguishedNameTest {
DistinguishedName pathE1 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE,ou=G,OU=L,OU=M, ou=foo");
DistinguishedName pathE2 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE");
assertTrue("Contains MIG", path1.contains(migpath));
assertTrue("Contains MIG", path2.contains(migpath));
assertTrue("Contains MIG", path3.contains(migpath));
assertTrue("Contains MIG", path4.contains(migpath));
assertThat(path1.contains(migpath)).isTrue();
assertThat(path2.contains(migpath)).isTrue();
assertThat(path3.contains(migpath)).isTrue();
assertThat(path4.contains(migpath)).isTrue();
assertFalse("Does not contain MIG", pathE1.contains(migpath));
assertFalse("Does not contain MIG", pathE2.contains(migpath));
assertThat(pathE1.contains(migpath)).isFalse();
assertThat(pathE2.contains(migpath)).isFalse();
}
@Test
@@ -154,7 +151,7 @@ public class DistinguishedNameTest {
path1.append(path2);
assertEquals("Append failed", "ou=baz,ou=foo,ou=bar", path1.toString());
assertThat(path1.toString()).isEqualTo("ou=baz,ou=foo,ou=bar");
}
@Test
@@ -164,7 +161,7 @@ public class DistinguishedNameTest {
path1.prepend(path2);
assertEquals("Append failed", "ou=foo,ou=bar,cn=fie,ou=baz", path1.toString());
assertThat(path1.toString()).isEqualTo("ou=foo,ou=bar,cn=fie,ou=baz");
}
@Test
@@ -195,10 +192,10 @@ public class DistinguishedNameTest {
DistinguishedName path2 = (DistinguishedName) path1.clone();
assertEquals("Should be equal", path1, path2);
assertThat(path2).as("Should be equal").isEqualTo(path1);
path2.removeFirst();
assertFalse("Should not be equal", path1.equals(path2));
assertThat(path1.equals(path2)).isFalse();
}
@@ -210,8 +207,8 @@ public class DistinguishedNameTest {
DistinguishedName path2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com");
DistinguishedName ending2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU");
assertTrue(path1.endsWith(ending1));
assertTrue(path2.endsWith(ending2));
assertThat(path1.endsWith(ending1)).isTrue();
assertThat(path2.endsWith(ending2)).isTrue();
}
@Test
@@ -222,8 +219,8 @@ public class DistinguishedNameTest {
DistinguishedName path2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com");
DistinguishedName ending2 = new DistinguishedName("ou=EU, o=example.com");
assertFalse(path1.endsWith(ending1));
assertFalse(path2.endsWith(ending2));
assertThat(path1.endsWith(ending1)).isFalse();
assertThat(path2.endsWith(ending2)).isFalse();
}
@Test
@@ -233,16 +230,16 @@ public class DistinguishedNameTest {
Enumeration elements = path.getAll();
String element = (String) elements.nextElement();
assertEquals("o=example.com", element);
assertThat(element).isEqualTo("o=example.com");
element = (String) elements.nextElement();
assertEquals("ou=EU", element);
assertThat(element).isEqualTo("ou=EU");
element = (String) elements.nextElement();
assertEquals("ou=people", element);
assertThat(element).isEqualTo("ou=people");
element = (String) elements.nextElement();
assertEquals("uid=mtah.test", element);
assertThat(element).isEqualTo("uid=mtah.test");
}
@Test
@@ -251,16 +248,16 @@ public class DistinguishedNameTest {
String string = path.get(1);
assertEquals("ou=EU", string);
assertThat(string).isEqualTo("ou=EU");
}
@Test
public void testSize() {
DistinguishedName path1 = new DistinguishedName();
assertEquals(0, path1.size());
assertThat(path1.size()).isEqualTo(0);
DistinguishedName path2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com");
assertEquals(4, path2.size());
assertThat(path2.size()).isEqualTo(4);
}
@Test
@@ -268,16 +265,16 @@ public class DistinguishedNameTest {
DistinguishedName path = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com");
Name prefix = path.getPrefix(0);
assertEquals(0, prefix.size());
assertThat(prefix.size()).isEqualTo(0);
prefix = path.getPrefix(1);
assertEquals(1, prefix.size());
assertEquals("o=example.com", prefix.get(0));
assertThat(prefix.size()).isEqualTo(1);
assertThat(prefix.get(0)).isEqualTo("o=example.com");
prefix = path.getPrefix(2);
assertEquals(2, prefix.size());
assertEquals("o=example.com", prefix.get(0));
assertEquals("ou=EU", prefix.get(1));
assertThat(prefix.size()).isEqualTo(2);
assertThat(prefix.get(0)).isEqualTo("o=example.com");
assertThat(prefix.get(1)).isEqualTo("ou=EU");
}
@Test
@@ -285,21 +282,21 @@ public class DistinguishedNameTest {
DistinguishedName path = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com");
Name suffix = path.getSuffix(0);
assertEquals(4, suffix.size());
assertThat(suffix.size()).isEqualTo(4);
suffix = path.getSuffix(2);
assertEquals(2, suffix.size());
assertEquals("ou=people", suffix.get(0));
assertThat(suffix.size()).isEqualTo(2);
assertThat(suffix.get(0)).isEqualTo("ou=people");
suffix = path.getSuffix(4);
assertEquals(0, suffix.size());
assertThat(suffix.size()).isEqualTo(0);
try {
path.getSuffix(5);
fail("ArrayIndexOutOfBoundsException expected");
}
catch (ArrayIndexOutOfBoundsException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -311,8 +308,8 @@ public class DistinguishedNameTest {
DistinguishedName path2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com");
DistinguishedName start2 = new DistinguishedName("ou=people, ou=EU, o=example.com");
assertTrue(path1.startsWith(start1));
assertTrue(path2.startsWith(start2));
assertThat(path1.startsWith(start1)).isTrue();
assertThat(path2.startsWith(start2)).isTrue();
}
@Test
@@ -323,8 +320,8 @@ public class DistinguishedNameTest {
DistinguishedName path2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com");
DistinguishedName start2 = new DistinguishedName("uid=mtah.test, ou=EU, ou=people");
assertFalse(path1.startsWith(start1));
assertFalse(path2.startsWith(start2));
assertThat(path1.startsWith(start1)).isFalse();
assertThat(path2.startsWith(start2)).isFalse();
}
@Test
@@ -333,7 +330,7 @@ public class DistinguishedNameTest {
DistinguishedName path2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com, o=a.com");
assertFalse(path1.startsWith(path2));
assertThat(path1.startsWith(path2)).isFalse();
}
@Test
@@ -342,19 +339,19 @@ public class DistinguishedNameTest {
DistinguishedName path2 = new DistinguishedName();
assertFalse(path1.startsWith(path2));
assertThat(path1.startsWith(path2)).isFalse();
}
@Test
public void testIsEmpty_True() {
DistinguishedName path = new DistinguishedName();
assertTrue(path.isEmpty());
assertThat(path.isEmpty()).isTrue();
}
@Test
public void testIsEmpty_False() {
DistinguishedName path = new DistinguishedName("o=example.com");
assertFalse(path.isEmpty());
assertThat(path.isEmpty()).isFalse();
}
@Test
@@ -364,7 +361,7 @@ public class DistinguishedNameTest {
path1.addAll(path2);
assertEquals("AddAll failed", "ou=baz,ou=foo,ou=bar", path1.toString());
assertThat(path1.toString()).isEqualTo("ou=baz,ou=foo,ou=bar");
}
@Test
@@ -374,7 +371,7 @@ public class DistinguishedNameTest {
path1.addAll(1, path2);
assertEquals("AddAll failed", "ou=foo,ou=baz,ou=bar", path1.toString());
assertThat(path1.toString()).isEqualTo("ou=foo,ou=baz,ou=bar");
}
@Test
@@ -382,7 +379,7 @@ public class DistinguishedNameTest {
DistinguishedName path1 = new DistinguishedName("ou=foo, ou=bar");
path1.add("ou=baz");
assertEquals("Add failed", "ou=baz,ou=foo,ou=bar", path1.toString());
assertThat(path1.toString()).isEqualTo("ou=baz,ou=foo,ou=bar");
}
@Test
@@ -390,7 +387,7 @@ public class DistinguishedNameTest {
DistinguishedName path1 = new DistinguishedName("ou=foo, ou=bar");
path1.add(1, "ou=baz");
assertEquals("Add failed", "ou=foo,ou=baz,ou=bar", path1.toString());
assertThat(path1.toString()).isEqualTo("ou=foo,ou=baz,ou=bar");
}
@Test
@@ -398,14 +395,14 @@ public class DistinguishedNameTest {
DistinguishedName path = new DistinguishedName("dc=jayway, dc=se");
String url = path.toUrl();
assertEquals("dc=jayway,dc=se", url);
assertThat(url).isEqualTo("dc=jayway,dc=se");
}
@Test
public void testMultiValueRdn() throws Exception {
DistinguishedName path = new DistinguishedName("firstName=Rod+lastName=Johnson,ou=UK,dc=interface21,dc=com");
assertEquals(4, path.size());
assertEquals("firstname=Rod+lastname=Johnson", path.get(3));
assertThat(path.size()).isEqualTo(4);
assertThat(path.get(3)).isEqualTo("firstname=Rod+lastname=Johnson");
}
@Test
@@ -414,7 +411,7 @@ public class DistinguishedNameTest {
DistinguishedName name2 = new DistinguishedName("cn=john doe, ou=Some company, c=SE");
int result = name1.compareTo(name2);
assertEquals(0, result);
assertThat(result).isEqualTo(0);
}
@Test
@@ -423,7 +420,7 @@ public class DistinguishedNameTest {
DistinguishedName name2 = new DistinguishedName("cn=john doe, ou=Some company, c=SE");
int result = name1.compareTo(name2);
assertTrue(result < 0);
assertThat(result < 0).isTrue();
}
@Test
@@ -432,7 +429,7 @@ public class DistinguishedNameTest {
DistinguishedName name2 = new DistinguishedName("cn=john doe, ou=Some company, c=SE");
int result = name1.compareTo(name2);
assertTrue(result < 0);
assertThat(result < 0).isTrue();
}
@Test
@@ -441,7 +438,7 @@ public class DistinguishedNameTest {
DistinguishedName name2 = new DistinguishedName("cn=john doe, ou=Some company, c=DK");
int result = name1.compareTo(name2);
assertTrue(result > 0);
assertThat(result > 0).isTrue();
}
@Test
@@ -450,7 +447,7 @@ public class DistinguishedNameTest {
DistinguishedName name2 = new DistinguishedName("cn=john doe, ou=Some company, c=SE");
int result = name1.compareTo(name2);
assertTrue(result > 0);
assertThat(result > 0).isTrue();
}
@Test
@@ -459,14 +456,14 @@ public class DistinguishedNameTest {
DistinguishedName name2 = new DistinguishedName("leaf=someleaf, cn=john doe, ou=Some company, c=SE");
int result = name1.compareTo(name2);
assertTrue(result < 0);
assertThat(result < 0).isTrue();
}
@Test
public void testGetLdapRdnForKey() throws Exception {
DistinguishedName dn = new DistinguishedName("cn=john doe, ou=Some company, c=SE");
LdapRdn ldapRdn = dn.getLdapRdn("ou");
assertEquals(new LdapRdn("ou=Some company"), ldapRdn);
assertThat(ldapRdn).isEqualTo(new LdapRdn("ou=Some company"));
}
@Test(expected = IllegalArgumentException.class)
@@ -479,7 +476,7 @@ public class DistinguishedNameTest {
public void testGetValue() throws Exception {
DistinguishedName dn = new DistinguishedName("cn=john doe, ou=Some company, c=SE");
String value = dn.getValue("ou");
assertEquals("Some company", value);
assertThat(value).isEqualTo("Some company");
}
@Test(expected = IllegalArgumentException.class)
@@ -491,7 +488,7 @@ public class DistinguishedNameTest {
@Test
public void test_longDN() throws InvalidNameException {
DistinguishedName name = new DistinguishedName("");
assertNotNull(name);
assertThat(name).isNotNull();
}
/**
@@ -500,7 +497,7 @@ public class DistinguishedNameTest {
@Test
public void testParseAtSign() {
DistinguishedName name = new DistinguishedName("cn=testname@example.com");
assertNotNull(name);
assertThat(name).isNotNull();
}
/**
@@ -509,7 +506,7 @@ public class DistinguishedNameTest {
@Test
public void testParseAtSign2() {
DistinguishedName name = new DistinguishedName("cn=te\\+stname@example.com");
assertNotNull(name);
assertThat(name).isNotNull();
}
/**
@@ -526,7 +523,7 @@ public class DistinguishedNameTest {
@Test
public void testParseValidQuotation() {
DistinguishedName name = new DistinguishedName("cn=jo\"hn doe");
assertNotNull(name);
assertThat(name).isNotNull();
}
@Test
@@ -534,7 +531,7 @@ public class DistinguishedNameTest {
DistinguishedName tested = new DistinguishedName("dc=mycompany,dc=com");
tested.append("ou", "company1").append("cn", "john doe");
assertEquals("cn=john doe,ou=company1,dc=mycompany,dc=com", tested.toString());
assertThat(tested.toString()).isEqualTo("cn=john doe,ou=company1,dc=mycompany,dc=com");
}
@Test(expected = UnsupportedOperationException.class)
@@ -571,7 +568,7 @@ public class DistinguishedNameTest {
public void testUnmodifiableDistinguishedNameEqualsIdenticalMutableOne() throws Exception {
DistinguishedName immutable = DistinguishedName.immutableDistinguishedName("cn=john doe");
DistinguishedName mutable = new DistinguishedName("cn=john doe");
assertTrue(immutable.equals(mutable));
assertThat(immutable.equals(mutable)).isTrue();
}
/**
@@ -580,7 +577,7 @@ public class DistinguishedNameTest {
@Test
public void testDistinguishedNameWithCRParsesProperly() {
DistinguishedName name = new DistinguishedName("cn=foo \r bar");
assertNotNull(name);
assertThat(name).isNotNull();
}
/**
@@ -589,13 +586,13 @@ public class DistinguishedNameTest {
@Test
public void testDistinguishedNameWithDotParsesProperly() {
DistinguishedName name = new DistinguishedName("cn=first.last,OU=DevTest Users,DC=xyz,DC=com");
assertEquals("cn=first.last,ou=DevTest Users,dc=xyz,dc=com", name.toCompactString());
assertThat(name.toCompactString()).isEqualTo("cn=first.last,ou=DevTest Users,dc=xyz,dc=com");
DistinguishedName dn = new DistinguishedName();
dn.parse("cn=first.last,OU=DevTest Users,DC=xyz,DC=com");
assertEquals("first.last", dn.getValue("cn"));
assertEquals("DevTest Users", dn.getValue("ou"));
assertEquals("xyz", dn.getLdapRdn(1).getValue());
assertEquals("com", dn.getLdapRdn(0).getValue());
assertThat(dn.getValue("cn")).isEqualTo("first.last");
assertThat(dn.getValue("ou")).isEqualTo("DevTest Users");
assertThat(dn.getLdapRdn(1).getValue()).isEqualTo("xyz");
assertThat(dn.getLdapRdn(0).getValue()).isEqualTo("com");
}
@Test
@@ -603,9 +600,9 @@ public class DistinguishedNameTest {
try {
DistinguishedName name = new DistinguishedName("cn=john doe, ou=company");
// First check the default
assertEquals("cn=john doe,ou=company", name.toString());
assertThat(name.toString()).isEqualTo("cn=john doe,ou=company");
System.setProperty(DistinguishedName.SPACED_DN_FORMAT_PROPERTY, "true");
assertEquals("cn=john doe, ou=company", name.toString());
assertThat(name.toString()).isEqualTo("cn=john doe, ou=company");
}
finally {
// Always restore the system setting
@@ -620,12 +617,12 @@ public class DistinguishedNameTest {
DistinguishedName name = new DistinguishedName(dnString);
// First check the default
assertEquals("ou=foo,ou=bar,ou=baz,ou=bim", name.toString());
assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim");
System.setProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY, DistinguishedName.KEY_CASE_FOLD_NONE);
name = new DistinguishedName(dnString);
System.out.println(dnString + " folded as \"" + DistinguishedName.KEY_CASE_FOLD_NONE + "\": " + name);
assertEquals(dnString, name.toString());
assertThat(name.toString()).isEqualTo(dnString);
}
finally {
// Always restore the system setting
@@ -640,12 +637,12 @@ public class DistinguishedNameTest {
DistinguishedName name = new DistinguishedName(dnString);
// First check the default
assertEquals("ou=foo,ou=bar,ou=baz,ou=bim", name.toString());
assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim");
System.setProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY, DistinguishedName.KEY_CASE_FOLD_UPPER);
name = new DistinguishedName(dnString);
System.out.println(dnString + " folded as \"" + DistinguishedName.KEY_CASE_FOLD_UPPER + "\": " + name);
assertEquals("OU=foo,OU=bar,OU=baz,OU=bim", name.toString());
assertThat(name.toString()).isEqualTo("OU=foo,OU=bar,OU=baz,OU=bim");
}
finally {
// Always restore the system setting
@@ -660,12 +657,12 @@ public class DistinguishedNameTest {
DistinguishedName name = new DistinguishedName(dnString);
// First check the default
assertEquals("ou=foo,ou=bar,ou=baz,ou=bim", name.toString());
assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim");
System.setProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY, DistinguishedName.KEY_CASE_FOLD_LOWER);
name = new DistinguishedName(dnString);
System.out.println(dnString + " folded as \"" + DistinguishedName.KEY_CASE_FOLD_LOWER + "\": " + name);
assertEquals("ou=foo,ou=bar,ou=baz,ou=bim", name.toString());
assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim");
}
finally {
// Always restore the system setting
@@ -680,12 +677,12 @@ public class DistinguishedNameTest {
DistinguishedName name = new DistinguishedName(dnString);
// First check the default
assertEquals("ou=foo,ou=bar,ou=baz,ou=bim", name.toString());
assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim");
System.setProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY, "whatever");
name = new DistinguishedName(dnString);
System.out.println(dnString + " folded as \"whatever\": " + name);
assertEquals("ou=foo,ou=bar,ou=baz,ou=bim", name.toString());
assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim");
}
finally {
// Always restore the system setting
@@ -695,25 +692,19 @@ public class DistinguishedNameTest {
@Test
public void testHashSignLdap229() {
assertEquals(
new DistinguishedName("cn=Foo\\#Bar"),
new DistinguishedName("cn=Foo#Bar")
);
assertThat(new DistinguishedName("cn=Foo\\#Bar")).isEqualTo(
new DistinguishedName("cn=Foo#Bar"));
}
@Test
public void testEqualsSignLdap229() {
assertEquals(
new DistinguishedName("cn=Foo\\=Bar"),
new DistinguishedName("cn=Foo=Bar")
);
assertThat(new DistinguishedName("cn=Foo\\=Bar")).isEqualTo(
new DistinguishedName("cn=Foo=Bar"));
}
@Test
public void testSpaceSignLdap229() {
assertEquals(
new DistinguishedName("cn=Foo\\ Bar"),
new DistinguishedName("cn=Foo Bar")
);
assertThat(new DistinguishedName("cn=Foo\\ Bar")).isEqualTo(
new DistinguishedName("cn=Foo Bar"));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,7 @@ package org.springframework.ldap.core;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for LdapRdnComponent.
@@ -32,7 +31,7 @@ public class LdapRdnComponentTest {
LdapRdnComponent component1 = new LdapRdnComponent("cn", "john doe");
LdapRdnComponent component2 = new LdapRdnComponent("sn", "doe");
int result = component1.compareTo(component2);
assertTrue(result < 0);
assertThat(result < 0).isTrue();
}
@Test
@@ -40,7 +39,7 @@ public class LdapRdnComponentTest {
LdapRdnComponent component1 = new LdapRdnComponent("sn", "doe");
LdapRdnComponent component2 = new LdapRdnComponent("cn", "john doe");
int result = component1.compareTo(component2);
assertTrue(result > 0);
assertThat(result > 0).isTrue();
}
@Test
@@ -48,7 +47,7 @@ public class LdapRdnComponentTest {
LdapRdnComponent component1 = new LdapRdnComponent("cn", "john doe");
LdapRdnComponent component2 = new LdapRdnComponent("cn", "john doe");
int result = component1.compareTo(component2);
assertEquals(0, result);
assertThat(result).isEqualTo(0);
}
@Test
@@ -56,8 +55,8 @@ public class LdapRdnComponentTest {
LdapRdnComponent component1 = new LdapRdnComponent("cn", "john doe");
LdapRdnComponent component2 = new LdapRdnComponent("CN", "John Doe");
assertEquals("Should be equal", component1, component2);
assertTrue("0 should be returned by compareTo", component1.compareTo(component2) == 0);
assertThat(component2).as("Should be equal").isEqualTo(component1);
assertThat(component1.compareTo(component2) == 0).as("0 should be returned by compareTo").isTrue();
}
@Test
@@ -65,7 +64,7 @@ public class LdapRdnComponentTest {
LdapRdnComponent component1 = new LdapRdnComponent("cn", "john doe");
LdapRdnComponent component2 = new LdapRdnComponent("CN", "John Doe");
assertEquals("Should be equal", component1.hashCode(), component2.hashCode());
assertThat(component2.hashCode()).as("Should be equal").isEqualTo(component1.hashCode());
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,8 +20,7 @@ import com.gargoylesoftware.base.testing.EqualsTester;
import org.junit.Test;
import org.springframework.ldap.BadLdapGrammarException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit test for the LdapRdn class.
@@ -35,11 +34,11 @@ public class LdapRdnTest {
LdapRdn rdn = new LdapRdn("foo=bar");
assertEquals("foo", rdn.getComponent().getKey());
assertEquals("bar", rdn.getComponent().getValue());
assertEquals("foo=bar", rdn.getComponent().getLdapEncoded());
assertEquals("foo", rdn.getKey());
assertEquals("bar", rdn.getValue());
assertThat(rdn.getComponent().getKey()).isEqualTo("foo");
assertThat(rdn.getComponent().getValue()).isEqualTo("bar");
assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar");
assertThat(rdn.getKey()).isEqualTo("foo");
assertThat(rdn.getValue()).isEqualTo("bar");
}
@Test
@@ -47,9 +46,9 @@ public class LdapRdnTest {
LdapRdn rdn = new LdapRdn(" foo = bar ");
assertEquals("foo", rdn.getComponent().getKey());
assertEquals("bar", rdn.getComponent().getValue());
assertEquals("foo=bar", rdn.getComponent().getLdapEncoded());
assertThat(rdn.getComponent().getKey()).isEqualTo("foo");
assertThat(rdn.getComponent().getValue()).isEqualTo("bar");
assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar");
}
@Test
@@ -57,9 +56,9 @@ public class LdapRdnTest {
LdapRdn rdn = new LdapRdn("foo=bar\\=fum");
assertEquals("foo", rdn.getComponent().getKey());
assertEquals("bar=fum", rdn.getComponent().getValue());
assertEquals("foo=bar\\=fum", rdn.getComponent().getLdapEncoded());
assertThat(rdn.getComponent().getKey()).isEqualTo("foo");
assertThat(rdn.getComponent().getValue()).isEqualTo("bar=fum");
assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar\\=fum");
}
@Test
@@ -67,9 +66,9 @@ public class LdapRdnTest {
LdapRdn rdn = new LdapRdn("foo=bar\\0dfum");
assertEquals("foo", rdn.getComponent().getKey());
assertEquals("bar\rfum", rdn.getComponent().getValue());
assertEquals("foo=bar\\0Dfum", rdn.getComponent().getLdapEncoded());
assertThat(rdn.getComponent().getKey()).isEqualTo("foo");
assertThat(rdn.getComponent().getValue()).isEqualTo("bar\rfum");
assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar\\0Dfum");
}
@Test(expected = BadLdapGrammarException.class)
@@ -81,9 +80,9 @@ public class LdapRdnTest {
public void testLdapRdn_parse_spaces_escape() {
LdapRdn rdn = new LdapRdn(" foo = \\ bar\\20 \\ ");
assertEquals("foo", rdn.getComponent().getKey());
assertEquals(" bar ", rdn.getComponent().getValue());
assertEquals("foo=\\ bar \\ ", rdn.getComponent().getLdapEncoded());
assertThat(rdn.getComponent().getKey()).isEqualTo("foo");
assertThat(rdn.getComponent().getValue()).isEqualTo(" bar ");
assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=\\ bar \\ ");
}
@Test(expected = BadLdapGrammarException.class)
@@ -95,11 +94,9 @@ public class LdapRdnTest {
public void testLdapRdn_parse_slash() {
LdapRdn rdn = new LdapRdn("ou=Clerical / Secretarial Staff");
assertEquals("ou", rdn.getComponent().getKey());
assertEquals("Clerical / Secretarial Staff", rdn.getComponent()
.getValue());
assertEquals("ou=Clerical / Secretarial Staff", rdn.getComponent()
.getLdapEncoded());
assertThat(rdn.getComponent().getKey()).isEqualTo("ou");
assertThat(rdn.getComponent().getValue()).isEqualTo("Clerical / Secretarial Staff");
assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("ou=Clerical / Secretarial Staff");
}
@Test(expected = BadLdapGrammarException.class)
@@ -111,42 +108,42 @@ public class LdapRdnTest {
public void testLdapRdn_KeyValue_simple() {
LdapRdn rdn = new LdapRdn("foo", "bar");
assertEquals("foo", rdn.getComponent().getKey());
assertEquals("bar", rdn.getComponent().getValue());
assertEquals("foo=bar", rdn.getComponent().getLdapEncoded());
assertThat(rdn.getComponent().getKey()).isEqualTo("foo");
assertThat(rdn.getComponent().getValue()).isEqualTo("bar");
assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar");
}
@Test
public void testLdapRdn_KeyValue_valueNeedsEscape() {
LdapRdn rdn = new LdapRdn("foo", "bar\\");
assertEquals("foo", rdn.getComponent().getKey());
assertEquals("bar\\", rdn.getComponent().getValue());
assertEquals("foo=bar\\\\", rdn.getComponent().getLdapEncoded());
assertThat(rdn.getComponent().getKey()).isEqualTo("foo");
assertThat(rdn.getComponent().getValue()).isEqualTo("bar\\");
assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar\\\\");
}
@Test
public void testEncodeUrl() {
LdapRdn rdn = new LdapRdn("o = example.com ");
assertEquals("o=example.com", rdn.encodeUrl());
assertThat(rdn.encodeUrl()).isEqualTo("o=example.com");
}
@Test
public void testEncodeUrl_SpacesInValue() {
LdapRdn rdn = new LdapRdn("o = my organization ");
assertEquals("o=my%20organization", rdn.encodeUrl());
assertThat(rdn.encodeUrl()).isEqualTo("o=my%20organization");
}
@Test
public void testLdapRdn_Parse_MultipleComponents() {
LdapRdn rdn = new LdapRdn("cn=John Doe+sn=Doe");
assertEquals("cn=John Doe", rdn.getComponent(0).encodeLdap());
assertEquals("sn=Doe", rdn.getComponent(1).encodeLdap());
assertEquals("cn=John Doe+sn=Doe", rdn.getLdapEncoded());
assertEquals("cn", rdn.getKey());
assertEquals("John Doe", rdn.getValue());
assertEquals("John Doe", rdn.getValue("cn"));
assertEquals("Doe", rdn.getValue("sn"));
assertThat(rdn.getComponent(0).encodeLdap()).isEqualTo("cn=John Doe");
assertThat(rdn.getComponent(1).encodeLdap()).isEqualTo("sn=Doe");
assertThat(rdn.getLdapEncoded()).isEqualTo("cn=John Doe+sn=Doe");
assertThat(rdn.getKey()).isEqualTo("cn");
assertThat(rdn.getValue()).isEqualTo("John Doe");
assertThat(rdn.getValue("cn")).isEqualTo("John Doe");
assertThat(rdn.getValue("sn")).isEqualTo("Doe");
}
@Test(expected = IllegalArgumentException.class)
@@ -187,7 +184,7 @@ public class LdapRdnTest {
LdapRdn rdn2 = new LdapRdn("cn=john doe");
int result = rdn1.compareTo(rdn2);
assertEquals(0, result);
assertThat(result).isEqualTo(0);
}
@Test
@@ -195,7 +192,7 @@ public class LdapRdnTest {
LdapRdn rdn1 = new LdapRdn("cn=john doe+sn=doe");
LdapRdn rdn2 = new LdapRdn("sn=doe+cn=john doe");
assertEquals("Should be equal", rdn1, rdn2);
assertThat(rdn2).as("Should be equal").isEqualTo(rdn1);
}
@Test
@@ -203,7 +200,7 @@ public class LdapRdnTest {
LdapRdn rdn1 = new LdapRdn("cn=john doe+sn=doe");
LdapRdn rdn2 = new LdapRdn("sn=doe+cn=john doe");
assertEquals("Should be equal", rdn1.hashCode(), rdn2.hashCode());
assertThat(rdn2.hashCode()).as("Should be equal").isEqualTo(rdn1.hashCode());
}
@Test
@@ -212,7 +209,7 @@ public class LdapRdnTest {
LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doe");
int result = rdn1.compareTo(rdn2);
assertEquals(0, result);
assertThat(result).isEqualTo(0);
}
@Test
@@ -221,7 +218,7 @@ public class LdapRdnTest {
LdapRdn rdn2 = new LdapRdn("cn=john doe+tn=doe");
int result = rdn1.compareTo(rdn2);
assertTrue(result < 0);
assertThat(result < 0).isTrue();
}
@Test
@@ -230,7 +227,7 @@ public class LdapRdnTest {
LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doe");
int result = rdn1.compareTo(rdn2);
assertTrue(result < 0);
assertThat(result < 0).isTrue();
}
@Test
@@ -239,7 +236,7 @@ public class LdapRdnTest {
LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doa");
int result = rdn1.compareTo(rdn2);
assertTrue(result > 0);
assertThat(result > 0).isTrue();
}
@Test
@@ -248,7 +245,7 @@ public class LdapRdnTest {
LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doe+description=tjo");
int result = rdn1.compareTo(rdn2);
assertTrue(result < 0);
assertThat(result < 0).isTrue();
}
@Test
@@ -257,6 +254,6 @@ public class LdapRdnTest {
LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doe");
int result = rdn1.compareTo(rdn2);
assertTrue(result > 0);
assertThat(result > 0).isTrue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,11 +30,8 @@ import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -137,9 +134,9 @@ public class LdapTemplateListTest {
verify(dirContextMock).close();
verify(namingEnumerationMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(NAME, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(NAME);
}
@Test
@@ -155,9 +152,9 @@ public class LdapTemplateListTest {
verify(dirContextMock).close();
verify(namingEnumerationMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(NAME, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(NAME);
}
@Test
@@ -201,7 +198,7 @@ public class LdapTemplateListTest {
tested.list(NAME);
fail("PartialResultException expected");
} catch (PartialResultException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -220,8 +217,8 @@ public class LdapTemplateListTest {
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(0, list.size());
assertThat(list).isNotNull();
assertThat(list).isEmpty();
}
@Test
@@ -235,7 +232,7 @@ public class LdapTemplateListTest {
tested.list(NAME);
fail("LimitExceededException expected");
} catch (LimitExceededException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -256,9 +253,9 @@ public class LdapTemplateListTest {
verify(dirContextMock).close();
verify(namingEnumerationMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(NAME, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(NAME);
}
@Test
@@ -274,9 +271,9 @@ public class LdapTemplateListTest {
verify(dirContextMock).close();
verify(namingEnumerationMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(NAME, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(NAME);
}
@Test
@@ -296,9 +293,9 @@ public class LdapTemplateListTest {
verify(dirContextMock).close();
verify(namingEnumerationMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -318,8 +315,8 @@ public class LdapTemplateListTest {
verify(dirContextMock).close();
verify(namingEnumerationMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,9 +29,8 @@ import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -88,7 +87,7 @@ public class LdapTemplateLookupTest {
verify(dirContextMock).close();
assertSame(expected, actual);
assertThat(actual).isSameAs(expected);
}
@Test
@@ -102,7 +101,7 @@ public class LdapTemplateLookupTest {
verify(dirContextMock).close();
assertSame(expected, actual);
assertThat(actual).isSameAs(expected);
}
@Test
@@ -116,7 +115,7 @@ public class LdapTemplateLookupTest {
tested.lookup(nameMock);
fail("NameNotFoundException expected");
} catch (NameNotFoundException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -138,7 +137,7 @@ public class LdapTemplateLookupTest {
verify(dirContextMock).close();
assertSame(expected, actual);
assertThat(actual).isSameAs(expected);
}
@Test
@@ -156,7 +155,7 @@ public class LdapTemplateLookupTest {
verify(dirContextMock).close();
assertSame(expected, actual);
assertThat(actual).isSameAs(expected);
}
@Test
@@ -170,7 +169,7 @@ public class LdapTemplateLookupTest {
tested.lookup(nameMock, attributesMapperMock);
fail("NameNotFoundException expected");
} catch (NameNotFoundException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -192,7 +191,7 @@ public class LdapTemplateLookupTest {
verify(dirContextMock).close();
assertSame(transformed, actual);
assertThat(actual).isSameAs(transformed);
}
@Test
@@ -208,7 +207,7 @@ public class LdapTemplateLookupTest {
// Perform test
Object result = tested.findByDn(nameMock, expectedClass);
assertSame(transformed, result);
assertThat(result).isSameAs(transformed);
verify(odmMock).manageClass(expectedClass);
}
@@ -229,7 +228,7 @@ public class LdapTemplateLookupTest {
verify(dirContextMock).close();
assertSame(transformed, actual);
assertThat(actual).isSameAs(transformed);
}
@Test
@@ -243,7 +242,7 @@ public class LdapTemplateLookupTest {
tested.lookup(nameMock, contextMapperMock);
fail("NameNotFoundException expected");
} catch (NameNotFoundException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -270,7 +269,7 @@ public class LdapTemplateLookupTest {
verify(dirContextMock).close();
assertSame(expected, actual);
assertThat(actual).isSameAs(expected);
}
@Test
@@ -293,7 +292,7 @@ public class LdapTemplateLookupTest {
verify(dirContextMock).close();
assertSame(expected, actual);
assertThat(actual).isSameAs(expected);
}
// Tests for lookup(name, attributes, ContextMapper)
@@ -320,7 +319,7 @@ public class LdapTemplateLookupTest {
verify(dirContextMock).close();
assertSame(transformed, actual);
assertThat(actual).isSameAs(transformed);
}
@Test
@@ -347,6 +346,6 @@ public class LdapTemplateLookupTest {
verify(dirContextMock).close();
assertSame(transformed, actual);
assertThat(actual).isSameAs(transformed);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,8 +25,8 @@ import javax.naming.Name;
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -91,7 +91,7 @@ public class LdapTemplateRenameTest {
tested.rename(oldNameMock, newNameMock);
fail("NameAlreadyBoundException expected");
} catch (NameAlreadyBoundException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -109,7 +109,7 @@ public class LdapTemplateRenameTest {
tested.rename(oldNameMock, newNameMock);
fail("UncategorizedLdapException expected");
} catch (UncategorizedLdapException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,12 +49,8 @@ import javax.naming.ldap.LdapName;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
@@ -228,7 +224,7 @@ public class LdapTemplateTest {
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
}
@@ -320,9 +316,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -347,9 +343,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -374,9 +370,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -400,9 +396,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -428,9 +424,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -456,9 +452,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -488,9 +484,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -513,9 +509,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -538,9 +534,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -563,9 +559,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -588,9 +584,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -609,9 +605,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -635,7 +631,7 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertSame(expectedResult, result);
assertThat(result).isSameAs(expectedResult);
}
@Test
@@ -652,7 +648,7 @@ public class LdapTemplateTest {
tested.findOne(query().where("ou").is("somevalue"), expectedClass);
fail("EmptyResultDataAccessException expected");
} catch (EmptyResultDataAccessException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(namingEnumerationMock).close();
@@ -680,7 +676,7 @@ public class LdapTemplateTest {
tested.findOne(query().where("ou").is("somevalue"), expectedClass);
fail("EmptyResultDataAccessException expected");
} catch (IncorrectResultSizeDataAccessException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(namingEnumerationMock).close();
@@ -709,9 +705,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -736,9 +732,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -761,9 +757,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -783,9 +779,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -807,9 +803,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -831,9 +827,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -860,9 +856,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -884,9 +880,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -909,9 +905,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -934,9 +930,9 @@ public class LdapTemplateTest {
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertNotNull(list);
assertEquals(1, list.size());
assertSame(expectedResult, list.get(0));
assertThat(list).isNotNull();
assertThat(list).hasSize(1);
assertThat(list.get(0)).isSameAs(expectedResult);
}
@Test
@@ -977,7 +973,7 @@ public class LdapTemplateTest {
fail("LimitExceededException expected");
}
catch (LimitExceededException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -1024,7 +1020,7 @@ public class LdapTemplateTest {
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -1090,7 +1086,7 @@ public class LdapTemplateTest {
tested.create(expectedObject);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -1283,7 +1279,7 @@ public class LdapTemplateTest {
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -1300,7 +1296,7 @@ public class LdapTemplateTest {
verify(dirContextMock).close();
assertSame(object, result);
assertThat(result).isSameAs(object);
}
@Test
@@ -1315,7 +1311,7 @@ public class LdapTemplateTest {
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -1332,7 +1328,7 @@ public class LdapTemplateTest {
verify(dirContextMock).close();
assertSame(object, result);
assertThat(result).isSameAs(object);
}
@Test
@@ -1347,7 +1343,7 @@ public class LdapTemplateTest {
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -1385,7 +1381,7 @@ public class LdapTemplateTest {
fail("LimitExceededException expected");
}
catch (LimitExceededException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextProcessorMock).preProcess(dirContextMock);
@@ -1423,7 +1419,7 @@ public class LdapTemplateTest {
fail("LimitExceededException expected");
}
catch (LimitExceededException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -1443,7 +1439,7 @@ public class LdapTemplateTest {
fail("LimitExceededException expected");
}
catch (LimitExceededException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(namingEnumerationMock).close();
@@ -1461,7 +1457,7 @@ public class LdapTemplateTest {
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -1479,7 +1475,7 @@ public class LdapTemplateTest {
fail("PartialResultException expected");
}
catch (PartialResultException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextProcessorMock).preProcess(dirContextMock);
@@ -1509,13 +1505,13 @@ public class LdapTemplateTest {
final LdapName expectedName = LdapUtils.emptyLdapName();
LdapTemplate tested = new LdapTemplate() {
public Object lookup(Name dn) {
assertSame(dn, dn);
assertThat(dn).isSameAs(dn);
return expectedResult;
}
};
DirContextOperations result = tested.lookupContext(expectedName);
assertSame(expectedResult, result);
assertThat(result).isSameAs(expectedResult);
}
@@ -1526,13 +1522,13 @@ public class LdapTemplateTest {
LdapTemplate tested = new LdapTemplate() {
public Object lookup(String dn) {
assertSame(expectedName, dn);
assertThat(dn).isSameAs(expectedName);
return expectedResult;
}
};
DirContextOperations result = tested.lookupContext(expectedName);
assertSame(expectedResult, result);
assertThat(result).isSameAs(expectedResult);
}
@Test
@@ -1546,8 +1542,8 @@ public class LdapTemplateTest {
LdapTemplate tested = new LdapTemplate() {
public void modifyAttributes(Name dn, ModificationItem[] mods) {
assertSame(epectedDn, dn);
assertSame(expectedModifications, mods);
assertThat(dn).isSameAs(epectedDn);
assertThat(mods).isSameAs(expectedModifications);
}
};
@@ -1571,7 +1567,7 @@ public class LdapTemplateTest {
fail("IllegalStateException expected");
}
catch (IllegalStateException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -1590,7 +1586,7 @@ public class LdapTemplateTest {
fail("IllegalStateException expected");
}
catch (IllegalStateException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -1610,8 +1606,8 @@ public class LdapTemplateTest {
verify(dirContextMock).close();
assertNotNull(result);
assertSame(expectedResult, result);
assertThat(result).isNotNull();
assertThat(result).isSameAs(expectedResult);
}
@Test
@@ -1640,7 +1636,7 @@ public class LdapTemplateTest {
fail("IncorrectResultSizeDataAccessException expected");
}
catch (IncorrectResultSizeDataAccessException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(namingEnumerationMock).close();
@@ -1658,7 +1654,7 @@ public class LdapTemplateTest {
fail("EmptyResultDataAccessException expected");
}
catch (EmptyResultDataAccessException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
verify(dirContextMock).close();
@@ -1684,7 +1680,7 @@ public class LdapTemplateTest {
verify(authenticatedContextMock).close();
verify(dirContextMock).close();
assertTrue(result);
assertThat(result).isTrue();
}
@Test
@@ -1719,7 +1715,7 @@ public class LdapTemplateTest {
verify(dirContextMock).close();
assertFalse(result);
assertThat(result).isFalse();
}
@Test
@@ -1779,7 +1775,7 @@ public class LdapTemplateTest {
verify(dirContextMock).close();
assertFalse(result);
assertThat(result).isFalse();
}
@Test
@@ -1804,7 +1800,7 @@ public class LdapTemplateTest {
verify(authenticatedContextMock).close();
verify(dirContextMock).close();
assertFalse(result);
assertThat(result).isFalse();
}
private void noSearchResults(SearchControls controls) throws Exception {

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.core;
import org.junit.Test;
@@ -5,9 +21,7 @@ import org.springframework.ldap.support.LdapUtils;
import javax.naming.NamingException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Mattias Hellborg Arthursson
@@ -18,7 +32,7 @@ public class NameAwareAttributeTest {
NameAwareAttribute attr1 = new NameAwareAttribute("someAttribute");
NameAwareAttribute attr2 = new NameAwareAttribute("someOtherAttribute");
assertFalse(attr1.equals(attr2));
assertThat(attr1.equals(attr2)).isFalse();
}
@Test
@@ -26,8 +40,8 @@ public class NameAwareAttributeTest {
NameAwareAttribute attr1 = new NameAwareAttribute("someAttribute");
NameAwareAttribute attr2 = new NameAwareAttribute("someAttribute");
assertTrue(attr1.equals(attr2));
assertEquals(attr1.hashCode(), attr2.hashCode());
assertThat(attr1.equals(attr2)).isTrue();
assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode());
}
@Test
@@ -41,8 +55,8 @@ public class NameAwareAttributeTest {
attr2.add("value2");
attr2.add("value3");
assertTrue(attr1.equals(attr2));
assertEquals(attr1.hashCode(), attr2.hashCode());
assertThat(attr1.equals(attr2)).isTrue();
assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode());
}
@Test
@@ -56,8 +70,8 @@ public class NameAwareAttributeTest {
attr2.add(new byte[]{3, 2, 1});
attr2.add(new byte[]{1});
assertTrue(attr1.equals(attr2));
assertEquals(attr1.hashCode(), attr2.hashCode());
assertThat(attr1.equals(attr2)).isTrue();
assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode());
}
@Test
@@ -71,8 +85,8 @@ public class NameAwareAttributeTest {
attr2.add(new byte[]{1});
attr2.add(new byte[]{1, 2, 3});
assertTrue(attr1.equals(attr2));
assertEquals(attr1.hashCode(), attr2.hashCode());
assertThat(attr1.equals(attr2)).isTrue();
assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode());
}
@Test
@@ -86,7 +100,7 @@ public class NameAwareAttributeTest {
attr2.add(new byte[]{3, 2, 1});
attr2.add(new byte[]{1});
assertFalse(attr1.equals(attr2));
assertThat(attr1.equals(attr2)).isFalse();
}
@Test
@@ -99,7 +113,7 @@ public class NameAwareAttributeTest {
attr2.add(new byte[]{1, 2, 3});
attr2.add(new byte[]{1});
assertFalse(attr1.equals(attr2));
assertThat(attr1.equals(attr2)).isFalse();
}
@Test
@@ -113,8 +127,8 @@ public class NameAwareAttributeTest {
attr2.add(new byte[]{3, 2, 1});
attr2.add(new byte[]{1});
assertTrue(attr1.equals(attr2));
assertEquals(attr1.hashCode(), attr2.hashCode());
assertThat(attr1.equals(attr2)).isTrue();
assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode());
}
@Test
@@ -128,8 +142,8 @@ public class NameAwareAttributeTest {
attr2.add(new byte[]{3, 2, 1});
attr2.add(new byte[]{1});
assertTrue(attr1.equals(attr2));
assertEquals(attr1.hashCode(), attr2.hashCode());
assertThat(attr1.equals(attr2)).isTrue();
assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode());
}
@Test
@@ -143,7 +157,7 @@ public class NameAwareAttributeTest {
attr2.add(new byte[]{1});
attr2.add(new byte[]{1, 2, 3});
assertFalse(attr1.equals(attr2));
assertThat(attr1.equals(attr2)).isFalse();
}
@Test
@@ -155,10 +169,10 @@ public class NameAwareAttributeTest {
NameAwareAttribute attr2 = new NameAwareAttribute("someAttribute");
attr2.add(LdapUtils.newLdapName(expectedName));
assertEquals(attr1, attr2);
assertEquals(attr1.hashCode(), attr2.hashCode());
assertEquals(expectedName, attr1.get());
assertEquals(expectedName, attr2.get());
assertThat(attr2).isEqualTo(attr1);
assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode());
assertThat(attr1.get()).isEqualTo(expectedName);
assertThat(attr2.get()).isEqualTo(expectedName);
}
@Test
@@ -172,10 +186,10 @@ public class NameAwareAttributeTest {
NameAwareAttribute attr2 = new NameAwareAttribute("someAttribute");
attr2.add(LdapUtils.newLdapName(expectedName2));
assertEquals(attr1, attr2);
assertEquals(attr1.hashCode(), attr2.hashCode());
assertEquals(expectedName1, attr1.get());
assertEquals(expectedName2, attr2.get());
assertThat(attr2).isEqualTo(attr1);
assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode());
assertThat(attr1.get()).isEqualTo(expectedName1);
assertThat(attr2.get()).isEqualTo(expectedName2);
}
@Test
@@ -189,9 +203,9 @@ public class NameAwareAttributeTest {
NameAwareAttribute attr2 = new NameAwareAttribute("someAttribute");
attr2.add(LdapUtils.newLdapName(expectedName2));
assertFalse(attr1.equals(attr2));
assertEquals(expectedName1, attr1.get());
assertEquals(expectedName2, attr2.get());
assertThat(attr1.equals(attr2)).isFalse();
assertThat(attr1.get()).isEqualTo(expectedName1);
assertThat(attr2.get()).isEqualTo(expectedName2);
}
@Test
@@ -207,10 +221,10 @@ public class NameAwareAttributeTest {
attr1.initValuesAsNames();
assertTrue(attr1.equals(attr2));
assertEquals(attr1.hashCode(), attr2.hashCode());
assertEquals(expectedName1, attr1.get());
assertEquals(expectedName2, attr2.get());
assertThat(attr1.equals(attr2)).isTrue();
assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode());
assertThat(attr1.get()).isEqualTo(expectedName1);
assertThat(attr2.get()).isEqualTo(expectedName2);
}
@Test
@@ -224,9 +238,9 @@ public class NameAwareAttributeTest {
NameAwareAttribute attr2 = new NameAwareAttribute("someAttribute");
attr2.add(LdapUtils.newLdapName(expectedName2));
assertFalse(attr1.equals(attr2));
assertEquals(expectedName1, attr1.get());
assertEquals(expectedName2, attr2.get());
assertThat(attr1.equals(attr2)).isFalse();
assertThat(attr1.get()).isEqualTo(expectedName1);
assertThat(attr2.get()).isEqualTo(expectedName2);
}
@Test
@@ -240,8 +254,8 @@ public class NameAwareAttributeTest {
NameAwareAttribute attr2 = new NameAwareAttribute("someAttribute");
attr2.add(expectedValue2);
assertFalse(attr1.equals(attr2));
assertEquals(expectedName1, attr1.get());
assertEquals(expectedValue2, attr2.get());
assertThat(attr1.equals(attr2)).isFalse();
assertThat(attr1.get()).isEqualTo(expectedName1);
assertThat(attr2.get()).isEqualTo(expectedValue2);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import org.junit.Test;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Mattias Hellborg Arthursson
@@ -33,7 +33,7 @@ public class AbstractContextSourceTest {
LdapName ldapName = new LdapName("dc=261consulting, dc=com");
String result = AbstractContextSource.formatForUrl(ldapName);
assertEquals("dc=261consulting,dc=com", result);
assertThat(result).isEqualTo("dc=261consulting,dc=com");
}
@Test
@@ -41,7 +41,7 @@ public class AbstractContextSourceTest {
LdapName ldapName = new LdapName("dc=261consulting?, dc=com");
String result = AbstractContextSource.formatForUrl(ldapName);
assertEquals("dc=261consulting%3F,dc=com", result);
assertThat(result).isEqualTo("dc=261consulting%3F,dc=com");
}
@Test
@@ -49,7 +49,7 @@ public class AbstractContextSourceTest {
LdapName ldapName = new LdapName("ou=some department, dc=261consulting, dc=com");
String result = AbstractContextSource.formatForUrl(ldapName);
assertEquals("ou=some%20department,dc=261consulting,dc=com", result);
assertThat(result).isEqualTo("ou=some%20department,dc=261consulting,dc=com");
}
@Test
@@ -57,6 +57,6 @@ public class AbstractContextSourceTest {
LdapName ldapName = new LdapName("");
String result = AbstractContextSource.formatForUrl(ldapName);
assertEquals("", result);
assertThat(result).isEqualTo("");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ import org.springframework.ldap.support.LdapUtils;
import java.util.HashMap;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -62,7 +62,7 @@ public class BaseLdapPathBeanPostProcessorTest {
verify(ldapPathAwareMock).setBaseLdapPath(new DistinguishedName(expectedPath));
assertSame(ldapPathAwareMock, result);
assertThat(result).isSameAs(ldapPathAwareMock);
}
@Test
@@ -74,7 +74,7 @@ public class BaseLdapPathBeanPostProcessorTest {
verify(ldapNameAwareMock).setBaseLdapPath(LdapUtils.newLdapName(expectedPath));
assertSame(ldapNameAwareMock, result);
assertThat(result).isSameAs(ldapNameAwareMock);
}
@@ -94,7 +94,7 @@ public class BaseLdapPathBeanPostProcessorTest {
verify(ldapPathAwareMock).setBaseLdapPath(new DistinguishedName(expectedPath));
assertSame(ldapPathAwareMock, result);
assertThat(result).isSameAs(ldapPathAwareMock);
}
@Test
@@ -113,7 +113,7 @@ public class BaseLdapPathBeanPostProcessorTest {
verify(ldapNameAwareMock).setBaseLdapPath(LdapUtils.newLdapName(expectedPath));
assertSame(ldapNameAwareMock, result);
assertThat(result).isSameAs(ldapNameAwareMock);
}
@Test
@@ -129,7 +129,7 @@ public class BaseLdapPathBeanPostProcessorTest {
BaseLdapPathSource result = tested.getBaseLdapPathSourceFromApplicationContext();
assertSame(expectedContextSource, result);
assertThat(result).isSameAs(expectedContextSource);
}
@Test(expected = NoSuchBeanDefinitionException.class)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@ import javax.naming.NamingException;
import javax.naming.ldap.Control;
import javax.naming.ldap.HasControls;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -72,7 +72,7 @@ public class ContextMapperCallbackHandlerWithControlsTest {
Object actualResult = tested.getObjectFromNameClassPair(expectedBinding);
assertEquals(expectedResult, actualResult);
assertThat(actualResult).isEqualTo(expectedResult);
}
@Test
@@ -85,7 +85,7 @@ public class ContextMapperCallbackHandlerWithControlsTest {
Object actualResult = tested.getObjectFromNameClassPair(expectedBinding);
assertEquals(expectedResult, actualResult);
assertThat(actualResult).isEqualTo(expectedResult);
}
@Test(expected = ObjectRetrievalException.class)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ import org.junit.Test;
import javax.naming.directory.SearchResult;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
public class CountNameClassPairResultCallbackHandlerTest {
@@ -38,7 +38,7 @@ public class CountNameClassPairResultCallbackHandlerTest {
tested.handleNameClassPair(dummy);
tested.handleNameClassPair(dummy);
assertEquals(3, tested.getNoOfRows());
assertThat(tested.getNoOfRows()).isEqualTo(3);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes;
import java.util.Hashtable;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -64,8 +64,8 @@ public class DefaultDirObjectFactoryTest {
verify(contextMock).close();
assertEquals(DN, adapter.getDn());
assertEquals(expectedAttributes, adapter.getAttributes());
assertThat(adapter.getDn()).isEqualTo(DN);
assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes);
}
@Test
@@ -81,8 +81,8 @@ public class DefaultDirObjectFactoryTest {
verify(contextMock).close();
assertEquals(DN, adapter.getDn());
assertEquals(expectedAttributes, adapter.getAttributes());
assertThat(adapter.getDn()).isEqualTo(DN);
assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes);
}
@Test
@@ -93,8 +93,8 @@ public class DefaultDirObjectFactoryTest {
DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(null, DN, null, new Hashtable(),
expectedAttributes);
assertEquals(DN, adapter.getDn());
assertEquals(expectedAttributes, adapter.getAttributes());
assertThat(adapter.getDn()).isEqualTo(DN);
assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes);
}
@Test
@@ -105,8 +105,8 @@ public class DefaultDirObjectFactoryTest {
DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(new Object(), DN, null,
new Hashtable(), expectedAttributes);
assertEquals(DN, adapter.getDn());
assertEquals(expectedAttributes, adapter.getAttributes());
assertThat(adapter.getDn()).isEqualTo(DN);
assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes);
}
/**
@@ -126,9 +126,9 @@ public class DefaultDirObjectFactoryTest {
verify(contextMock).close();
assertEquals("ou=some unit", adapter.getDn().toString());
assertEquals("ou=some unit,dc=jayway,dc=se", adapter.getNameInNamespace());
assertEquals(expectedAttributes, adapter.getAttributes());
assertThat(adapter.getDn().toString()).isEqualTo("ou=some unit");
assertThat(adapter.getNameInNamespace()).isEqualTo("ou=some unit,dc=jayway,dc=se");
assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes);
}
@Test
@@ -138,8 +138,8 @@ public class DefaultDirObjectFactoryTest {
DefaultDirObjectFactory tested = new DefaultDirObjectFactory();
DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, "");
assertEquals("ou=People,o=JNDITutorial", result.getDn().toString());
assertEquals("ldap://localhost:389", result.getReferralUrl().toString());
assertThat(result.getDn().toString()).isEqualTo("ou=People,o=JNDITutorial");
assertThat(result.getReferralUrl().toString()).isEqualTo("ldap://localhost:389");
}
@Test
@@ -149,8 +149,8 @@ public class DefaultDirObjectFactoryTest {
DefaultDirObjectFactory tested = new DefaultDirObjectFactory();
DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, "");
assertEquals("ou=People,o=JNDITutorial", result.getDn().toString());
assertEquals("ldaps://localhost:389", result.getReferralUrl().toString());
assertThat(result.getDn().toString()).isEqualTo("ou=People,o=JNDITutorial");
assertThat(result.getReferralUrl().toString()).isEqualTo("ldaps://localhost:389");
}
@Test
@@ -160,8 +160,8 @@ public class DefaultDirObjectFactoryTest {
DefaultDirObjectFactory tested = new DefaultDirObjectFactory();
DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, "");
assertEquals("", result.getDn().toString());
assertEquals("ldap://localhost:389", result.getReferralUrl().toString());
assertThat(result.getDn().toString()).isEqualTo("");
assertThat(result.getReferralUrl().toString()).isEqualTo("ldap://localhost:389");
}
@Test
@@ -171,7 +171,7 @@ public class DefaultDirObjectFactoryTest {
DefaultDirObjectFactory tested = new DefaultDirObjectFactory();
DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, "");
assertEquals("", result.getDn().toString());
assertEquals("ldap://localhost:389", result.getReferralUrl().toString());
assertThat(result.getDn().toString()).isEqualTo("");
assertThat(result.getReferralUrl().toString()).isEqualTo("ldap://localhost:389");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,10 +24,7 @@ import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* IncrementalAttributesMapper Tester.
@@ -47,15 +44,15 @@ public class DefaultIncrementalAttributesMapperTest {
public void testGetAttributesArray() throws Exception {
String[] attributes = tested.getAttributesForLookup();
assertEquals(1, attributes.length);
assertEquals("member", attributes[0]);
assertThat(attributes.length).isEqualTo(1);
assertThat(attributes[0]).isEqualTo("member");
tested = new DefaultIncrementalAttributesMapper(10, "member");
attributes = tested.getAttributesForLookup();
assertEquals(1, attributes.length);
assertEquals("member;Range=0-10", attributes[0]);
assertThat(attributes.length).isEqualTo(1);
assertThat(attributes[0]).isEqualTo("member;Range=0-10");
}
@Test
@@ -63,22 +60,22 @@ public class DefaultIncrementalAttributesMapperTest {
tested = new DefaultIncrementalAttributesMapper(20, new String[]{"member", "cn"});
String[] attributes = tested.getAttributesForLookup();
assertEquals(2, attributes.length);
assertThat(attributes.length).isEqualTo(2);
assertEquals("member;Range=0-20", attributes[0]);
assertEquals("cn;Range=0-20", attributes[1]);
assertThat(attributes[0]).isEqualTo("member;Range=0-20");
assertThat(attributes[1]).isEqualTo("cn;Range=0-20");
}
@Test
public void testLoopEmpty() throws Exception {
assertTrue(tested.hasMore());
assertThat(tested.hasMore()).isTrue();
Attributes attributes = new BasicAttributes();
tested.mapFromAttributes(attributes);
assertFalse(tested.hasMore());
assertNull(tested.getValues("member"));
assertThat(tested.hasMore()).isFalse();
assertThat(tested.getValues("member")).isNull();
}
@Test
@@ -87,15 +84,15 @@ public class DefaultIncrementalAttributesMapperTest {
tested.mapFromAttributes(attributes);
assertTrue(tested.hasMore());
assertEquals(11, tested.getValues("member").size());
assertThat(tested.hasMore()).isTrue();
assertThat(tested.getValues("member")).hasSize(11);
attributes = createAttributes("member", new RangeOption(11), 5);
tested.mapFromAttributes(attributes);
assertFalse(tested.hasMore());
assertEquals(16, tested.getValues("member").size());
assertThat(tested.hasMore()).isFalse();
assertThat(tested.getValues("member")).hasSize(16);
}
@Test
@@ -106,8 +103,8 @@ public class DefaultIncrementalAttributesMapperTest {
tested.mapFromAttributes(attributes);
assertFalse(tested.hasMore());
assertEquals(11, tested.getValues("member").size());
assertThat(tested.hasMore()).isFalse();
assertThat(tested.getValues("member")).hasSize(11);
}
@Test
@@ -118,15 +115,15 @@ public class DefaultIncrementalAttributesMapperTest {
tested.mapFromAttributes(attributes);
assertTrue(tested.hasMore());
assertEquals(11, tested.getValues("member").size());
assertThat(tested.hasMore()).isTrue();
assertThat(tested.getValues("member")).hasSize(11);
attributes = createAttributes("member", new RangeOption(11, 30));
tested.mapFromAttributes(attributes);
assertFalse(tested.hasMore());
assertEquals(31, tested.getValues("member").size());
assertThat(tested.hasMore()).isFalse();
assertThat(tested.getValues("member")).hasSize(31);
}
@Test
@@ -137,15 +134,15 @@ public class DefaultIncrementalAttributesMapperTest {
tested.mapFromAttributes(attributes);
assertTrue(tested.hasMore());
assertEquals(11, tested.getValues("member").size());
assertThat(tested.hasMore()).isTrue();
assertThat(tested.getValues("member")).hasSize(11);
attributes = createAttributes("member", new RangeOption(11), 5);
tested.mapFromAttributes(attributes);
assertFalse(tested.hasMore());
assertEquals(16, tested.getValues("member").size());
assertThat(tested.hasMore()).isFalse();
assertThat(tested.getValues("member")).hasSize(16);
}
@Test
@@ -157,18 +154,18 @@ public class DefaultIncrementalAttributesMapperTest {
tested.mapFromAttributes(attributes);
assertTrue(tested.hasMore());
assertEquals(6, tested.getValues("member").size());
assertEquals(10, tested.getValues("cn").size());
assertThat(tested.hasMore()).isTrue();
assertThat(tested.getValues("member")).hasSize(6);
assertThat(tested.getValues("cn")).hasSize(10);
assertEquals(1, tested.getAttributesForLookup().length);
assertThat(tested.getAttributesForLookup().length).isEqualTo(1);
attributes = createAttributes("member", new RangeOption(6), 5);
tested.mapFromAttributes(attributes);
assertFalse(tested.hasMore());
assertEquals(11, tested.getValues("member").size());
assertThat(tested.hasMore()).isFalse();
assertThat(tested.getValues("member")).hasSize(11);
}
private Attributes createAttributes(String attributeName, RangeOption range) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,8 +24,7 @@ import javax.naming.Context;
import java.util.HashMap;
import java.util.Hashtable;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for the LdapContextSource class.
@@ -69,13 +68,13 @@ public class LdapContextSourceTest {
tested.setPassword("secret");
tested.afterPropertiesSet();
Hashtable env = tested.getAnonymousEnv();
assertEquals("ldap://ldap.example.com:389/dc=some%20example,dc=se", env.get(Context.PROVIDER_URL));
assertEquals("true", env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG));
assertNull(env.get(Context.SECURITY_PRINCIPAL));
assertNull(env.get(Context.SECURITY_CREDENTIALS));
assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389/dc=some%20example,dc=se");
assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isEqualTo("true");
assertThat(env.get(Context.SECURITY_PRINCIPAL)).isNull();
assertThat(env.get(Context.SECURITY_CREDENTIALS)).isNull();
// check that base was added to environment
assertEquals(LdapUtils.newLdapName("dc=some example,dc=se"), env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY));
assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isEqualTo(LdapUtils.newLdapName("dc=some example,dc=se"));
// Verify that changing values does not change the environment values.
tested.setBase("dc=other,dc=se");
@@ -83,12 +82,12 @@ public class LdapContextSourceTest {
tested.setPooled(false);
env = tested.getAnonymousEnv();
assertEquals("ldap://ldap.example.com:389/dc=some%20example,dc=se", env.get(Context.PROVIDER_URL));
assertEquals("true", env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG));
assertNull(env.get(Context.SECURITY_PRINCIPAL));
assertNull(env.get(Context.SECURITY_CREDENTIALS));
assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389/dc=some%20example,dc=se");
assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isEqualTo("true");
assertThat(env.get(Context.SECURITY_PRINCIPAL)).isNull();
assertThat(env.get(Context.SECURITY_CREDENTIALS)).isNull();
assertEquals(LdapUtils.newLdapName("dc=some example,dc=se"), env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY));
assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isEqualTo(LdapUtils.newLdapName("dc=some example,dc=se"));
}
@Test
@@ -96,10 +95,10 @@ public class LdapContextSourceTest {
tested.setUrl("ldap://ldap.example.com:389");
tested.afterPropertiesSet();
Hashtable env = tested.getAnonymousEnv();
assertEquals("ldap://ldap.example.com:389", env.get(Context.PROVIDER_URL));
assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389");
// check that base was not added to environment
assertNull(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY));
assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isNull();
}
@Test
@@ -110,8 +109,8 @@ public class LdapContextSourceTest {
tested.setBaseEnvironmentProperties(map);
tested.afterPropertiesSet();
Hashtable env = tested.getAnonymousEnv();
assertEquals("ldap://ldap.example.com:389", env.get(Context.PROVIDER_URL));
assertNull(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG));
assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389");
assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isNull();
}
@Test
@@ -123,8 +122,8 @@ public class LdapContextSourceTest {
tested.setPooled(false);
tested.afterPropertiesSet();
Hashtable env = tested.getAnonymousEnv();
assertEquals("ldap://ldap.example.com:389", env.get(Context.PROVIDER_URL));
assertNull(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG));
assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389");
assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isNull();
}
@Test
@@ -133,10 +132,10 @@ public class LdapContextSourceTest {
tested.setBase(null);
tested.afterPropertiesSet();
Hashtable env = tested.getAnonymousEnv();
assertEquals("ldap://ldap.example.com:389", env.get(Context.PROVIDER_URL));
assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389");
// check that base was not added to environment
assertNull(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY));
assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isNull();
}
@Test
@@ -151,7 +150,7 @@ public class LdapContextSourceTest {
// check that base was not added to environment
Hashtable env = tested.getAnonymousEnv();
assertNull(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY));
assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isNull();
}
@Test(expected = IllegalArgumentException.class)
@@ -179,7 +178,7 @@ public class LdapContextSourceTest {
// check that base was not added to environment
Hashtable env = tested.getAnonymousEnv();
assertNull(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY));
assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isNull();
}
@Test
@@ -192,13 +191,13 @@ public class LdapContextSourceTest {
tested.afterPropertiesSet();
Hashtable env = tested.getAuthenticatedEnv("cn=Some User", "secret");
assertEquals("ldap://ldap.example.com:389/dc=example,dc=se", env.get(Context.PROVIDER_URL));
assertEquals("true", env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG));
assertEquals("cn=Some User", env.get(Context.SECURITY_PRINCIPAL));
assertEquals("secret", env.get(Context.SECURITY_CREDENTIALS));
assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389/dc=example,dc=se");
assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isEqualTo("true");
assertThat(env.get(Context.SECURITY_PRINCIPAL)).isEqualTo("cn=Some User");
assertThat(env.get(Context.SECURITY_CREDENTIALS)).isEqualTo("secret");
// check that base was added to environment
assertEquals(LdapUtils.newLdapName("dc=example,dc=se"), env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY));
assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isEqualTo(LdapUtils.newLdapName("dc=example,dc=se"));
}
@Test
@@ -211,13 +210,13 @@ public class LdapContextSourceTest {
tested.setCacheEnvironmentProperties(false);
tested.afterPropertiesSet();
Hashtable env = tested.getAnonymousEnv();
assertEquals("ldap://ldap.example.com:389/dc=example,dc=se", env.get(Context.PROVIDER_URL));
assertEquals("true", env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG));
assertNull(env.get(Context.SECURITY_PRINCIPAL));
assertNull(env.get(Context.SECURITY_CREDENTIALS));
assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389/dc=example,dc=se");
assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isEqualTo("true");
assertThat(env.get(Context.SECURITY_PRINCIPAL)).isNull();
assertThat(env.get(Context.SECURITY_CREDENTIALS)).isNull();
tested.setUrl("ldap://ldap2.example.com:389");
env = tested.getAnonymousEnv();
assertEquals("ldap://ldap2.example.com:389/dc=example,dc=se", env.get(Context.PROVIDER_URL));
assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap2.example.com:389/dc=example,dc=se");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,10 +18,8 @@ package org.springframework.ldap.core.support;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
/**
* IncrementalAttributesMapper Tester.
@@ -37,7 +35,7 @@ public class RangeOptionTest {
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
@@ -45,7 +43,7 @@ public class RangeOptionTest {
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
@@ -53,7 +51,7 @@ public class RangeOptionTest {
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
@@ -61,82 +59,82 @@ public class RangeOptionTest {
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@Test
public void testToString() throws Exception {
RangeOption range = new RangeOption(0, 100);
assertEquals("Range=0-100", range.toString());
assertThat(range.toString()).isEqualTo("Range=0-100");
range = new RangeOption(0, RangeOption.TERMINAL_END_OF_RANGE);
assertEquals("Range=0-*", range.toString());
assertThat(range.toString()).isEqualTo("Range=0-*");
range = new RangeOption(0, RangeOption.TERMINAL_MISSING);
assertEquals("Range=0", range.toString());
assertThat(range.toString()).isEqualTo("Range=0");
}
@Test
public void testParse() throws Exception {
RangeOption range = RangeOption.parse("Range=0-100");
assertEquals(0, range.getInitial());
assertEquals(100, range.getTerminal());
assertThat(range.getInitial()).isEqualTo(0);
assertThat(range.getTerminal()).isEqualTo(100);
range = RangeOption.parse("range=0-100");
assertEquals(0, range.getInitial());
assertEquals(100, range.getTerminal());
assertThat(range.getInitial()).isEqualTo(0);
assertThat(range.getTerminal()).isEqualTo(100);
range = RangeOption.parse("RANGE=0-100");
assertEquals(0, range.getInitial());
assertEquals(100, range.getTerminal());
assertThat(range.getInitial()).isEqualTo(0);
assertThat(range.getTerminal()).isEqualTo(100);
range = RangeOption.parse("Range=0-*");
assertEquals(0, range.getInitial());
assertEquals(RangeOption.TERMINAL_END_OF_RANGE, range.getTerminal());
assertThat(range.getInitial()).isEqualTo(0);
assertThat(range.getTerminal()).isEqualTo(RangeOption.TERMINAL_END_OF_RANGE);
range = RangeOption.parse("Range=10");
assertEquals(10, range.getInitial());
assertEquals(RangeOption.TERMINAL_MISSING, range.getTerminal());
assertThat(range.getInitial()).isEqualTo(10);
assertThat(range.getTerminal()).isEqualTo(RangeOption.TERMINAL_MISSING);
}
@Test
public void testParseInvalid() {
assertNull(RangeOption.parse("Range=10-"));
assertNull(RangeOption.parse("Range=10-a"));
assertNull(RangeOption.parse("lang-en"));
assertNull(RangeOption.parse("member;Range=10-100"));
assertNull(RangeOption.parse(";Range=10-100"));
assertNull(RangeOption.parse("Range=10-100;"));
assertNull(RangeOption.parse("Range=10-100;lang-de"));
assertThat(RangeOption.parse("Range=10-")).isNull();
assertThat(RangeOption.parse("Range=10-a")).isNull();
assertThat(RangeOption.parse("lang-en")).isNull();
assertThat(RangeOption.parse("member;Range=10-100")).isNull();
assertThat(RangeOption.parse(";Range=10-100")).isNull();
assertThat(RangeOption.parse("Range=10-100;")).isNull();
assertThat(RangeOption.parse("Range=10-100;lang-de")).isNull();
}
@Test
public void testCompare() {
RangeOption range1 = RangeOption.parse("Range=10-500");
RangeOption range2 = RangeOption.parse("Range=10-500");
assertTrue(range1.compareTo(range2) == 0);
assertTrue(range2.compareTo(range1) == 0);
assertThat(range1.compareTo(range2) == 0).isTrue();
assertThat(range2.compareTo(range1) == 0).isTrue();
range1 = RangeOption.parse("Range=0-*");
range2 = RangeOption.parse("Range=0-*");
assertTrue(range1.compareTo(range2) == 0);
assertTrue(range2.compareTo(range1) == 0);
assertThat(range1.compareTo(range2) == 0).isTrue();
assertThat(range2.compareTo(range1) == 0).isTrue();
range1 = RangeOption.parse("Range=0");
range2 = RangeOption.parse("Range=0");
assertTrue(range1.compareTo(range2) == 0);
assertTrue(range2.compareTo(range1) == 0);
assertThat(range1.compareTo(range2) == 0).isTrue();
assertThat(range2.compareTo(range1) == 0).isTrue();
range1 = RangeOption.parse("Range=0-101");
range2 = RangeOption.parse("Range=0-100");
assertTrue(range1.compareTo(range2) > 0);
assertTrue(range2.compareTo(range1) < 0);
assertThat(range1.compareTo(range2) > 0).isTrue();
assertThat(range2.compareTo(range1) < 0).isTrue();
range1 = RangeOption.parse("Range=0-*");
range2 = RangeOption.parse("Range=0-100");
assertTrue(range1.compareTo(range2) > 0);
assertTrue(range2.compareTo(range1) < 0);
assertThat(range1.compareTo(range2) > 0).isTrue();
assertThat(range2.compareTo(range1) < 0).isTrue();
}
@Test
@@ -145,33 +143,33 @@ public class RangeOptionTest {
RangeOption range2 = RangeOption.parse("Range=11-500");
try {
assertTrue(range1.compareTo(range2) == 0);
assertThat(range1.compareTo(range2) == 0).isTrue();
fail("IllegalStateException expected");
} catch (IllegalStateException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
range1 = RangeOption.parse("Range=10");
range2 = RangeOption.parse("Range=10-500");
try {
assertTrue(range1.compareTo(range2) == 0);
assertThat(range1.compareTo(range2) == 0).isTrue();
fail("IllegalStateException expected");
} catch (IllegalStateException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
range1 = RangeOption.parse("Range=10-500");
range2 = RangeOption.parse("Range=10");
try {
assertTrue(range1.compareTo(range2) == 0);
assertThat(range1.compareTo(range2) == 0).isTrue();
fail("IllegalStateException expected");
} catch (IllegalStateException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -180,15 +178,15 @@ public class RangeOptionTest {
RangeOption range = RangeOption.parse("Range=0-100");
range = range.nextRange(100);
assertEquals(101, range.getInitial());
assertEquals(200, range.getTerminal());
assertThat(range.getInitial()).isEqualTo(101);
assertThat(range.getTerminal()).isEqualTo(200);
range = range.nextRange(10);
assertEquals(201, range.getInitial());
assertEquals(210, range.getTerminal());
assertThat(range.getInitial()).isEqualTo(201);
assertThat(range.getTerminal()).isEqualTo(210);
range = range.nextRange(RangeOption.TERMINAL_END_OF_RANGE);
assertEquals(211, range.getInitial());
assertEquals(RangeOption.TERMINAL_END_OF_RANGE, range.getTerminal());
assertThat(range.getInitial()).isEqualTo(211);
assertThat(range.getTerminal()).isEqualTo(RangeOption.TERMINAL_END_OF_RANGE);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,8 +21,7 @@ import org.junit.Test;
import javax.naming.Context;
import java.util.Hashtable;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
public class SimpleDirContextAuthenticationStrategyTest {
private SimpleDirContextAuthenticationStrategy tested;
@@ -37,9 +36,9 @@ public class SimpleDirContextAuthenticationStrategyTest {
Hashtable env = new Hashtable();
tested.setupEnvironment(env, "cn=John Doe", "pw");
assertEquals("simple", env.get(Context.SECURITY_AUTHENTICATION));
assertEquals("cn=John Doe", env.get(Context.SECURITY_PRINCIPAL));
assertEquals("pw", env.get(Context.SECURITY_CREDENTIALS));
assertThat(env.get(Context.SECURITY_AUTHENTICATION)).isEqualTo("simple");
assertThat(env.get(Context.SECURITY_PRINCIPAL)).isEqualTo("cn=John Doe");
assertThat(env.get(Context.SECURITY_CREDENTIALS)).isEqualTo("pw");
}
@Test
@@ -47,7 +46,7 @@ public class SimpleDirContextAuthenticationStrategyTest {
Hashtable env = new Hashtable();
tested.processContextAfterCreation(null, "cn=John Doe", "pw");
assertTrue(env.isEmpty());
assertThat(env.isEmpty()).isTrue();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ import javax.naming.directory.DirContext;
import java.lang.reflect.Proxy;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
@@ -59,7 +59,7 @@ public class SingleContextSourceTest {
@Override
public Object executeWithContext(DirContext ctx) throws NamingException {
Object targetContex = Whitebox.getInternalState(Proxy.getInvocationHandler(ctx), "target");
assertSame(dirContextMock, targetContex);
assertThat(targetContex).isSameAs(dirContextMock);
return false;
}
});
@@ -70,7 +70,7 @@ public class SingleContextSourceTest {
@Override
public Object executeWithContext(DirContext ctx) throws NamingException {
Object targetContex = Whitebox.getInternalState(Proxy.getInvocationHandler(ctx), "target");
assertSame(dirContextMock, targetContex);
assertThat(targetContex).isSameAs(dirContextMock);
return false;
}
});

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@ package org.springframework.ldap.filter;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Adam Skogman
@@ -36,7 +36,7 @@ public class AbstractFilterTest {
}
};
assertEquals("foo", af.encode());
assertThat(af.encode()).isEqualTo("foo");
}
@@ -52,7 +52,7 @@ public class AbstractFilterTest {
}
};
assertEquals("foo", af.toString());
assertThat(af.toString()).isEqualTo("foo");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ package org.springframework.ldap.filter;
import com.gargoylesoftware.base.testing.EqualsTester;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Adam Skogman
@@ -30,14 +30,14 @@ public class AndFilterTest {
public void testZero() {
AndFilter aq = new AndFilter();
assertEquals("", aq.encode());
assertThat(aq.encode()).isEqualTo("");
}
@Test
public void testOne() {
AndFilter aq = new AndFilter().and(new EqualsFilter("a", "b"));
assertEquals("(a=b)", aq.encode());
assertThat(aq.encode()).isEqualTo("(a=b)");
}
@Test
@@ -45,7 +45,7 @@ public class AndFilterTest {
AndFilter aq = new AndFilter().and(new EqualsFilter("a", "b")).and(
new EqualsFilter("c", "d"));
assertEquals("(&(a=b)(c=d))", aq.encode());
assertThat(aq.encode()).isEqualTo("(&(a=b)(c=d))");
}
@Test
@@ -53,7 +53,7 @@ public class AndFilterTest {
AndFilter aq = new AndFilter().and(new EqualsFilter("a", "b")).and(
new EqualsFilter("c", "d")).and(new EqualsFilter("e", "f"));
assertEquals("(&(a=b)(c=d)(e=f))", aq.encode());
assertThat(aq.encode()).isEqualTo("(&(a=b)(c=d)(e=f))");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ package org.springframework.ldap.filter;
import com.gargoylesoftware.base.testing.EqualsTester;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Adam Skogman
@@ -34,7 +34,7 @@ public class EqualsFilterTest {
StringBuffer buff = new StringBuffer();
eqq.encode(buff);
assertEquals("(foo=\\2abar\\28fie\\29)", buff.toString());
assertThat(buff.toString()).isEqualTo("(foo=\\2abar\\28fie\\29)");
}
@@ -46,7 +46,7 @@ public class EqualsFilterTest {
StringBuffer buff = new StringBuffer();
eqq.encode(buff);
assertEquals("(foo=456)", buff.toString());
assertThat(buff.toString()).isEqualTo("(foo=456)");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ package org.springframework.ldap.filter;
import com.gargoylesoftware.base.testing.EqualsTester;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Mattias Hellborg Arthursson
@@ -35,7 +35,7 @@ public class GreaterThanOrEqualsFilterTest {
StringBuffer buff = new StringBuffer();
eqq.encode(buff);
assertEquals("(foo>=\\2abar\\28fie\\29)", buff.toString());
assertThat(buff.toString()).isEqualTo("(foo>=\\2abar\\28fie\\29)");
}
@@ -48,7 +48,7 @@ public class GreaterThanOrEqualsFilterTest {
StringBuffer buff = new StringBuffer();
eqq.encode(buff);
assertEquals("(foo>=456)", buff.toString());
assertThat(buff.toString()).isEqualTo("(foo>=456)");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@ package org.springframework.ldap.filter;
import com.gargoylesoftware.base.testing.EqualsTester;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for the HardcodedFilter class.
@@ -30,20 +30,20 @@ public class HardcodedFilterTest {
@Test
public void testHardcodedFilter() {
HardcodedFilter filter = new HardcodedFilter("(foo=a*b)");
assertEquals("(foo=a*b)", filter.encode());
assertThat(filter.encode()).isEqualTo("(foo=a*b)");
NotFilter notFilter = new NotFilter(new HardcodedFilter("(foo=a*b)"));
assertEquals("(!(foo=a*b))", notFilter.encode());
assertThat(notFilter.encode()).isEqualTo("(!(foo=a*b))");
AndFilter andFilter = new AndFilter();
andFilter.and(new HardcodedFilter("(foo=a*b)"));
andFilter.and(new HardcodedFilter("(bar=a*b)"));
assertEquals("(&(foo=a*b)(bar=a*b))", andFilter.encode());
assertThat(andFilter.encode()).isEqualTo("(&(foo=a*b)(bar=a*b))");
andFilter = new AndFilter();
andFilter.and(new HardcodedFilter("(foo=a*b)"));
andFilter.and(new NotFilter(new HardcodedFilter("(bar=a*b)")));
assertEquals("(&(foo=a*b)(!(bar=a*b)))", andFilter.encode());
assertThat(andFilter.encode()).isEqualTo("(&(foo=a*b)(!(bar=a*b)))");
}
@Test
@@ -58,4 +58,4 @@ public class HardcodedFilterTest {
new EqualsTester(originalObject, identicalObject, differentObject,
subclassObject);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ package org.springframework.ldap.filter;
import com.gargoylesoftware.base.testing.EqualsTester;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Mattias Hellborg Arthursson
@@ -35,7 +35,7 @@ public class LessThanOrEqualsFilterTest {
StringBuffer buff = new StringBuffer();
eqq.encode(buff);
assertEquals("(foo<=\\2abar\\28fie\\29)", buff.toString());
assertThat(buff.toString()).isEqualTo("(foo<=\\2abar\\28fie\\29)");
}
@@ -47,7 +47,7 @@ public class LessThanOrEqualsFilterTest {
StringBuffer buff = new StringBuffer();
eqq.encode(buff);
assertEquals("(foo<=456)", buff.toString());
assertThat(buff.toString()).isEqualTo("(foo<=456)");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ package org.springframework.ldap.filter;
import com.gargoylesoftware.base.testing.EqualsTester;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Anders Henja
@@ -28,25 +28,25 @@ public class LikeFilterTest {
@Test
public void testEncodeValue_blank() {
assertEquals("", new LikeFilter("", null).getEncodedValue());
assertEquals(" ", new LikeFilter("", " ").getEncodedValue());
assertThat("").isEqualTo(new LikeFilter("", null).getEncodedValue());
assertThat(" ").isEqualTo(new LikeFilter("", " ").getEncodedValue());
}
@Test
public void testEncodeValue_normal() {
assertEquals("foo", new LikeFilter("", "foo").getEncodedValue());
assertEquals("foo*bar", new LikeFilter("", "foo*bar").getEncodedValue());
assertEquals("*foo*bar*", new LikeFilter("", "*foo*bar*")
assertThat("foo").isEqualTo(new LikeFilter("", "foo").getEncodedValue());
assertThat("foo*bar").isEqualTo(new LikeFilter("", "foo*bar").getEncodedValue());
assertThat("*foo*bar*").isEqualTo(new LikeFilter("", "*foo*bar*")
.getEncodedValue());
assertEquals("**foo**bar**", new LikeFilter("", "**foo**bar**")
assertThat("**foo**bar**").isEqualTo(new LikeFilter("", "**foo**bar**")
.getEncodedValue());
}
@Test
public void testEncodeValue_escape() {
assertEquals("*\\28*\\29*", new LikeFilter("", "*(*)*")
assertThat("*\\28*\\29*").isEqualTo(new LikeFilter("", "*(*)*")
.getEncodedValue());
assertEquals("*\\5c2a*", new LikeFilter("", "*\\2a*").getEncodedValue());
assertThat("*\\5c2a*").isEqualTo(new LikeFilter("", "*\\2a*").getEncodedValue());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ package org.springframework.ldap.filter;
import com.gargoylesoftware.base.testing.EqualsTester;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for the NotFilter class.
@@ -33,7 +33,7 @@ public class NotFilterTest {
EqualsFilter filter = new EqualsFilter("a", "b");
NotFilter notFilter = new NotFilter(filter);
assertEquals("(!(a=b))", notFilter.encode());
assertThat(notFilter.encode()).isEqualTo("(!(a=b))");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@ package org.springframework.ldap.filter;
import com.gargoylesoftware.base.testing.EqualsTester;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for the NotPresentFilter class.
@@ -30,20 +30,20 @@ public class NotPresentFilterTest {
@Test
public void testNotPresentFilter() {
NotPresentFilter filter = new NotPresentFilter("foo");
assertEquals("(!(foo=*))", filter.encode());
assertThat(filter.encode()).isEqualTo("(!(foo=*))");
NotFilter notFilter = new NotFilter(new NotPresentFilter("foo"));
assertEquals("(!(!(foo=*)))", notFilter.encode());
assertThat(notFilter.encode()).isEqualTo("(!(!(foo=*)))");
AndFilter andFilter = new AndFilter();
andFilter.and(new NotPresentFilter("foo"));
andFilter.and(new NotPresentFilter("bar"));
assertEquals("(&(!(foo=*))(!(bar=*)))", andFilter.encode());
assertThat(andFilter.encode()).isEqualTo("(&(!(foo=*))(!(bar=*)))");
andFilter = new AndFilter();
andFilter.and(new NotPresentFilter("foo"));
andFilter.and(new NotFilter(new NotPresentFilter("bar")));
assertEquals("(&(!(foo=*))(!(!(bar=*))))", andFilter.encode());
assertThat(andFilter.encode()).isEqualTo("(&(!(foo=*))(!(!(bar=*))))");
}
@Test
@@ -58,4 +58,4 @@ public class NotPresentFilterTest {
new EqualsTester(originalObject, identicalObject, differentObject,
subclassObject);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@ package org.springframework.ldap.filter;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for the OrFilter class.
@@ -31,14 +31,14 @@ public class OrFilterTest {
public void testZero() {
OrFilter of = new OrFilter();
assertEquals("", of.encode());
assertThat(of.encode()).isEqualTo("");
}
@Test
public void testOne() {
OrFilter of = new OrFilter().or(new EqualsFilter("a", "b"));
assertEquals("(a=b)", of.encode());
assertThat(of.encode()).isEqualTo("(a=b)");
}
@Test
@@ -46,7 +46,7 @@ public class OrFilterTest {
OrFilter of = new OrFilter().or(new EqualsFilter("a", "b")).or(
new EqualsFilter("c", "d"));
assertEquals("(|(a=b)(c=d))", of.encode());
assertThat(of.encode()).isEqualTo("(|(a=b)(c=d))");
}
@Test
@@ -54,7 +54,7 @@ public class OrFilterTest {
OrFilter of = new OrFilter().or(new EqualsFilter("a", "b")).or(
new EqualsFilter("c", "d")).or(new EqualsFilter("e", "f"));
assertEquals("(|(a=b)(c=d)(e=f))", of.encode());
assertThat(of.encode()).isEqualTo("(|(a=b)(c=d)(e=f))");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@ package org.springframework.ldap.filter;
import com.gargoylesoftware.base.testing.EqualsTester;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for the PresentFilter class.
@@ -30,20 +30,20 @@ public class PresentFilterTest {
@Test
public void testPresentFilter() {
PresentFilter filter = new PresentFilter("foo");
assertEquals("(foo=*)", filter.encode());
assertThat(filter.encode()).isEqualTo("(foo=*)");
NotFilter notFilter = new NotFilter(new PresentFilter("foo"));
assertEquals("(!(foo=*))", notFilter.encode());
assertThat(notFilter.encode()).isEqualTo("(!(foo=*))");
AndFilter andFilter = new AndFilter();
andFilter.and(new PresentFilter("foo"));
andFilter.and(new PresentFilter("bar"));
assertEquals("(&(foo=*)(bar=*))", andFilter.encode());
assertThat(andFilter.encode()).isEqualTo("(&(foo=*)(bar=*))");
andFilter = new AndFilter();
andFilter.and(new PresentFilter("foo"));
andFilter.and(new NotFilter(new PresentFilter("bar")));
assertEquals("(&(foo=*)(!(bar=*)))", andFilter.encode());
assertThat(andFilter.encode()).isEqualTo("(&(foo=*)(!(bar=*)))");
}
@Test
@@ -58,4 +58,4 @@ public class PresentFilterTest {
new EqualsTester(originalObject, identicalObject, differentObject,
subclassObject);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@ package org.springframework.ldap.filter;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for the WhitespaceWildcardsFilter class.
@@ -31,13 +31,13 @@ public class WhitespaceWildcardsFilterTest {
public void testEncodeValue_blank() {
// blank
assertEquals("*", new WhitespaceWildcardsFilter("", null)
assertThat("*").isEqualTo(new WhitespaceWildcardsFilter("", null)
.getEncodedValue());
assertEquals("*", new WhitespaceWildcardsFilter("", " ")
assertThat("*").isEqualTo(new WhitespaceWildcardsFilter("", " ")
.getEncodedValue());
assertEquals("*", new WhitespaceWildcardsFilter("", " ")
assertThat("*").isEqualTo(new WhitespaceWildcardsFilter("", " ")
.getEncodedValue());
assertEquals("*", new WhitespaceWildcardsFilter("", "\t")
assertThat("*").isEqualTo(new WhitespaceWildcardsFilter("", "\t")
.getEncodedValue());
}
@@ -45,25 +45,24 @@ public class WhitespaceWildcardsFilterTest {
@Test
public void testEncodeValue_normal() {
assertEquals("*foo*", new WhitespaceWildcardsFilter("", "foo")
assertThat("*foo*").isEqualTo(new WhitespaceWildcardsFilter("", "foo")
.getEncodedValue());
assertEquals("*foo*bar*", new WhitespaceWildcardsFilter("", "foo bar")
assertThat("*foo*bar*").isEqualTo(new WhitespaceWildcardsFilter("", "foo bar")
.getEncodedValue());
assertEquals("*foo*bar*",
new WhitespaceWildcardsFilter("", " foo bar ")
.getEncodedValue());
assertEquals("*foo*bar*", new WhitespaceWildcardsFilter("",
" \t foo \n bar \r ").getEncodedValue());
assertThat(new WhitespaceWildcardsFilter("", " foo bar ")
.getEncodedValue()).isEqualTo("*foo*bar*");
assertThat(new WhitespaceWildcardsFilter("",
" \t foo \n bar \r ").getEncodedValue()).isEqualTo("*foo*bar*");
}
@Test
public void testEncodeValue_escape() {
assertEquals("*\\28\\2a\\29*", new WhitespaceWildcardsFilter("", "(*)")
assertThat("*\\28\\2a\\29*").isEqualTo(new WhitespaceWildcardsFilter("", "(*)")
.getEncodedValue());
assertEquals("*\\2a*", new WhitespaceWildcardsFilter("", "*")
assertThat("*\\2a*").isEqualTo(new WhitespaceWildcardsFilter("", "*")
.getEncodedValue());
assertEquals("*\\5c*", new WhitespaceWildcardsFilter("", " \\ ")
assertThat("*\\5c*").isEqualTo(new WhitespaceWildcardsFilter("", " \\ ")
.getEncodedValue());
}

View File

@@ -1,30 +1,25 @@
package org.springframework.ldap.odm.core.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.spy;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.springframework.ldap.query.LdapQueryBuilder.query;
import java.lang.reflect.Field;
import javax.naming.Name;
import org.junit.Before;
import org.junit.Test;
import org.junit.matchers.JUnitMatchers;
import org.junit.runner.RunWith;
import org.mockito.internal.util.reflection.Whitebox;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.core.SpringVersion;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.powermock.api.mockito.PowerMockito.spy;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.springframework.ldap.query.LdapQueryBuilder.query;
/**
* @author Mattias Hellborg Arthursson
*/
@@ -48,7 +43,7 @@ public class DefaultObjectDirectoryMapperTest {
DefaultObjectDirectoryMapper mapper = new DefaultObjectDirectoryMapper();
// LDAP-300
assertNotNull(Whitebox.getInternalState(mapper,"converterManager"));
assertThat(Whitebox.getInternalState(mapper,"converterManager")).isNotNull();
}
@Test
@@ -57,23 +52,23 @@ public class DefaultObjectDirectoryMapperTest {
DefaultObjectDirectoryMapper.EntityData entityData = tested.getMetaDataMap().get(UnitTestPerson.class);
assertNotNull(entityData);
assertEquals(query().
assertThat(entityData).isNotNull();
assertThat(entityData.ocFilter).isEqualTo(query().
where("objectclass").is("inetOrgPerson")
.and("objectclass").is("organizationalPerson")
.and("objectclass").is("person")
.and("objectclass").is("top")
.filter(), entityData.ocFilter);
.filter());
assertEquals(7, entityData.metaData.size());
assertThat(entityData.metaData).hasSize(7);
AttributeMetaData idAttribute = entityData.metaData.getIdAttribute();
assertEquals("dn", idAttribute.getField().getName());
assertTrue(idAttribute.isId());
assertFalse(idAttribute.isBinary());
assertFalse(idAttribute.isDnAttribute());
assertFalse(idAttribute.isTransient());
assertFalse(idAttribute.isCollection());
assertThat(idAttribute.getField().getName()).isEqualTo("dn");
assertThat(idAttribute.isId()).isTrue();
assertThat(idAttribute.isBinary()).isFalse();
assertThat(idAttribute.isDnAttribute()).isFalse();
assertThat(idAttribute.isTransient()).isFalse();
assertThat(idAttribute.isCollection()).isFalse();
assertField(entityData, "fullName", "cn", "cn", false, false, false);
assertField(entityData, "lastName", "sn", null, false, false, false);
@@ -88,7 +83,7 @@ public class DefaultObjectDirectoryMapperTest {
try {
tested.manageClass(UnitTestPersonWithInvalidFieldType.class);
} catch (InvalidEntryException expected) {
assertThat(expected.getMessage(), JUnitMatchers.containsString("Missing converter from"));
assertThat(expected.getMessage()).contains("Missing converter from");
}
}
@@ -103,7 +98,7 @@ public class DefaultObjectDirectoryMapperTest {
Name calculatedId = tested.getCalculatedId(testPerson);
assertEquals(LdapUtils.newLdapName("cn=Some Person, ou=Some Company, c=Sweden"), calculatedId);
assertThat(calculatedId).isEqualTo(LdapUtils.newLdapName("cn=Some Person, ou=Some Company, c=Sweden"));
}
@Test(expected = MetaDataException.class)
@@ -123,21 +118,21 @@ public class DefaultObjectDirectoryMapperTest {
if (fieldName.equals(field.getName())) {
AttributeMetaData attribute = entityData.metaData.getAttribute(field);
if (StringUtils.hasLength(expectedAttributeName)) {
assertEquals(expectedAttributeName, attribute.getName().toString());
assertThat(attribute.getName().toString()).isEqualTo(expectedAttributeName);
} else {
assertNull(attribute.getName());
assertThat(attribute.getName()).isNull();
}
if (StringUtils.hasLength(expectedDnAttributeName)) {
assertTrue(attribute.isDnAttribute());
assertEquals(expectedDnAttributeName, attribute.getDnAttribute().value());
assertThat(attribute.isDnAttribute()).isTrue();
assertThat(attribute.getDnAttribute().value()).isEqualTo(expectedDnAttributeName);
} else {
assertFalse(attribute.isDnAttribute());
assertThat(attribute.isDnAttribute()).isFalse();
}
assertEquals(expectedBinary, attribute.isBinary());
assertEquals(expectedTransient, attribute.isTransient());
assertEquals(expectedList, attribute.isCollection());
assertThat(attribute.isBinary()).isEqualTo(expectedBinary);
assertThat(attribute.isTransient()).isEqualTo(expectedTransient);
assertThat(attribute.isCollection()).isEqualTo(expectedList);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,11 +22,8 @@ import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -44,7 +41,7 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
new DelegatingContext(null, contextMock, DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
@@ -52,14 +49,14 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
new DelegatingContext(keyedObjectPoolMock, contextMock, null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -70,11 +67,11 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
final Context delegateContext = delegatingContext.getDelegateContext();
assertEquals(contextMock, delegateContext);
assertThat(delegateContext).isEqualTo(contextMock);
final Context innerDelegateContext = delegatingContext
.getInnermostDelegateContext();
assertEquals(contextMock, innerDelegateContext);
assertThat(innerDelegateContext).isEqualTo(contextMock);
delegatingContext.assertOpen();
@@ -87,11 +84,11 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
final Context delegateContext2 = delegatingContext2
.getDelegateContext();
assertEquals(delegatingContext, delegateContext2);
assertThat(delegateContext2).isEqualTo(delegatingContext);
final Context innerDelegateContext2 = delegatingContext2
.getInnermostDelegateContext();
assertEquals(contextMock, innerDelegateContext2);
assertThat(innerDelegateContext2).isEqualTo(contextMock);
delegatingContext2.assertOpen();
@@ -100,11 +97,11 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
final Context delegateContext2closed = delegatingContext2
.getDelegateContext();
assertNull(delegateContext2closed);
assertThat(delegateContext2closed).isNull();
final Context innerDelegateContext2closed = delegatingContext2
.getInnermostDelegateContext();
assertNull(innerDelegateContext2closed);
assertThat(innerDelegateContext2closed).isNull();
try {
delegatingContext2.assertOpen();
@@ -118,11 +115,11 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
final Context delegateContextclosed = delegatingContext
.getDelegateContext();
assertNull(delegateContextclosed);
assertThat(delegateContextclosed).isNull();
final Context innerDelegateContextclosed = delegatingContext
.getInnermostDelegateContext();
assertNull(innerDelegateContextclosed);
assertThat(innerDelegateContextclosed).isNull();
try {
delegatingContext.assertOpen();
@@ -141,31 +138,31 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
// Wrap the Context once
final DelegatingContext delegatingContext = new DelegatingContext(
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
assertEquals(contextMock.toString(), delegatingContext.toString());
assertThat(delegatingContext.toString()).isEqualTo(contextMock.toString());
delegatingContext.hashCode(); // Run it to make sure it doesn't fail
assertTrue(delegatingContext.equals(delegatingContext));
assertFalse(delegatingContext.equals(new Object()));
assertThat(delegatingContext.equals(delegatingContext)).isTrue();
assertThat(delegatingContext.equals(new Object())).isFalse();
final DelegatingContext delegatingContext2 = new DelegatingContext(
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
assertTrue(delegatingContext.equals(delegatingContext2));
assertTrue(delegatingContext2.equals(delegatingContext));
assertTrue(delegatingContext.equals(contextMock));
assertThat(delegatingContext.equals(delegatingContext2)).isTrue();
assertThat(delegatingContext2.equals(delegatingContext)).isTrue();
assertThat(delegatingContext.equals(contextMock)).isTrue();
// Close the contextMock and try again
delegatingContext.close();
assertEquals("Context is closed", delegatingContext.toString());
assertEquals(0, delegatingContext.hashCode()); // Run it to make sure
assertThat(delegatingContext.toString()).isEqualTo("Context is closed");
assertThat(delegatingContext.hashCode()).isEqualTo(0); // Run it to make sure
// it doesn't fail
assertTrue(delegatingContext.equals(delegatingContext));
assertFalse(delegatingContext.equals(new Object()));
assertThat(delegatingContext.equals(delegatingContext)).isTrue();
assertThat(delegatingContext.equals(new Object())).isFalse();
assertFalse(delegatingContext.equals(delegatingContext2));
assertFalse(delegatingContext2.equals(delegatingContext));
assertFalse(delegatingContext.equals(contextMock));
assertThat(delegatingContext.equals(delegatingContext2)).isFalse();
assertThat(delegatingContext2.equals(delegatingContext)).isFalse();
assertThat(delegatingContext.equals(contextMock)).isFalse();
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, contextMock);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,11 +24,8 @@ import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -45,14 +42,14 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
new DelegatingDirContext(keyedObjectPoolMock, dirContextMock, null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -65,15 +62,15 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
final Context delegateContext = delegatingDirContext
.getDelegateContext();
assertEquals(dirContextMock, delegateContext);
assertThat(delegateContext).isEqualTo(dirContextMock);
final DirContext delegateDirContext = delegatingDirContext
.getDelegateDirContext();
assertEquals(dirContextMock, delegateDirContext);
assertThat(delegateDirContext).isEqualTo(dirContextMock);
final DirContext innerDelegateDirContext = delegatingDirContext
.getInnermostDelegateDirContext();
assertEquals(dirContextMock, innerDelegateDirContext);
assertThat(innerDelegateDirContext).isEqualTo(dirContextMock);
delegatingDirContext.assertOpen();
@@ -86,11 +83,11 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
final DirContext delegateDirContext2 = delegatingDirContext2
.getDelegateDirContext();
assertEquals(delegatingDirContext, delegateDirContext2);
assertThat(delegateDirContext2).isEqualTo(delegatingDirContext);
final DirContext innerDelegateDirContext2 = delegatingDirContext2
.getInnermostDelegateDirContext();
assertEquals(dirContextMock, innerDelegateDirContext2);
assertThat(innerDelegateDirContext2).isEqualTo(dirContextMock);
delegatingDirContext2.assertOpen();
@@ -99,11 +96,11 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
final DirContext delegateContext2closed = delegatingDirContext2
.getDelegateDirContext();
assertNull(delegateContext2closed);
assertThat(delegateContext2closed).isNull();
final DirContext innerDelegateContext2closed = delegatingDirContext2
.getInnermostDelegateDirContext();
assertNull(innerDelegateContext2closed);
assertThat(innerDelegateContext2closed).isNull();
try {
delegatingDirContext2.assertOpen();
@@ -117,11 +114,11 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
final DirContext delegateDirContextClosed = delegatingDirContext
.getDelegateDirContext();
assertNull(delegateDirContextClosed);
assertThat(delegateDirContextClosed).isNull();
final DirContext innerDelegateDirContextClosed = delegatingDirContext
.getInnermostDelegateDirContext();
assertNull(innerDelegateDirContextClosed);
assertThat(innerDelegateDirContextClosed).isNull();
try {
delegatingDirContext.assertOpen();
@@ -140,33 +137,33 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
// Wrap the DirContext once
final DelegatingDirContext delegatingDirContext = new DelegatingDirContext(
keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY);
assertEquals(dirContextMock.toString(), delegatingDirContext.toString());
assertThat(delegatingDirContext.toString()).isEqualTo(dirContextMock.toString());
delegatingDirContext.hashCode(); // Run it to make sure it doesn't
// fail
assertTrue(delegatingDirContext.equals(delegatingDirContext));
assertFalse(delegatingDirContext.equals(new Object()));
assertThat(delegatingDirContext.equals(delegatingDirContext)).isTrue();
assertThat(delegatingDirContext.equals(new Object())).isFalse();
final DelegatingDirContext delegatingDirContext2 = new DelegatingDirContext(
keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY);
assertTrue(delegatingDirContext.equals(delegatingDirContext2));
assertTrue(delegatingDirContext2.equals(delegatingDirContext));
assertTrue(delegatingDirContext.equals(dirContextMock));
assertThat(delegatingDirContext.equals(delegatingDirContext2)).isTrue();
assertThat(delegatingDirContext2.equals(delegatingDirContext)).isTrue();
assertThat(delegatingDirContext.equals(dirContextMock)).isTrue();
// Close the context and try again
delegatingDirContext.close();
assertEquals("DirContext is closed", delegatingDirContext.toString());
assertEquals(0, delegatingDirContext.hashCode()); // Run it to make
assertThat(delegatingDirContext.toString()).isEqualTo("DirContext is closed");
assertThat(delegatingDirContext.hashCode()).isEqualTo(0); // Run it to make
// sure it doesn't
// fail
assertTrue(delegatingDirContext.equals(delegatingDirContext));
assertFalse(delegatingDirContext.equals(new Object()));
assertThat(delegatingDirContext.equals(delegatingDirContext)).isTrue();
assertThat(delegatingDirContext.equals(new Object())).isFalse();
assertFalse(delegatingDirContext.equals(delegatingDirContext2));
assertFalse(delegatingDirContext2.equals(delegatingDirContext));
assertFalse(delegatingDirContext.equals(dirContextMock));
assertThat(delegatingDirContext.equals(delegatingDirContext2)).isFalse();
assertThat(delegatingDirContext2.equals(delegatingDirContext)).isFalse();
assertThat(delegatingDirContext.equals(dirContextMock)).isFalse();
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, dirContextMock);
}
@@ -384,4 +381,4 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
verify(keyedObjectPoolMock, times(1)).returnObject(DirContextType.READ_ONLY, dirContextMock);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,11 +22,8 @@ import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -43,7 +40,7 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
@@ -51,7 +48,7 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -63,15 +60,15 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
final DirContext delegateDirContext = delegatingLdapContext
.getDelegateDirContext();
assertEquals(ldapContextMock, delegateDirContext);
assertThat(delegateDirContext).isEqualTo(ldapContextMock);
final LdapContext delegateLdapContext = delegatingLdapContext
.getDelegateLdapContext();
assertEquals(ldapContextMock, delegateLdapContext);
assertThat(delegateLdapContext).isEqualTo(ldapContextMock);
final LdapContext innerDelegateLdapContext = delegatingLdapContext
.getInnermostDelegateLdapContext();
assertEquals(ldapContextMock, innerDelegateLdapContext);
assertThat(innerDelegateLdapContext).isEqualTo(ldapContextMock);
delegatingLdapContext.assertOpen();
@@ -84,11 +81,11 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
final LdapContext delegateLdapContext2 = delegatingLdapContext2
.getDelegateLdapContext();
assertEquals(delegatingLdapContext, delegateLdapContext2);
assertThat(delegateLdapContext2).isEqualTo(delegatingLdapContext);
final LdapContext innerDelegateLdapContext2 = delegatingLdapContext2
.getInnermostDelegateLdapContext();
assertEquals(ldapContextMock, innerDelegateLdapContext2);
assertThat(innerDelegateLdapContext2).isEqualTo(ldapContextMock);
delegatingLdapContext2.assertOpen();
@@ -97,11 +94,11 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
final LdapContext delegateContext2closed = delegatingLdapContext2
.getDelegateLdapContext();
assertNull(delegateContext2closed);
assertThat(delegateContext2closed).isNull();
final LdapContext innerDelegateContext2closed = delegatingLdapContext2
.getInnermostDelegateLdapContext();
assertNull(innerDelegateContext2closed);
assertThat(innerDelegateContext2closed).isNull();
try {
delegatingLdapContext2.assertOpen();
@@ -115,11 +112,11 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
final LdapContext delegateLdapContextClosed = delegatingLdapContext
.getDelegateLdapContext();
assertNull(delegateLdapContextClosed);
assertThat(delegateLdapContextClosed).isNull();
final LdapContext innerDelegateLdapContextClosed = delegatingLdapContext
.getInnermostDelegateLdapContext();
assertNull(innerDelegateLdapContextClosed);
assertThat(innerDelegateLdapContextClosed).isNull();
try {
delegatingLdapContext.assertOpen();
@@ -138,33 +135,32 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
// Wrap the LdapContext once
final DelegatingLdapContext delegatingLdapContext = new DelegatingLdapContext(
keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY);
assertEquals(ldapContextMock.toString(),
delegatingLdapContext.toString());
assertThat(delegatingLdapContext.toString()).isEqualTo(ldapContextMock.toString());
delegatingLdapContext.hashCode(); // Run it to make sure it doesn't fail
assertTrue(delegatingLdapContext.equals(delegatingLdapContext));
assertFalse(delegatingLdapContext.equals(new Object()));
assertThat(delegatingLdapContext.equals(delegatingLdapContext)).isTrue();
assertThat(delegatingLdapContext.equals(new Object())).isFalse();
final DelegatingLdapContext delegatingLdapContext2 = new DelegatingLdapContext(
keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY);
assertTrue(delegatingLdapContext.equals(delegatingLdapContext2));
assertTrue(delegatingLdapContext2.equals(delegatingLdapContext));
assertTrue(delegatingLdapContext.equals(ldapContextMock));
assertThat(delegatingLdapContext.equals(delegatingLdapContext2)).isTrue();
assertThat(delegatingLdapContext2.equals(delegatingLdapContext)).isTrue();
assertThat(delegatingLdapContext.equals(ldapContextMock)).isTrue();
// Close the context and try again
delegatingLdapContext.close();
assertEquals("LdapContext is closed", delegatingLdapContext.toString());
assertEquals(0, delegatingLdapContext.hashCode()); // Run it to make
assertThat(delegatingLdapContext.toString()).isEqualTo("LdapContext is closed");
assertThat(delegatingLdapContext.hashCode()).isEqualTo(0); // Run it to make
// sure it doesn't
// fail
assertTrue(delegatingLdapContext.equals(delegatingLdapContext));
assertFalse(delegatingLdapContext.equals(new Object()));
assertThat(delegatingLdapContext.equals(delegatingLdapContext)).isTrue();
assertThat(delegatingLdapContext.equals(new Object())).isFalse();
assertFalse(delegatingLdapContext.equals(delegatingLdapContext2));
assertFalse(delegatingLdapContext2.equals(delegatingLdapContext));
assertFalse(delegatingLdapContext.equals(ldapContextMock));
assertThat(delegatingLdapContext.equals(delegatingLdapContext2)).isFalse();
assertThat(delegatingLdapContext2.equals(delegatingLdapContext)).isFalse();
assertThat(delegatingLdapContext.equals(ldapContextMock)).isFalse();
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, ldapContextMock);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,10 +27,8 @@ import javax.naming.directory.DirContext;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import static org.junit.Assert.assertEquals;
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.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -52,12 +50,12 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase {
catch (IllegalArgumentException iae) {
// Expected
}
objectFactory.setContextSource(contextSourceMock);
final ContextSource contextSource2 = objectFactory.getContextSource();
assertEquals(contextSourceMock, contextSource2);
assertThat(contextSource2).isEqualTo(contextSourceMock);
try {
objectFactory.setDirContextValidator(null);
fail("DirContextPoolableObjectFactory.setDirContextValidator should have thrown an IllegalArgumentException");
@@ -65,10 +63,10 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase {
catch (IllegalArgumentException iae) {
// Expected
}
objectFactory.setDirContextValidator(dirContextValidatorMock);
final DirContextValidator dirContextValidator2 = objectFactory.getDirContextValidator();
assertEquals(dirContextValidatorMock, dirContextValidator2);
assertThat(dirContextValidator2).isEqualTo(dirContextValidatorMock);
}
@Test
@@ -79,23 +77,23 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase {
objectFactory.makeObject(DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
objectFactory.setContextSource(contextSourceMock);
try {
objectFactory.makeObject(null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@Test
public void testMakeObjectReadOnly() throws Exception {
final DirContextPoolableObjectFactory objectFactory = new DirContextPoolableObjectFactory();
DirContext readOnlyContextMock = mock(DirContext.class);
when(contextSourceMock.getReadOnlyContext()).thenReturn(readOnlyContextMock);
@@ -103,13 +101,13 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase {
final Object createdDirContext = objectFactory.makeObject(DirContextType.READ_ONLY);
InvocationHandler invocationHandler = Proxy.getInvocationHandler(createdDirContext);
assertEquals(readOnlyContextMock, Whitebox.getInternalState(invocationHandler, "target"));
assertThat(readOnlyContextMock).isEqualTo(Whitebox.getInternalState(invocationHandler, "target"));
}
@Test
public void testMakeObjectReadWrite() throws Exception {
final DirContextPoolableObjectFactory objectFactory = new DirContextPoolableObjectFactory();
DirContext readWriteContextMock = mock(DirContext.class);
when(contextSourceMock.getReadWriteContext()).thenReturn(readWriteContextMock);
@@ -118,7 +116,7 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase {
final Object createdDirContext = objectFactory.makeObject(DirContextType.READ_WRITE);
InvocationHandler invocationHandler = Proxy.getInvocationHandler(createdDirContext);
assertEquals(readWriteContextMock, Whitebox.getInternalState(invocationHandler, "target"));
assertThat(readWriteContextMock).isEqualTo(Whitebox.getInternalState(invocationHandler, "target"));
}
@Test
@@ -129,37 +127,37 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase {
objectFactory.validateObject(DirContextType.READ_ONLY, dirContextMock);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
objectFactory.setDirContextValidator(dirContextValidatorMock);
try {
objectFactory.validateObject(null, dirContextMock);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
objectFactory.validateObject(new Object(), dirContextMock);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
objectFactory.validateObject(DirContextType.READ_ONLY, null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
objectFactory.validateObject(DirContextType.READ_ONLY, new Object());
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -171,46 +169,46 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase {
final DirContextPoolableObjectFactory objectFactory = new DirContextPoolableObjectFactory();
objectFactory.setDirContextValidator(dirContextValidatorMock);
final boolean valid = objectFactory.validateObject(DirContextType.READ_ONLY, dirContextMock);
assertTrue(valid);
assertThat(valid).isTrue();
//Check exception in validator
DirContextValidator secondDirContextValidatorMock = mock(DirContextValidator.class);
when(secondDirContextValidatorMock.validateDirContext(DirContextType.READ_ONLY, dirContextMock))
.thenThrow(new RuntimeException("Failed to validate"));
objectFactory.setDirContextValidator(secondDirContextValidatorMock);
final boolean valid2 = objectFactory.validateObject(DirContextType.READ_ONLY, dirContextMock);
assertFalse(valid2);
assertThat(valid2).isFalse();
}
@Test
public void testDestroyObjectAssertions() throws Exception {
final DirContextPoolableObjectFactory objectFactory = new DirContextPoolableObjectFactory();
try {
objectFactory.destroyObject(DirContextType.READ_ONLY, null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
objectFactory.validateObject(DirContextType.READ_ONLY, new Object());
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@Test
public void testDestroyObject() throws Exception {
final DirContextPoolableObjectFactory objectFactory = new DirContextPoolableObjectFactory();
objectFactory.destroyObject(DirContextType.READ_ONLY, dirContextMock);
DirContext throwingDirContextMock = Mockito.mock(DirContext.class);
doThrow(new RuntimeException("Failed to close"))

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import org.springframework.ldap.pool.MutableDelegatingLdapContext;
import javax.naming.directory.DirContext;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
/**
@@ -42,6 +42,6 @@ public class MutablePoolingContextSourceTest extends AbstractPoolTestCase {
// Get a context
final DirContext result = poolingContextSource.getReadOnlyContext();
assertEquals(MutableDelegatingLdapContext.class, result.getClass());
assertThat(result.getClass()).isEqualTo(MutableDelegatingLdapContext.class);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,8 +25,8 @@ import org.springframework.ldap.pool.validation.DirContextValidator;
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -48,7 +48,7 @@ public class PoolingContextSourceTest extends AbstractPoolTestCase {
}
poolingContextSource.setContextSource(contextSourceMock);
final ContextSource contextSource2 = poolingContextSource.getContextSource();
assertEquals(contextSourceMock, contextSource2);
assertThat(contextSource2).isEqualTo(contextSourceMock);
try {
poolingContextSource.setDirContextValidator(null);
@@ -59,61 +59,61 @@ public class PoolingContextSourceTest extends AbstractPoolTestCase {
}
poolingContextSource.setDirContextValidator(dirContextValidatorMock);
final DirContextValidator dirContextValidator2 = poolingContextSource.getDirContextValidator();
assertEquals(dirContextValidatorMock, dirContextValidator2);
assertThat(dirContextValidator2).isEqualTo(dirContextValidatorMock);
poolingContextSource.setMaxActive(1000);
final int maxActive = poolingContextSource.getMaxActive();
assertEquals(1000, maxActive);
assertThat(maxActive).isEqualTo(1000);
poolingContextSource.setMaxIdle(500);
final int maxIdle = poolingContextSource.getMaxIdle();
assertEquals(500, maxIdle);
assertThat(maxIdle).isEqualTo(500);
poolingContextSource.setMaxTotal(5000);
final int maxTotal = poolingContextSource.getMaxTotal();
assertEquals(5000, maxTotal);
assertThat(maxTotal).isEqualTo(5000);
poolingContextSource.setMaxWait(2000L);
final long maxWait = poolingContextSource.getMaxWait();
assertEquals(2000L, maxWait);
assertThat(maxWait).isEqualTo(2000L);
poolingContextSource.setMinEvictableIdleTimeMillis(60000L);
final long minEvictableIdleTimeMillis = poolingContextSource.getMinEvictableIdleTimeMillis();
assertEquals(60000L, minEvictableIdleTimeMillis);
assertThat(minEvictableIdleTimeMillis).isEqualTo(60000L);
poolingContextSource.setMinIdle(100);
final int minIdle = poolingContextSource.getMinIdle();
assertEquals(100, minIdle);
assertThat(minIdle).isEqualTo(100);
poolingContextSource.setNumTestsPerEvictionRun(5);
final int numTestsPerEvictionRun = poolingContextSource.getNumTestsPerEvictionRun();
assertEquals(5, numTestsPerEvictionRun);
assertThat(numTestsPerEvictionRun).isEqualTo(5);
poolingContextSource.setTestOnBorrow(true);
final boolean testOnBorrow = poolingContextSource.getTestOnBorrow();
assertEquals(true, testOnBorrow);
assertThat(testOnBorrow).isEqualTo(true);
poolingContextSource.setTestOnReturn(true);
final boolean testOnReturn = poolingContextSource.getTestOnReturn();
assertEquals(true, testOnReturn);
assertThat(testOnReturn).isEqualTo(true);
poolingContextSource.setTestWhileIdle(true);
final boolean testWhileIdle = poolingContextSource.getTestWhileIdle();
assertEquals(true, testWhileIdle);
assertThat(testWhileIdle).isEqualTo(true);
poolingContextSource.setTimeBetweenEvictionRunsMillis(120000L);
final long timeBetweenEvictionRunsMillis = poolingContextSource.getTimeBetweenEvictionRunsMillis();
assertEquals(120000L, timeBetweenEvictionRunsMillis);
assertThat(timeBetweenEvictionRunsMillis).isEqualTo(120000L);
poolingContextSource.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK);
final byte whenExhaustedAction = poolingContextSource.getWhenExhaustedAction();
assertEquals(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK, whenExhaustedAction);
assertThat(whenExhaustedAction).isEqualTo(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK);
final int numActive = poolingContextSource.getNumActive();
assertEquals(0, numActive);
assertThat(numActive).isEqualTo(0);
final int numIdle = poolingContextSource.getNumIdle();
assertEquals(0, numIdle);
assertThat(numIdle).isEqualTo(0);
}
@Test
@@ -127,36 +127,36 @@ public class PoolingContextSourceTest extends AbstractPoolTestCase {
//Get a context
final DirContext readOnlyContext1 = poolingContextSource.getReadOnlyContext();
assertEquals(readOnlyContext1, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, poolingContextSource.getNumActive());
assertEquals(0, poolingContextSource.getNumIdle());
assertThat(readOnlyContext1).isEqualTo(dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(poolingContextSource.getNumActive()).isEqualTo(1);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(0);
//Close the context
readOnlyContext1.close();
assertEquals(0, poolingContextSource.getNumActive());
assertEquals(1, poolingContextSource.getNumIdle());
assertThat(poolingContextSource.getNumActive()).isEqualTo(0);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(1);
//Get the context again
final DirContext readOnlyContext2 = poolingContextSource.getReadOnlyContext();
assertEquals(readOnlyContext2, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, poolingContextSource.getNumActive());
assertEquals(0, poolingContextSource.getNumIdle());
assertThat(readOnlyContext2).isEqualTo(dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(poolingContextSource.getNumActive()).isEqualTo(1);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(0);
//Get a new context
final DirContext readOnlyContext3 = poolingContextSource.getReadOnlyContext();
assertEquals(readOnlyContext3, secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(2, poolingContextSource.getNumActive());
assertEquals(0, poolingContextSource.getNumIdle());
assertThat(readOnlyContext3).isEqualTo(secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(poolingContextSource.getNumActive()).isEqualTo(2);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(0);
//Close context
readOnlyContext2.close();
assertEquals(1, poolingContextSource.getNumActive());
assertEquals(1, poolingContextSource.getNumIdle());
assertThat(poolingContextSource.getNumActive()).isEqualTo(1);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(1);
//Close context
readOnlyContext3.close();
assertEquals(0, poolingContextSource.getNumActive());
assertEquals(2, poolingContextSource.getNumIdle());
assertThat(poolingContextSource.getNumActive()).isEqualTo(0);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(2);
}
@Test
@@ -170,36 +170,36 @@ public class PoolingContextSourceTest extends AbstractPoolTestCase {
//Get a context
final DirContext readOnlyContext1 = poolingContextSource.getReadWriteContext();
assertEquals(readOnlyContext1, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, poolingContextSource.getNumActive());
assertEquals(0, poolingContextSource.getNumIdle());
assertThat(readOnlyContext1).isEqualTo(dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(poolingContextSource.getNumActive()).isEqualTo(1);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(0);
//Close the context
readOnlyContext1.close();
assertEquals(0, poolingContextSource.getNumActive());
assertEquals(1, poolingContextSource.getNumIdle());
assertThat(poolingContextSource.getNumActive()).isEqualTo(0);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(1);
//Get the context again
final DirContext readOnlyContext2 = poolingContextSource.getReadWriteContext();
assertEquals(readOnlyContext2, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, poolingContextSource.getNumActive());
assertEquals(0, poolingContextSource.getNumIdle());
assertThat(readOnlyContext2).isEqualTo(dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(poolingContextSource.getNumActive()).isEqualTo(1);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(0);
//Get a new context
final DirContext readOnlyContext3 = poolingContextSource.getReadWriteContext();
assertEquals(readOnlyContext3, secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(2, poolingContextSource.getNumActive());
assertEquals(0, poolingContextSource.getNumIdle());
assertThat(readOnlyContext3).isEqualTo(secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(poolingContextSource.getNumActive()).isEqualTo(2);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(0);
//Close context
readOnlyContext2.close();
assertEquals(1, poolingContextSource.getNumActive());
assertEquals(1, poolingContextSource.getNumIdle());
assertThat(poolingContextSource.getNumActive()).isEqualTo(1);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(1);
//Close context
readOnlyContext3.close();
assertEquals(0, poolingContextSource.getNumActive());
assertEquals(2, poolingContextSource.getNumIdle());
assertThat(poolingContextSource.getNumActive()).isEqualTo(0);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(2);
}
@Test
@@ -230,35 +230,35 @@ public class PoolingContextSourceTest extends AbstractPoolTestCase {
//Get a context
final DirContext readOnlyContext1 = poolingContextSource.getReadOnlyContext();
assertEquals(readOnlyContext1, ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, poolingContextSource.getNumActive());
assertEquals(0, poolingContextSource.getNumIdle());
assertThat(readOnlyContext1).isEqualTo(ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(poolingContextSource.getNumActive()).isEqualTo(1);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(0);
//Close the context
readOnlyContext1.close();
assertEquals(0, poolingContextSource.getNumActive());
assertEquals(1, poolingContextSource.getNumIdle());
assertThat(poolingContextSource.getNumActive()).isEqualTo(0);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(1);
//Get the context again
final DirContext readOnlyContext2 = poolingContextSource.getReadOnlyContext();
assertEquals(readOnlyContext2, ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, poolingContextSource.getNumActive());
assertEquals(0, poolingContextSource.getNumIdle());
assertThat(readOnlyContext2).isEqualTo(ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(poolingContextSource.getNumActive()).isEqualTo(1);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(0);
//Get a new context
final DirContext readOnlyContext3 = poolingContextSource.getReadOnlyContext();
assertEquals(readOnlyContext3, secondLdapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(2, poolingContextSource.getNumActive());
assertEquals(0, poolingContextSource.getNumIdle());
assertThat(readOnlyContext3).isEqualTo(secondLdapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(poolingContextSource.getNumActive()).isEqualTo(2);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(0);
//Close context
readOnlyContext2.close();
assertEquals(1, poolingContextSource.getNumActive());
assertEquals(1, poolingContextSource.getNumIdle());
assertThat(poolingContextSource.getNumActive()).isEqualTo(1);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(1);
//Close context
readOnlyContext3.close();
assertEquals(0, poolingContextSource.getNumActive());
assertEquals(2, poolingContextSource.getNumIdle());
assertThat(poolingContextSource.getNumActive()).isEqualTo(0);
assertThat(poolingContextSource.getNumIdle()).isEqualTo(2);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,10 +24,8 @@ import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import static org.junit.Assert.assertEquals;
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.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -51,21 +49,21 @@ public class DefaultDirContextValidatorTest {
@Test
public void testSearchScopeOneLevelScopeSetInConstructorIsUsed() throws Exception {
DefaultDirContextValidator tested = new DefaultDirContextValidator(SearchControls.ONELEVEL_SCOPE);
assertEquals("ONELEVEL_SCOPE, ", SearchControls.ONELEVEL_SCOPE, tested.getSearchControls().getSearchScope());
assertThat(tested.getSearchControls().getSearchScope()).as("ONELEVEL_SCOPE, ").isEqualTo(SearchControls.ONELEVEL_SCOPE);
}
// LDAP-189
@Test
public void testSearchScopeSubTreeScopeSetInConstructorIsUsed() throws Exception {
DefaultDirContextValidator tested = new DefaultDirContextValidator(SearchControls.SUBTREE_SCOPE);
assertEquals("SUBTREE_SCOPE, ", SearchControls.SUBTREE_SCOPE, tested.getSearchControls().getSearchScope());
assertThat(tested.getSearchControls().getSearchScope()).as("SUBTREE_SCOPE, ").isEqualTo(SearchControls.SUBTREE_SCOPE);
}
// LDAP-189
@Test
public void testSearchScopeObjectScopeSetInConstructorIsUsed() throws Exception {
DefaultDirContextValidator tested = new DefaultDirContextValidator(SearchControls.OBJECT_SCOPE);
assertEquals("OBJECT_SCOPE, ", SearchControls.OBJECT_SCOPE, tested.getSearchControls().getSearchScope());
assertThat(tested.getSearchControls().getSearchScope()).as("OBJECT_SCOPE, ").isEqualTo(SearchControls.OBJECT_SCOPE);
}
@Test
@@ -74,28 +72,28 @@ public class DefaultDirContextValidatorTest {
dirContextValidator.setBase("baseName");
final String baseName = dirContextValidator.getBase();
assertEquals("baseName", baseName);
assertThat(baseName).isEqualTo("baseName");
try {
dirContextValidator.setFilter(null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
dirContextValidator.setFilter("filter");
final String filter = dirContextValidator.getFilter();
assertEquals("filter", filter);
assertThat(filter).isEqualTo("filter");
try {
dirContextValidator.setSearchControls(null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
final SearchControls sc = new SearchControls();
dirContextValidator.setSearchControls(sc);
final SearchControls sc2 = dirContextValidator.getSearchControls();
assertEquals(sc, sc2);
assertThat(sc2).isEqualTo(sc);
}
@Test
@@ -107,14 +105,14 @@ public class DefaultDirContextValidatorTest {
null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
dirContextValidator.validateDirContext(null, dirContextMock);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -133,7 +131,7 @@ public class DefaultDirContextValidatorTest {
final boolean valid = dirContextValidator.validateDirContext(
DirContextType.READ_ONLY, dirContextMock);
assertTrue(valid);
assertThat(valid).isTrue();
}
@Test
@@ -152,7 +150,7 @@ public class DefaultDirContextValidatorTest {
final boolean valid = dirContextValidator.validateDirContext(
DirContextType.READ_ONLY, dirContextMock);
assertFalse(valid);
assertThat(valid).isFalse();
}
@Test
@@ -170,6 +168,6 @@ public class DefaultDirContextValidatorTest {
final boolean valid = dirContextValidator.validateDirContext(
DirContextType.READ_ONLY, dirContextMock);
assertFalse(valid);
assertThat(valid).isFalse();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2015 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,8 +22,12 @@ import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/**
* @author Eric Dalquist <a
@@ -37,7 +41,7 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
new DelegatingContext(null, contextMock, DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
@@ -45,14 +49,14 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
new DelegatingContext(keyedObjectPoolMock, contextMock, null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -63,11 +67,11 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
final Context delegateContext = delegatingContext.getDelegateContext();
assertEquals(contextMock, delegateContext);
assertThat(delegateContext).isEqualTo(contextMock);
final Context innerDelegateContext = delegatingContext
.getInnermostDelegateContext();
assertEquals(contextMock, innerDelegateContext);
assertThat(innerDelegateContext).isEqualTo(contextMock);
delegatingContext.assertOpen();
@@ -80,11 +84,11 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
final Context delegateContext2 = delegatingContext2
.getDelegateContext();
assertEquals(delegatingContext, delegateContext2);
assertThat(delegateContext2).isEqualTo(delegatingContext);
final Context innerDelegateContext2 = delegatingContext2
.getInnermostDelegateContext();
assertEquals(contextMock, innerDelegateContext2);
assertThat(innerDelegateContext2).isEqualTo(contextMock);
delegatingContext2.assertOpen();
@@ -93,11 +97,11 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
final Context delegateContext2closed = delegatingContext2
.getDelegateContext();
assertNull(delegateContext2closed);
assertThat(delegateContext2closed).isNull();
final Context innerDelegateContext2closed = delegatingContext2
.getInnermostDelegateContext();
assertNull(innerDelegateContext2closed);
assertThat(innerDelegateContext2closed).isNull();
try {
delegatingContext2.assertOpen();
@@ -111,11 +115,11 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
final Context delegateContextclosed = delegatingContext
.getDelegateContext();
assertNull(delegateContextclosed);
assertThat(delegateContextclosed).isNull();
final Context innerDelegateContextclosed = delegatingContext
.getInnermostDelegateContext();
assertNull(innerDelegateContextclosed);
assertThat(innerDelegateContextclosed).isNull();
try {
delegatingContext.assertOpen();
@@ -134,31 +138,31 @@ public class DelegatingContextTest extends AbstractPoolTestCase {
// Wrap the Context once
final DelegatingContext delegatingContext = new DelegatingContext(
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
assertEquals(contextMock.toString(), delegatingContext.toString());
assertThat(delegatingContext.toString()).isEqualTo(contextMock.toString());
delegatingContext.hashCode(); // Run it to make sure it doesn't fail
assertTrue(delegatingContext.equals(delegatingContext));
assertFalse(delegatingContext.equals(new Object()));
assertThat(delegatingContext.equals(delegatingContext)).isTrue();
assertThat(delegatingContext.equals(new Object())).isFalse();
final DelegatingContext delegatingContext2 = new DelegatingContext(
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
assertTrue(delegatingContext.equals(delegatingContext2));
assertTrue(delegatingContext2.equals(delegatingContext));
assertTrue(delegatingContext.equals(contextMock));
assertThat(delegatingContext.equals(delegatingContext2)).isTrue();
assertThat(delegatingContext2.equals(delegatingContext)).isTrue();
assertThat(delegatingContext.equals(contextMock)).isTrue();
// Close the contextMock and try again
delegatingContext.close();
assertEquals("Context is closed", delegatingContext.toString());
assertEquals(0, delegatingContext.hashCode()); // Run it to make sure
assertThat(delegatingContext.toString()).isEqualTo("Context is closed");
assertThat(delegatingContext.hashCode()).isEqualTo(0); // Run it to make sure
// it doesn't fail
assertTrue(delegatingContext.equals(delegatingContext));
assertFalse(delegatingContext.equals(new Object()));
assertThat(delegatingContext.equals(delegatingContext)).isTrue();
assertThat(delegatingContext.equals(new Object())).isFalse();
assertFalse(delegatingContext.equals(delegatingContext2));
assertFalse(delegatingContext2.equals(delegatingContext));
assertFalse(delegatingContext.equals(contextMock));
assertThat(delegatingContext.equals(delegatingContext2)).isFalse();
assertThat(delegatingContext2.equals(delegatingContext)).isFalse();
assertThat(delegatingContext.equals(contextMock)).isFalse();
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, contextMock);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2015 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,8 +24,11 @@ import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/**
* @author Eric Dalquist <a
@@ -39,14 +42,14 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
new DelegatingDirContext(keyedObjectPoolMock, dirContextMock, null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -59,15 +62,15 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
final Context delegateContext = delegatingDirContext
.getDelegateContext();
assertEquals(dirContextMock, delegateContext);
assertThat(delegateContext).isEqualTo(dirContextMock);
final DirContext delegateDirContext = delegatingDirContext
.getDelegateDirContext();
assertEquals(dirContextMock, delegateDirContext);
assertThat(delegateDirContext).isEqualTo(dirContextMock);
final DirContext innerDelegateDirContext = delegatingDirContext
.getInnermostDelegateDirContext();
assertEquals(dirContextMock, innerDelegateDirContext);
assertThat(innerDelegateDirContext).isEqualTo(dirContextMock);
delegatingDirContext.assertOpen();
@@ -80,11 +83,11 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
final DirContext delegateDirContext2 = delegatingDirContext2
.getDelegateDirContext();
assertEquals(delegatingDirContext, delegateDirContext2);
assertThat(delegateDirContext2).isEqualTo(delegatingDirContext);
final DirContext innerDelegateDirContext2 = delegatingDirContext2
.getInnermostDelegateDirContext();
assertEquals(dirContextMock, innerDelegateDirContext2);
assertThat(innerDelegateDirContext2).isEqualTo(dirContextMock);
delegatingDirContext2.assertOpen();
@@ -93,11 +96,11 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
final DirContext delegateContext2closed = delegatingDirContext2
.getDelegateDirContext();
assertNull(delegateContext2closed);
assertThat(delegateContext2closed).isNull();
final DirContext innerDelegateContext2closed = delegatingDirContext2
.getInnermostDelegateDirContext();
assertNull(innerDelegateContext2closed);
assertThat(innerDelegateContext2closed).isNull();
try {
delegatingDirContext2.assertOpen();
@@ -111,11 +114,11 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
final DirContext delegateDirContextClosed = delegatingDirContext
.getDelegateDirContext();
assertNull(delegateDirContextClosed);
assertThat(delegateDirContextClosed).isNull();
final DirContext innerDelegateDirContextClosed = delegatingDirContext
.getInnermostDelegateDirContext();
assertNull(innerDelegateDirContextClosed);
assertThat(innerDelegateDirContextClosed).isNull();
try {
delegatingDirContext.assertOpen();
@@ -134,33 +137,33 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
// Wrap the DirContext once
final DelegatingDirContext delegatingDirContext = new DelegatingDirContext(
keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY);
assertEquals(dirContextMock.toString(), delegatingDirContext.toString());
assertThat(delegatingDirContext.toString()).isEqualTo(dirContextMock.toString());
delegatingDirContext.hashCode(); // Run it to make sure it doesn't
// fail
assertTrue(delegatingDirContext.equals(delegatingDirContext));
assertFalse(delegatingDirContext.equals(new Object()));
assertThat(delegatingDirContext.equals(delegatingDirContext)).isTrue();
assertThat(delegatingDirContext.equals(new Object())).isFalse();
final DelegatingDirContext delegatingDirContext2 = new DelegatingDirContext(
keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY);
assertTrue(delegatingDirContext.equals(delegatingDirContext2));
assertTrue(delegatingDirContext2.equals(delegatingDirContext));
assertTrue(delegatingDirContext.equals(dirContextMock));
assertThat(delegatingDirContext.equals(delegatingDirContext2)).isTrue();
assertThat(delegatingDirContext2.equals(delegatingDirContext)).isTrue();
assertThat(delegatingDirContext.equals(dirContextMock)).isTrue();
// Close the context and try again
delegatingDirContext.close();
assertEquals("DirContext is closed", delegatingDirContext.toString());
assertEquals(0, delegatingDirContext.hashCode()); // Run it to make
assertThat(delegatingDirContext.toString()).isEqualTo("DirContext is closed");
assertThat(delegatingDirContext.hashCode()).isEqualTo(0); // Run it to make
// sure it doesn't
// fail
assertTrue(delegatingDirContext.equals(delegatingDirContext));
assertFalse(delegatingDirContext.equals(new Object()));
assertThat(delegatingDirContext.equals(delegatingDirContext)).isTrue();
assertThat(delegatingDirContext.equals(new Object())).isFalse();
assertFalse(delegatingDirContext.equals(delegatingDirContext2));
assertFalse(delegatingDirContext2.equals(delegatingDirContext));
assertFalse(delegatingDirContext.equals(dirContextMock));
assertThat(delegatingDirContext.equals(delegatingDirContext2)).isFalse();
assertThat(delegatingDirContext2.equals(delegatingDirContext)).isFalse();
assertThat(delegatingDirContext.equals(dirContextMock)).isFalse();
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, dirContextMock);
}
@@ -378,4 +381,4 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase {
verify(keyedObjectPoolMock, times(1)).returnObject(DirContextType.READ_ONLY, dirContextMock);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2015 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,8 +22,11 @@ import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/**
* @author Eric Dalquist <a
@@ -37,7 +40,7 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
@@ -45,7 +48,7 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -57,15 +60,15 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
final DirContext delegateDirContext = delegatingLdapContext
.getDelegateDirContext();
assertEquals(ldapContextMock, delegateDirContext);
assertThat(delegateDirContext).isEqualTo(ldapContextMock);
final LdapContext delegateLdapContext = delegatingLdapContext
.getDelegateLdapContext();
assertEquals(ldapContextMock, delegateLdapContext);
assertThat(delegateLdapContext).isEqualTo(ldapContextMock);
final LdapContext innerDelegateLdapContext = delegatingLdapContext
.getInnermostDelegateLdapContext();
assertEquals(ldapContextMock, innerDelegateLdapContext);
assertThat(innerDelegateLdapContext).isEqualTo(ldapContextMock);
delegatingLdapContext.assertOpen();
@@ -78,11 +81,11 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
final LdapContext delegateLdapContext2 = delegatingLdapContext2
.getDelegateLdapContext();
assertEquals(delegatingLdapContext, delegateLdapContext2);
assertThat(delegateLdapContext2).isEqualTo(delegatingLdapContext);
final LdapContext innerDelegateLdapContext2 = delegatingLdapContext2
.getInnermostDelegateLdapContext();
assertEquals(ldapContextMock, innerDelegateLdapContext2);
assertThat(innerDelegateLdapContext2).isEqualTo(ldapContextMock);
delegatingLdapContext2.assertOpen();
@@ -91,11 +94,11 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
final LdapContext delegateContext2closed = delegatingLdapContext2
.getDelegateLdapContext();
assertNull(delegateContext2closed);
assertThat(delegateContext2closed).isNull();
final LdapContext innerDelegateContext2closed = delegatingLdapContext2
.getInnermostDelegateLdapContext();
assertNull(innerDelegateContext2closed);
assertThat(innerDelegateContext2closed).isNull();
try {
delegatingLdapContext2.assertOpen();
@@ -109,11 +112,11 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
final LdapContext delegateLdapContextClosed = delegatingLdapContext
.getDelegateLdapContext();
assertNull(delegateLdapContextClosed);
assertThat(delegateLdapContextClosed).isNull();
final LdapContext innerDelegateLdapContextClosed = delegatingLdapContext
.getInnermostDelegateLdapContext();
assertNull(innerDelegateLdapContextClosed);
assertThat(innerDelegateLdapContextClosed).isNull();
try {
delegatingLdapContext.assertOpen();
@@ -132,33 +135,32 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase {
// Wrap the LdapContext once
final DelegatingLdapContext delegatingLdapContext = new DelegatingLdapContext(
keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY);
assertEquals(ldapContextMock.toString(),
delegatingLdapContext.toString());
assertThat(delegatingLdapContext.toString()).isEqualTo(ldapContextMock.toString());
delegatingLdapContext.hashCode(); // Run it to make sure it doesn't fail
assertTrue(delegatingLdapContext.equals(delegatingLdapContext));
assertFalse(delegatingLdapContext.equals(new Object()));
assertThat(delegatingLdapContext.equals(delegatingLdapContext)).isTrue();
assertThat(delegatingLdapContext.equals(new Object())).isFalse();
final DelegatingLdapContext delegatingLdapContext2 = new DelegatingLdapContext(
keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY);
assertTrue(delegatingLdapContext.equals(delegatingLdapContext2));
assertTrue(delegatingLdapContext2.equals(delegatingLdapContext));
assertTrue(delegatingLdapContext.equals(ldapContextMock));
assertThat(delegatingLdapContext.equals(delegatingLdapContext2)).isTrue();
assertThat(delegatingLdapContext2.equals(delegatingLdapContext)).isTrue();
assertThat(delegatingLdapContext.equals(ldapContextMock)).isTrue();
// Close the context and try again
delegatingLdapContext.close();
assertEquals("LdapContext is closed", delegatingLdapContext.toString());
assertEquals(0, delegatingLdapContext.hashCode()); // Run it to make
assertThat(delegatingLdapContext.toString()).isEqualTo("LdapContext is closed");
assertThat(delegatingLdapContext.hashCode()).isEqualTo(0); // Run it to make
// sure it doesn't
// fail
assertTrue(delegatingLdapContext.equals(delegatingLdapContext));
assertFalse(delegatingLdapContext.equals(new Object()));
assertThat(delegatingLdapContext.equals(delegatingLdapContext)).isTrue();
assertThat(delegatingLdapContext.equals(new Object())).isFalse();
assertFalse(delegatingLdapContext.equals(delegatingLdapContext2));
assertFalse(delegatingLdapContext2.equals(delegatingLdapContext));
assertFalse(delegatingLdapContext.equals(ldapContextMock));
assertThat(delegatingLdapContext.equals(delegatingLdapContext2)).isFalse();
assertThat(delegatingLdapContext2.equals(delegatingLdapContext)).isFalse();
assertThat(delegatingLdapContext.equals(ldapContextMock)).isFalse();
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, ldapContextMock);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2015 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ package org.springframework.ldap.pool2.factory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.pool2.DirContextType;
@@ -29,8 +28,12 @@ import javax.naming.directory.DirContext;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* @author Eric Dalquist
@@ -49,12 +52,12 @@ public class DirContextPooledObjectFactoryTest extends AbstractPoolTestCase {
catch (IllegalArgumentException iae) {
// Expected
}
objectFactory.setContextSource(contextSourceMock);
final ContextSource contextSource2 = objectFactory.getContextSource();
assertEquals(contextSourceMock, contextSource2);
assertThat(contextSource2).isEqualTo(contextSourceMock);
try {
objectFactory.setDirContextValidator(null);
fail("DirContextPooledObjectFactory.setDirContextValidator should have thrown an IllegalArgumentException");
@@ -62,10 +65,10 @@ public class DirContextPooledObjectFactoryTest extends AbstractPoolTestCase {
catch (IllegalArgumentException iae) {
// Expected
}
objectFactory.setDirContextValidator(dirContextValidatorMock);
final DirContextValidator dirContextValidator2 = objectFactory.getDirContextValidator();
assertEquals(dirContextValidatorMock, dirContextValidator2);
assertThat(dirContextValidator2).isEqualTo(dirContextValidatorMock);
}
@Test
@@ -76,23 +79,23 @@ public class DirContextPooledObjectFactoryTest extends AbstractPoolTestCase {
objectFactory.makeObject(DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
objectFactory.setContextSource(contextSourceMock);
try {
objectFactory.makeObject(null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@Test
public void testMakeObjectReadOnly() throws Exception {
final DirContextPooledObjectFactory objectFactory = new DirContextPooledObjectFactory();
DirContext readOnlyContextMock = mock(DirContext.class);
when(contextSourceMock.getReadOnlyContext()).thenReturn(readOnlyContextMock);
@@ -100,13 +103,13 @@ public class DirContextPooledObjectFactoryTest extends AbstractPoolTestCase {
final PooledObject createdDirContext = objectFactory.makeObject(DirContextType.READ_ONLY);
InvocationHandler invocationHandler = Proxy.getInvocationHandler(createdDirContext.getObject());
assertEquals(readOnlyContextMock, Whitebox.getInternalState(invocationHandler, "target"));
assertThat(readOnlyContextMock).isEqualTo(Whitebox.getInternalState(invocationHandler, "target"));
}
@Test
public void testMakeObjectReadWrite() throws Exception {
final DirContextPooledObjectFactory objectFactory = new DirContextPooledObjectFactory();
DirContext readWriteContextMock = mock(DirContext.class);
when(contextSourceMock.getReadWriteContext()).thenReturn(readWriteContextMock);
@@ -115,7 +118,7 @@ public class DirContextPooledObjectFactoryTest extends AbstractPoolTestCase {
final PooledObject createdDirContext = objectFactory.makeObject(DirContextType.READ_WRITE);
InvocationHandler invocationHandler = Proxy.getInvocationHandler(createdDirContext.getObject());
assertEquals(readWriteContextMock, Whitebox.getInternalState(invocationHandler, "target"));
assertThat(readWriteContextMock).isEqualTo(Whitebox.getInternalState(invocationHandler, "target"));
}
@Test
@@ -127,40 +130,40 @@ public class DirContextPooledObjectFactoryTest extends AbstractPoolTestCase {
objectFactory.validateObject(DirContextType.READ_ONLY, pooledObject);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
objectFactory.setDirContextValidator(dirContextValidatorMock);
try {
PooledObject pooledObject = new DefaultPooledObject(dirContextMock);
objectFactory.validateObject(null, pooledObject);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
PooledObject pooledObject = new DefaultPooledObject(dirContextMock);
objectFactory.validateObject(new Object(), pooledObject);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
objectFactory.validateObject(DirContextType.READ_ONLY, null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
PooledObject pooledObject = new DefaultPooledObject(new Object());
objectFactory.validateObject(DirContextType.READ_ONLY, pooledObject);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -175,8 +178,8 @@ public class DirContextPooledObjectFactoryTest extends AbstractPoolTestCase {
PooledObject pooledObject = new DefaultPooledObject(dirContextMock);
final boolean valid = objectFactory.validateObject(DirContextType.READ_ONLY, pooledObject);
assertTrue(valid);
assertThat(valid).isTrue();
//Check exception in validator
DirContextValidator secondDirContextValidatorMock = mock(DirContextValidator.class);
@@ -185,26 +188,26 @@ public class DirContextPooledObjectFactoryTest extends AbstractPoolTestCase {
objectFactory.setDirContextValidator(secondDirContextValidatorMock);
final boolean valid2 = objectFactory.validateObject(DirContextType.READ_ONLY, pooledObject);
assertFalse(valid2);
assertThat(valid2).isFalse();
}
@Test
public void testDestroyObjectAssertions() throws Exception {
final DirContextPooledObjectFactory objectFactory = new DirContextPooledObjectFactory();
try {
objectFactory.destroyObject(DirContextType.READ_ONLY, null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
try {
PooledObject pooledObject = new DefaultPooledObject(new Object());
objectFactory.validateObject(DirContextType.READ_ONLY, pooledObject);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -214,8 +217,8 @@ public class DirContextPooledObjectFactoryTest extends AbstractPoolTestCase {
PooledObject pooledObject = new DefaultPooledObject(dirContextMock);
objectFactory.destroyObject(DirContextType.READ_ONLY, pooledObject);
DirContext throwingDirContextMock = Mockito.mock(DirContext.class);
DirContext throwingDirContextMock = mock(DirContext.class);
doThrow(new RuntimeException("Failed to close"))
.when(throwingDirContextMock).close();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2015 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import org.springframework.ldap.pool2.MutableDelegatingLdapContext;
import javax.naming.directory.DirContext;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
/**
@@ -43,6 +43,6 @@ public class MutablePooledContextSourceTest extends AbstractPoolTestCase {
// Get a context
final DirContext result = poolingContextSource.getReadOnlyContext();
assertEquals(MutableDelegatingLdapContext.class, result.getClass());
assertThat(result.getClass()).isEqualTo(MutableDelegatingLdapContext.class);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2015 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
import org.junit.Test;
import org.springframework.ldap.pool2.AbstractPoolTestCase;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Anindya Chatterjee
@@ -32,82 +32,82 @@ public class PoolConfigTest extends AbstractPoolTestCase {
poolConfig.setMaxTotalPerKey(5);
final int maxTotalPerKey = poolConfig.getMaxTotalPerKey();
assertEquals(5, maxTotalPerKey);
assertThat(maxTotalPerKey).isEqualTo(5);
poolConfig.setMaxIdlePerKey(500);
final int maxIdle = poolConfig.getMaxIdlePerKey();
assertEquals(500, maxIdle);
assertThat(maxIdle).isEqualTo(500);
poolConfig.setMaxTotal(5000);
final int maxTotal = poolConfig.getMaxTotal();
assertEquals(5000, maxTotal);
assertThat(maxTotal).isEqualTo(5000);
poolConfig.setMaxWaitMillis(2000L);
final long maxWait = poolConfig.getMaxWaitMillis();
assertEquals(2000L, maxWait);
assertThat(maxWait).isEqualTo(2000L);
poolConfig.setMinEvictableIdleTimeMillis(60000L);
final long minEvictableIdleTimeMillis = poolConfig.getMinEvictableIdleTimeMillis();
assertEquals(60000L, minEvictableIdleTimeMillis);
assertThat(minEvictableIdleTimeMillis).isEqualTo(60000L);
poolConfig.setMinIdlePerKey(100);
final int minIdle = poolConfig.getMinIdlePerKey();
assertEquals(100, minIdle);
assertThat(minIdle).isEqualTo(100);
poolConfig.setNumTestsPerEvictionRun(5);
final int numTestsPerEvictionRun = poolConfig.getNumTestsPerEvictionRun();
assertEquals(5, numTestsPerEvictionRun);
assertThat(numTestsPerEvictionRun).isEqualTo(5);
poolConfig.setTestOnBorrow(true);
final boolean testOnBorrow = poolConfig.isTestOnBorrow();
assertEquals(true, testOnBorrow);
assertThat(testOnBorrow).isEqualTo(true);
poolConfig.setTestOnReturn(true);
final boolean testOnReturn = poolConfig.isTestOnReturn();
assertEquals(true, testOnReturn);
assertThat(testOnReturn).isEqualTo(true);
poolConfig.setTestWhileIdle(true);
final boolean testWhileIdle = poolConfig.isTestWhileIdle();
assertEquals(true, testWhileIdle);
assertThat(testWhileIdle).isEqualTo(true);
poolConfig.setTestOnCreate(true);
final boolean testOnCreate = poolConfig.isTestOnCreate();
assertEquals(true, testOnCreate);
assertThat(testOnCreate).isEqualTo(true);
poolConfig.setTimeBetweenEvictionRunsMillis(120000L);
final long timeBetweenEvictionRunsMillis = poolConfig.getTimeBetweenEvictionRunsMillis();
assertEquals(120000L, timeBetweenEvictionRunsMillis);
assertThat(timeBetweenEvictionRunsMillis).isEqualTo(120000L);
poolConfig.setSoftMinEvictableIdleTimeMillis(120000L);
final long softMinEvictableIdleTimeMillis = poolConfig.getSoftMinEvictableIdleTimeMillis();
assertEquals(120000L, softMinEvictableIdleTimeMillis);
assertThat(softMinEvictableIdleTimeMillis).isEqualTo(120000L);
poolConfig.setBlockWhenExhausted(true);
final boolean whenExhaustedAction = poolConfig.isBlockWhenExhausted();
assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED, whenExhaustedAction);
assertThat(whenExhaustedAction).isEqualTo(GenericKeyedObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED);
poolConfig.setEvictionPolicyClassName(GenericKeyedObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME);
final String evictionPolicyClassName = poolConfig.getEvictionPolicyClassName();
assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME, evictionPolicyClassName);
assertThat(evictionPolicyClassName).isEqualTo(GenericKeyedObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME);
poolConfig.setFairness(true);
final boolean fairness = poolConfig.isFairness();
assertEquals(true, fairness);
assertThat(fairness).isEqualTo(true);
poolConfig.setJmxEnabled(true);
final boolean jmxEnabled = poolConfig.isJmxEnabled();
assertEquals(true, jmxEnabled);
assertThat(jmxEnabled).isEqualTo(true);
poolConfig.setJmxNameBase("test");
final String jmxBaseName = poolConfig.getJmxNameBase();
assertEquals("test", jmxBaseName);
assertThat(jmxBaseName).isEqualTo("test");
poolConfig.setJmxNamePrefix("pool");
final String prefix = poolConfig.getJmxNamePrefix();
assertEquals("pool", prefix);
assertThat(prefix).isEqualTo("pool");
poolConfig.setLifo(true);
final boolean lifo = poolConfig.isLifo();
assertEquals(true, lifo);
assertThat(lifo).isEqualTo(true);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2015 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,8 +24,8 @@ import org.springframework.ldap.pool2.AbstractPoolTestCase;
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -69,7 +69,7 @@ public class PooledContextSourceTest extends AbstractPoolTestCase {
}
PooledContextSource.setContextSource(contextSourceMock);
final ContextSource contextSource2 = PooledContextSource.getContextSource();
assertEquals(contextSourceMock, contextSource2);
assertThat(contextSource2).isEqualTo(contextSourceMock);
try {
PooledContextSource.setDirContextValidator(null);
@@ -80,13 +80,13 @@ public class PooledContextSourceTest extends AbstractPoolTestCase {
}
PooledContextSource.setDirContextValidator(dirContextValidatorMock);
final DirContextValidator dirContextValidator2 = PooledContextSource.getDirContextValidator();
assertEquals(dirContextValidatorMock, dirContextValidator2);
assertThat(dirContextValidator2).isEqualTo(dirContextValidatorMock);
final int numActive = PooledContextSource.getNumActive();
assertEquals(0, numActive);
assertThat(numActive).isEqualTo(0);
final int numIdle = PooledContextSource.getNumIdle();
assertEquals(0, numIdle);
assertThat(numIdle).isEqualTo(0);
}
@Test
@@ -100,36 +100,36 @@ public class PooledContextSourceTest extends AbstractPoolTestCase {
//Get a context
final DirContext readOnlyContext1 = PooledContextSource.getReadOnlyContext();
assertEquals(readOnlyContext1, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, PooledContextSource.getNumActive());
assertEquals(0, PooledContextSource.getNumIdle());
assertThat(readOnlyContext1).isEqualTo(dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(PooledContextSource.getNumActive()).isEqualTo(1);
assertThat(PooledContextSource.getNumIdle()).isEqualTo(0);
//Close the context
readOnlyContext1.close();
assertEquals(0, PooledContextSource.getNumActive());
assertEquals(1, PooledContextSource.getNumIdle());
assertThat(PooledContextSource.getNumActive()).isEqualTo(0);
assertThat(PooledContextSource.getNumIdle()).isEqualTo(1);
//Get the context again
final DirContext readOnlyContext2 = PooledContextSource.getReadOnlyContext();
assertEquals(readOnlyContext2, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, PooledContextSource.getNumActive());
assertEquals(0, PooledContextSource.getNumIdle());
assertThat(readOnlyContext2).isEqualTo(dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(PooledContextSource.getNumActive()).isEqualTo(1);
assertThat(PooledContextSource.getNumIdle()).isEqualTo(0);
//Get a new context
final DirContext readOnlyContext3 = PooledContextSource.getReadOnlyContext();
assertEquals(readOnlyContext3, secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(2, PooledContextSource.getNumActive());
assertEquals(0, PooledContextSource.getNumIdle());
assertThat(readOnlyContext3).isEqualTo(secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(PooledContextSource.getNumActive()).isEqualTo(2);
assertThat(PooledContextSource.getNumIdle()).isEqualTo(0);
//Close context
readOnlyContext2.close();
assertEquals(1, PooledContextSource.getNumActive());
assertEquals(1, PooledContextSource.getNumIdle());
assertThat(PooledContextSource.getNumActive()).isEqualTo(1);
assertThat(PooledContextSource.getNumIdle()).isEqualTo(1);
//Close context
readOnlyContext3.close();
assertEquals(0, PooledContextSource.getNumActive());
assertEquals(2, PooledContextSource.getNumIdle());
assertThat(PooledContextSource.getNumActive()).isEqualTo(0);
assertThat(PooledContextSource.getNumIdle()).isEqualTo(2);
}
@Test
@@ -143,36 +143,36 @@ public class PooledContextSourceTest extends AbstractPoolTestCase {
//Get a context
final DirContext readOnlyContext1 = PooledContextSource.getReadWriteContext();
assertEquals(readOnlyContext1, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, PooledContextSource.getNumActive());
assertEquals(0, PooledContextSource.getNumIdle());
assertThat(readOnlyContext1).isEqualTo(dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(PooledContextSource.getNumActive()).isEqualTo(1);
assertThat(PooledContextSource.getNumIdle()).isEqualTo(0);
//Close the context
readOnlyContext1.close();
assertEquals(0, PooledContextSource.getNumActive());
assertEquals(1, PooledContextSource.getNumIdle());
assertThat(PooledContextSource.getNumActive()).isEqualTo(0);
assertThat(PooledContextSource.getNumIdle()).isEqualTo(1);
//Get the context again
final DirContext readOnlyContext2 = PooledContextSource.getReadWriteContext();
assertEquals(readOnlyContext2, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, PooledContextSource.getNumActive());
assertEquals(0, PooledContextSource.getNumIdle());
assertThat(readOnlyContext2).isEqualTo(dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(PooledContextSource.getNumActive()).isEqualTo(1);
assertThat(PooledContextSource.getNumIdle()).isEqualTo(0);
//Get a new context
final DirContext readOnlyContext3 = PooledContextSource.getReadWriteContext();
assertEquals(readOnlyContext3, secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(2, PooledContextSource.getNumActive());
assertEquals(0, PooledContextSource.getNumIdle());
assertThat(readOnlyContext3).isEqualTo(secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(PooledContextSource.getNumActive()).isEqualTo(2);
assertThat(PooledContextSource.getNumIdle()).isEqualTo(0);
//Close context
readOnlyContext2.close();
assertEquals(1, PooledContextSource.getNumActive());
assertEquals(1, PooledContextSource.getNumIdle());
assertThat(PooledContextSource.getNumActive()).isEqualTo(1);
assertThat(PooledContextSource.getNumIdle()).isEqualTo(1);
//Close context
readOnlyContext3.close();
assertEquals(0, PooledContextSource.getNumActive());
assertEquals(2, PooledContextSource.getNumIdle());
assertThat(PooledContextSource.getNumActive()).isEqualTo(0);
assertThat(PooledContextSource.getNumIdle()).isEqualTo(2);
}
@Test
@@ -203,35 +203,35 @@ public class PooledContextSourceTest extends AbstractPoolTestCase {
//Get a context
final DirContext readOnlyContext1 = pooledContextSource.getReadOnlyContext();
assertEquals(readOnlyContext1, ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, pooledContextSource.getNumActive());
assertEquals(0, pooledContextSource.getNumIdle());
assertThat(readOnlyContext1).isEqualTo(ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(pooledContextSource.getNumActive()).isEqualTo(1);
assertThat(pooledContextSource.getNumIdle()).isEqualTo(0);
//Close the context
readOnlyContext1.close();
assertEquals(0, pooledContextSource.getNumActive());
assertEquals(1, pooledContextSource.getNumIdle());
assertThat(pooledContextSource.getNumActive()).isEqualTo(0);
assertThat(pooledContextSource.getNumIdle()).isEqualTo(1);
//Get the context again
final DirContext readOnlyContext2 = pooledContextSource.getReadOnlyContext();
assertEquals(readOnlyContext2, ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, pooledContextSource.getNumActive());
assertEquals(0, pooledContextSource.getNumIdle());
assertThat(readOnlyContext2).isEqualTo(ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(pooledContextSource.getNumActive()).isEqualTo(1);
assertThat(pooledContextSource.getNumIdle()).isEqualTo(0);
//Get a new context
final DirContext readOnlyContext3 = pooledContextSource.getReadOnlyContext();
assertEquals(readOnlyContext3, secondLdapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(2, pooledContextSource.getNumActive());
assertEquals(0, pooledContextSource.getNumIdle());
assertThat(readOnlyContext3).isEqualTo(secondLdapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertThat(pooledContextSource.getNumActive()).isEqualTo(2);
assertThat(pooledContextSource.getNumIdle()).isEqualTo(0);
//Close context
readOnlyContext2.close();
assertEquals(1, pooledContextSource.getNumActive());
assertEquals(1, pooledContextSource.getNumIdle());
assertThat(pooledContextSource.getNumActive()).isEqualTo(1);
assertThat(pooledContextSource.getNumIdle()).isEqualTo(1);
//Close context
readOnlyContext3.close();
assertEquals(0, pooledContextSource.getNumActive());
assertEquals(2, pooledContextSource.getNumIdle());
assertThat(pooledContextSource.getNumActive()).isEqualTo(0);
assertThat(pooledContextSource.getNumIdle()).isEqualTo(2);
}
}

View File

@@ -3,8 +3,7 @@ package org.springframework.ldap.query;
import org.junit.Test;
import org.springframework.ldap.support.LdapUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.ldap.query.LdapQueryBuilder.query;
/**
@@ -16,32 +15,32 @@ public class LdapQueryBuilderTest {
public void buildSimpleWithDefaults() {
LdapQuery result = query().where("cn").is("John Doe");
assertEquals(LdapUtils.emptyLdapName(), result.base());
assertNull(result.searchScope());
assertNull(result.timeLimit());
assertNull(result.countLimit());
assertEquals("(cn=John Doe)", result.filter().encode());
assertThat(result.base()).isEqualTo(LdapUtils.emptyLdapName());
assertThat(result.searchScope()).isNull();
assertThat(result.timeLimit()).isNull();
assertThat(result.countLimit()).isNull();
assertThat(result.filter().encode()).isEqualTo("(cn=John Doe)");
}
@Test
public void buildGreaterThanOrEquals() {
LdapQuery result = query().where("cn").gte("John Doe");
assertEquals("(cn>=John Doe)", result.filter().encode());
assertThat(result.filter().encode()).isEqualTo("(cn>=John Doe)");
}
@Test
public void buildLessThanOrEquals() {
LdapQuery result = query().where("cn").lte("John Doe");
assertEquals("(cn<=John Doe)", result.filter().encode());
assertThat(result.filter().encode()).isEqualTo("(cn<=John Doe)");
}
@Test
public void buildLike() {
LdapQuery result = query().where("cn").like("J*hn Doe");
assertEquals("(cn=J*hn Doe)", result.filter().encode());
assertThat(result.filter().encode()).isEqualTo("(cn=J*hn Doe)");
}
@@ -49,21 +48,21 @@ public class LdapQueryBuilderTest {
public void buildWhitespaceWildcards() {
LdapQuery result = query().where("cn").whitespaceWildcardsLike("John Doe");
assertEquals("(cn=*John*Doe*)", result.filter().encode());
assertThat(result.filter().encode()).isEqualTo("(cn=*John*Doe*)");
}
@Test
public void buildPresent() {
LdapQuery result = query().where("cn").isPresent();
assertEquals("(cn=*)", result.filter().encode());
assertThat(result.filter().encode()).isEqualTo("(cn=*)");
}
@Test
public void buildHardcodedFilter() {
LdapQuery result = query().filter("(cn=Person*)");
assertEquals("(cn=Person*)", result.filter().encode());
assertThat(result.filter().encode()).isEqualTo("(cn=Person*)");
}
@Test(expected = IllegalStateException.class)
@@ -84,7 +83,7 @@ public class LdapQueryBuilderTest {
public void buildFilterFormat() {
LdapQuery result = query().filter("(|(cn={0})(cn={1}))", "Person*", "Parson*");
assertEquals("(|(cn=Person\\2a)(cn=Parson\\2a))", result.filter().encode());
assertThat(result.filter().encode()).isEqualTo("(|(cn=Person\\2a)(cn=Parson\\2a))");
}
@Test
@@ -96,18 +95,18 @@ public class LdapQueryBuilderTest {
.countLimit(221)
.where("objectclass").is("person").and("cn").is("John Doe");
assertEquals(LdapUtils.newLdapName("dc=261consulting, dc=com"), query.base());
assertEquals(SearchScope.ONELEVEL, query.searchScope());
assertEquals(Integer.valueOf(200), query.timeLimit());
assertEquals(Integer.valueOf(221), query.countLimit());
assertEquals("(&(objectclass=person)(cn=John Doe))", query.filter().encode());
assertThat(query.base()).isEqualTo(LdapUtils.newLdapName("dc=261consulting, dc=com"));
assertThat(query.searchScope()).isEqualTo(SearchScope.ONELEVEL);
assertThat(query.timeLimit()).isEqualTo(Integer.valueOf(200));
assertThat(query.countLimit()).isEqualTo(Integer.valueOf(221));
assertThat(query.filter().encode()).isEqualTo("(&(objectclass=person)(cn=John Doe))");
}
@Test
public void buildSimpleOr() {
LdapQuery result = query().where("objectclass").is("person").or("cn").is("John Doe");
assertEquals("(|(objectclass=person)(cn=John Doe))", result.filter().encode());
assertThat(result.filter().encode()).isEqualTo("(|(objectclass=person)(cn=John Doe))");
}
@Test
@@ -116,13 +115,13 @@ public class LdapQueryBuilderTest {
.and("cn").is("John Doe")
.or(query().where("sn").is("Doe"));
assertEquals("(|(&(objectclass=person)(cn=John Doe))(sn=Doe))", result.filter().encode());
assertThat(result.filter().encode()).isEqualTo("(|(&(objectclass=person)(cn=John Doe))(sn=Doe))");
}
@Test
public void buildOrNegatedSubQueries() {
LdapQuery result = query().where("objectclass").not().is("person").or("sn").not().is("Doe");
assertEquals("(|(!(objectclass=person))(!(sn=Doe)))", result.filter().encode());
assertThat(result.filter().encode()).isEqualTo("(|(!(objectclass=person))(!(sn=Doe)))");
}
@Test
@@ -132,7 +131,7 @@ public class LdapQueryBuilderTest {
.and(query()
.where("sn").is("Doe")
.or("sn").like("Die"));
assertEquals("(&(objectclass=person)(|(sn=Doe)(sn=Die)))", result.filter().encode());
assertThat(result.filter().encode()).isEqualTo("(&(objectclass=person)(|(sn=Doe)(sn=Die)))");
}
@Test(expected = IllegalStateException.class)

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.repository;
import org.junit.Before;
@@ -18,11 +34,7 @@ import javax.naming.ldap.LdapName;
import java.util.Arrays;
import java.util.Iterator;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
@@ -54,10 +66,10 @@ public class SimpleLdapRepositoryTest {
long count = tested.count();
assertEquals(0, count);
assertThat(count).isEqualTo(0);
LdapQuery query = ldapQuery.getValue();
assertEquals(filterMock, query.filter());
assertArrayEquals(new String[]{"objectclass"}, query.attributes());
assertThat(query.filter()).isEqualTo(filterMock);
assertThat(query.attributes()).isEqualTo(new String[]{"objectclass"});
}
@Test
@@ -147,7 +159,7 @@ public class SimpleLdapRepositoryTest {
Object actualResult = tested.findOne(expectedName);
assertSame(expectedResult, actualResult);
assertThat(actualResult).isSameAs(expectedResult);
}
@Test
@@ -158,7 +170,7 @@ public class SimpleLdapRepositoryTest {
Object actualResult = tested.findOne(expectedName);
assertNull(actualResult);
assertThat(actualResult).isNull();
}
@Test
@@ -175,10 +187,10 @@ public class SimpleLdapRepositoryTest {
Iterable<Object> actualResult = tested.findAll(Arrays.asList(expectedName1, expectedName2));
Iterator<Object> iterator = actualResult.iterator();
assertSame(expectedResult1, iterator.next());
assertSame(expectedResult2, iterator.next());
assertThat(iterator.next()).isSameAs(expectedResult1);
assertThat(iterator.next()).isSameAs(expectedResult2);
assertFalse(iterator.hasNext());
assertThat(iterator.hasNext()).isFalse();
}
@Test
@@ -194,9 +206,9 @@ public class SimpleLdapRepositoryTest {
Iterable<Object> actualResult = tested.findAll(Arrays.asList(expectedName1, expectedName2));
Iterator<Object> iterator = actualResult.iterator();
assertSame(expectedResult2, iterator.next());
assertThat(iterator.next()).isSameAs(expectedResult2);
assertFalse(iterator.hasNext());
assertThat(iterator.hasNext()).isFalse();
}
}

View File

@@ -4,7 +4,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.ldap.config.DummyLdapRepository;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Mattias Hellborg Arthursson
@@ -16,6 +16,6 @@ public class AnnotationConfigTest {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-annotation-config.xml");
DummyLdapRepository repository = ctx.getBean(DummyLdapRepository.class);
assertNotNull(repository);
assertThat(repository).isNotNull();
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.repository.query;
import org.junit.Before;
@@ -15,7 +31,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import java.lang.reflect.Method;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Mattias Hellborg Arthursson
@@ -165,7 +181,7 @@ public class PartTreeLdapRepositoryQueryTest extends AbstractJUnit4SpringContext
LdapQuery query = tested.createQuery(expectedParams);
String base = query.base().toString();
assertEquals(expectedBase, base);
assertEquals(expectedFilter, query.filter().encode());
assertThat(base).isEqualTo(expectedBase);
assertThat(query.filter().encode()).isEqualTo(expectedFilter);
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.repository.support;
import com.querydsl.core.types.Expression;
@@ -8,7 +24,7 @@ import org.springframework.ldap.odm.core.ObjectDirectoryMapper;
import org.springframework.ldap.odm.core.impl.DefaultObjectDirectoryMapper;
import org.springframework.ldap.odm.core.impl.UnitTestPerson;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Mattias Hellborg Arthursson
@@ -30,21 +46,21 @@ public class QueryDslFilterGeneratorTest {
public void testEqualsFilter() {
Expression<?> expression = person.fullName.eq("John Doe");
Filter result = tested.handle(expression);
assertEquals("(cn=John Doe)", result.toString());
assertThat(result.toString()).isEqualTo("(cn=John Doe)");
}
@Test
public void testAndFilter() {
Expression<?> expression = person.fullName.eq("John Doe").and(person.lastName.eq("Doe"));
Filter result = tested.handle(expression);
assertEquals("(&(cn=John Doe)(sn=Doe))", result.toString());
assertThat(result.toString()).isEqualTo("(&(cn=John Doe)(sn=Doe))");
}
@Test
public void testOrFilter() {
Expression<?> expression = person.fullName.eq("John Doe").or(person.lastName.eq("Doe"));
Filter result = tested.handle(expression);
assertEquals("(|(cn=John Doe)(sn=Doe))", result.toString());
assertThat(result.toString()).isEqualTo("(|(cn=John Doe)(sn=Doe))");
}
@Test
@@ -53,55 +69,55 @@ public class QueryDslFilterGeneratorTest {
.and(person.lastName.eq("Doe").or(person.lastName.eq("Die")));
Filter result = tested.handle(expression);
assertEquals("(&(cn=John Doe)(|(sn=Doe)(sn=Die)))", result.toString());
assertThat(result.toString()).isEqualTo("(&(cn=John Doe)(|(sn=Doe)(sn=Die)))");
}
@Test
public void testNot() {
Expression<?> expression = person.fullName.eq("John Doe").not();
Filter result = tested.handle(expression);
assertEquals("(!(cn=John Doe))", result.toString());
assertThat(result.toString()).isEqualTo("(!(cn=John Doe))");
}
@Test
public void testIsLike() {
Expression<?> expression = person.fullName.like("kalle*");
Filter result = tested.handle(expression);
assertEquals("(cn=kalle*)", result.toString());
assertThat(result.toString()).isEqualTo("(cn=kalle*)");
}
@Test
public void testStartsWith() {
Expression<?> expression = person.fullName.startsWith("kalle");
Filter result = tested.handle(expression);
assertEquals("(cn=kalle*)", result.toString());
assertThat(result.toString()).isEqualTo("(cn=kalle*)");
}
@Test
public void testEndsWith() {
Expression<?> expression = person.fullName.endsWith("kalle");
Filter result = tested.handle(expression);
assertEquals("(cn=*kalle)", result.toString());
assertThat(result.toString()).isEqualTo("(cn=*kalle)");
}
@Test
public void testContains() {
Expression<?> expression = person.fullName.contains("kalle");
Filter result = tested.handle(expression);
assertEquals("(cn=*kalle*)", result.toString());
assertThat(result.toString()).isEqualTo("(cn=*kalle*)");
}
@Test
public void testNotNull() {
Expression<?> expression = person.fullName.isNotNull();
Filter result = tested.handle(expression);
assertEquals("(cn=*)", result.toString());
assertThat(result.toString()).isEqualTo("(cn=*)");
}
@Test
public void testNull() {
Expression<?> expression = person.fullName.isNull();
Filter result = tested.handle(expression);
assertEquals("(!(cn=*))", result.toString());
assertThat(result.toString()).isEqualTo("(!(cn=*))");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ package org.springframework.ldap.support;
import org.junit.Test;
import org.springframework.ldap.BadLdapGrammarException;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit test for the LdapEncode class.
@@ -31,7 +31,7 @@ public class LdapEncoderTest {
@Test
public void testFilterEncode() {
String correct = "\\2aa\\2ab\\28c\\29d\\2a\\5c";
assertEquals(correct, LdapEncoder.filterEncode("*a*b(c)d*\\"));
assertThat(LdapEncoder.filterEncode("*a*b(c)d*\\")).isEqualTo(correct);
}
@@ -40,7 +40,7 @@ public class LdapEncoderTest {
String res = LdapEncoder.nameEncode("# foo ,+\"\\<>; ");
assertEquals("\\# foo \\,\\+\\\"\\\\\\<\\>\\;\\ ", res);
assertThat(res).isEqualTo("\\# foo \\,\\+\\\"\\\\\\<\\>\\;\\ ");
}
@Test
@@ -49,7 +49,7 @@ public class LdapEncoderTest {
String res = LdapEncoder
.nameDecode("\\# foo \\,\\+\\\"\\\\\\<\\>\\;\\ ");
assertEquals("# foo ,+\"\\<>; ", res);
assertThat(res).isEqualTo("# foo ,+\"\\<>; ");
}
@Test(expected = BadLdapGrammarException.class)

View File

@@ -2,7 +2,7 @@ package org.springframework.ldap.support;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Mattias Hellborg Arthursson
@@ -12,43 +12,43 @@ public class LdapNameBuilderTest {
@Test
public void testAddComponentToEmpty() {
LdapNameBuilder tested = LdapNameBuilder.newInstance().add("dc", "com").add("dc", "261consulting");
assertEquals("dc=261consulting,dc=com", tested.build().toString());
assertThat(tested.build().toString()).isEqualTo("dc=261consulting,dc=com");
}
@Test
public void testAddComponentToBaseString() {
LdapNameBuilder tested = LdapNameBuilder.newInstance("dc=com").add("dc", "261consulting");
assertEquals("dc=261consulting,dc=com", tested.build().toString());
assertThat(tested.build().toString()).isEqualTo("dc=261consulting,dc=com");
}
@Test
public void testAddComponentToBaseName() {
LdapNameBuilder tested = LdapNameBuilder.newInstance(LdapUtils.newLdapName("dc=com")).add("dc", "261consulting");
assertEquals("dc=261consulting,dc=com", tested.build().toString());
assertThat(tested.build().toString()).isEqualTo("dc=261consulting,dc=com");
}
@Test
public void testAddStringNameToBaseString() {
LdapNameBuilder tested = LdapNameBuilder.newInstance("dc=261consulting,dc=com").add("ou=people");
assertEquals("ou=people,dc=261consulting,dc=com", tested.build().toString());
assertThat(tested.build().toString()).isEqualTo("ou=people,dc=261consulting,dc=com");
}
@Test
public void testAddNameToBaseString() {
LdapNameBuilder tested = LdapNameBuilder.newInstance("dc=261consulting,dc=com").add(LdapUtils.newLdapName("ou=people"));
assertEquals("ou=people,dc=261consulting,dc=com", tested.build().toString());
assertThat(tested.build().toString()).isEqualTo("ou=people,dc=261consulting,dc=com");
}
@Test
public void testAddNameToEmpty() {
LdapNameBuilder tested = LdapNameBuilder.newInstance().add(LdapUtils.newLdapName("ou=people"));
assertEquals("ou=people", tested.build().toString());
assertThat(tested.build().toString()).isEqualTo("ou=people");
}
@Test
public void testAddEmptyToEmpty() {
LdapNameBuilder tested = LdapNameBuilder.newInstance().add("");
assertEquals("", tested.build().toString());
assertThat(tested.build().toString()).isEqualTo("");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,10 +28,8 @@ import javax.naming.directory.BasicAttributes;
import javax.naming.ldap.LdapName;
import java.util.LinkedList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -60,9 +58,9 @@ public class LdapUtilsTest {
LinkedList list = new LinkedList();
LdapUtils.collectAttributeValues(attributes, expectedAttributeName, list);
assertEquals(2, list.size());
assertEquals("value1", list.get(0));
assertEquals("value2", list.get(1));
assertThat(list).hasSize(2);
assertThat(list.get(0)).isEqualTo("value1");
assertThat(list.get(1)).isEqualTo("value2");
}
@Test
@@ -75,7 +73,7 @@ public class LdapUtilsTest {
LdapUtils.collectAttributeValues(attributes, expectedAttributeName, list);
fail("NoSuchAttributeException expected");
} catch (NoSuchAttributeException expected) {
assertTrue(true);
assertThat(true).isTrue();
}
}
@@ -115,7 +113,7 @@ public class LdapUtilsTest {
(byte) 0x82, (byte) 0x05, (byte) 0x1e, (byte) 0x6c,
(byte) 0x28, (byte) 0x06, (byte) 0x00, (byte) 0x00};
String result = LdapUtils.convertBinarySidToString(sid);
assertEquals("S-1-5-21-2562418665-3218585558-1813906818-1576", result);
assertThat(result).isEqualTo("S-1-5-21-2562418665-3218585558-1813906818-1576");
}
/**
@@ -131,7 +129,7 @@ public class LdapUtilsTest {
(byte) 0xe7, (byte) 0x7c, (byte) 0x87, (byte) 0x70,
(byte) 0x09, (byte) 0x1c, (byte) 0x01, (byte) 0x00};
String result = LdapUtils.convertBinarySidToString(sid);
assertEquals("S-1-5-21-2127521184-1604012920-1887927527-72713", result);
assertThat(result).isEqualTo("S-1-5-21-2127521184-1604012920-1887927527-72713");
}
/**
@@ -147,51 +145,51 @@ public class LdapUtilsTest {
(byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00};
String result = LdapUtils.convertBinarySidToString(sid);
assertEquals("S-1-5-21-1-2-3-4", result);
assertThat(result).isEqualTo("S-1-5-21-1-2-3-4");
}
@Test
public void testSmallNumberToBytesBigEndian() throws Exception {
byte[] result = LdapUtils.numberToBytes("5", 6, true);
assertEquals(6, result.length);
assertEquals(0, result[0]);
assertEquals(0, result[1]);
assertEquals(0, result[2]);
assertEquals(0, result[3]);
assertEquals(0, result[4]);
assertEquals(5, result[5]);
assertThat(result.length).isEqualTo(6);
assertThat(result[0]).isEqualTo((byte)0);
assertThat(result[1]).isEqualTo((byte)0);
assertThat(result[2]).isEqualTo((byte)0);
assertThat(result[3]).isEqualTo((byte)0);
assertThat(result[4]).isEqualTo((byte)0);
assertThat(result[5]).isEqualTo((byte)5);
}
@Test
public void testLargeNumberToBytesBigEndian() throws Exception {
byte[] result = LdapUtils.numberToBytes("1183728", 6, true);
assertEquals(6, result.length);
assertEquals(0, result[0]);
assertEquals(0, result[1]);
assertEquals(0, result[2]);
assertEquals(18, result[3]);
assertEquals(15, result[4]);
assertEquals(-16, result[5]);
assertThat(result.length).isEqualTo(6);
assertThat(result[0]).isEqualTo((byte)0);
assertThat(result[1]).isEqualTo((byte)0);
assertThat(result[2]).isEqualTo((byte)0);
assertThat(result[3]).isEqualTo((byte)18);
assertThat(result[4]).isEqualTo((byte)15);
assertThat(result[5]).isEqualTo((byte)-16);
}
@Test
public void testSmallNumberToBytesLittleEndian() throws Exception {
byte[] result = LdapUtils.numberToBytes("21", 4, false);
assertEquals(4, result.length);
assertEquals(21, result[0]);
assertEquals(0, result[1]);
assertEquals(0, result[2]);
assertEquals(0, result[3]);
assertThat(result.length).isEqualTo(4);
assertThat(result[0]).isEqualTo((byte)21);
assertThat(result[1]).isEqualTo((byte)0);
assertThat(result[2]).isEqualTo((byte)0);
assertThat(result[3]).isEqualTo((byte)0);
}
@Test
public void testLargeNumberToBytesLittleEndian() throws Exception {
byte[] result = LdapUtils.numberToBytes("2127521184", 4, false);
assertEquals(4, result.length);
assertEquals(-96, result[0]);
assertEquals(101, result[1]);
assertEquals(-49, result[2]);
assertEquals(126, result[3]);
assertThat(result.length).isEqualTo(4);
assertThat(result[0]).isEqualTo((byte)-96);
assertThat(result[1]).isEqualTo((byte)101);
assertThat(result[2]).isEqualTo((byte)-49);
assertThat(result[3]).isEqualTo((byte)126);
}
/**
@@ -207,9 +205,9 @@ public class LdapUtilsTest {
(byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00};
byte[] result = LdapUtils.convertStringSidToBinary("S-1-5-21-1-2-3-4");
assertTrue("incorrect length of array", ArrayUtils.isSameLength(expectedSid, result));
assertThat(ArrayUtils.isSameLength(expectedSid, result)).isTrue();
for (int i = 0; i < result.length; i++) {
assertEquals("i=" + i + ",", expectedSid[i], result[i]);
assertThat(expectedSid[i]).isEqualTo(result[i]);
}
}
@@ -226,9 +224,9 @@ public class LdapUtilsTest {
(byte) 0x82, (byte) 0x05, (byte) 0x1e, (byte) 0x6c,
(byte) 0x28, (byte) 0x06, (byte) 0x00, (byte) 0x00};
byte[] result = LdapUtils.convertStringSidToBinary("S-1-5-21-2562418665-3218585558-1813906818-1576");
assertTrue("incorrect length of array", ArrayUtils.isSameLength(expectedSid, result));
assertThat(ArrayUtils.isSameLength(expectedSid, result)).as("incorrect length of array").isTrue();
for (int i = 0; i < result.length; i++) {
assertEquals("i=" + i + ",", expectedSid[i], result[i]);
assertThat(expectedSid[i]).isEqualTo(result[i]);
}
}
@@ -237,19 +235,19 @@ public class LdapUtilsTest {
LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
LdapName result = LdapUtils.newLdapName(ldapName);
assertEquals(ldapName, result);
assertThat(result).isEqualTo(ldapName);
}
@Test
public void testNewLdapNameFromCompositeName() throws InvalidNameException {
LdapName result = LdapUtils.newLdapName(new CompositeName(EXPECTED_DN_STRING));
assertEquals(new LdapName(EXPECTED_DN_STRING), result);
assertThat(result).isEqualTo(new LdapName(EXPECTED_DN_STRING));
}
@Test
public void testEmptyLdapName() {
LdapName ldapName = LdapUtils.emptyLdapName();
assertEquals("", ldapName.toString());
assertThat(ldapName.toString()).isEqualTo("");
}
@Test
@@ -257,8 +255,8 @@ public class LdapUtilsTest {
LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
LdapName result = LdapUtils.removeFirst(ldapName, new LdapName("OU=I,OU=M"));
assertNotSame(ldapName, result);
assertEquals(new LdapName("cn=john.doe, OU=Users,OU=SE,OU=G"), result);
assertThat(result).isNotSameAs(ldapName);
assertThat(result).isEqualTo(new LdapName("cn=john.doe, OU=Users,OU=SE,OU=G"));
}
@Test
@@ -266,8 +264,8 @@ public class LdapUtilsTest {
LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
LdapName result = LdapUtils.removeFirst(ldapName, new LdapName("OU=oooooo,OU=M"));
assertNotSame(ldapName, result);
assertEquals(ldapName, result);
assertThat(result).isNotSameAs(ldapName);
assertThat(result).isEqualTo(ldapName);
}
@Test
@@ -275,174 +273,306 @@ public class LdapUtilsTest {
LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
LdapName result = LdapUtils.removeFirst(ldapName, LdapUtils.emptyLdapName());
assertNotSame(ldapName, result);
assertEquals(ldapName, result);
assertThat(result).isNotSameAs(ldapName);
assertThat(result).isEqualTo(ldapName);
}
@Test
public void testGetValueNamed() throws InvalidNameException {
LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
assertEquals("john.doe", LdapUtils.getValue(ldapName, "cn"));
assertThat("john.doe").isEqualTo(LdapUtils.getValue(ldapName, "cn"));
}
@Test
public void testGetValueNamedReturnesFirstFound() throws InvalidNameException {
LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
assertEquals("M", LdapUtils.getValue(ldapName, "ou"));
assertThat("M").isEqualTo(LdapUtils.getValue(ldapName, "ou"));
}
@Test
public void testGetValueNamedWithMultivalue() throws InvalidNameException {
LdapName ldapName = new LdapName(EXPECTED_MULTIVALUE_DN_STRING);
assertEquals("GR", LdapUtils.getValue(ldapName, "o"));
assertThat("GR").isEqualTo(LdapUtils.getValue(ldapName, "o"));
}
@Test
public void testGetValueIndexed() throws InvalidNameException {
LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
assertEquals("G", LdapUtils.getValue(ldapName, 2));
assertThat("G").isEqualTo(LdapUtils.getValue(ldapName, 2));
}
@Test
public void testGetStringValueIndexed() throws InvalidNameException {
LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
assertEquals("I", LdapUtils.getValue(ldapName, 1));
assertThat("I").isEqualTo(LdapUtils.getValue(ldapName, 1));
}
@Test
public void testConvertLdapExceptions() {
// Test the Exceptions in the javax.naming package
assertEquals(org.springframework.ldap.AttributeInUseException.class,
LdapUtils.convertLdapException(new javax.naming.directory.AttributeInUseException()).getClass());
assertEquals(org.springframework.ldap.AttributeModificationException.class,
LdapUtils.convertLdapException(new javax.naming.directory.AttributeModificationException()).getClass());
assertEquals(org.springframework.ldap.CannotProceedException.class,
LdapUtils.convertLdapException(new javax.naming.CannotProceedException()).getClass());
assertEquals(org.springframework.ldap.CommunicationException.class,
LdapUtils.convertLdapException(new javax.naming.CommunicationException()).getClass());
assertEquals(org.springframework.ldap.ConfigurationException.class,
LdapUtils.convertLdapException(new javax.naming.ConfigurationException()).getClass());
assertEquals(org.springframework.ldap.ContextNotEmptyException.class,
LdapUtils.convertLdapException(new javax.naming.ContextNotEmptyException()).getClass());
assertEquals(org.springframework.ldap.InsufficientResourcesException.class,
LdapUtils.convertLdapException(new javax.naming.InsufficientResourcesException()).getClass());
assertEquals(org.springframework.ldap.InterruptedNamingException.class,
LdapUtils.convertLdapException(new javax.naming.InterruptedNamingException()).getClass());
assertEquals(org.springframework.ldap.InvalidAttributeIdentifierException.class,
LdapUtils.convertLdapException(new javax.naming.directory.InvalidAttributeIdentifierException()).getClass());
assertEquals(org.springframework.ldap.InvalidAttributesException.class,
LdapUtils.convertLdapException(new javax.naming.directory.InvalidAttributesException()).getClass());
assertEquals(org.springframework.ldap.InvalidAttributeValueException.class,
LdapUtils.convertLdapException(new javax.naming.directory.InvalidAttributeValueException()).getClass());
assertEquals(org.springframework.ldap.InvalidNameException.class,
LdapUtils.convertLdapException(new javax.naming.InvalidNameException()).getClass());
assertEquals(org.springframework.ldap.InvalidSearchControlsException.class,
LdapUtils.convertLdapException(new javax.naming.directory.InvalidSearchControlsException()).getClass());
assertEquals(org.springframework.ldap.InvalidSearchFilterException.class,
LdapUtils.convertLdapException(new javax.naming.directory.InvalidSearchFilterException()).getClass());
assertEquals(org.springframework.ldap.SizeLimitExceededException.class,
LdapUtils.convertLdapException(new javax.naming.SizeLimitExceededException()).getClass());
assertEquals(org.springframework.ldap.TimeLimitExceededException.class,
LdapUtils.convertLdapException(new javax.naming.TimeLimitExceededException()).getClass());
assertEquals(org.springframework.ldap.LimitExceededException.class,
LdapUtils.convertLdapException(new javax.naming.LimitExceededException()).getClass());
assertEquals(org.springframework.ldap.LinkLoopException.class,
LdapUtils.convertLdapException(new javax.naming.LinkLoopException()).getClass());
assertEquals(org.springframework.ldap.MalformedLinkException.class,
LdapUtils.convertLdapException(new javax.naming.MalformedLinkException()).getClass());
assertEquals(org.springframework.ldap.LinkException.class,
LdapUtils.convertLdapException(new javax.naming.LinkException()).getClass());
assertEquals(org.springframework.ldap.NameAlreadyBoundException.class,
LdapUtils.convertLdapException(new javax.naming.NameAlreadyBoundException()).getClass());
assertEquals(org.springframework.ldap.NameNotFoundException.class,
LdapUtils.convertLdapException(new javax.naming.NameNotFoundException()).getClass());
assertEquals(org.springframework.ldap.NoPermissionException.class,
LdapUtils.convertLdapException(new javax.naming.NoPermissionException()).getClass());
assertEquals(org.springframework.ldap.AuthenticationException.class,
LdapUtils.convertLdapException(new javax.naming.AuthenticationException()).getClass());
assertEquals(org.springframework.ldap.AuthenticationNotSupportedException.class,
LdapUtils.convertLdapException(new javax.naming.AuthenticationNotSupportedException()).getClass());
assertEquals(org.springframework.ldap.NoInitialContextException.class,
LdapUtils.convertLdapException(new javax.naming.NoInitialContextException()).getClass());
assertEquals(org.springframework.ldap.NoSuchAttributeException.class,
LdapUtils.convertLdapException(new javax.naming.directory.NoSuchAttributeException()).getClass());
assertEquals(org.springframework.ldap.NotContextException.class,
LdapUtils.convertLdapException(new javax.naming.NotContextException()).getClass());
assertEquals(org.springframework.ldap.OperationNotSupportedException.class,
LdapUtils.convertLdapException(new javax.naming.OperationNotSupportedException()).getClass());
assertEquals(org.springframework.ldap.PartialResultException.class,
LdapUtils.convertLdapException(new javax.naming.PartialResultException()).getClass());
assertEquals(org.springframework.ldap.SchemaViolationException.class,
LdapUtils.convertLdapException(new javax.naming.directory.SchemaViolationException()).getClass());
assertEquals(org.springframework.ldap.ServiceUnavailableException.class,
LdapUtils.convertLdapException(new javax.naming.ServiceUnavailableException()).getClass());
assertThat(
LdapUtils.convertLdapException(
new javax.naming.directory.AttributeInUseException()).getClass())
.isEqualTo(org.springframework.ldap.AttributeInUseException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.directory.AttributeModificationException())
.getClass()).isEqualTo(
org.springframework.ldap.AttributeModificationException.class);
assertThat(
LdapUtils.convertLdapException(new javax.naming.CannotProceedException())
.getClass()).isEqualTo(
org.springframework.ldap.CannotProceedException.class);
assertThat(
LdapUtils.convertLdapException(new javax.naming.CommunicationException())
.getClass()).isEqualTo(
org.springframework.ldap.CommunicationException.class);
assertThat(
LdapUtils.convertLdapException(new javax.naming.ConfigurationException())
.getClass()).isEqualTo(
org.springframework.ldap.ConfigurationException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.ContextNotEmptyException()).getClass())
.isEqualTo(org.springframework.ldap.ContextNotEmptyException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.InsufficientResourcesException()).getClass())
.isEqualTo(org.springframework.ldap.InsufficientResourcesException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.InterruptedNamingException()).getClass())
.isEqualTo(org.springframework.ldap.InterruptedNamingException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.directory.InvalidAttributeIdentifierException())
.getClass()).isEqualTo(
org.springframework.ldap.InvalidAttributeIdentifierException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.directory.InvalidAttributesException())
.getClass()).isEqualTo(
org.springframework.ldap.InvalidAttributesException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.directory.InvalidAttributeValueException())
.getClass()).isEqualTo(
org.springframework.ldap.InvalidAttributeValueException.class);
assertThat(
LdapUtils.convertLdapException(new javax.naming.InvalidNameException())
.getClass()).isEqualTo(
org.springframework.ldap.InvalidNameException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.directory.InvalidSearchControlsException())
.getClass()).isEqualTo(
org.springframework.ldap.InvalidSearchControlsException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.directory.InvalidSearchFilterException())
.getClass()).isEqualTo(
org.springframework.ldap.InvalidSearchFilterException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.SizeLimitExceededException()).getClass())
.isEqualTo(org.springframework.ldap.SizeLimitExceededException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.TimeLimitExceededException()).getClass())
.isEqualTo(org.springframework.ldap.TimeLimitExceededException.class);
assertThat(
LdapUtils.convertLdapException(new javax.naming.LimitExceededException())
.getClass()).isEqualTo(
org.springframework.ldap.LimitExceededException.class);
assertThat(
LdapUtils.convertLdapException(new javax.naming.LinkLoopException())
.getClass()).isEqualTo(
org.springframework.ldap.LinkLoopException.class);
assertThat(
LdapUtils.convertLdapException(new javax.naming.MalformedLinkException())
.getClass()).isEqualTo(
org.springframework.ldap.MalformedLinkException.class);
assertThat(
LdapUtils.convertLdapException(new javax.naming.LinkException())
.getClass()).isEqualTo(
org.springframework.ldap.LinkException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.NameAlreadyBoundException()).getClass())
.isEqualTo(org.springframework.ldap.NameAlreadyBoundException.class);
assertThat(
LdapUtils.convertLdapException(new javax.naming.NameNotFoundException())
.getClass()).isEqualTo(
org.springframework.ldap.NameNotFoundException.class);
assertThat(
LdapUtils.convertLdapException(new javax.naming.NoPermissionException())
.getClass()).isEqualTo(
org.springframework.ldap.NoPermissionException.class);
assertThat(
LdapUtils
.convertLdapException(new javax.naming.AuthenticationException())
.getClass()).isEqualTo(
org.springframework.ldap.AuthenticationException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.AuthenticationNotSupportedException())
.getClass()).isEqualTo(
org.springframework.ldap.AuthenticationNotSupportedException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.NoInitialContextException()).getClass())
.isEqualTo(org.springframework.ldap.NoInitialContextException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.directory.NoSuchAttributeException()).getClass())
.isEqualTo(org.springframework.ldap.NoSuchAttributeException.class);
assertThat(
LdapUtils.convertLdapException(new javax.naming.NotContextException())
.getClass()).isEqualTo(
org.springframework.ldap.NotContextException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.OperationNotSupportedException()).getClass())
.isEqualTo(org.springframework.ldap.OperationNotSupportedException.class);
assertThat(
LdapUtils.convertLdapException(new javax.naming.PartialResultException())
.getClass()).isEqualTo(
org.springframework.ldap.PartialResultException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.directory.SchemaViolationException()).getClass())
.isEqualTo(org.springframework.ldap.SchemaViolationException.class);
assertThat(
LdapUtils.convertLdapException(
new javax.naming.ServiceUnavailableException()).getClass())
.isEqualTo(org.springframework.ldap.ServiceUnavailableException.class);
// Test Exceptions that extend javax.naming packaage extensions
assertEquals(org.springframework.ldap.AttributeInUseException.class,
LdapUtils.convertLdapException(new MockAttributeInUseException()).getClass());
assertEquals(org.springframework.ldap.AttributeModificationException.class,
LdapUtils.convertLdapException(new MockAttributeModificationException()).getClass());
assertEquals(org.springframework.ldap.CannotProceedException.class,
LdapUtils.convertLdapException(new MockCannotProceedException()).getClass());
assertEquals(org.springframework.ldap.CommunicationException.class,
LdapUtils.convertLdapException(new MockCommunicationException()).getClass());
assertEquals(org.springframework.ldap.ConfigurationException.class,
LdapUtils.convertLdapException(new MockConfigurationException()).getClass());
assertEquals(org.springframework.ldap.ContextNotEmptyException.class,
LdapUtils.convertLdapException(new MockContextNotEmptyException()).getClass());
assertEquals(org.springframework.ldap.InsufficientResourcesException.class,
LdapUtils.convertLdapException(new MockInsufficientResourcesException()).getClass());
assertEquals(org.springframework.ldap.InterruptedNamingException.class,
LdapUtils.convertLdapException(new MockInterruptedNamingException()).getClass());
assertEquals(org.springframework.ldap.InvalidAttributeIdentifierException.class,
LdapUtils.convertLdapException(new MockInvalidAttributeIdentifierException()).getClass());
assertEquals(org.springframework.ldap.InvalidAttributesException.class,
LdapUtils.convertLdapException(new MockInvalidAttributesException()).getClass());
assertEquals(org.springframework.ldap.InvalidAttributeValueException.class,
LdapUtils.convertLdapException(new MockInvalidAttributeValueException()).getClass());
assertEquals(org.springframework.ldap.InvalidNameException.class,
LdapUtils.convertLdapException(new MockInvalidNameException()).getClass());
assertEquals(org.springframework.ldap.InvalidSearchControlsException.class,
LdapUtils.convertLdapException(new MockInvalidSearchControlsException()).getClass());
assertEquals(org.springframework.ldap.InvalidSearchFilterException.class,
LdapUtils.convertLdapException(new MockInvalidSearchFilterException()).getClass());
assertEquals(org.springframework.ldap.SizeLimitExceededException.class,
LdapUtils.convertLdapException(new MockSizeLimitExceededException()).getClass());
assertEquals(org.springframework.ldap.TimeLimitExceededException.class,
LdapUtils.convertLdapException(new MockTimeLimitExceededException()).getClass());
assertEquals(org.springframework.ldap.LimitExceededException.class,
LdapUtils.convertLdapException(new MockLimitExceededException()).getClass());
assertEquals(org.springframework.ldap.LinkLoopException.class,
LdapUtils.convertLdapException(new MockLinkLoopException()).getClass());
assertEquals(org.springframework.ldap.MalformedLinkException.class,
LdapUtils.convertLdapException(new MockMalformedLinkException()).getClass());
assertEquals(org.springframework.ldap.LinkException.class,
LdapUtils.convertLdapException(new MockLinkException()).getClass());
assertEquals(org.springframework.ldap.NameAlreadyBoundException.class,
LdapUtils.convertLdapException(new MockNameAlreadyBoundException()).getClass());
assertEquals(org.springframework.ldap.NameNotFoundException.class,
LdapUtils.convertLdapException(new MockNameNotFoundException()).getClass());
assertEquals(org.springframework.ldap.NoPermissionException.class,
LdapUtils.convertLdapException(new MockNoPermissionException()).getClass());
assertEquals(org.springframework.ldap.AuthenticationException.class,
LdapUtils.convertLdapException(new MockAuthenticationException()).getClass());
assertEquals(org.springframework.ldap.AuthenticationNotSupportedException.class,
LdapUtils.convertLdapException(new MockAuthenticationNotSupportedException()).getClass());
assertEquals(org.springframework.ldap.NoInitialContextException.class,
LdapUtils.convertLdapException(new MockNoInitialContextException()).getClass());
assertEquals(org.springframework.ldap.NoSuchAttributeException.class,
LdapUtils.convertLdapException(new MockNoSuchAttributeException()).getClass());
assertEquals(org.springframework.ldap.NotContextException.class,
LdapUtils.convertLdapException(new MockNotContextException()).getClass());
assertEquals(org.springframework.ldap.OperationNotSupportedException.class,
LdapUtils.convertLdapException(new MockOperationNotSupportedException()).getClass());
assertEquals(org.springframework.ldap.PartialResultException.class,
LdapUtils.convertLdapException(new MockPartialResultException()).getClass());
assertEquals(org.springframework.ldap.SchemaViolationException.class,
LdapUtils.convertLdapException(new MockSchemaViolationException()).getClass());
assertEquals(org.springframework.ldap.ServiceUnavailableException.class,
LdapUtils.convertLdapException(new MockServiceUnavailableException()).getClass());
assertThat(
LdapUtils.convertLdapException(new MockAttributeInUseException())
.getClass()).isEqualTo(
org.springframework.ldap.AttributeInUseException.class);
assertThat(
LdapUtils.convertLdapException(new MockAttributeModificationException())
.getClass()).isEqualTo(
org.springframework.ldap.AttributeModificationException.class);
assertThat(
LdapUtils.convertLdapException(new MockCannotProceedException())
.getClass()).isEqualTo(
org.springframework.ldap.CannotProceedException.class);
assertThat(
LdapUtils.convertLdapException(new MockCommunicationException())
.getClass()).isEqualTo(
org.springframework.ldap.CommunicationException.class);
assertThat(
LdapUtils.convertLdapException(new MockConfigurationException())
.getClass()).isEqualTo(
org.springframework.ldap.ConfigurationException.class);
assertThat(
LdapUtils.convertLdapException(new MockContextNotEmptyException())
.getClass()).isEqualTo(
org.springframework.ldap.ContextNotEmptyException.class);
assertThat(
LdapUtils.convertLdapException(new MockInsufficientResourcesException())
.getClass()).isEqualTo(
org.springframework.ldap.InsufficientResourcesException.class);
assertThat(
LdapUtils.convertLdapException(new MockInterruptedNamingException())
.getClass()).isEqualTo(
org.springframework.ldap.InterruptedNamingException.class);
assertThat(
LdapUtils.convertLdapException(
new MockInvalidAttributeIdentifierException()).getClass())
.isEqualTo(
org.springframework.ldap.InvalidAttributeIdentifierException.class);
assertThat(
LdapUtils.convertLdapException(new MockInvalidAttributesException())
.getClass()).isEqualTo(
org.springframework.ldap.InvalidAttributesException.class);
assertThat(
LdapUtils.convertLdapException(new MockInvalidAttributeValueException())
.getClass()).isEqualTo(
org.springframework.ldap.InvalidAttributeValueException.class);
assertThat(
LdapUtils.convertLdapException(new MockInvalidNameException()).getClass())
.isEqualTo(org.springframework.ldap.InvalidNameException.class);
assertThat(
LdapUtils.convertLdapException(new MockInvalidSearchControlsException())
.getClass()).isEqualTo(
org.springframework.ldap.InvalidSearchControlsException.class);
assertThat(
LdapUtils.convertLdapException(new MockInvalidSearchFilterException())
.getClass()).isEqualTo(
org.springframework.ldap.InvalidSearchFilterException.class);
assertThat(
LdapUtils.convertLdapException(new MockSizeLimitExceededException())
.getClass()).isEqualTo(
org.springframework.ldap.SizeLimitExceededException.class);
assertThat(
LdapUtils.convertLdapException(new MockTimeLimitExceededException())
.getClass()).isEqualTo(
org.springframework.ldap.TimeLimitExceededException.class);
assertThat(
LdapUtils.convertLdapException(new MockLimitExceededException())
.getClass()).isEqualTo(
org.springframework.ldap.LimitExceededException.class);
assertThat(LdapUtils.convertLdapException(new MockLinkLoopException()).getClass())
.isEqualTo(org.springframework.ldap.LinkLoopException.class);
assertThat(
LdapUtils.convertLdapException(new MockMalformedLinkException())
.getClass()).isEqualTo(
org.springframework.ldap.MalformedLinkException.class);
assertThat(LdapUtils.convertLdapException(new MockLinkException()).getClass())
.isEqualTo(org.springframework.ldap.LinkException.class);
assertThat(
LdapUtils.convertLdapException(new MockNameAlreadyBoundException())
.getClass()).isEqualTo(
org.springframework.ldap.NameAlreadyBoundException.class);
assertThat(
LdapUtils.convertLdapException(new MockNameNotFoundException())
.getClass()).isEqualTo(
org.springframework.ldap.NameNotFoundException.class);
assertThat(
LdapUtils.convertLdapException(new MockNoPermissionException())
.getClass()).isEqualTo(
org.springframework.ldap.NoPermissionException.class);
assertThat(
LdapUtils.convertLdapException(new MockAuthenticationException())
.getClass()).isEqualTo(
org.springframework.ldap.AuthenticationException.class);
assertThat(
LdapUtils.convertLdapException(
new MockAuthenticationNotSupportedException()).getClass())
.isEqualTo(
org.springframework.ldap.AuthenticationNotSupportedException.class);
assertThat(
LdapUtils.convertLdapException(new MockNoInitialContextException())
.getClass()).isEqualTo(
org.springframework.ldap.NoInitialContextException.class);
assertThat(
LdapUtils.convertLdapException(new MockNoSuchAttributeException())
.getClass()).isEqualTo(
org.springframework.ldap.NoSuchAttributeException.class);
assertThat(
LdapUtils.convertLdapException(new MockNotContextException()).getClass())
.isEqualTo(org.springframework.ldap.NotContextException.class);
assertThat(
LdapUtils.convertLdapException(new MockOperationNotSupportedException())
.getClass()).isEqualTo(
org.springframework.ldap.OperationNotSupportedException.class);
assertThat(
LdapUtils.convertLdapException(new MockPartialResultException())
.getClass()).isEqualTo(
org.springframework.ldap.PartialResultException.class);
assertThat(
LdapUtils.convertLdapException(new MockSchemaViolationException())
.getClass()).isEqualTo(
org.springframework.ldap.SchemaViolationException.class);
assertThat(
LdapUtils.convertLdapException(new MockServiceUnavailableException())
.getClass()).isEqualTo(
org.springframework.ldap.ServiceUnavailableException.class);
}
public class MockAttributeInUseException extends javax.naming.directory.AttributeInUseException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ import org.springframework.transaction.compensating.CompensatingTransactionOpera
import javax.naming.directory.BasicAttributes;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
@@ -51,11 +51,11 @@ public class BindOperationRecorderTest {
.recordOperation(new Object[] { expectedDn, expectedObject,
expectedAttributes });
assertTrue(operation instanceof BindOperationExecutor);
assertThat(operation instanceof BindOperationExecutor).isTrue();
BindOperationExecutor rollbackOperation = (BindOperationExecutor) operation;
assertSame(expectedDn, rollbackOperation.getDn());
assertSame(ldapOperationsMock, rollbackOperation.getLdapOperations());
assertSame(expectedObject, rollbackOperation.getOriginalObject());
assertThat(rollbackOperation.getDn()).isSameAs(expectedDn);
assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock);
assertThat(rollbackOperation.getOriginalObject()).isSameAs(expectedObject);
assertSame(expectedAttributes, rollbackOperation
.getOriginalAttributes());
}
@@ -73,10 +73,10 @@ public class BindOperationRecorderTest {
.recordOperation(new Object[] { expectedDn, expectedObject,
expectedAttributes });
assertTrue(operation instanceof BindOperationExecutor);
assertThat(operation instanceof BindOperationExecutor).isTrue();
BindOperationExecutor rollbackOperation = (BindOperationExecutor) operation;
assertEquals(expectedDn, rollbackOperation.getDn().toString());
assertSame(ldapOperationsMock, rollbackOperation.getLdapOperations());
assertThat(rollbackOperation.getDn().toString()).isEqualTo(expectedDn);
assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock);
}
@Test(expected = IllegalArgumentException.class)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,9 +22,7 @@ import org.springframework.transaction.compensating.CompensatingTransactionOpera
import javax.naming.directory.DirContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
public class LdapCompensatingTransactionOperationFactoryTest {
@@ -46,7 +44,7 @@ public class LdapCompensatingTransactionOperationFactoryTest {
renamingStrategyMock) {
LdapOperations createLdapOperationsInstance(DirContext ctx) {
assertEquals(dirContextMock, ctx);
assertThat(ctx).isEqualTo(dirContextMock);
return ldapOperationsMock;
}
};
@@ -57,50 +55,46 @@ public class LdapCompensatingTransactionOperationFactoryTest {
CompensatingTransactionOperationRecorder result = tested
.createRecordingOperation(dirContextMock, "bind");
assertTrue(result instanceof BindOperationRecorder);
assertThat(result instanceof BindOperationRecorder).isTrue();
BindOperationRecorder bindOperationRecorder = (BindOperationRecorder) result;
assertSame(ldapOperationsMock, bindOperationRecorder
.getLdapOperations());
assertThat(bindOperationRecorder.getLdapOperations()).isSameAs(ldapOperationsMock);
}
@Test
public void testGetRecordingOperation_Rebind() throws Exception {
CompensatingTransactionOperationRecorder result = tested
.createRecordingOperation(dirContextMock, "rebind");
assertTrue(result instanceof RebindOperationRecorder);
assertThat(result instanceof RebindOperationRecorder).isTrue();
RebindOperationRecorder rebindOperationRecorder = (RebindOperationRecorder) result;
assertSame(ldapOperationsMock, rebindOperationRecorder
.getLdapOperations());
assertSame(renamingStrategyMock, rebindOperationRecorder
.getRenamingStrategy());
assertThat(rebindOperationRecorder.getLdapOperations()).isSameAs(ldapOperationsMock);
assertThat(rebindOperationRecorder.getRenamingStrategy()).isSameAs(renamingStrategyMock);
}
@Test
public void testGetRecordingOperation_Rename() throws Exception {
CompensatingTransactionOperationRecorder result = tested
.createRecordingOperation(dirContextMock, "rename");
assertTrue(result instanceof RenameOperationRecorder);
assertThat(result instanceof RenameOperationRecorder).isTrue();
RenameOperationRecorder recordingOperation = (RenameOperationRecorder) result;
assertSame(ldapOperationsMock, recordingOperation.getLdapOperations());
assertThat(recordingOperation.getLdapOperations()).isSameAs(ldapOperationsMock);
}
@Test
public void testGetRecordingOperation_ModifyAttributes() throws Exception {
CompensatingTransactionOperationRecorder result = tested
.createRecordingOperation(dirContextMock, "modifyAttributes");
assertTrue(result instanceof ModifyAttributesOperationRecorder);
assertThat(result instanceof ModifyAttributesOperationRecorder).isTrue();
ModifyAttributesOperationRecorder recordingOperation = (ModifyAttributesOperationRecorder) result;
assertSame(ldapOperationsMock, recordingOperation.getLdapOperations());
assertThat(recordingOperation.getLdapOperations()).isSameAs(ldapOperationsMock);
}
@Test
public void testGetRecordingOperation_Unbind() throws Exception {
CompensatingTransactionOperationRecorder result = tested
.createRecordingOperation(dirContextMock, "unbind");
assertTrue(result instanceof UnbindOperationRecorder);
assertThat(result instanceof UnbindOperationRecorder).isTrue();
UnbindOperationRecorder recordingOperation = (UnbindOperationRecorder) result;
assertSame(ldapOperationsMock, recordingOperation.getLdapOperations());
assertSame(renamingStrategyMock, recordingOperation
.getRenamingStrategy());
assertThat(recordingOperation.getLdapOperations()).isSameAs(ldapOperationsMock);
assertThat(recordingOperation.getRenamingStrategy()).isSameAs(renamingStrategyMock);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,9 +32,7 @@ import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -71,8 +69,8 @@ public class ModifyAttributesOperationRecorderTest {
protected ModificationItem getCompensatingModificationItem(
Attributes originalAttributes,
ModificationItem modificationItem) {
assertSame(expectedAttributes, originalAttributes);
assertSame(incomingItem, modificationItem);
assertThat(originalAttributes).isSameAs(expectedAttributes);
assertThat(modificationItem).isSameAs(incomingItem);
return compensatingItem;
}
};
@@ -92,16 +90,15 @@ public class ModifyAttributesOperationRecorderTest {
.recordOperation(new Object[]{expectedName, incomingMods});
// Verify outcome
assertTrue(operation instanceof ModifyAttributesOperationExecutor);
assertThat(operation instanceof ModifyAttributesOperationExecutor).isTrue();
ModifyAttributesOperationExecutor rollbackOperation = (ModifyAttributesOperationExecutor) operation;
assertSame(expectedName, rollbackOperation.getDn());
assertSame(ldapOperationsMock, rollbackOperation.getLdapOperations());
assertThat(rollbackOperation.getDn()).isSameAs(expectedName);
assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock);
ModificationItem[] actualModifications = rollbackOperation.getActualModifications();
assertEquals(incomingMods.length, actualModifications.length);
assertEquals(incomingMods[0], actualModifications[0]);
assertEquals(1, rollbackOperation.getCompensatingModifications().length);
assertSame(compensatingItem, rollbackOperation
.getCompensatingModifications()[0]);
assertThat(actualModifications.length).isEqualTo(incomingMods.length);
assertThat(actualModifications[0]).isEqualTo(incomingMods[0]);
assertThat(rollbackOperation.getCompensatingModifications().length).isEqualTo(1);
assertThat(rollbackOperation.getCompensatingModifications()[0]).isSameAs(compensatingItem);
}
@Test
@@ -121,12 +118,12 @@ public class ModifyAttributesOperationRecorderTest {
attributes, originalItem);
// Verify result
assertEquals(DirContext.ADD_ATTRIBUTE, result.getModificationOp());
assertThat(result.getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE);
Attribute resultAttribute = result.getAttribute();
assertEquals("someattr", resultAttribute.getID());
assertThat(resultAttribute.getID()).isEqualTo("someattr");
Object object = resultAttribute.get(0);
assertEquals("value1", object);
assertEquals("value2", resultAttribute.get(1));
assertThat(object).isEqualTo("value1");
assertThat(resultAttribute.get(1)).isEqualTo("value2");
}
@Test
@@ -150,12 +147,12 @@ public class ModifyAttributesOperationRecorderTest {
attributes, originalItem);
// Verify result
assertEquals(DirContext.ADD_ATTRIBUTE, result.getModificationOp());
assertThat(result.getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE);
Attribute resultAttribute = result.getAttribute();
assertEquals("someattr", resultAttribute.getID());
assertThat(resultAttribute.getID()).isEqualTo("someattr");
Object object = resultAttribute.get(0);
assertEquals("value1", object);
assertEquals("value2", resultAttribute.get(1));
assertThat(object).isEqualTo("value1");
assertThat(resultAttribute.get(1)).isEqualTo("value2");
}
@Test
@@ -178,12 +175,12 @@ public class ModifyAttributesOperationRecorderTest {
attributes, originalItem);
// Verify result
assertEquals(DirContext.REPLACE_ATTRIBUTE, result.getModificationOp());
assertThat(result.getModificationOp()).isEqualTo(DirContext.REPLACE_ATTRIBUTE);
Attribute resultAttribute = result.getAttribute();
assertEquals("someattr", resultAttribute.getID());
assertThat(resultAttribute.getID()).isEqualTo("someattr");
Object object = resultAttribute.get(0);
assertEquals("value1", object);
assertEquals("value2", resultAttribute.get(1));
assertThat(object).isEqualTo("value1");
assertThat(resultAttribute.get(1)).isEqualTo("value2");
}
@Test
@@ -202,10 +199,10 @@ public class ModifyAttributesOperationRecorderTest {
attributes, originalItem);
// Verify result
assertEquals(DirContext.REMOVE_ATTRIBUTE, result.getModificationOp());
assertThat(result.getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE);
Attribute resultAttribute = result.getAttribute();
assertEquals("someattr", resultAttribute.getID());
assertEquals(0, resultAttribute.size());
assertThat(resultAttribute.getID()).isEqualTo("someattr");
assertThat(resultAttribute.size()).isEqualTo(0);
}
@Test
@@ -224,10 +221,10 @@ public class ModifyAttributesOperationRecorderTest {
attributes, originalItem);
// Verify result
assertEquals(DirContext.REMOVE_ATTRIBUTE, result.getModificationOp());
assertThat(result.getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE);
Attribute resultAttribute = result.getAttribute();
assertEquals("someattr", resultAttribute.getID());
assertEquals(0, resultAttribute.size());
assertThat(resultAttribute.getID()).isEqualTo("someattr");
assertThat(resultAttribute.size()).isEqualTo(0);
}
@Test
@@ -250,10 +247,10 @@ public class ModifyAttributesOperationRecorderTest {
attributes, originalItem);
// Verify result
assertEquals(DirContext.REPLACE_ATTRIBUTE, result.getModificationOp());
assertThat(result.getModificationOp()).isEqualTo(DirContext.REPLACE_ATTRIBUTE);
Attribute resultAttribute = result.getAttribute();
assertEquals("someattr", resultAttribute.getID());
assertEquals("value1", result.getAttribute().get(0));
assertEquals("value2", result.getAttribute().get(1));
assertThat(resultAttribute.getID()).isEqualTo("someattr");
assertThat(result.getAttribute().get(0)).isEqualTo("value1");
assertThat(result.getAttribute().get(1)).isEqualTo("value2");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,8 +24,7 @@ import org.springframework.transaction.compensating.CompensatingTransactionOpera
import javax.naming.directory.BasicAttributes;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -60,13 +59,12 @@ public class RebindOperationRecorderTest {
CompensatingTransactionOperationExecutor result = tested
.recordOperation(new Object[] { expectedDn, expectedObject,
expectedAttributes });
assertTrue(result instanceof RebindOperationExecutor);
assertThat(result instanceof RebindOperationExecutor).isTrue();
RebindOperationExecutor rollbackOperation = (RebindOperationExecutor) result;
assertSame(ldapOperationsMock, rollbackOperation.getLdapOperations());
assertSame(expectedDn, rollbackOperation.getOriginalDn());
assertSame(expectedTempDn, rollbackOperation.getTemporaryDn());
assertSame(expectedObject, rollbackOperation.getOriginalObject());
assertSame(expectedAttributes, rollbackOperation
.getOriginalAttributes());
assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock);
assertThat(rollbackOperation.getOriginalDn()).isSameAs(expectedDn);
assertThat(rollbackOperation.getTemporaryDn()).isSameAs(expectedTempDn);
assertThat(rollbackOperation.getOriginalObject()).isSameAs(expectedObject);
assertThat(rollbackOperation.getOriginalAttributes()).isSameAs(expectedAttributes);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,9 +20,7 @@ import org.junit.Test;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
public class RenameOperationRecorderTest {
@@ -43,10 +41,10 @@ public class RenameOperationRecorderTest {
CompensatingTransactionOperationExecutor operation = tested
.recordOperation(new Object[] { "ou=someou", "ou=newou" });
assertTrue(operation instanceof RenameOperationExecutor);
assertThat(operation instanceof RenameOperationExecutor).isTrue();
RenameOperationExecutor rollbackOperation = (RenameOperationExecutor) operation;
assertSame(ldapOperationsMock, rollbackOperation.getLdapOperations());
assertEquals("ou=newou", rollbackOperation.getNewDn().toString());
assertEquals("ou=someou", rollbackOperation.getOriginalDn().toString());
assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock);
assertThat(rollbackOperation.getNewDn().toString()).isEqualTo("ou=newou");
assertThat(rollbackOperation.getOriginalDn().toString()).isEqualTo("ou=someou");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,8 +23,7 @@ import org.springframework.transaction.compensating.CompensatingTransactionOpera
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -57,11 +56,11 @@ public class UnbindOperationRecorderTest {
.recordOperation(new Object[] { expectedDn });
// Verify result
assertTrue(operation instanceof UnbindOperationExecutor);
assertThat(operation instanceof UnbindOperationExecutor).isTrue();
UnbindOperationExecutor rollbackOperation = (UnbindOperationExecutor) operation;
assertSame(ldapOperationsMock, rollbackOperation.getLdapOperations());
assertSame(expectedDn, rollbackOperation.getOriginalDn());
assertSame(expectedTempName, rollbackOperation.getTemporaryDn());
assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock);
assertThat(rollbackOperation.getOriginalDn()).isSameAs(expectedDn);
assertThat(rollbackOperation.getTemporaryDn()).isSameAs(expectedTempName);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,11 +36,8 @@ import javax.naming.directory.DirContext;
import javax.sql.DataSource;
import java.sql.Connection;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -78,10 +75,10 @@ public class ContextSourceTransactionManagerTest {
public void testDoGetTransaction() {
Object result = tested.doGetTransaction();
assertNotNull(result);
assertTrue(result instanceof CompensatingTransactionObject);
assertThat(result).isNotNull();
assertThat(result instanceof CompensatingTransactionObject).isTrue();
CompensatingTransactionObject transactionObject = (CompensatingTransactionObject) result;
assertNull(transactionObject.getHolder());
assertThat(transactionObject.getHolder()).isNull();
}
@Test
@@ -89,7 +86,7 @@ public class ContextSourceTransactionManagerTest {
CompensatingTransactionHolderSupport expectedContextHolder = new DirContextHolder(null, null);
TransactionSynchronizationManager.bindResource(contextSourceMock, expectedContextHolder);
Object result = tested.doGetTransaction();
assertSame(expectedContextHolder, ((CompensatingTransactionObject) result).getHolder());
assertThat(((CompensatingTransactionObject) result).getHolder()).isSameAs(expectedContextHolder);
}
@Test
@@ -101,7 +98,7 @@ public class ContextSourceTransactionManagerTest {
DirContextHolder foundContextHolder = (DirContextHolder) TransactionSynchronizationManager
.getResource(contextSourceMock);
assertSame(contextMock, foundContextHolder.getCtx());
assertThat(foundContextHolder.getCtx()).isSameAs(contextMock);
}
@Test
@@ -124,8 +121,8 @@ public class ContextSourceTransactionManagerTest {
tested.doCleanupAfterCompletion(new CompensatingTransactionObject(expectedContextHolder));
assertNull(TransactionSynchronizationManager.getResource(contextSourceMock));
assertNull(expectedContextHolder.getTransactionOperationManager());
assertThat(TransactionSynchronizationManager.getResource(contextSourceMock)).isNull();
assertThat(expectedContextHolder.getTransactionOperationManager()).isNull();
verify(contextMock).close();
}
@@ -138,7 +135,7 @@ public class ContextSourceTransactionManagerTest {
ContextSource result = tested.getContextSource();
// Verify result
assertSame(contextSourceMock, result);
assertThat(result).isSameAs(contextSourceMock);
}
@Test
@@ -191,7 +188,7 @@ public class ContextSourceTransactionManagerTest {
fail("Exception should be thrown");
}
catch (CannotCreateTransactionException expected) {
assertSame("Should be thrown exception", connectException, expected.getCause());
assertThat(expected.getCause()).as("Should be thrown exception").isSameAs(connectException);
}
verify(connectionMock).rollback();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,9 +23,7 @@ import org.springframework.ldap.core.DirContextProxy;
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -55,11 +53,9 @@ public class TransactionAwareContextSourceProxyTest {
DirContext result = tested.getReadWriteContext();
assertNotNull("Result should not be null", result);
assertTrue("Should be an LdapContext instance",
result instanceof LdapContext);
assertTrue("Should be a DirContextProxy instance",
result instanceof DirContextProxy);
assertThat(result).isNotNull();
assertThat(result instanceof LdapContext).isTrue();
assertThat(result instanceof DirContextProxy).isTrue();
}
@Test
@@ -68,13 +64,10 @@ public class TransactionAwareContextSourceProxyTest {
DirContext result = tested.getReadWriteContext();
assertNotNull("Result should not be null", result);
assertTrue("Should be a DirContext instance",
result instanceof DirContext);
assertFalse("Should not be an LdapContext instance",
result instanceof LdapContext);
assertTrue("Should be a DirContextProxy instance",
result instanceof DirContextProxy);
assertThat(result).as("Result should not be null").isNotNull();
assertThat(result instanceof DirContext).isTrue();
assertThat(result instanceof LdapContext).isFalse();
assertThat(result instanceof DirContextProxy).isTrue();
}
@Test
@@ -83,10 +76,8 @@ public class TransactionAwareContextSourceProxyTest {
DirContext result = tested.getReadOnlyContext();
assertNotNull("Result should not be null", result);
assertTrue("Should be an LdapContext instance",
result instanceof LdapContext);
assertTrue("Should be a DirContextProxy instance",
result instanceof DirContextProxy);
assertThat(result).as("Result should not be null").isNotNull();
assertThat(result instanceof LdapContext).isTrue();
assertThat(result instanceof DirContextProxy).isTrue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,8 +21,7 @@ import org.springframework.ldap.support.LdapUtils;
import javax.naming.Name;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.assertj.core.api.Assertions.assertThat;
public class DefaultTempEntryRenamingStrategyTest {
@@ -33,9 +32,8 @@ public class DefaultTempEntryRenamingStrategyTest {
DefaultTempEntryRenamingStrategy tested = new DefaultTempEntryRenamingStrategy();
Name result = tested.getTemporaryName(expectedOriginalName);
assertEquals("cn=john doe_temp,ou=somecompany,c=SE", result
.toString());
assertNotSame(expectedOriginalName, result);
assertThat(result.toString()).isEqualTo("cn=john doe_temp,ou=somecompany,c=SE");
assertThat(result).isNotSameAs(expectedOriginalName);
}
@Test
@@ -45,8 +43,7 @@ public class DefaultTempEntryRenamingStrategyTest {
DefaultTempEntryRenamingStrategy tested = new DefaultTempEntryRenamingStrategy();
Name result = tested.getTemporaryName(expectedOriginalName);
assertEquals("cn=john doe+sn=doe_temp,ou=somecompany,c=SE", result
.toString());
assertThat(result.toString()).isEqualTo("cn=john doe+sn=doe_temp,ou=somecompany,c=SE");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import org.springframework.ldap.support.LdapUtils;
import javax.naming.Name;
import javax.naming.ldap.LdapName;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
public class DifferentSubtreeTempEntryRenamingStrategyTest {
@Test
@@ -37,8 +37,7 @@ public class DifferentSubtreeTempEntryRenamingStrategyTest {
Name result = tested.getTemporaryName(originalName);
// Verify result
assertEquals("cn=john doe" + nextSequenceNo + ",ou=tempEntries",
result.toString());
assertThat(result.toString()).isEqualTo("cn=john doe" + nextSequenceNo + ",ou=tempEntries");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,8 +22,7 @@ import org.springframework.ldap.support.ListComparator;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for ListComparator.
@@ -45,7 +44,7 @@ public class ListComparatorTest {
List<Integer> list2 = Arrays.asList(0, 0);
int result = tested.compare(list1, list2);
assertEquals(0, result);
assertThat(result).isEqualTo(0);
}
@Test
@@ -54,7 +53,7 @@ public class ListComparatorTest {
List<Integer> list2 = Arrays.asList(0, 1);
int result = tested.compare(list1, list2);
assertTrue(result < 0);
assertThat(result < 0).isTrue();
}
@Test
@@ -63,7 +62,7 @@ public class ListComparatorTest {
List<Integer> list2 = Arrays.asList(0, 0);
int result = tested.compare(list1, list2);
assertTrue(result > 0);
assertThat(result > 0).isTrue();
}
@Test
@@ -72,7 +71,7 @@ public class ListComparatorTest {
List<Integer> list2 = Arrays.asList(0, 0);
int result = tested.compare(list1, list2);
assertTrue(result > 0);
assertThat(result > 0).isTrue();
}
@Test
@@ -81,6 +80,6 @@ public class ListComparatorTest {
List<Integer> list2 = Arrays.asList(0, 0, 0);
int result = tested.compare(list1, list2);
assertTrue(result < 0);
assertThat(result < 0).isTrue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,8 +24,7 @@ import org.springframework.transaction.compensating.CompensatingTransactionOpera
import java.util.Stack;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -60,8 +59,8 @@ public class DefaultCompensatingTransactionOperationManagerTest {
verify(operationExecutorMock).performOperation();
Stack result = tested.getOperationExecutors();
assertFalse(result.isEmpty());
assertSame(operationExecutorMock, result.peek());
assertThat(result.isEmpty()).isFalse();
assertThat(result.peek()).isSameAs(operationExecutorMock);
}
@Test

View File

@@ -21,6 +21,7 @@ ext.queryDslVersion = '4.0.9'
ext.slf4jVersion = '1.7.12'
ext.powerMockVersion = '1.6.2'
ext.commonsPool2Version = '2.4.2'
ext.assertjVersion= '2.3.0'
ext.powerMockDependencies = [
"org.powermock:powermock-core:$powerMockVersion",
@@ -45,4 +46,4 @@ ext.apachedsDependencies = [
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/libs-snapshot' }
}
}

View File

@@ -13,6 +13,7 @@ dependencies {
"org.springframework:spring-context:$springVersion",
"org.springframework:spring-aop:$springVersion",
"org.springframework:spring-test:$springVersion",
"org.assertj:assertj-core:$assertjVersion"
testCompile("org.springframework.batch:spring-batch-test:$springBatchVersion") {
exclude group: "org.springframework", module: "spring-test"
@@ -27,4 +28,4 @@ project.tasks.withType(Test).all { t->
if(name.startsWith('springIo')) {
exclude '**/Batch20*.class'
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,21 +27,20 @@ import org.springframework.batch.test.AbstractJobTests;
import org.springframework.batch.test.AssertFile;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.Assert;
import java.net.MalformedURLException;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.fail;
@RunWith(SpringJUnit4ClassRunner.class)
public abstract class LdifReaderTest extends AbstractJobTests {
private static Logger log = LoggerFactory.getLogger(LdifReaderTest.class);
private Resource expected;
private Resource actual;
public LdifReaderTest() {
try {
expected = new UrlResource("file:src/test/resources/expectedOutput.ldif");
@@ -50,34 +49,34 @@ public abstract class LdifReaderTest extends AbstractJobTests {
log.error("Unexpected error", e);
}
}
@Before
public void checkFiles() {
Assert.isTrue(expected.exists(), "Expected does not exist.");
}
@Test
public void testValidRun() {
try {
JobExecution jobExecution = this.launchStep("step1");
//Ensure job completed successfully.
Assert.isTrue(jobExecution.getExitStatus().equals(ExitStatus.COMPLETED), "Step Execution did not complete normally: " + jobExecution.getExitStatus());
//Check output.
Assert.isTrue(actual.exists(), "Actual does not exist.");
AssertFile.assertFileEquals(expected.getFile(), actual.getFile());
} catch (Exception e) {
e.printStackTrace();
fail();
fail(e.getMessage());
}
}
@Test
public void testResourceNotExists() {
JobExecution jobExecution = this.launchStep("step2");
Assert.isTrue(jobExecution.getExitStatus().getExitCode().equals("FAILED"), "The job exit status is not FAILED.");
Assert.isTrue(jobExecution.getExitStatus().getExitDescription().contains("Failed to initialize the reader"), "The job failed for the wrong reason.");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,21 +27,20 @@ import org.springframework.batch.test.AbstractJobTests;
import org.springframework.batch.test.AssertFile;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.Assert;
import java.net.MalformedURLException;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.fail;
@RunWith(SpringJUnit4ClassRunner.class)
public abstract class MappingLdifReaderTest extends AbstractJobTests {
private static Logger log = LoggerFactory.getLogger(MappingLdifReaderTest.class);
private Resource expected;
private Resource actual;
public MappingLdifReaderTest() {
try {
expected = new UrlResource("file:src/test/resources/expectedOutput.ldif");
@@ -50,34 +49,34 @@ public abstract class MappingLdifReaderTest extends AbstractJobTests {
log.error("Unexpected error", e);
}
}
@Before
public void checkFiles() {
Assert.isTrue(expected.exists(), "Expected does not exist.");
}
@Test
public void testValidRun() {
try {
JobExecution jobExecution = this.launchStep("step1");
//Ensure job completed successfully.
Assert.isTrue(jobExecution.getExitStatus().equals(ExitStatus.COMPLETED), "Step Execution did not complete normally: " + jobExecution.getExitStatus());
//Check output.
Assert.isTrue(actual.exists(), "Actual does not exist.");
AssertFile.assertFileEquals(expected.getFile(), actual.getFile());
} catch (Exception e) {
e.printStackTrace();
fail();
fail(e.getMessage());
}
}
@Test
public void testResourceNotExists() {
JobExecution jobExecution = this.launchStep("step2");
Assert.isTrue(jobExecution.getExitStatus().getExitCode().equals("FAILED"), "The job exit status is not FAILED.");
Assert.isTrue(jobExecution.getExitStatus().getExitDescription().contains("Failed to initialize the reader"), "The job failed for the wrong reason.");
}

View File

@@ -3,10 +3,11 @@ dependencies {
compile project(":spring-ldap-core")
testCompile "junit:junit:$junitVersion",
"commons-io:commons-io:$commonsIoVersion"
"commons-io:commons-io:$commonsIoVersion",
"org.assertj:assertj-core:$assertjVersion"
testCompile ("log4j:log4j:$log4jVersion") {
exclude group: 'javax.jms'
exclude group: 'com.sun.jdmk'
exclude group: 'com.sun.jmx'
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,10 +32,8 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
/**
* Parses a preselected set of attributes to test the full spectrum of functionality
@@ -136,30 +134,30 @@ public class DefaultAttributeValidationPolicyTest {
try {
LdapAttribute attribute = (LdapAttribute) policy.parse(line);
assertTrue("IDs do not match: [expected: " + attribute.getID() + ", obtained: " + id + "]", id.equalsIgnoreCase(attribute.getID()));
assertThat(id.equalsIgnoreCase(attribute.getID())).as("IDs do not match: [expected: " + attribute.getID() + ", obtained: " + id + "]").isTrue();
String[] expected = !StringUtils.hasLength(options) ? new String[] {} : options.replaceFirst(";","").split(";");
Arrays.sort(expected);
String[] obtained = attribute.getOptions().toArray(new String[] {});
Arrays.sort(obtained);
assertArrayEquals("Options do not match: ", expected, obtained);
assertThat(obtained).as("Options do not match: ").isEqualTo(expected);
switch(type) {
case STRING:
assertTrue("Value is not a string.", attribute.get() instanceof String);
assertEquals("Values do not match: ", value, attribute.get());
assertThat(attribute.get() instanceof String).as("Value is not a string.").isTrue();
assertThat(attribute.get()).as("Values do not match: ").isEqualTo(value);
break;
case BASE64:
byte[] bytes = LdapEncoder.parseBase64Binary(value);
assertTrue("Value is not a byte[].", attribute.get() instanceof byte[]);
assertArrayEquals("Values do not match: ", bytes, (byte[]) attribute.get());
assertThat(attribute.get() instanceof byte[]).as("Value is not a byte[].").isTrue();
assertThat((byte[]) attribute.get()).as("Values do not match: ").isEqualTo(bytes);
break;
case URL:
URI url = new URI(value);
assertTrue("Value is not a URL.", attribute.get() instanceof URI);
assertEquals("Values do not match: ", url, attribute.get());
assertThat(attribute.get() instanceof URI).as("Value is not a URL.").isTrue();
assertThat(attribute.get()).as("Values do not match: ").isEqualTo(url);
break;
}

View File

@@ -1,52 +1,52 @@
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.ldif;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.springframework.ldap.ldif.parser.LdifParser;
import org.springframework.ldap.schema.BasicSchemaSpecification;
import java.io.File;
import java.io.IOException;
import static org.junit.Assert.assertNull;
/**
* @author Mattias Hellborg Arthursson
*/
public class Ldap233LdifParserTest {
/**
* This previously went into endless loop.
*
* @throws IOException
*/
@Test
public void ldap233Test() throws IOException {
File testFile = File.createTempFile("ldapTest", ".ldif");
FileUtils.write(testFile, "This is just some random text");
LdifParser parser = new LdifParser(testFile);
parser.setRecordSpecification(new BasicSchemaSpecification());
parser.open();
assertNull(parser.getRecord());
testFile.delete();
}
}
/*
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.ldif;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.springframework.ldap.ldif.parser.LdifParser;
import org.springframework.ldap.schema.BasicSchemaSpecification;
import java.io.File;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Mattias Hellborg Arthursson
*/
public class Ldap233LdifParserTest {
/**
* This previously went into endless loop.
*
* @throws IOException
*/
@Test
public void ldap233Test() throws IOException {
File testFile = File.createTempFile("ldapTest", ".ldif");
FileUtils.write(testFile, "This is just some random text");
LdifParser parser = new LdifParser(testFile);
parser.setRecordSpecification(new BasicSchemaSpecification());
parser.open();
assertThat(parser.getRecord()).isNull();
testFile.delete();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,12 +28,12 @@ import org.springframework.ldap.schema.BasicSchemaSpecification;
import java.io.IOException;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
/**
* Unit test for LdifParser.
*
*
* Test results in complete end to end test of all LdifParser functionality:
* 1.) Open a file
* 2.) Read lines and compose an attribute.
@@ -41,17 +41,17 @@ import static org.junit.Assert.fail;
* 4.) Repeat until end of record (Identify end of record).
* 5.) Return a valid LdapAttributes object.
* 6.) Close file upon completion.
*
*
* Provided test file is comprised of sample LDIFs from RFC2849 and exhausts the full range of
* the functionality prescribed by RFC2849 for the LDAP Data Interchange Format (LDIF).
*
*
* @author Keith Barlow
*
*
*/
public class LdifParserTest {
private static Logger log = LoggerFactory.getLogger(LdifParserTest.class);
private LdifParser parser;
/**
@@ -63,7 +63,7 @@ public class LdifParserTest {
parser = new LdifParser(new ClassPathResource("test.ldif"));
parser.setRecordSpecification(new BasicSchemaSpecification());
}
/**
* Setup: opens file.
*/
@@ -75,44 +75,46 @@ public class LdifParserTest {
fail(e.getMessage());
}
}
/**
* Executes test: reads all records from LDIF file and validates an LdapAttributes object is successfully created.
*/
@Test
public void parseLdif() {
int count = 0;
try {
LdapAttributes attributes;
while (parser.hasMoreRecords()) {
try {
attributes = parser.getRecord();
log.info("attributes:\n" + attributes);
if (attributes != null) {
assertTrue("A dn is required.", attributes.getDN() != null);
assertTrue("Object class is required.", attributes.get("objectclass") != null);
assertThat(attributes.getDN() != null).isTrue();
assertThat(attributes.get("objectclass") != null).isTrue();
count++;
}
} catch (InvalidAttributeFormatException e) {
log.error("Invalid attribute", e);
if (count != 6) fail();
if (count != 6) {
fail(e.getMessage());
}
}
log.debug("hasMoreRecords: " + parser.hasMoreRecords());
}
log.info("record count: " + count);
//assertTrue("An incorrect number of records were parsed.", count == 8);
//assertThat(count == 8).as("An incorrect number of records were parsed.").isTrue();
log.info("Done!");
} catch (IOException e) {
fail(e.getMessage());
}
}
/**
* Cleanup: closes file.
*/

View File

@@ -12,5 +12,6 @@ dependencies {
runtime 'ch.qos.logback:logback-classic:1.0.13'
testCompile "org.springframework:spring-test:$springVersion",
"junit:junit:$junitVersion"
}
"junit:junit:$junitVersion",
"org.assertj:assertj-core:$assertjVersion"
}

View File

@@ -1,132 +1,129 @@
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.samples.odm.dao;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.samples.plain.dao.PersonDao;
import org.springframework.ldap.samples.plain.domain.Person;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* Abstract base class for PersonDao integration tests.
*
* @author Mattias Hellborg Arthursson
* @author Ulrik Sandberg
*/
@ContextConfiguration("/config/testContext.xml")
public class PersonDaoSampleIntegrationTest extends
AbstractJUnit4SpringContextTests {
protected Person person;
@Autowired
private PersonDao personDao;
@Before
public void preparePerson() throws Exception {
person = new Person();
person.setCountry("Sweden");
person.setCompany("company1");
person.setFullName("Some Person");
person.setLastName("Person");
person
.setDescription("Sweden, Company1, Some Person");
person.setPhone("+46 555-123456");
}
/**
* Having a single test method test create, update and delete is not exactly
* the ideal way of testing, since they depend on each other. A better way
* would be to separate the tests and load a test fixture before each
* operation, in order to guarantee the expected state every time. See the
* ldaptemplate-person sample for the correct way to do this.
*/
@Test
public void testCreateUpdateDelete() {
try {
person.setFullName("Another Person");
personDao.create(person);
personDao.findByPrimaryKey(
"Sweden", "company1",
"Another Person");
// if we got here, create succeeded
person.setDescription("Another description");
personDao.update(person);
Person result = personDao
.findByPrimaryKey(
"Sweden", "company1",
"Another Person");
assertEquals(
"Another description", result
.getDescription());
} catch(Exception e){
e.printStackTrace();
}
finally {
personDao.delete(person);
try {
personDao.findByPrimaryKey(
"Sweden", "company1",
"Another Person");
fail("NameNotFoundException (when using Spring LDAP) or RuntimeException (when using traditional) expected");
} catch (NameNotFoundException expected) {
// expected
} catch (RuntimeException expected) {
// expected
}
}
}
@Test
public void testGetAllPersonNames() {
List<String> result = personDao.getAllPersonNames();
assertEquals(2, result.size());
String first = result.get(0);
assertEquals("Some Person", first);
}
@Test
public void testFindAll() {
List<Person> result = personDao.findAll();
assertEquals(2, result.size());
Person first = result.get(0);
assertEquals("Some Person", first
.getFullName());
}
@Test
public void testFindByPrimaryKey() {
Person result = personDao.findByPrimaryKey(
"Sweden", "company1", "Some Person");
assertEquals("Sweden", result.getCountry());
assertEquals("company1", result.getCompany());
assertEquals("Sweden, Company1, Some Person", result.getDescription());
assertEquals("+46 555-123456", result.getPhone());
assertEquals("Some Person", result.getFullName());
assertEquals("Person", result.getLastName());
}
}
/*
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.samples.odm.dao;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.samples.plain.dao.PersonDao;
import org.springframework.ldap.samples.plain.domain.Person;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
/**
* Abstract base class for PersonDao integration tests.
*
* @author Mattias Hellborg Arthursson
* @author Ulrik Sandberg
*/
@ContextConfiguration("/config/testContext.xml")
public class PersonDaoSampleIntegrationTest extends
AbstractJUnit4SpringContextTests {
protected Person person;
@Autowired
private PersonDao personDao;
@Before
public void preparePerson() throws Exception {
person = new Person();
person.setCountry("Sweden");
person.setCompany("company1");
person.setFullName("Some Person");
person.setLastName("Person");
person
.setDescription("Sweden, Company1, Some Person");
person.setPhone("+46 555-123456");
}
/**
* Having a single test method test create, update and delete is not exactly
* the ideal way of testing, since they depend on each other. A better way
* would be to separate the tests and load a test fixture before each
* operation, in order to guarantee the expected state every time. See the
* ldaptemplate-person sample for the correct way to do this.
*/
@Test
public void testCreateUpdateDelete() {
try {
person.setFullName("Another Person");
personDao.create(person);
personDao.findByPrimaryKey(
"Sweden", "company1",
"Another Person");
// if we got here, create succeeded
person.setDescription("Another description");
personDao.update(person);
Person result = personDao
.findByPrimaryKey(
"Sweden", "company1",
"Another Person");
assertThat(result.getDescription()).isEqualTo("Another description");
} catch(Exception e){
e.printStackTrace();
}
finally {
personDao.delete(person);
try {
personDao.findByPrimaryKey(
"Sweden", "company1",
"Another Person");
fail("NameNotFoundException (when using Spring LDAP) or RuntimeException (when using traditional) expected");
} catch (NameNotFoundException expected) {
// expected
} catch (RuntimeException expected) {
// expected
}
}
}
@Test
public void testGetAllPersonNames() {
List<String> result = personDao.getAllPersonNames();
assertThat(result).hasSize(2);
String first = result.get(0);
assertThat(first).isEqualTo("Some Person");
}
@Test
public void testFindAll() {
List<Person> result = personDao.findAll();
assertThat(result).hasSize(2);
Person first = result.get(0);
assertThat(first.getFullName()).isEqualTo("Some Person");
}
@Test
public void testFindByPrimaryKey() {
Person result = personDao.findByPrimaryKey(
"Sweden", "company1", "Some Person");
assertThat(result.getCountry()).isEqualTo("Sweden");
assertThat(result.getCompany()).isEqualTo("company1");
assertThat(result.getDescription()).isEqualTo("Sweden, Company1, Some Person");
assertThat(result.getPhone()).isEqualTo("+46 555-123456");
assertThat(result.getFullName()).isEqualTo("Some Person");
assertThat(result.getLastName()).isEqualTo("Person");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import static junit.framework.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
@ContextConfiguration(locations = { "/config/testContext.xml" })
public class LdapTreeBuilderIntegrationTest extends AbstractJUnit4SpringContextTests {
@@ -63,8 +63,8 @@ public class LdapTreeBuilderIntegrationTest extends AbstractJUnit4SpringContextT
public void visit(DirContextOperations node, int currentDepth) {
LdapName next = keyIterator.next();
assertEquals(next, node.getDn());
assertEquals(names.get(next).intValue(), currentDepth);
assertThat(node.getDn()).isEqualTo(next);
assertThat(currentDepth).isEqualTo(names.get(next).intValue());
}
}

View File

@@ -12,5 +12,6 @@ dependencies {
runtime 'ch.qos.logback:logback-classic:1.0.13'
testCompile "org.springframework:spring-test:$springVersion",
"junit:junit:$junitVersion"
}
"junit:junit:$junitVersion",
"org.assertj:assertj-core:$assertjVersion"
}

View File

@@ -1,122 +1,119 @@
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.samples.plain.dao;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.samples.plain.domain.Person;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* Abstract base class for PersonDao integration tests.
*
* @author Mattias Hellborg Arthursson
* @author Ulrik Sandberg
*/
@ContextConfiguration("/config/testContext.xml")
public class PersonDaoSampleIntegrationTest extends
AbstractJUnit4SpringContextTests {
protected Person person;
@Autowired
private PersonDao personDao;
@Before
public void preparePerson() throws Exception {
person = new Person();
person.setCountry("Sweden");
person.setCompany("company1");
person.setFullName("Some Person");
person.setLastName("Person");
person
.setDescription("Sweden, Company1, Some Person");
person.setPhone("+46 555-123456");
}
/**
* Having a single test method test create, update and delete is not exactly
* the ideal way of testing, since they depend on each other. A better way
* would be to separate the tests and load a test fixture before each
* operation, in order to guarantee the expected state every time. See the
* ldaptemplate-person sample for the correct way to do this.
*/
@Test
public void testCreateUpdateDelete() {
try {
person.setFullName("Another Person");
personDao.create(person);
personDao.findByPrimaryKey(
"Sweden", "company1",
"Another Person");
// if we got here, create succeeded
person.setDescription("Another description");
personDao.update(person);
Person result = personDao
.findByPrimaryKey(
"Sweden", "company1",
"Another Person");
assertEquals(
"Another description", result
.getDescription());
} finally {
personDao.delete(person);
try {
personDao.findByPrimaryKey(
"Sweden", "company1",
"Another Person");
fail("NameNotFoundException (when using Spring LDAP) or RuntimeException (when using traditional) expected");
} catch (NameNotFoundException expected) {
// expected
} catch (RuntimeException expected) {
// expected
}
}
}
@Test
public void testGetAllPersonNames() {
List result = personDao.getAllPersonNames();
assertEquals(2, result.size());
String first = (String) result.get(0);
assertEquals("Some Person", first);
}
@Test
public void testFindAll() {
List result = personDao.findAll();
assertEquals(2, result.size());
Person first = (Person) result.get(0);
assertEquals("Some Person", first
.getFullName());
}
@Test
public void testFindByPrimaryKey() {
Person result = personDao.findByPrimaryKey(
"Sweden", "company1", "Some Person");
assertEquals(person, result);
}
}
/*
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.samples.plain.dao;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.samples.plain.domain.Person;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
/**
* Abstract base class for PersonDao integration tests.
*
* @author Mattias Hellborg Arthursson
* @author Ulrik Sandberg
*/
@ContextConfiguration("/config/testContext.xml")
public class PersonDaoSampleIntegrationTest extends
AbstractJUnit4SpringContextTests {
protected Person person;
@Autowired
private PersonDao personDao;
@Before
public void preparePerson() throws Exception {
person = new Person();
person.setCountry("Sweden");
person.setCompany("company1");
person.setFullName("Some Person");
person.setLastName("Person");
person
.setDescription("Sweden, Company1, Some Person");
person.setPhone("+46 555-123456");
}
/**
* Having a single test method test create, update and delete is not exactly
* the ideal way of testing, since they depend on each other. A better way
* would be to separate the tests and load a test fixture before each
* operation, in order to guarantee the expected state every time. See the
* ldaptemplate-person sample for the correct way to do this.
*/
@Test
public void testCreateUpdateDelete() {
try {
person.setFullName("Another Person");
personDao.create(person);
personDao.findByPrimaryKey(
"Sweden", "company1",
"Another Person");
// if we got here, create succeeded
person.setDescription("Another description");
personDao.update(person);
Person result = personDao
.findByPrimaryKey(
"Sweden", "company1",
"Another Person");
assertThat(result.getDescription()).isEqualTo("Another description");
} finally {
personDao.delete(person);
try {
personDao.findByPrimaryKey(
"Sweden", "company1",
"Another Person");
fail("NameNotFoundException (when using Spring LDAP) or RuntimeException (when using traditional) expected");
} catch (NameNotFoundException expected) {
// expected
} catch (RuntimeException expected) {
// expected
}
}
}
@Test
public void testGetAllPersonNames() {
List result = personDao.getAllPersonNames();
assertThat(result).hasSize(2);
String first = (String) result.get(0);
assertThat(first).isEqualTo("Some Person");
}
@Test
public void testFindAll() {
List result = personDao.findAll();
assertThat(result).hasSize(2);
Person first = (Person) result.get(0);
assertThat(first.getFullName()).isEqualTo("Some Person");
}
@Test
public void testFindByPrimaryKey() {
Person result = personDao.findByPrimaryKey(
"Sweden", "company1", "Some Person");
assertThat(result).isEqualTo(person);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import static junit.framework.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
@ContextConfiguration(locations = { "/config/testContext.xml" })
public class LdapTreeBuilderIntegrationTest extends AbstractJUnit4SpringContextTests {
@@ -63,8 +63,8 @@ public class LdapTreeBuilderIntegrationTest extends AbstractJUnit4SpringContextT
public void visit(DirContextOperations node, int currentDepth) {
LdapName next = keyIterator.next();
assertEquals(next, node.getDn());
assertEquals(names.get(next).intValue(), currentDepth);
assertThat(node.getDn()).isEqualTo(next);
assertThat(currentDepth).isEqualTo(names.get(next).intValue());
}
}

View File

@@ -7,5 +7,6 @@ dependencies {
testCompile "junit:junit:$junitVersion",
"org.mockito:mockito-core:$mockitoVersion",
"gsbase:gsbase:$gsbaseVersion"
}
"gsbase:gsbase:$gsbaseVersion",
"org.assertj:assertj-core:$assertjVersion"
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,9 +29,8 @@ import javax.naming.ldap.Control;
import javax.naming.ldap.LdapContext;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -64,8 +63,8 @@ public class VirtualListViewControlDirContextProcessorTest {
new VirtualListViewResultsCookie(new byte[0], 0, 0));
VirtualListViewControl result = (VirtualListViewControl) tested
.createRequestControl();
assertNotNull(result);
assertEquals(OID_REQUEST, result.getID());
assertThat(result).isNotNull();
assertThat(result.getID()).isEqualTo(OID_REQUEST);
// verify that the values have been encoded as we expect
int expectedBeforeCount = 0;
@@ -89,8 +88,8 @@ public class VirtualListViewControlDirContextProcessorTest {
tested.setOffsetPercentage(true);
VirtualListViewControl result = (VirtualListViewControl) tested
.createRequestControl();
assertNotNull(result);
assertEquals(OID_REQUEST, result.getID());
assertThat(result).isNotNull();
assertThat(result.getID()).isEqualTo(OID_REQUEST);
int expectedBeforeCount = 2;
int expectedAfterCount = 2;
@@ -125,14 +124,12 @@ public class VirtualListViewControlDirContextProcessorTest {
}
catch (OperationNotSupportedException expected) {
Throwable cause = expected.getCause();
assertEquals(javax.naming.OperationNotSupportedException.class,
cause.getClass());
assertEquals("[LDAP: error code 53 - Unwilling To Perform]", cause
.getMessage());
assertThat(cause.getClass()).isEqualTo(javax.naming.OperationNotSupportedException.class);
assertThat(cause.getMessage()).isEqualTo("[LDAP: error code 53 - Unwilling To Perform]");
}
assertNotNull(tested.getCookie());
assertEquals(0, tested.getCookie().getCookie().length);
assertThat(tested.getCookie()).isNotNull();
assertThat(tested.getCookie().getCookie().length).isEqualTo(0);
}
@Test
@@ -180,11 +177,10 @@ public class VirtualListViewControlDirContextProcessorTest {
case 0: // byOffset
int actualOffset = ber.parseInt();
int actualContentCount = ber.parseInt();
assertEquals("beforeCount,", expectedBeforeCount, actualBeforeCount);
assertEquals("afterCount,", expectedAfterCount, actualAfterCount);
assertEquals("offset,", expectedOffset, actualOffset);
assertEquals("contentCount,", expectedContentCount,
actualContentCount);
assertThat(expectedBeforeCount).isEqualTo(actualBeforeCount);
assertThat(expectedAfterCount).isEqualTo(actualAfterCount);
assertThat(expectedOffset).isEqualTo(actualOffset);
assertThat(actualContentCount).isEqualTo(expectedContentCount);
break;
case 1: // greaterThanOrEqual
@@ -210,7 +206,7 @@ public class VirtualListViewControlDirContextProcessorTest {
if (expectedContextId != null && actualContextId == null) {
fail("expected <" + expectedContextId + ">, got <null>");
}
assertEquals(expectedContextId.length, actualContextId.length);
assertThat(actualContextId.length).isEqualTo(expectedContextId.length);
}
private void assertEncodedResponse(byte[] encodedValue,
@@ -218,18 +214,16 @@ public class VirtualListViewControlDirContextProcessorTest {
int expectedContentCount, int expectedVirtualListViewResult,
byte[] expectedContextId) throws Exception {
dumpEncodedValue("VirtualListViewResponse\n", encodedValue);
assertEquals(expectedEncodingLength, encodedValue.length);
assertThat(encodedValue.length).isEqualTo(expectedEncodingLength);
BerDecoder ber = new BerDecoder(encodedValue, 0, encodedValue.length);
ber.parseSeq(null);
int actualTargetPosition = ber.parseInt();
int actualContentCount = ber.parseInt();
int actualVirtualListViewResult = ber.parseEnumeration();
assertEquals("targetPosition,", expectedTargetPosition,
actualTargetPosition);
assertEquals("contentCount,", expectedContentCount, actualContentCount);
assertEquals("virtualListViewResult,", expectedVirtualListViewResult,
actualVirtualListViewResult);
assertThat(actualTargetPosition).isEqualTo(expectedTargetPosition);
assertThat(actualContentCount).as("contentCount,").isEqualTo(expectedContentCount);
assertThat(actualVirtualListViewResult).isEqualTo(expectedVirtualListViewResult);
byte[] bs = ber.parseOctetString(Ber.ASN_OCTET_STR, null);
assertContextId(expectedContextId, bs);
}

View File

@@ -10,7 +10,8 @@ dependencies {
testCompile "org.springframework:spring-test:$springVersion",
"junit:junit:$junitVersion",
"org.slf4j:slf4j-log4j12:$slf4jVersion"
"org.slf4j:slf4j-log4j12:$slf4jVersion",
"org.assertj:assertj-core:$assertjVersion"
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,12 +40,8 @@ import javax.naming.directory.ModificationItem;
import java.io.UnsupportedEncodingException;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
/**
* @author Mattias Hellborg Arthursson
@@ -159,36 +155,36 @@ public class IncrementalAttributeMapperITest extends AbstractJUnit4SpringContext
// The 'member' attribute consists of > 1500 entries and will not be returned without range specifier.
DirContextOperations ctx = ldapTemplate.lookupContext(testgroupDn);
assertNull(ctx.getStringAttribute("member"));
assertThat(ctx.getStringAttribute("member")).isNull();
DefaultIncrementalAttributesMapper attributeMapper = new DefaultIncrementalAttributesMapper(new String[]{"member", "cn"});
assertTrue("There should be more results to get", attributeMapper.hasMore());
assertThat(attributeMapper.hasMore()).as("There should be more results to get").isTrue();
String[] attributesArray = attributeMapper.getAttributesForLookup();
assertEquals(2, attributesArray.length);
assertEquals("member", attributesArray[0]);
assertEquals("cn", attributesArray[1]);
assertThat(attributesArray.length).isEqualTo(2);
assertThat(attributesArray[0]).isEqualTo("member");
assertThat(attributesArray[1]).isEqualTo("cn");
// First iteration - there should now be more members left, but all cn values should have been collected.
ldapTemplate.lookup(testgroupDn, attributesArray, attributeMapper);
assertTrue("There should be more results to get", attributeMapper.hasMore());
assertThat(attributeMapper.hasMore()).as("There should be more results to get").isTrue();
// Only member attribute should be requested in this query.
attributesArray = attributeMapper.getAttributesForLookup();
assertEquals(1, attributesArray.length);
assertEquals("member;Range=1500-*", attributesArray[0]);
assertThat(attributesArray.length).isEqualTo(1);
assertThat(attributesArray[0]).isEqualTo("member;Range=1500-*");
// Second iteration - all data should now have been collected.
ldapTemplate.lookup(testgroupDn, attributeMapper.getAttributesForLookup(), attributeMapper);
assertFalse("There should be no more results to get", attributeMapper.hasMore());
assertThat(attributeMapper.hasMore()).as("There should be no more results to get").isFalse();
List memberValues = attributeMapper.getValues("member");
assertNotNull(memberValues);
assertEquals(1501, memberValues.size());
assertThat(memberValues).isNotNull();
assertThat(memberValues).hasSize(1501);
List cnValues = attributeMapper.getValues("cn");
assertNotNull(cnValues);
assertEquals(1, cnValues.size());
assertThat(cnValues).isNotNull();
assertThat(cnValues).hasSize(1);
}
@Test
@@ -217,10 +213,9 @@ public class IncrementalAttributeMapperITest extends AbstractJUnit4SpringContext
}
// LDAP-234: After rollback the attribute values were cleared after rollback
assertEquals(
1501,
assertThat(
DefaultIncrementalAttributesMapper.lookupAttributeValues(
ldapTemplate, GROUP_DN, "member").size());
ldapTemplate, GROUP_DN, "member").size()).isEqualTo(1501);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
// Tests the generation of entry Java classes from LDAP schema
public final class SchemaToJavaAdITest {
@@ -192,21 +192,21 @@ public final class SchemaToJavaAdITest {
// Check some returned values
Method getDnMethod=clazz.getMethod("getDn");
Object dn=getDnMethod.invoke(fromDirectory);
assertEquals(testDn, dn);
assertThat(dn).isEqualTo(testDn);
Method getCnIteratorMethod=clazz.getMethod("getCn");
@SuppressWarnings("unchecked")
String cn=(String)getCnIteratorMethod.invoke(fromDirectory);
assertEquals("William Hartnell", cn);
assertThat(cn).isEqualTo("William Hartnell");
Method telephoneNumberIteratorMethod=clazz.getMethod("getTelephoneNumber");
@SuppressWarnings("unchecked")
String telephoneNumber=(String)telephoneNumberIteratorMethod.invoke(fromDirectory);
assertEquals("1", telephoneNumber);
assertThat(telephoneNumber).isEqualTo("1");
// Reread and check whether equals and hashCode are at least sane
Object fromDirectory2=odmManager.read(clazz, testDn);
assertEquals(fromDirectory, fromDirectory2);
assertEquals(fromDirectory.hashCode(), fromDirectory2.hashCode());
assertThat(fromDirectory2).isEqualTo(fromDirectory);
assertThat(fromDirectory2.hashCode()).isEqualTo(fromDirectory.hashCode());
}
}

Some files were not shown because too many files have changed in this diff Show More