IN PROGRESS - issue LDAP-33: Remove package dependency cycle between ldap.core and ldap.support

http://opensource.atlassian.com/projects/spring/browse/LDAP-33
Remove package dependency cycle
This commit is contained in:
Ulrik Sandberg
2007-01-12 12:17:43 +00:00
parent f2344a8c64
commit 14113e449c
18 changed files with 55 additions and 1306 deletions

View File

@@ -1,51 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" path="target/gen-java-src"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="src" output="target/itest-classes" path="src/itest/java"/>
<classpathentry kind="src" output="target/itest-openldap-classes" path="src/itest-openldap/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/global/commons-logging.jar" sourcepath="lib/source/commons-logging-src.zip"/>
<classpathentry kind="lib" path="lib/global/spring-beans.jar" sourcepath="lib/source/spring-src.zip"/>
<classpathentry kind="lib" path="lib/global/spring-context.jar" sourcepath="lib/source/spring-src.zip"/>
<classpathentry kind="lib" path="lib/global/spring-core.jar" sourcepath="lib/source/spring-src.zip"/>
<classpathentry kind="lib" path="lib/global/spring-dao.jar" sourcepath="lib/source/spring-src.zip"/>
<classpathentry kind="lib" path="lib/test/spring-mock.jar" sourcepath="lib/source/spring-src.zip"/>
<classpathentry kind="lib" path="lib/test/gsbase.jar"/>
<classpathentry kind="lib" path="lib/global/commons-lang.jar" sourcepath="lib/source/commons-lang-src.zip"/>
<classpathentry kind="lib" path="lib/global/commons-collections.jar" sourcepath="lib/source/commons-collections-src.zip"/>
<classpathentry kind="lib" path="lib/test/junit.jar" sourcepath="lib/source/junit-src.zip"/>
<classpathentry kind="lib" path="lib/test/easymock.jar" sourcepath="lib/source/easymock-src.zip"/>
<classpathentry kind="lib" path="lib/test/clover.jar"/>
<classpathentry kind="lib" path="lib/test/ehcache.jar"/>
<classpathentry kind="lib" path="lib/test/ehcache-constructs.jar"/>
<classpathentry kind="lib" path="lib/test/jxl.jar"/>
<classpathentry kind="lib" path="lib/test/cglib-nodep.jar"/>
<classpathentry kind="lib" path="lib/buildtime/acegi-security.jar" sourcepath="lib/source/acegi-security-src.zip"/>
<classpathentry kind="lib" path="lib/test/antlr.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-core.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-core-shared.jar"/>
<classpathentry kind="lib" path="lib/test/jdbm.jar"/>
<classpathentry kind="lib" path="lib/test/shared-asn1.jar"/>
<classpathentry kind="lib" path="lib/test/shared-ldap.jar"/>
<classpathentry kind="lib" path="lib/test/slf4j-log4j12.jar"/>
<classpathentry kind="lib" path="lib/test/log4j.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-server-jndi.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-protocol-shared.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-protocol-changepw.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-protocol-kerberos.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-kerberos-shared.jar"/>
<classpathentry kind="lib" path="lib/test/mina-core.jar"/>
<classpathentry kind="lib" path="lib/test/mina-filter-ssl.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-server-main.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-protocol-ldap.jar"/>
<classpathentry kind="lib" path="lib/test/junit-addons.jar"/>
<classpathentry kind="lib" path="lib/test/DDSteps.jar"/>
<classpathentry kind="lib" path="lib/global/ldapbp.jar"/>
<classpathentry kind="lib" path="lib/test/junitperf.jar"/>
<classpathentry kind="lib" path="lib/test/backport-util-concurrent.jar"/>
<classpathentry kind="lib" path="lib/test/shared-asn1-codec.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="target/gen-java-src"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="src/itest/java"/>
<classpathentry kind="src" path="src/itest-openldap/java"/>
<classpathentry kind="src" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/global/commons-logging.jar" sourcepath="lib/source/commons-logging-src.zip"/>
<classpathentry kind="lib" path="lib/global/spring-beans.jar" sourcepath="lib/source/spring-src.zip"/>
<classpathentry kind="lib" path="lib/global/spring-context.jar" sourcepath="lib/source/spring-src.zip"/>
<classpathentry kind="lib" path="lib/global/spring-core.jar" sourcepath="lib/source/spring-src.zip"/>
<classpathentry kind="lib" path="lib/global/spring-dao.jar" sourcepath="lib/source/spring-src.zip"/>
<classpathentry kind="lib" path="lib/test/spring-mock.jar" sourcepath="lib/source/spring-src.zip"/>
<classpathentry kind="lib" path="lib/test/gsbase.jar"/>
<classpathentry kind="lib" path="lib/global/commons-lang.jar" sourcepath="lib/source/commons-lang-src.zip"/>
<classpathentry kind="lib" path="lib/global/commons-collections.jar" sourcepath="lib/source/commons-collections-src.zip"/>
<classpathentry kind="lib" path="lib/test/junit.jar" sourcepath="lib/source/junit-src.zip"/>
<classpathentry kind="lib" path="lib/test/easymock.jar" sourcepath="lib/source/easymock-src.zip"/>
<classpathentry kind="lib" path="lib/test/clover.jar"/>
<classpathentry kind="lib" path="lib/test/ehcache.jar"/>
<classpathentry kind="lib" path="lib/test/ehcache-constructs.jar"/>
<classpathentry kind="lib" path="lib/test/jxl.jar"/>
<classpathentry kind="lib" path="lib/test/cglib-nodep.jar"/>
<classpathentry kind="lib" path="lib/buildtime/acegi-security.jar" sourcepath="lib/source/acegi-security-src.zip"/>
<classpathentry kind="lib" path="lib/test/antlr.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-core.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-core-shared.jar"/>
<classpathentry kind="lib" path="lib/test/jdbm.jar"/>
<classpathentry kind="lib" path="lib/test/shared-asn1.jar"/>
<classpathentry kind="lib" path="lib/test/shared-ldap.jar"/>
<classpathentry kind="lib" path="lib/test/slf4j-log4j12.jar"/>
<classpathentry kind="lib" path="lib/test/log4j.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-server-jndi.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-protocol-shared.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-protocol-changepw.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-protocol-kerberos.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-kerberos-shared.jar"/>
<classpathentry kind="lib" path="lib/test/mina-core.jar"/>
<classpathentry kind="lib" path="lib/test/mina-filter-ssl.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-server-main.jar"/>
<classpathentry kind="lib" path="lib/test/apacheds-protocol-ldap.jar"/>
<classpathentry kind="lib" path="lib/test/junit-addons.jar"/>
<classpathentry kind="lib" path="lib/test/DDSteps.jar"/>
<classpathentry kind="lib" path="lib/global/ldapbp.jar"/>
<classpathentry kind="lib" path="lib/test/junitperf.jar"/>
<classpathentry kind="lib" path="lib/test/backport-util-concurrent.jar"/>
<classpathentry kind="lib" path="lib/test/shared-asn1-codec.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -83,10 +83,9 @@ The HTML report is ${target.testresults.html.dir}/index.html
</target>
<target name="gen.main">
<mkdir dir="${target.gen.java.dir}/org/springframework/ldap/support" />
<javacc javacchome="${javacc.home.dir}" target="${src.javacc.dir}/DnParserImpl.jj" outputdirectory="${target.gen.java.dir}/org/springframework/ldap/support" />
<property name="javacc.out.dir" location="${target.gen.java.dir}/org/springframework/ldap/core" />
<mkdir dir="${javacc.out.dir}" />
<javacc javacchome="${javacc.home.dir}" target="${src.javacc.dir}/DnParserImpl.jj" outputdirectory="${javacc.out.dir}" />
</target>
</project>

