From 0138ccf8c142a684a009a109d9ca9381c930d651 Mon Sep 17 00:00:00 2001 From: Ulrik Sandberg Date: Fri, 12 Jan 2007 13:50:19 +0000 Subject: [PATCH] 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 --- .../ldap/filter/AbstractFilterTest.java | 67 ++++++++++++++++ .../ldap/filter/AndFilterTest.java | 79 +++++++++++++++++++ .../ldap/filter/EqualsFilterTest.java | 71 +++++++++++++++++ .../filter/GreaterThanOrEqualsFilterTest.java | 61 ++++++++++++++ .../filter/LessThanOrEqualsFilterTest.java | 60 ++++++++++++++ .../ldap/filter/LikeFilterTest.java | 56 +++++++++++++ .../ldap/filter/NotFilterTest.java | 50 ++++++++++++ .../ldap/filter/OrFilterTest.java | 64 +++++++++++++++ .../filter/WhitespaceWildcardsFilterTest.java | 75 ++++++++++++++++++ 9 files changed, 583 insertions(+) create mode 100644 spring-ldap/src/test/java/org/springframework/ldap/filter/AbstractFilterTest.java create mode 100644 spring-ldap/src/test/java/org/springframework/ldap/filter/AndFilterTest.java create mode 100644 spring-ldap/src/test/java/org/springframework/ldap/filter/EqualsFilterTest.java create mode 100644 spring-ldap/src/test/java/org/springframework/ldap/filter/GreaterThanOrEqualsFilterTest.java create mode 100644 spring-ldap/src/test/java/org/springframework/ldap/filter/LessThanOrEqualsFilterTest.java create mode 100644 spring-ldap/src/test/java/org/springframework/ldap/filter/LikeFilterTest.java create mode 100644 spring-ldap/src/test/java/org/springframework/ldap/filter/NotFilterTest.java create mode 100644 spring-ldap/src/test/java/org/springframework/ldap/filter/OrFilterTest.java create mode 100644 spring-ldap/src/test/java/org/springframework/ldap/filter/WhitespaceWildcardsFilterTest.java diff --git a/spring-ldap/src/test/java/org/springframework/ldap/filter/AbstractFilterTest.java b/spring-ldap/src/test/java/org/springframework/ldap/filter/AbstractFilterTest.java new file mode 100644 index 00000000..7fad9e46 --- /dev/null +++ b/spring-ldap/src/test/java/org/springframework/ldap/filter/AbstractFilterTest.java @@ -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()); + + } + +} diff --git a/spring-ldap/src/test/java/org/springframework/ldap/filter/AndFilterTest.java b/spring-ldap/src/test/java/org/springframework/ldap/filter/AndFilterTest.java new file mode 100644 index 00000000..c1feccbc --- /dev/null +++ b/spring-ldap/src/test/java/org/springframework/ldap/filter/AndFilterTest.java @@ -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); + } +} diff --git a/spring-ldap/src/test/java/org/springframework/ldap/filter/EqualsFilterTest.java b/spring-ldap/src/test/java/org/springframework/ldap/filter/EqualsFilterTest.java new file mode 100644 index 00000000..58122f1e --- /dev/null +++ b/spring-ldap/src/test/java/org/springframework/ldap/filter/EqualsFilterTest.java @@ -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); + } +} diff --git a/spring-ldap/src/test/java/org/springframework/ldap/filter/GreaterThanOrEqualsFilterTest.java b/spring-ldap/src/test/java/org/springframework/ldap/filter/GreaterThanOrEqualsFilterTest.java new file mode 100644 index 00000000..6a483973 --- /dev/null +++ b/spring-ldap/src/test/java/org/springframework/ldap/filter/GreaterThanOrEqualsFilterTest.java @@ -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()); + + } + +} diff --git a/spring-ldap/src/test/java/org/springframework/ldap/filter/LessThanOrEqualsFilterTest.java b/spring-ldap/src/test/java/org/springframework/ldap/filter/LessThanOrEqualsFilterTest.java new file mode 100644 index 00000000..3a152f45 --- /dev/null +++ b/spring-ldap/src/test/java/org/springframework/ldap/filter/LessThanOrEqualsFilterTest.java @@ -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()); + + } + +} diff --git a/spring-ldap/src/test/java/org/springframework/ldap/filter/LikeFilterTest.java b/spring-ldap/src/test/java/org/springframework/ldap/filter/LikeFilterTest.java new file mode 100644 index 00000000..af3d9d1d --- /dev/null +++ b/spring-ldap/src/test/java/org/springframework/ldap/filter/LikeFilterTest.java @@ -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()); + } + +} diff --git a/spring-ldap/src/test/java/org/springframework/ldap/filter/NotFilterTest.java b/spring-ldap/src/test/java/org/springframework/ldap/filter/NotFilterTest.java new file mode 100644 index 00000000..58788e7c --- /dev/null +++ b/spring-ldap/src/test/java/org/springframework/ldap/filter/NotFilterTest.java @@ -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); + } + +} diff --git a/spring-ldap/src/test/java/org/springframework/ldap/filter/OrFilterTest.java b/spring-ldap/src/test/java/org/springframework/ldap/filter/OrFilterTest.java new file mode 100644 index 00000000..f5f5360d --- /dev/null +++ b/spring-ldap/src/test/java/org/springframework/ldap/filter/OrFilterTest.java @@ -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()); + } + +} diff --git a/spring-ldap/src/test/java/org/springframework/ldap/filter/WhitespaceWildcardsFilterTest.java b/spring-ldap/src/test/java/org/springframework/ldap/filter/WhitespaceWildcardsFilterTest.java new file mode 100644 index 00000000..d781c281 --- /dev/null +++ b/spring-ldap/src/test/java/org/springframework/ldap/filter/WhitespaceWildcardsFilterTest.java @@ -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()); + + } + +}