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 13:50:19 +00:00
parent 89890376d4
commit 0138ccf8c1
9 changed files with 583 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
/*
* 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

@@ -0,0 +1,79 @@
/*
* 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

@@ -0,0 +1,71 @@
/*
* 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

@@ -0,0 +1,61 @@
/*
* 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

@@ -0,0 +1,60 @@
/*
* 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

@@ -0,0 +1,56 @@
/*
* 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

@@ -0,0 +1,50 @@
/*
* 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

@@ -0,0 +1,64 @@
/*
* 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

@@ -0,0 +1,75 @@
/*
* 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());
}
}