View File

@@ -1,129 +0,0 @@
/*
* Copyright 2002-2005 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.support.authentication;
import junit.framework.TestCase;
import org.acegisecurity.Authentication;
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.userdetails.User;
import org.acegisecurity.userdetails.ldap.LdapUserDetails;
import org.easymock.MockControl;
import org.springframework.ldap.support.authentication.AcegiAuthenticationSource;
public class AcegiAuthenticationSourceTest extends TestCase {
private MockControl authenticationControl;
private Authentication authenticationMock;
private MockControl ldapUserDetailsControl;
private LdapUserDetails ldapUserDetailsMock;
private AcegiAuthenticationSource tested;
protected void setUp() throws Exception {
super.setUp();
authenticationControl = MockControl.createControl(Authentication.class);
authenticationMock = (Authentication) authenticationControl.getMock();
ldapUserDetailsControl = MockControl
.createControl(LdapUserDetails.class);
ldapUserDetailsMock = (LdapUserDetails) ldapUserDetailsControl
.getMock();
tested = new AcegiAuthenticationSource();
}
protected void tearDown() throws Exception {
super.tearDown();
authenticationControl = null;
authenticationMock = null;
ldapUserDetailsControl = null;
ldapUserDetailsMock = null;
tested = null;
}
protected void replay() {
authenticationControl.replay();
ldapUserDetailsControl.replay();
}
protected void verify() {
authenticationControl.verify();
ldapUserDetailsControl.verify();
}
public void testGetPrincipalAndCredentials() {
authenticationControl.expectAndReturn(
authenticationMock.getPrincipal(), ldapUserDetailsMock);
authenticationControl.expectAndReturn(authenticationMock
.getCredentials(), "secret");
ldapUserDetailsControl.expectAndDefaultReturn(ldapUserDetailsMock
.getDn(), "cn=Manager");
SecurityContextHolder.getContext()
.setAuthentication(authenticationMock);
replay();
String principal = tested.getPrincipal();
String credentials = tested.getCredentials();
verify();
assertEquals("secret", credentials);
assertEquals("cn=Manager", principal);
}
public void testGetPrincipalAndCredentials_nullAuthentication() {
SecurityContextHolder.getContext().setAuthentication(null);
replay();
assertEquals("", tested.getPrincipal());
assertEquals("", tested.getCredentials());
verify();
}
public void testGetPrincipal_InvalidPrincipal() {
authenticationControl.expectAndReturn(
authenticationMock.getPrincipal(), new User("dummy", "dummy",
true, true, true, true, new GrantedAuthority[0]));
SecurityContextHolder.getContext()
.setAuthentication(authenticationMock);
replay();
try {
tested.getPrincipal();
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
verify();
}
}

View File

@@ -1,119 +0,0 @@
package org.springframework.ldap.support.authentication;
import org.easymock.MockControl;
import org.springframework.ldap.core.AuthenticationSource;
import org.springframework.ldap.support.authentication.DefaultValuesAuthenticationSourceDecorator;
import junit.framework.TestCase;
public class DefaultValuesAuthenticationSourceDecoratorTest extends TestCase {
private static final String DEFAULT_PASSWORD = "defaultPassword";
private static final String DEFAULT_USER = "cn=defaultUser";
private DefaultValuesAuthenticationSourceDecorator tested;
private MockControl authenticationSourceControl;
private AuthenticationSource authenticationSourceMock;
protected void setUp() throws Exception {
super.setUp();
authenticationSourceControl = MockControl
.createControl(AuthenticationSource.class);
authenticationSourceMock = (AuthenticationSource) authenticationSourceControl
.getMock();
tested = new DefaultValuesAuthenticationSourceDecorator();
tested.setDefaultUser(DEFAULT_USER);
tested.setDefaultPassword(DEFAULT_PASSWORD);
tested.setTarget(authenticationSourceMock);
}
protected void tearDown() throws Exception {
super.tearDown();
tested = null;
authenticationSourceControl = null;
authenticationSourceMock = null;
}
public void testGetPrincipal_TargetHasPrincipal() {
authenticationSourceControl.expectAndDefaultReturn(
authenticationSourceMock.getPrincipal(), "cn=someUser");
authenticationSourceControl.replay();
String principal = tested.getPrincipal();
authenticationSourceControl.verify();
assertEquals("cn=someUser", principal);
}
public void testGetPrincipal_TargetHasNoPrincipal() {
authenticationSourceControl.expectAndDefaultReturn(
authenticationSourceMock.getPrincipal(), "");
authenticationSourceControl.replay();
String principal = tested.getPrincipal();
authenticationSourceControl.verify();
assertEquals(DEFAULT_USER, principal);
}
public void testGetCredentials_TargetHasPrincipal() {
authenticationSourceControl.expectAndDefaultReturn(
authenticationSourceMock.getPrincipal(), "cn=someUser");
authenticationSourceControl.expectAndDefaultReturn(
authenticationSourceMock.getCredentials(), "somepassword");
authenticationSourceControl.replay();
String credentials = tested.getCredentials();
authenticationSourceControl.verify();
assertEquals("somepassword", credentials);
}
public void testGetCredentials_TargetHasNoPrincipal() {
authenticationSourceControl.expectAndDefaultReturn(
authenticationSourceMock.getPrincipal(), "");
authenticationSourceControl.expectAndDefaultReturn(
authenticationSourceMock.getCredentials(), "somepassword");
authenticationSourceControl.replay();
String credentials = tested.getCredentials();
authenticationSourceControl.verify();
assertEquals(DEFAULT_PASSWORD, credentials);
}
public void testAfterPropertiesSet_noTarget() throws Exception {
tested.setTarget(null);
try {
tested.afterPropertiesSet();
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
public void testAfterPropertiesSet_noDefaultUser() throws Exception {
tested.setDefaultUser(null);
try {
tested.afterPropertiesSet();
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
public void testAfterPropertiesSet_noDefaultPassword() throws Exception {
tested.setDefaultPassword(null);
try {
tested.afterPropertiesSet();
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
}

View File

@@ -1,144 +0,0 @@
/*
* Copyright 2002-2005 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.support.control;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.ldap.Control;
import javax.naming.ldap.LdapContext;
import junit.framework.TestCase;
import org.easymock.MockControl;
public class AbstractRequestControlDirContextProcessorTest extends TestCase {
private AbstractRequestControlDirContextProcessor tested;
private MockControl requestControlControl;
private Control requestControlMock;
private MockControl requestControl2Control;
private Control requestControl2Mock;
private MockControl ldapContextControl;
private LdapContext ldapContextMock;
private MockControl dirContextControl;
private DirContext dirContextMock;
protected void setUp() throws Exception {
super.setUp();
// Create requestControl mock
requestControlControl = MockControl.createControl(Control.class);
requestControlMock = (Control) requestControlControl.getMock();
// Create requestControl2 mock
requestControl2Control = MockControl.createControl(Control.class);
requestControl2Mock = (Control) requestControl2Control.getMock();
// Create ldapContext mock
ldapContextControl = MockControl.createControl(LdapContext.class);
ldapContextMock = (LdapContext) ldapContextControl.getMock();
// Create dirContext mock
dirContextControl = MockControl.createControl(DirContext.class);
dirContextMock = (DirContext) dirContextControl.getMock();
tested = new AbstractRequestControlDirContextProcessor() {
public Control createRequestControl() {
return requestControlMock;
}
public void postProcess(DirContext ctx) throws NamingException {
}
};
}
protected void tearDown() throws Exception {
super.tearDown();
requestControlControl = null;
requestControlMock = null;
requestControl2Control = null;
requestControl2Mock = null;
ldapContextControl = null;
ldapContextMock = null;
dirContextControl = null;
dirContextMock = null;
}
protected void replay() {
requestControlControl.replay();
requestControl2Control.replay();
ldapContextControl.replay();
dirContextControl.replay();
}
protected void verify() {
requestControlControl.verify();
requestControl2Control.verify();
ldapContextControl.verify();
dirContextControl.verify();
}
public void testPreProcess() throws NamingException {
ldapContextControl.setDefaultMatcher(MockControl.ARRAY_MATCHER);
ldapContextControl.expectAndDefaultReturn(ldapContextMock
.getRequestControls(), new Control[] { requestControl2Mock });
ldapContextMock.setRequestControls(new Control[] { requestControl2Mock,
requestControlMock });
replay();
tested.preProcess(ldapContextMock);
verify();
}
public void testPreProcess_NoExistingControls() throws NamingException {
ldapContextControl.setDefaultMatcher(MockControl.ARRAY_MATCHER);
ldapContextControl.expectAndDefaultReturn(ldapContextMock
.getRequestControls(), new Control[0]);
ldapContextMock
.setRequestControls(new Control[] { requestControlMock });
replay();
tested.preProcess(ldapContextMock);
verify();
}
public void testPreProcess_NotLdapContext() throws Exception {
try {
tested.preProcess(dirContextMock);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2002-2005 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.support.control;
import java.util.LinkedList;
import java.util.List;
import com.gargoylesoftware.base.testing.EqualsTester;
import junit.framework.TestCase;
public class PagedResultTest extends TestCase {
public void testEquals() throws Exception {
List expectedList = new LinkedList();
expectedList.add("dummy");
List otherList = new LinkedList();
otherList.add("different");
PagedResult originalObject = new PagedResult(expectedList,
new PagedResultsCookie(null));
PagedResult identicalObject = new PagedResult(expectedList,
new PagedResultsCookie(null));
PagedResult differentObject = new PagedResult(otherList,
new PagedResultsCookie(null));
PagedResult subclassObject = new PagedResult(expectedList,
new PagedResultsCookie(null)) {
};
new EqualsTester(originalObject, identicalObject, differentObject,
subclassObject);
}
}

View File

@@ -1,41 +0,0 @@
/*
* Copyright 2002-2005 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.support.control;
import com.gargoylesoftware.base.testing.EqualsTester;
import junit.framework.TestCase;
public class PagedResultsCookieTest extends TestCase {
public void testEquals() {
byte[] expectedCookie = new byte[] { 1, 2 };
byte[] differentCookie = new byte[] { 2, 3 };
PagedResultsCookie originalObject = new PagedResultsCookie(
expectedCookie);
PagedResultsCookie identicalObject = new PagedResultsCookie(
expectedCookie);
PagedResultsCookie differentObject = new PagedResultsCookie(
differentCookie);
PagedResultsCookie subclassObject = new PagedResultsCookie(
expectedCookie) {
};
new EqualsTester(originalObject, identicalObject, differentObject,
subclassObject);
}
}

View File

@@ -1,188 +0,0 @@
/*
* Copyright 2002-2005 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.support.control;
import java.io.IOException;
import javax.naming.ldap.Control;
import javax.naming.ldap.LdapContext;
import junit.framework.TestCase;
import org.easymock.MockControl;
import com.sun.jndi.ldap.Ber;
import com.sun.jndi.ldap.BerDecoder;
import com.sun.jndi.ldap.BerEncoder;
import com.sun.jndi.ldap.ctl.DirSyncResponseControl;
import com.sun.jndi.ldap.ctl.PagedResultsControl;
import com.sun.jndi.ldap.ctl.PagedResultsResponseControl;
public class PagedResultsRequestControlTest extends TestCase {
private MockControl ldapContextControl;
private LdapContext ldapContextMock;
protected void setUp() throws Exception {
super.setUp();
// Create ldapContext mock
ldapContextControl = MockControl.createControl(LdapContext.class);
ldapContextMock = (LdapContext) ldapContextControl.getMock();
}
protected void tearDown() throws Exception {
super.tearDown();
ldapContextControl = null;
ldapContextMock = null;
}
protected void replay() {
ldapContextControl.replay();
}
protected void verify() {
ldapContextControl.verify();
}
public void testCreateRequestControl() throws Exception {
PagedResultsRequestControl tested = new PagedResultsRequestControl(20);
PagedResultsControl control = (PagedResultsControl) tested
.createRequestControl();
assertNotNull(control);
}
public void testCreateRequestControl_CookieSet() throws Exception {
PagedResultsCookie cookie = new PagedResultsCookie(new byte[0]);
PagedResultsRequestControl tested = new PagedResultsRequestControl(20,
cookie);
PagedResultsControl control = (PagedResultsControl) tested
.createRequestControl();
assertNotNull(control);
}
public void testPostProcess() throws Exception {
int resultSize = 50;
byte pageSize = 8;
byte[] value = new byte[1];
value[0] = pageSize;
byte[] cookie = encodeValue(resultSize, value);
PagedResultsResponseControl control = new PagedResultsResponseControl(
"dummy", true, cookie);
ldapContextControl.expectAndDefaultReturn(ldapContextMock
.getResponseControls(), new Control[] { control });
PagedResultsRequestControl tested = new PagedResultsRequestControl(20);
replay();
tested.postProcess(ldapContextMock);
verify();
PagedResultsCookie returnedCookie = tested.getCookie();
assertEquals(8, returnedCookie.getCookie()[0]);
assertEquals(20, tested.getPageSize());
assertEquals(50, tested.getResultSize());
}
public void testPostProcess_InvalidResponseControl() throws Exception {
int resultSize = 50;
byte pageSize = 8;
byte[] value = new byte[1];
value[0] = pageSize;
byte[] cookie = encodeDirSyncValue(resultSize, value);
// Using another response control to verify that it is ignored
DirSyncResponseControl control = new DirSyncResponseControl(
"dummy", true, cookie);
ldapContextControl.expectAndDefaultReturn(ldapContextMock
.getResponseControls(), new Control[] { control });
PagedResultsRequestControl tested = new PagedResultsRequestControl(20);
replay();
tested.postProcess(ldapContextMock);
verify();
assertNull(tested.getCookie());
assertEquals(20, tested.getPageSize());
assertEquals(0, tested.getResultSize());
}
public void testBerDecoding() throws Exception {
byte[] value = new byte[1];
value[0] = 8;
int pageSize = 20;
byte[] cookie = encodeValue(pageSize, value);
BerDecoder ber = new BerDecoder(cookie, 0, cookie.length);
ber.parseSeq(null);
int actualPageSize = ber.parseInt();
byte[] actualValue = ber.parseOctetString(Ber.ASN_OCTET_STR, null);
assertEquals("pageSize,", 20, actualPageSize);
assertEquals("value length", value.length, actualValue.length);
for (int i = 0; i < value.length; i++) {
assertEquals("value (index " + i + "),", value[i], actualValue[i]);
}
}
private byte[] encodeValue(int pageSize, byte[] cookie)
throws IOException {
// build the ASN.1 encoding
BerEncoder ber = new BerEncoder(10 + cookie.length);
ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
ber.encodeInt(pageSize);
ber.encodeOctetString(cookie, Ber.ASN_OCTET_STR);
ber.endSeq();
return ber.getTrimmedBuf();
}
/**
* Encode a value suitable for the DirSyncResponseControl used in a test.
*/
private byte[] encodeDirSyncValue(int pageSize, byte[] cookie)
throws IOException {
// build the ASN.1 encoding
BerEncoder ber = new BerEncoder(10 + cookie.length);
ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
ber.encodeInt(1); // flag
ber.encodeInt(pageSize); // maxReturnLength
ber.encodeOctetString(cookie, Ber.ASN_OCTET_STR);
ber.endSeq();
return ber.getTrimmedBuf();
}
}

View File

@@ -1,67 +0,0 @@
/*
* Copyright 2002-2005 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.support.filter;
import org.springframework.ldap.support.filter.AbstractFilter;
import junit.framework.TestCase;
/**
* @author Adam Skogman
*/
public class AbstractFilterTest extends TestCase {
/**
* Constructor for AbstractFilterTest.
*
* @param name
*/
public AbstractFilterTest(String name) {
super(name);
}
/*
* Test for String encode()
*/
public void testEncode() {
AbstractFilter af = new AbstractFilter() {
public StringBuffer encode(StringBuffer buff) {
return buff.append("foo");
}
};
assertEquals("foo", af.encode());
}
/*
* Test for toString()
*/
public void testToString() {
AbstractFilter af = new AbstractFilter() {
public StringBuffer encode(StringBuffer buff) {
return buff.append("foo");
}
};
assertEquals("foo", af.toString());
}
}

View File

@@ -1,79 +0,0 @@
/*
* Copyright 2002-2005 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.support.filter;
import org.springframework.ldap.support.filter.AndFilter;
import org.springframework.ldap.support.filter.EqualsFilter;
import com.gargoylesoftware.base.testing.EqualsTester;
import junit.framework.TestCase;
/**
* @author Adam Skogman
*/
public class AndFilterTest extends TestCase {
/**
* Constructor for AndFilterTest.
*
* @param name
*/
public AndFilterTest(String name) {
super(name);
}
public void testZero() {
AndFilter aq = new AndFilter();
assertEquals("", aq.encode());
}
public void testOne() {
AndFilter aq = new AndFilter().and(new EqualsFilter("a", "b"));
assertEquals("(a=b)", aq.encode());
}
public void testTwo() {
AndFilter aq = new AndFilter().and(new EqualsFilter("a", "b")).and(
new EqualsFilter("c", "d"));
assertEquals("(&(a=b)(c=d))", aq.encode());
}
public void testThree() {
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());
}
public void testEquals() {
AndFilter originalObject = new AndFilter().and(new EqualsFilter("a",
"b"));
AndFilter identicalObject = new AndFilter().and(new EqualsFilter("a",
"b"));
AndFilter differentObject = new AndFilter().and(new EqualsFilter("b",
"b"));
AndFilter subclassObject = new AndFilter() {
}.and(new EqualsFilter("a", "b"));
new EqualsTester(originalObject, identicalObject, differentObject,
subclassObject);
}
}

View File

@@ -1,71 +0,0 @@
/*
* Copyright 2002-2005 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.support.filter;
import org.springframework.ldap.support.filter.EqualsFilter;
import com.gargoylesoftware.base.testing.EqualsTester;
import junit.framework.TestCase;
/**
* @author Adam Skogman
*/
public class EqualsFilterTest extends TestCase {
/**
* Constructor for EqualsQueryTest.
*
* @param name
*/
public EqualsFilterTest(String name) {
super(name);
}
public void testEncode() {
EqualsFilter eqq = new EqualsFilter("foo", "*bar(fie)");
StringBuffer buff = new StringBuffer();
eqq.encode(buff);
assertEquals("(foo=\\2abar\\28fie\\29)", buff.toString());
}
public void testEncodeInt() {
EqualsFilter eqq = new EqualsFilter("foo", 456);
StringBuffer buff = new StringBuffer();
eqq.encode(buff);
assertEquals("(foo=456)", buff.toString());
}
public void testEquals() {
EqualsFilter originalObject = new EqualsFilter("a", "b");
EqualsFilter identicalObject = new EqualsFilter("a", "b");
EqualsFilter differentObject = new EqualsFilter("b", "b");
EqualsFilter subclassObject = new EqualsFilter("a", "b") {
};
new EqualsTester(originalObject, identicalObject, differentObject,
subclassObject);
}
}

View File

@@ -1,61 +0,0 @@
/*
* Copyright 2002-2005 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.support.filter;
import org.springframework.ldap.support.filter.GreaterThanOrEqualsFilter;
import junit.framework.TestCase;
/**
* @author Mattias Arthursson
*/
public class GreaterThanOrEqualsFilterTest extends TestCase {
/**
* Constructor for EqualsQueryTest.
*
* @param name
*/
public GreaterThanOrEqualsFilterTest(String name) {
super(name);
}
public void testEncode() {
GreaterThanOrEqualsFilter eqq = new GreaterThanOrEqualsFilter("foo",
"*bar(fie)");
StringBuffer buff = new StringBuffer();
eqq.encode(buff);
assertEquals("(foo>=\\2abar\\28fie\\29)", buff.toString());
}
public void testEncodeInt() {
GreaterThanOrEqualsFilter eqq = new GreaterThanOrEqualsFilter("foo",
456);
StringBuffer buff = new StringBuffer();
eqq.encode(buff);
assertEquals("(foo>=456)", buff.toString());
}
}

View File

@@ -1,60 +0,0 @@
/*
* Copyright 2002-2005 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.support.filter;
import org.springframework.ldap.support.filter.LessThanOrEqualsFilter;
import junit.framework.TestCase;
/**
* @author Mattias Arthursson
*/
public class LessThanOrEqualsFilterTest extends TestCase {
/**
* Constructor for EqualsQueryTest.
*
* @param name
*/
public LessThanOrEqualsFilterTest(String name) {
super(name);
}
public void testEncode() {
LessThanOrEqualsFilter eqq = new LessThanOrEqualsFilter("foo",
"*bar(fie)");
StringBuffer buff = new StringBuffer();
eqq.encode(buff);
assertEquals("(foo<=\\2abar\\28fie\\29)", buff.toString());
}
public void testEncodeInt() {
LessThanOrEqualsFilter eqq = new LessThanOrEqualsFilter("foo", 456);
StringBuffer buff = new StringBuffer();
eqq.encode(buff);
assertEquals("(foo<=456)", buff.toString());
}
}

View File

@@ -1,56 +0,0 @@
/*
* Copyright 2002-2005 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.support.filter;
import org.springframework.ldap.support.filter.LikeFilter;
import junit.framework.TestCase;
/**
* @author Anders Henja
*/
public class LikeFilterTest extends TestCase {
/**
* Constructor for LikeFilterTest.
*
* @param name
*/
public LikeFilterTest(String name) {
super(name);
}
final public void testEncodeValue_blank() {
assertEquals("", new LikeFilter("", null).getEncodedValue());
assertEquals(" ", new LikeFilter("", " ").getEncodedValue());
}
final 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*")
.getEncodedValue());
assertEquals("**foo**bar**", new LikeFilter("", "**foo**bar**")
.getEncodedValue());
}
final public void testEncodeValue_escape() {
assertEquals("*\\28*\\29*", new LikeFilter("", "*(*)*")
.getEncodedValue());
assertEquals("*\\5c2a*", new LikeFilter("", "*\\2a*").getEncodedValue());
}
}

View File

@@ -1,50 +0,0 @@
/*
* Copyright 2002-2005 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.support.filter;
import org.springframework.ldap.support.filter.EqualsFilter;
import org.springframework.ldap.support.filter.NotFilter;
import com.gargoylesoftware.base.testing.EqualsTester;
import junit.framework.TestCase;
/**
* @author Mattias Arthursson
*/
public class NotFilterTest extends TestCase {
public void testConstructor() {
EqualsFilter filter = new EqualsFilter("a", "b");
NotFilter notFilter = new NotFilter(filter);
assertEquals("(!(a=b))", notFilter.encode());
}
public void testEquals() {
EqualsFilter filter = new EqualsFilter("a", "b");
NotFilter originalObject = new NotFilter(filter);
NotFilter identicalObject = new NotFilter(filter);
NotFilter differentObject = new NotFilter(new EqualsFilter("a", "a"));
NotFilter subclassObject = new NotFilter(filter) {
};
new EqualsTester(originalObject, identicalObject, differentObject,
subclassObject);
}
}

View File

@@ -1,64 +0,0 @@
/*
* Copyright 2002-2005 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.support.filter;
import org.springframework.ldap.support.filter.EqualsFilter;
import org.springframework.ldap.support.filter.OrFilter;
import junit.framework.TestCase;
/**
* @author Adam Skogman
*/
public class OrFilterTest extends TestCase {
/**
* Constructor for OrFilterTest.
*
* @param name
*/
public OrFilterTest(String name) {
super(name);
}
public void testZero() {
OrFilter of = new OrFilter();
assertEquals("", of.encode());
}
public void testOne() {
OrFilter of = new OrFilter().or(new EqualsFilter("a", "b"));
assertEquals("(a=b)", of.encode());
}
public void testTwo() {
OrFilter of = new OrFilter().or(new EqualsFilter("a", "b")).or(
new EqualsFilter("c", "d"));
assertEquals("(|(a=b)(c=d))", of.encode());
}
public void testThree() {
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());
}
}

View File

@@ -1,75 +0,0 @@
/*
* Copyright 2002-2005 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.support.filter;
import org.springframework.ldap.support.filter.WhitespaceWildcardsFilter;
import junit.framework.TestCase;
/**
* @author Adam Skogman
*/
public class WhitespaceWildcardsFilterTest extends TestCase {
/**
* Constructor for WhitespaceWildcardsFilterTest.
*
* @param name
*/
public WhitespaceWildcardsFilterTest(String name) {
super(name);
}
final public void testEncodeValue_blank() {
// blank
assertEquals("*", new WhitespaceWildcardsFilter("", null)
.getEncodedValue());
assertEquals("*", new WhitespaceWildcardsFilter("", " ")
.getEncodedValue());
assertEquals("*", new WhitespaceWildcardsFilter("", " ")
.getEncodedValue());
assertEquals("*", new WhitespaceWildcardsFilter("", "\t")
.getEncodedValue());
}
final public void testEncodeValue_normal() {
assertEquals("*foo*", new WhitespaceWildcardsFilter("", "foo")
.getEncodedValue());
assertEquals("*foo*bar*", new WhitespaceWildcardsFilter("", "foo bar")
.getEncodedValue());
assertEquals("*foo*bar*",
new WhitespaceWildcardsFilter("", " foo bar ")
.getEncodedValue());
assertEquals("*foo*bar*", new WhitespaceWildcardsFilter("",
" \t foo \n bar \r ").getEncodedValue());
}
final public void testEncodeValue_escape() {
assertEquals("*\\28\\2a\\29*", new WhitespaceWildcardsFilter("", "(*)")
.getEncodedValue());
assertEquals("*\\2a*", new WhitespaceWildcardsFilter("", "*")
.getEncodedValue());
assertEquals("*\\5c*", new WhitespaceWildcardsFilter("", " \\ ")
.getEncodedValue());
}
}

View File

@@ -18,7 +18,7 @@ package org.springframework.ldap.util;
import java.util.Arrays;
import java.util.List;
import org.springframework.ldap.util.ListComparator;
import org.springframework.ldap.support.ListComparator;
import junit.framework.TestCase;