diff --git a/core/build.gradle b/core/build.gradle index 6c1c1480..6cd2839d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -14,8 +14,7 @@ dependencies { "org.springframework:spring-tx:$springVersion", "org.slf4j:slf4j-api:$slf4jVersion" - optional "org.springframework.data:spring-data-commons:$springDataVersion", - "org.springframework:spring-context:$springVersion", + optional "org.springframework:spring-context:$springVersion", "org.springframework:spring-jdbc:$springVersion", "org.springframework:spring-orm:$springVersion", "com.querydsl:querydsl-core:$queryDslVersion", diff --git a/core/src/main/java/org/springframework/ldap/config/LdapNamespaceHandler.java b/core/src/main/java/org/springframework/ldap/config/LdapNamespaceHandler.java index 3ad1addf..e77118ae 100644 --- a/core/src/main/java/org/springframework/ldap/config/LdapNamespaceHandler.java +++ b/core/src/main/java/org/springframework/ldap/config/LdapNamespaceHandler.java @@ -17,28 +17,16 @@ package org.springframework.ldap.config; import org.springframework.beans.factory.xml.NamespaceHandlerSupport; -import org.springframework.data.repository.config.RepositoryBeanDefinitionParser; -import org.springframework.ldap.repository.config.LdapRepositoryConfigurationExtension; -import org.springframework.util.ClassUtils; /** * @author Mattias Hellborg Arthursson * @author Rob Winch */ public class LdapNamespaceHandler extends NamespaceHandlerSupport { - static final String REPOSITORY_CLASS_NAME = "org.springframework.data.repository.config.RepositoryConfigurationExtension"; - @Override public void init() { - LdapRepositoryConfigurationExtension extension = new LdapRepositoryConfigurationExtension(); - registerBeanDefinitionParser(Elements.CONTEXT_SOURCE, new ContextSourceParser()); registerBeanDefinitionParser(Elements.LDAP_TEMPLATE, new LdapTemplateParser()); registerBeanDefinitionParser(Elements.TRANSACTION_MANAGER, new TransactionManagerParser()); - - if (ClassUtils.isPresent(REPOSITORY_CLASS_NAME, getClass().getClassLoader())) { - RepositoryBeanDefinitionParser repositoryParser = new RepositoryBeanDefinitionParser(extension); - registerBeanDefinitionParser(Elements.REPOSITORIES, repositoryParser); - } } } diff --git a/core/src/main/java/org/springframework/ldap/repository/LdapRepository.java b/core/src/main/java/org/springframework/ldap/repository/LdapRepository.java deleted file mode 100644 index d01c5b5f..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/LdapRepository.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.repository; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.ldap.query.LdapQuery; - -import javax.naming.Name; - -/** - * Ldap specific extensions to CrudRepository. - * - * @author Mattias Hellborg Arthursson - * @since 2.0 - */ -public interface LdapRepository extends CrudRepository { - /** - * Find one entry matching the specified query. - * - * @param ldapQuery the query specification. - * @return the found entry or null if no matching entry was found. - * @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one entry matches the query. - */ - T findOne(LdapQuery ldapQuery); - - /** - * Find all entries matching the specified query. - * - * @param ldapQuery the query specification. - * @return the entries matching the query. - */ - Iterable findAll(LdapQuery ldapQuery); -} diff --git a/core/src/main/java/org/springframework/ldap/repository/Query.java b/core/src/main/java/org/springframework/ldap/repository/Query.java deleted file mode 100644 index 342556cf..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/Query.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.repository; - -import org.springframework.ldap.query.SearchScope; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for use in {@link org.springframework.ldap.repository.LdapRepository} declarations - * to create automatic query methods based on statically defined queries. - * - * @author Mattias Hellborg Arthursson - * @since 2.0 - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface Query { - /** - * Search base, to be used as input to {@link org.springframework.ldap.query.LdapQueryBuilder#base(javax.naming.Name)}. - * - * @return the search base, default is {@link org.springframework.ldap.support.LdapUtils#emptyLdapName()} - */ - String base() default ""; - /** - * The filter format string, to be used as input to {@link org.springframework.ldap.query.LdapQueryBuilder#filter(String, Object...)}. - * - * @return search filter, must be specified. - */ - String value() default ""; - /** - * Search scope, to be used as input to {@link org.springframework.ldap.query.LdapQueryBuilder#searchScope(org.springframework.ldap.query.SearchScope)}. - * - * @return the search scope. - */ - SearchScope searchScope() default SearchScope.SUBTREE; - /** - * Time limit, to be used as input to {@link org.springframework.ldap.query.LdapQueryBuilder#timeLimit(int)}. - * - * @return the time limit. - */ - int timeLimit() default 0; - /** - * Count limit, to be used as input to {@link org.springframework.ldap.query.LdapQueryBuilder#countLimit(int)}. - * - * @return the count limit. - */ - int countLimit() default 0; -} diff --git a/core/src/main/java/org/springframework/ldap/repository/config/EnableLdapRepositories.java b/core/src/main/java/org/springframework/ldap/repository/config/EnableLdapRepositories.java deleted file mode 100644 index 51599cbc..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/config/EnableLdapRepositories.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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.repository.config; - -import org.springframework.context.annotation.ComponentScan.Filter; -import org.springframework.context.annotation.Import; -import org.springframework.data.repository.query.QueryLookupStrategy.Key; -import org.springframework.ldap.repository.support.LdapRepositoryFactoryBean; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation to activate Ldap repositories. If no base package is configured through either {@link #value()}, - * {@link #basePackages()} or {@link #basePackageClasses()} it will trigger scanning of the package of annotated class. - * - * @author Mattias Hellborg Arthursson - * @since 2.0 - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Inherited -@Import(LdapRepositoriesRegistrar.class) -public @interface EnableLdapRepositories { - - /** - * Alias for the {@link #basePackages()} attribute. Allows for more concise annotation declarations e.g.: - * {@code @EnableLdapRepositories("org.my.pkg")} instead of {@code @EnableLdapRepositories(basePackages="org.my.pkg")}. - */ - String[] value() default {}; - - /** - * Base packages to scan for annotated components. {@link #value()} is an alias for (and mutually exclusive with) this - * attribute. Use {@link #basePackageClasses()} for a type-safe alternative to String-based package names. - */ - String[] basePackages() default {}; - - /** - * Type-safe alternative to {@link #basePackages()} for specifying the packages to scan for annotated components. The - * package of each class specified will be scanned. Consider creating a special no-op marker class or interface in - * each package that serves no purpose other than being referenced by this attribute. - */ - Class[] basePackageClasses() default {}; - - /** - * Specifies which types are eligible for component scanning. Further narrows the set of candidate components from - * everything in {@link #basePackages()} to everything in the base packages that matches the given filter or filters. - */ - Filter[] includeFilters() default {}; - - /** - * Specifies which types are not eligible for component scanning. - */ - Filter[] excludeFilters() default {}; - - /** - * Returns the postfix to be used when looking up custom repository implementations. Defaults to {@literal Impl}. So - * for a repository named {@code PersonRepository} the corresponding implementation class will be looked up scanning - * for {@code PersonRepositoryImpl}. - * - * @return - */ - String repositoryImplementationPostfix() default ""; - - /** - * Configures the location of where to find the Spring Data named queries properties file. Will default to - * {@code META-INFO/mongo-named-queries.properties}. - * - * @return - */ - String namedQueriesLocation() default ""; - - /** - * Returns the key of the {@link org.springframework.data.repository.query.QueryLookupStrategy} to be used for lookup queries for query methods. Defaults to - * {@link org.springframework.data.repository.query.QueryLookupStrategy.Key#CREATE_IF_NOT_FOUND}. - * - * @return - */ - Key queryLookupStrategy() default Key.CREATE_IF_NOT_FOUND; - - /** - * Returns the {@link org.springframework.beans.factory.FactoryBean} class to be used for each repository instance. Defaults to - * {@link org.springframework.ldap.repository.support.LdapRepositoryFactoryBean}. - * - * @return - */ - Class repositoryFactoryBeanClass() default LdapRepositoryFactoryBean.class; - - /** - * Configures the name of the {@link org.springframework.ldap.core.LdapTemplate} bean to be used with the repositories detected. - * - * @return - */ - String ldapTemplateRef() default "ldapTemplate"; -} diff --git a/core/src/main/java/org/springframework/ldap/repository/config/LdapRepositoriesRegistrar.java b/core/src/main/java/org/springframework/ldap/repository/config/LdapRepositoriesRegistrar.java deleted file mode 100644 index 512be126..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/config/LdapRepositoriesRegistrar.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.repository.config; - -import org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport; -import org.springframework.data.repository.config.RepositoryConfigurationExtension; - -import java.lang.annotation.Annotation; - -/** - * LDAP-specific {@link org.springframework.context.annotation.ImportBeanDefinitionRegistrar}. - * - * @author Mattias Hellborg Arthursson - * @since 2.0 - */ -class LdapRepositoriesRegistrar extends RepositoryBeanDefinitionRegistrarSupport { - - @Override - protected Class getAnnotation() { - return EnableLdapRepositories.class; - } - - @Override - protected RepositoryConfigurationExtension getExtension() { - return new LdapRepositoryConfigurationExtension(); - } -} diff --git a/core/src/main/java/org/springframework/ldap/repository/config/LdapRepositoryConfigurationExtension.java b/core/src/main/java/org/springframework/ldap/repository/config/LdapRepositoryConfigurationExtension.java deleted file mode 100644 index b0395eb8..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/config/LdapRepositoryConfigurationExtension.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.repository.config; - -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.core.annotation.AnnotationAttributes; -import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource; -import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport; -import org.springframework.data.repository.config.XmlRepositoryConfigurationSource; -import org.springframework.ldap.repository.support.LdapRepositoryFactoryBean; -import org.springframework.util.StringUtils; -import org.w3c.dom.Element; - -/** - * @author Mattias Hellborg Arthursson - * @since 2.0 - */ -public class LdapRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport { - - private static final String ATT_LDAP_TEMPLATE_REF = "ldap-template-ref"; - - @Override - protected String getModulePrefix() { - return "ldap"; - } - - @Override - public String getRepositoryFactoryClassName() { - return LdapRepositoryFactoryBean.class.getName(); - } - - @Override - public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) { - Element element = config.getElement(); - String ldapTemplateRef = element.getAttribute(ATT_LDAP_TEMPLATE_REF); - if(!StringUtils.hasText(ldapTemplateRef)) { - ldapTemplateRef = "ldapTemplate"; - } - - builder.addPropertyReference("ldapOperations", ldapTemplateRef); - } - - @Override - public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) { - AnnotationAttributes attributes = config.getAttributes(); - - builder.addPropertyReference("ldapOperations", attributes.getString("ldapTemplateRef")); - } -} diff --git a/core/src/main/java/org/springframework/ldap/repository/query/AbstractLdapRepositoryQuery.java b/core/src/main/java/org/springframework/ldap/repository/query/AbstractLdapRepositoryQuery.java deleted file mode 100644 index ddbeeca3..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/query/AbstractLdapRepositoryQuery.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.repository.query; - -import org.springframework.dao.EmptyResultDataAccessException; -import org.springframework.data.repository.query.QueryMethod; -import org.springframework.data.repository.query.RepositoryQuery; -import org.springframework.ldap.core.LdapOperations; -import org.springframework.ldap.query.LdapQuery; - -/** - * @author Mattias Hellborg Arthursson - * @since 2.0 - */ -abstract class AbstractLdapRepositoryQuery implements RepositoryQuery { - private final LdapQueryMethod queryMethod; - private final Class clazz; - private final LdapOperations ldapOperations; - - public AbstractLdapRepositoryQuery(LdapQueryMethod queryMethod, - Class clazz, - LdapOperations ldapOperations) { - this.queryMethod = queryMethod; - this.clazz = clazz; - this.ldapOperations = ldapOperations; - } - - @Override - public final Object execute(Object[] parameters) { - LdapQuery query = createQuery(parameters); - - if(queryMethod.isCollectionQuery()) { - return ldapOperations.find(query, clazz); - } else { - try { - return ldapOperations.findOne(query, clazz); - } catch (EmptyResultDataAccessException e) { - return null; - } - } - } - - protected abstract LdapQuery createQuery(Object[] parameters); - - Class getClazz() { - return clazz; - } - - @Override - public final QueryMethod getQueryMethod() { - return queryMethod; - } -} diff --git a/core/src/main/java/org/springframework/ldap/repository/query/AnnotatedLdapRepositoryQuery.java b/core/src/main/java/org/springframework/ldap/repository/query/AnnotatedLdapRepositoryQuery.java deleted file mode 100644 index ceb67e58..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/query/AnnotatedLdapRepositoryQuery.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.repository.query; - -import org.springframework.ldap.core.LdapOperations; -import org.springframework.ldap.query.LdapQuery; -import org.springframework.ldap.repository.Query; -import org.springframework.util.Assert; - -import static org.springframework.ldap.query.LdapQueryBuilder.query; - -/** - * Handles queries for repository methods annotated with {@link org.springframework.ldap.repository.Query}. - * - * @author Mattias Hellborg Arthursson - * @since 2.0 - */ -public class AnnotatedLdapRepositoryQuery extends AbstractLdapRepositoryQuery { - private final Query queryAnnotation; - - /** - * Construct a new instance. - * @param queryMethod the QueryMethod. - * @param clazz the managed class. - * @param ldapOperations the LdapOperations instance to use. - */ - public AnnotatedLdapRepositoryQuery(LdapQueryMethod queryMethod, Class clazz, LdapOperations ldapOperations) { - super(queryMethod, clazz, ldapOperations); - queryAnnotation = queryMethod.getQueryAnnotation(); - - Assert.notNull(queryMethod, "Annotation must be present"); - Assert.hasLength(queryAnnotation.value(), "Query filter must be specified"); - } - - @Override - protected LdapQuery createQuery(Object[] parameters) { - return query() - .base(queryAnnotation.base()) - .searchScope(queryAnnotation.searchScope()) - .countLimit(queryAnnotation.countLimit()) - .timeLimit(queryAnnotation.timeLimit()) - .filter(queryAnnotation.value(), parameters); - } -} diff --git a/core/src/main/java/org/springframework/ldap/repository/query/LdapQueryCreator.java b/core/src/main/java/org/springframework/ldap/repository/query/LdapQueryCreator.java deleted file mode 100644 index 2d09198a..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/query/LdapQueryCreator.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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.repository.query; - -import org.springframework.data.domain.Sort; -import org.springframework.data.mapping.PropertyPath; -import org.springframework.data.repository.query.Parameters; -import org.springframework.data.repository.query.ParametersParameterAccessor; -import org.springframework.data.repository.query.parser.AbstractQueryCreator; -import org.springframework.data.repository.query.parser.Part; -import org.springframework.data.repository.query.parser.PartTree; -import org.springframework.ldap.odm.annotations.Entry; -import org.springframework.ldap.odm.core.ObjectDirectoryMapper; -import org.springframework.ldap.query.ConditionCriteria; -import org.springframework.ldap.query.ContainerCriteria; -import org.springframework.ldap.query.LdapQuery; - -import java.util.Iterator; - -import static org.springframework.ldap.query.LdapQueryBuilder.query; - -/** - * Creator of dynamic queries based on method names. - * @author Mattias Hellborg Arthursson - * @since 2.0 - */ -public class LdapQueryCreator extends AbstractQueryCreator { - private final Class clazz; - private final ObjectDirectoryMapper mapper; - - /** - * Construct a new instance. - */ - public LdapQueryCreator(PartTree tree, - Parameters parameters, - Class clazz, - ObjectDirectoryMapper mapper, - Object[] values) { - super(tree, new ParametersParameterAccessor(parameters, values)); - this.clazz = clazz; - this.mapper = mapper; - } - - @Override - protected ContainerCriteria create(Part part, Iterator iterator) { - String base = clazz.getAnnotation(Entry.class).base(); - ConditionCriteria criteria = query().base(base).where(getAttribute(part)); - - return appendCondition(part, iterator, criteria); - } - - private ContainerCriteria appendCondition(Part part, Iterator iterator, ConditionCriteria criteria) { - Part.Type type = part.getType(); - - String value = null; - if(iterator.hasNext()){ - value = iterator.next().toString(); - } - switch (type) { - case NEGATING_SIMPLE_PROPERTY: - return criteria.not().is(value); - case SIMPLE_PROPERTY: - return criteria.is(value); - case STARTING_WITH: - return criteria.like(value + "*"); - case ENDING_WITH: - return criteria.like("*" + value); - case CONTAINING: - return criteria.like("*" + value + "*"); - case LIKE: - return criteria.like(value); - case NOT_LIKE: - return criteria.not().like(value); - case GREATER_THAN_EQUAL: - return criteria.gte(value); - case LESS_THAN_EQUAL: - return criteria.lte(value); - case IS_NOT_NULL: - return criteria.isPresent(); - case IS_NULL: - return criteria.not().isPresent(); - } - - throw new IllegalArgumentException(String.format("%s queries are not supported for LDAP repositories", type)); - } - - private String getAttribute(Part part) { - PropertyPath path = part.getProperty(); - if(path.hasNext()) { - throw new IllegalArgumentException("Nested properties are not supported"); - } - - return mapper.attributeFor(clazz, path.getSegment()); - } - - @Override - protected ContainerCriteria and(Part part, ContainerCriteria base, Iterator iterator) { - ConditionCriteria criteria = base.and(getAttribute(part)); - - return appendCondition(part, iterator, criteria); - } - - @Override - protected ContainerCriteria or(ContainerCriteria base, ContainerCriteria criteria) { - return base.or(criteria); - } - - @Override - protected LdapQuery complete(ContainerCriteria criteria, Sort sort) { - return criteria; - } -} diff --git a/core/src/main/java/org/springframework/ldap/repository/query/LdapQueryMethod.java b/core/src/main/java/org/springframework/ldap/repository/query/LdapQueryMethod.java deleted file mode 100644 index 368b47ab..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/query/LdapQueryMethod.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.springframework.core.annotation.AnnotationUtils; -import org.springframework.data.projection.ProjectionFactory; -import org.springframework.data.repository.core.RepositoryMetadata; -import org.springframework.data.repository.query.QueryMethod; -import org.springframework.ldap.repository.Query; - -import java.lang.reflect.Method; - -/** - * QueryMethod for Ldap Queries. - * - * @author Mattias Hellborg Arthursson - * @author Eddu Melendez - * @since 2.0 - */ -public class LdapQueryMethod extends QueryMethod { - private final Method method; - - /** - * Creates a new LdapQueryMethod from the given parameters. - * - * @param method must not be {@literal null} - * @param metadata must not be {@literal null} - */ - public LdapQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) { - super(method, metadata, factory); - this.method = method; - } - - /** - * Check whether the target method is annotated with {@link org.springframework.ldap.repository.Query}. - * @return true if the target method is annotated with {@link org.springframework.ldap.repository.Query}, false - * otherwise. - */ - public boolean hasQueryAnnotation() { - return getQueryAnnotation() != null; - } - - /** - * Get the {@link org.springframework.ldap.repository.Query} annotation of the target method (if any). - * @return the {@link org.springframework.ldap.repository.Query} annotation of the target method if present, or null - * otherwise. - */ - Query getQueryAnnotation() { - return AnnotationUtils.getAnnotation(method, Query.class); - } -} diff --git a/core/src/main/java/org/springframework/ldap/repository/query/PartTreeLdapRepositoryQuery.java b/core/src/main/java/org/springframework/ldap/repository/query/PartTreeLdapRepositoryQuery.java deleted file mode 100644 index af14f098..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/query/PartTreeLdapRepositoryQuery.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.springframework.ldap.repository.query; - -import org.springframework.data.repository.query.Parameters; -import org.springframework.data.repository.query.parser.PartTree; -import org.springframework.ldap.core.LdapOperations; -import org.springframework.ldap.odm.core.ObjectDirectoryMapper; -import org.springframework.ldap.query.LdapQuery; - -/** - * @author Mattias Hellborg Arthursson - */ -public class PartTreeLdapRepositoryQuery extends AbstractLdapRepositoryQuery { - private final PartTree partTree; - private final Parameters parameters; - private final ObjectDirectoryMapper objectDirectoryMapper; - - public PartTreeLdapRepositoryQuery(LdapQueryMethod queryMethod, Class clazz, LdapOperations ldapOperations) { - super(queryMethod, clazz, ldapOperations); - partTree = new PartTree(queryMethod.getName(), clazz); - parameters = queryMethod.getParameters(); - objectDirectoryMapper = ldapOperations.getObjectDirectoryMapper(); - } - - - @Override - protected LdapQuery createQuery(Object[] actualParameters) { - LdapQueryCreator queryCreator = - new LdapQueryCreator(partTree, - this.parameters, - getClazz(), - objectDirectoryMapper, - actualParameters); - return queryCreator.createQuery(); - } -} diff --git a/core/src/main/java/org/springframework/ldap/repository/support/DefaultLdapAnnotationProcessorConfiguration.java b/core/src/main/java/org/springframework/ldap/repository/support/DefaultLdapAnnotationProcessorConfiguration.java deleted file mode 100644 index 5d026cb1..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/support/DefaultLdapAnnotationProcessorConfiguration.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.apt.DefaultConfiguration; -import org.springframework.ldap.odm.annotations.Id; - -import javax.annotation.processing.RoundEnvironment; -import javax.lang.model.element.VariableElement; -import java.lang.annotation.Annotation; -import java.util.Collection; -import java.util.Map; - -/** - * @author Mattias Hellborg Arthursson - * @author Eddu Melendez - * @since 2.0 - */ -class DefaultLdapAnnotationProcessorConfiguration extends DefaultConfiguration { - public DefaultLdapAnnotationProcessorConfiguration( - RoundEnvironment roundEnv, - Map options, - Collection keywords, - Class entitiesAnn, - Class entityAnn, - Class superTypeAnn, - Class embeddableAnn, - Class embeddedAnn, - Class skipAnn) { - - super(roundEnv, options, keywords, entitiesAnn, entityAnn, superTypeAnn, embeddableAnn, embeddedAnn, skipAnn); - } - - @Override - public boolean isBlockedField(VariableElement field) { - return super.isBlockedField(field) || field.getAnnotation(Id.class) != null; - } - - @Override - public boolean isValidField(VariableElement field) { - return super.isValidField(field) && field.getAnnotation(Id.class) == null; - } -} diff --git a/core/src/main/java/org/springframework/ldap/repository/support/LdapAnnotationProcessor.java b/core/src/main/java/org/springframework/ldap/repository/support/LdapAnnotationProcessor.java deleted file mode 100644 index c4da05db..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/support/LdapAnnotationProcessor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.apt.AbstractQuerydslProcessor; -import com.querydsl.apt.Configuration; -import com.querydsl.apt.DefaultConfiguration; -import com.querydsl.core.annotations.QueryEntities; -import org.springframework.ldap.odm.annotations.Entry; -import org.springframework.ldap.odm.annotations.Transient; - -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.annotation.processing.SupportedSourceVersion; -import javax.lang.model.SourceVersion; -import javax.tools.Diagnostic; -import java.util.Collections; - -/** - * QueryDSL Annotation Processor to generate QueryDSL classes for entity classes annotated with {@link Entry}. - * - * @author Mattias Hellborg Arthursson - * @author Eddu Melendez - * @since 2.0 - */ -@SupportedAnnotationTypes("org.springframework.ldap.odm.annotations.*") -@SupportedSourceVersion(SourceVersion.RELEASE_6) -public class LdapAnnotationProcessor extends AbstractQuerydslProcessor { - @Override - protected Configuration createConfiguration(RoundEnvironment roundEnv) { - processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Running " + getClass().getSimpleName()); - - DefaultConfiguration configuration = new DefaultLdapAnnotationProcessorConfiguration(roundEnv, processingEnv.getOptions(), - Collections.emptySet(), QueryEntities.class, Entry.class, null, null, null, Transient.class); - configuration.setUseFields(true); - configuration.setUseGetters(false); - - return configuration; - } -} diff --git a/core/src/main/java/org/springframework/ldap/repository/support/LdapRepositoryFactory.java b/core/src/main/java/org/springframework/ldap/repository/support/LdapRepositoryFactory.java deleted file mode 100644 index 84afc196..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/support/LdapRepositoryFactory.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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 org.springframework.data.projection.ProjectionFactory; -import org.springframework.data.querydsl.QueryDslPredicateExecutor; -import org.springframework.data.repository.core.EntityInformation; -import org.springframework.data.repository.core.NamedQueries; -import org.springframework.data.repository.core.RepositoryInformation; -import org.springframework.data.repository.core.RepositoryMetadata; -import org.springframework.data.repository.core.support.RepositoryFactorySupport; -import org.springframework.data.repository.query.QueryLookupStrategy; -import org.springframework.data.repository.query.RepositoryQuery; -import org.springframework.ldap.core.LdapOperations; -import org.springframework.ldap.repository.query.AnnotatedLdapRepositoryQuery; -import org.springframework.ldap.repository.query.LdapQueryMethod; -import org.springframework.ldap.repository.query.PartTreeLdapRepositoryQuery; - -import java.io.Serializable; -import java.lang.reflect.Method; - -import static org.springframework.data.querydsl.QueryDslUtils.QUERY_DSL_PRESENT; - -/** - * Factory to create {@link org.springframework.ldap.repository.LdapRepository} instances. - * @author Mattias Hellborg Arthursson - * @author Eddu Melendez - * @since 2.0 - */ -public class LdapRepositoryFactory extends RepositoryFactorySupport { - private final LdapOperations ldapOperations; - - public LdapRepositoryFactory(LdapOperations ldapOperations) { - this.ldapOperations = ldapOperations; - } - - @Override - public EntityInformation getEntityInformation(Class domainClass) { - return null; - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - protected Object getTargetRepository(RepositoryMetadata metadata) { - if(!isQueryDslRepository(metadata.getRepositoryInterface())) { - return new SimpleLdapRepository( - ldapOperations, - ldapOperations.getObjectDirectoryMapper(), - metadata.getDomainType()); - } else { - return new QueryDslLdapRepository( - ldapOperations, - ldapOperations.getObjectDirectoryMapper(), - metadata.getDomainType()); - } - - } - - protected Object getTargetRepository(RepositoryInformation metadata) { - return getTargetRepository((RepositoryMetadata) metadata); - } - - private static boolean isQueryDslRepository(Class repositoryInterface) { - return QUERY_DSL_PRESENT && QueryDslPredicateExecutor.class.isAssignableFrom(repositoryInterface); - } - - - @Override - protected Class getRepositoryBaseClass(RepositoryMetadata metadata) { - if(!isQueryDslRepository(metadata.getRepositoryInterface())) { - return SimpleLdapRepository.class; - } else { - return QueryDslLdapRepository.class; - } - } - - @Override - protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key) { - return new LdapQueryLookupStrategy(); - } - - private final class LdapQueryLookupStrategy implements QueryLookupStrategy { - @Override - public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { - LdapQueryMethod queryMethod = new LdapQueryMethod(method, metadata, factory); - Class domainType = metadata.getDomainType(); - - if(queryMethod.hasQueryAnnotation()) { - return new AnnotatedLdapRepositoryQuery(queryMethod, domainType, ldapOperations); - } else { - return new PartTreeLdapRepositoryQuery(queryMethod, domainType, ldapOperations); - } - } - } -} diff --git a/core/src/main/java/org/springframework/ldap/repository/support/LdapRepositoryFactoryBean.java b/core/src/main/java/org/springframework/ldap/repository/support/LdapRepositoryFactoryBean.java deleted file mode 100644 index 66888a56..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/support/LdapRepositoryFactoryBean.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.repository.support; - -import org.springframework.data.repository.Repository; -import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport; -import org.springframework.data.repository.core.support.RepositoryFactorySupport; -import org.springframework.ldap.core.LdapOperations; -import org.springframework.util.Assert; - -import javax.naming.Name; - -/** - * {@link org.springframework.beans.factory.FactoryBean} to create {@link org.springframework.ldap.repository.LdapRepository} instances. - * - * @author Mattias Hellborg Arthursson - * @since 2.0 - */ -public class LdapRepositoryFactoryBean, S> extends RepositoryFactoryBeanSupport { - private LdapOperations ldapOperations; - - public void setLdapOperations(LdapOperations ldapOperations) { - this.ldapOperations = ldapOperations; - } - - @Override - protected RepositoryFactorySupport createRepositoryFactory() { - return new LdapRepositoryFactory(ldapOperations); - } - - @Override - public void afterPropertiesSet() { - super.afterPropertiesSet(); - Assert.notNull(ldapOperations, "LdapOperations must be set"); - } -} diff --git a/core/src/main/java/org/springframework/ldap/repository/support/LdapSerializer.java b/core/src/main/java/org/springframework/ldap/repository/support/LdapSerializer.java deleted file mode 100644 index f4b82bd7..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/support/LdapSerializer.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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.Constant; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.FactoryExpression; -import com.querydsl.core.types.Operation; -import com.querydsl.core.types.Operator; -import com.querydsl.core.types.Ops; -import com.querydsl.core.types.ParamExpression; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.SubQueryExpression; -import com.querydsl.core.types.TemplateExpression; -import com.querydsl.core.types.Visitor; -import org.springframework.ldap.filter.AndFilter; -import org.springframework.ldap.filter.EqualsFilter; -import org.springframework.ldap.filter.Filter; -import org.springframework.ldap.filter.GreaterThanOrEqualsFilter; -import org.springframework.ldap.filter.LessThanOrEqualsFilter; -import org.springframework.ldap.filter.LikeFilter; -import org.springframework.ldap.filter.NotFilter; -import org.springframework.ldap.filter.OrFilter; -import org.springframework.ldap.filter.PresentFilter; -import org.springframework.ldap.odm.core.ObjectDirectoryMapper; - -/** - * Helper class for generating LDAP filters from QueryDSL Expressions. - * - * @author Mattias Hellborg Arthursson - * @author Eddu Melendez - * @since 2.0 - */ -class LdapSerializer implements Visitor { - - private final ObjectDirectoryMapper odm; - private final Class clazz; - - public LdapSerializer(ObjectDirectoryMapper odm, Class clazz) { - this.odm = odm; - this.clazz = clazz; - } - - public Filter handle(Expression expression) { - return (Filter) expression.accept(this, null); - } - - @Override - public Object visit(Constant expr, Void context) { - return expr.getConstant().toString(); - } - - @Override - public Object visit(FactoryExpression expr, Void context) { - throw new UnsupportedOperationException(); - } - - @Override - public Object visit(Operation expr, Void context) { - Operator operator = expr.getOperator(); - if (operator == Ops.EQ) { - return new EqualsFilter(attribute(expr), value(expr)); - } else if (operator == Ops.AND) { - return new AndFilter() - .and(handle(expr.getArg(0))) - .and(handle(expr.getArg(1))); - } else if (operator == Ops.OR) { - return new OrFilter() - .or(handle(expr.getArg(0))) - .or(handle(expr.getArg(1))); - } else if (operator == Ops.NOT) { - return new NotFilter(handle(expr.getArg(0))); - } else if (operator == Ops.LIKE) { - return new LikeFilter(attribute(expr), value(expr)); - } else if (operator == Ops.STARTS_WITH || operator == Ops.STARTS_WITH_IC) { - return new LikeFilter(attribute(expr), value(expr) + "*"); - } else if (operator == Ops.ENDS_WITH || operator == Ops.ENDS_WITH_IC) { - return new LikeFilter(attribute(expr), "*" + value(expr)); - } else if (operator == Ops.STRING_CONTAINS || operator == Ops.STRING_CONTAINS_IC) { - return new LikeFilter(attribute(expr), "*" + value(expr) + "*"); - } else if (operator == Ops.IS_NOT_NULL) { - return new PresentFilter(attribute(expr)); - } else if (operator == Ops.IS_NULL) { - return new NotFilter(new PresentFilter(attribute(expr))); - } else if (operator == Ops.GOE) { - return new GreaterThanOrEqualsFilter(attribute(expr), value(expr)); - } else if (operator == Ops.LOE) { - return new LessThanOrEqualsFilter(attribute(expr), value(expr)); - } - - - throw new UnsupportedOperationException("Unsupported operator " + operator.toString()); - } - - private String value(Operation expr) { - return (String) expr.getArg(1).accept(this, null); - } - - private String attribute(Operation expr) { - return odm.attributeFor(clazz, (String) expr.getArg(0).accept(this, null)); - } - - @Override - public Object visit(ParamExpression expr, Void context) { - throw new UnsupportedOperationException(); - } - - @Override - public Object visit(Path expr, Void context) { - return expr.getMetadata().getName(); - } - - @Override - public Object visit(SubQueryExpression expr, Void context) { - throw new UnsupportedOperationException(); - } - - @Override - public Object visit(TemplateExpression expr, Void context) { - throw new UnsupportedOperationException(); - } -} diff --git a/core/src/main/java/org/springframework/ldap/repository/support/QueryDslLdapQuery.java b/core/src/main/java/org/springframework/ldap/repository/support/QueryDslLdapQuery.java deleted file mode 100644 index e9092f48..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/support/QueryDslLdapQuery.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.DefaultQueryMetadata; -import com.querydsl.core.FilteredClause; -import com.querydsl.core.support.QueryMixin; -import com.querydsl.core.types.EntityPath; -import com.querydsl.core.types.Predicate; -import org.springframework.ldap.core.LdapOperations; -import org.springframework.ldap.query.LdapQuery; - -import java.util.List; - -import static org.springframework.ldap.query.LdapQueryBuilder.query; - -/** - * Spring LDAP specific {@link FilteredClause} implementation. - * - * @author Mattias Hellborg Arthursson - * @author Eddu Melendez - * @since 2.0 - */ -public class QueryDslLdapQuery implements FilteredClause> { - private final LdapOperations ldapOperations; - private final Class clazz; - - private QueryMixin> queryMixin = - new QueryMixin>(this, new DefaultQueryMetadata().noValidate()); - - private final LdapSerializer filterGenerator; - - @SuppressWarnings("unchecked") - public QueryDslLdapQuery(LdapOperations ldapOperations, EntityPath entityPath) { - this(ldapOperations, (Class) entityPath.getType()); - } - - public QueryDslLdapQuery(LdapOperations ldapOperations, Class clazz) { - this.ldapOperations = ldapOperations; - this.clazz = clazz; - this.filterGenerator = new LdapSerializer(ldapOperations.getObjectDirectoryMapper(), clazz); - } - - @Override - public QueryDslLdapQuery where(Predicate... o) { - return queryMixin.where(o); - } - - @SuppressWarnings("unchecked") - public List list() { - return (List) ldapOperations.find(buildQuery(), clazz); - } - - public K uniqueResult() { - return ldapOperations.findOne(buildQuery(), clazz); - } - - LdapQuery buildQuery() { - return query().filter(filterGenerator.handle(queryMixin.getMetadata().getWhere())); - } - -} diff --git a/core/src/main/java/org/springframework/ldap/repository/support/QueryDslLdapRepository.java b/core/src/main/java/org/springframework/ldap/repository/support/QueryDslLdapRepository.java deleted file mode 100644 index 56914e1c..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/support/QueryDslLdapRepository.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.OrderSpecifier; -import com.querydsl.core.types.Predicate; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.data.querydsl.QueryDslPredicateExecutor; -import org.springframework.ldap.core.LdapOperations; -import org.springframework.ldap.odm.core.ObjectDirectoryMapper; - -import java.util.List; - -/** - * Base repository implementation for QueryDSL support. - * - * @author Mattias Hellborg Arthursson - * @author Eddu Melendez - * @since 2.0 - */ -public class QueryDslLdapRepository extends SimpleLdapRepository implements QueryDslPredicateExecutor { - - public QueryDslLdapRepository(LdapOperations ldapOperations, - ObjectDirectoryMapper odm, - Class clazz) { - super(ldapOperations, odm, clazz); - } - - @Override - public T findOne(Predicate predicate) { - return queryFor(predicate).uniqueResult(); - } - - @Override - public List findAll(Predicate predicate) { - return queryFor(predicate).list(); - } - - @Override - public long count(Predicate predicate) { - return findAll(predicate).size(); - } - - public boolean exists(Predicate predicate) { - return count(predicate) > 0; - } - - public Iterable findAll(Predicate predicate, Sort sort) { - throw new UnsupportedOperationException(); - } - - private QueryDslLdapQuery queryFor(Predicate predicate) { - return new QueryDslLdapQuery(getLdapOperations(), getClazz()) - .where(predicate); - } - - public Iterable findAll(OrderSpecifier... orders) { - throw new UnsupportedOperationException(); - } - - @Override - public Iterable findAll(Predicate predicate, OrderSpecifier... orders) { - throw new UnsupportedOperationException(); - } - - @Override - public Page findAll(Predicate predicate, Pageable pageable) { - throw new UnsupportedOperationException(); - } -} diff --git a/core/src/main/java/org/springframework/ldap/repository/support/SimpleLdapRepository.java b/core/src/main/java/org/springframework/ldap/repository/support/SimpleLdapRepository.java deleted file mode 100644 index d17b2af8..00000000 --- a/core/src/main/java/org/springframework/ldap/repository/support/SimpleLdapRepository.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * 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.repository.support; - -import org.springframework.dao.EmptyResultDataAccessException; -import org.springframework.data.domain.Persistable; -import org.springframework.ldap.NameNotFoundException; -import org.springframework.ldap.core.LdapOperations; -import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler; -import org.springframework.ldap.filter.Filter; -import org.springframework.ldap.odm.core.ObjectDirectoryMapper; -import org.springframework.ldap.query.LdapQuery; -import org.springframework.ldap.repository.LdapRepository; -import org.springframework.util.Assert; - -import javax.naming.Name; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static org.springframework.ldap.query.LdapQueryBuilder.query; - -/** - * Base repository implementation for LDAP. - * - * @author Mattias Hellborg Arthursson - * @since 2.0 - */ -public class SimpleLdapRepository implements LdapRepository { - private static final String OBJECTCLASS_ATTRIBUTE = "objectclass"; - private final LdapOperations ldapOperations; - private final ObjectDirectoryMapper odm; - private final Class clazz; - - public SimpleLdapRepository(LdapOperations ldapOperations, ObjectDirectoryMapper odm, Class clazz) { - this.ldapOperations = ldapOperations; - this.odm = odm; - this.clazz = clazz; - } - - protected LdapOperations getLdapOperations() { - return ldapOperations; - } - - protected Class getClazz() { - return clazz; - } - - @Override - public long count() { - Filter filter = odm.filterFor(clazz, null); - CountNameClassPairCallbackHandler callback = new CountNameClassPairCallbackHandler(); - LdapQuery query = query().attributes(OBJECTCLASS_ATTRIBUTE).filter(filter); - ldapOperations.search(query, callback); - - return callback.getNoOfRows(); - } - - private boolean isNew(S entity, Name id) { - if (entity instanceof Persistable) { - Persistable persistable = (Persistable) entity; - return persistable.isNew(); - } else { - return id == null; - } - } - - @Override - public S save(S entity) { - Assert.notNull(entity, "Entity must not be null"); - Name declaredId = odm.getId(entity); - - if (isNew(entity, declaredId)) { - ldapOperations.create(entity); - } else { - ldapOperations.update(entity); - } - - return entity; - } - - @Override - public Iterable save(Iterable entities) { - return new TransformingIterable(entities, new Function() { - @Override - public S transform(S entry) { - return save(entry); - } - }); - } - - @Override - public T findOne(Name name) { - Assert.notNull(name, "Id must not be null"); - try { - return ldapOperations.findByDn(name, clazz); - } catch (NameNotFoundException e) { - return null; - } - } - - @Override - public List findAll(LdapQuery ldapQuery) { - Assert.notNull(ldapQuery, "LdapQuery must not be null"); - return ldapOperations.find(ldapQuery, clazz); - } - - @Override - public T findOne(LdapQuery ldapQuery) { - Assert.notNull(ldapQuery, "LdapQuery must not be null"); - try { - return ldapOperations.findOne(ldapQuery, clazz); - } catch (EmptyResultDataAccessException e) { - return null; - } - } - - @Override - public boolean exists(Name name) { - Assert.notNull(name, "Id must not be null"); - return findOne(name) != null; - } - - @Override - public List findAll() { - return ldapOperations.findAll(clazz); - } - - @Override - public List findAll(final Iterable names) { - Iterable found = new TransformingIterable(names, new Function() { - @Override - public T transform(Name name) { - return findOne(name); - } - }); - - LinkedList list = new LinkedList(); - for (T entry : found) { - if (entry != null) { - list.add(entry); - } - } - - return list; - } - - @Override - public void delete(Name name) { - Assert.notNull(name, "Id must not be null"); - ldapOperations.unbind(name); - } - - @Override - public void delete(T entity) { - Assert.notNull(entity, "Entity must not be null"); - ldapOperations.delete(entity); - } - - @Override - public void delete(Iterable entities) { - for (T entity : entities) { - delete(entity); - } - } - - @Override - public void deleteAll() { - delete(findAll()); - } - - private static final class TransformingIterable implements Iterable { - private final Iterable target; - private final Function function; - - private TransformingIterable(Iterable target, Function function) { - this.target = target; - this.function = function; - } - - @Override - public Iterator iterator() { - final Iterator targetIterator = target.iterator(); - return new Iterator() { - @Override - public boolean hasNext() { - return targetIterator.hasNext(); - } - - @Override - public T next() { - return function.transform(targetIterator.next()); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Remove is not supported for this iterator"); - } - }; - } - } - - private interface Function { - T transform(F entry); - } -} diff --git a/core/src/test/java/org/springframework/ldap/config/DummyEntity.java b/core/src/test/java/org/springframework/ldap/config/DummyEntity.java deleted file mode 100644 index 8d7eccef..00000000 --- a/core/src/test/java/org/springframework/ldap/config/DummyEntity.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.springframework.ldap.config; - -/** - * @author Mattias Hellborg Arthursson - */ -public class DummyEntity { -} diff --git a/core/src/test/java/org/springframework/ldap/config/DummyLdapRepository.java b/core/src/test/java/org/springframework/ldap/config/DummyLdapRepository.java deleted file mode 100644 index 77b24737..00000000 --- a/core/src/test/java/org/springframework/ldap/config/DummyLdapRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.config; - -import org.springframework.data.repository.CrudRepository; - -import javax.naming.Name; - -/** - * @author Mattias Hellborg Arthursson - */ -public interface DummyLdapRepository extends CrudRepository { -} diff --git a/core/src/test/java/org/springframework/ldap/config/LdapNamespaceHandlerTests.java b/core/src/test/java/org/springframework/ldap/config/LdapNamespaceHandlerTests.java deleted file mode 100644 index 32c4e99a..00000000 --- a/core/src/test/java/org/springframework/ldap/config/LdapNamespaceHandlerTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2002-2015 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.config; - -import static org.junit.Assert.*; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.powermock.api.mockito.PowerMockito.spy; -import static org.powermock.api.mockito.PowerMockito.when; - -import java.util.Map; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.internal.WhiteboxImpl; -import org.springframework.beans.factory.xml.BeanDefinitionParser; -import org.springframework.util.ClassUtils; - -/** - * - * @author Rob Winch - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({ ClassUtils.class }) -public class LdapNamespaceHandlerTests { - - // LDAP-335 - @Test - public void repositoryClassNotLoadedIfNotOnClasspath() throws Exception { - spy(ClassUtils.class); - when(ClassUtils.class, "isPresent", - eq(LdapNamespaceHandler.REPOSITORY_CLASS_NAME), any(ClassLoader.class)) - .thenReturn(false); - - LdapNamespaceHandler handler = new LdapNamespaceHandler(); - - handler.init(); - - Map parsers = WhiteboxImpl.getInternalState(handler, "parsers"); - assertFalse(parsers.containsKey(Elements.REPOSITORIES)); - } -} \ No newline at end of file diff --git a/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTest.java b/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTest.java index 6ccdb1ff..183cc49f 100644 --- a/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTest.java +++ b/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTest.java @@ -355,14 +355,6 @@ public class LdapTemplateNamespaceHandlerTest { new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-with-native.xml"); } - @Test - public void verifyAutomaticRepositorySupport() { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-with-repositories.xml"); - DummyLdapRepository repository = ctx.getBean(DummyLdapRepository.class); - - assertThat(repository).isNotNull(); - } - @Test public void verifyParsePooling2Defaults() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling2-defaults.xml"); diff --git a/core/src/test/java/org/springframework/ldap/repository/SimpleLdapRepositoryTest.java b/core/src/test/java/org/springframework/ldap/repository/SimpleLdapRepositoryTest.java deleted file mode 100644 index b21f9208..00000000 --- a/core/src/test/java/org/springframework/ldap/repository/SimpleLdapRepositoryTest.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * 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; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.springframework.data.domain.Persistable; -import org.springframework.ldap.NameNotFoundException; -import org.springframework.ldap.core.LdapOperations; -import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler; -import org.springframework.ldap.filter.Filter; -import org.springframework.ldap.odm.core.ObjectDirectoryMapper; -import org.springframework.ldap.query.LdapQuery; -import org.springframework.ldap.repository.support.SimpleLdapRepository; -import org.springframework.ldap.support.LdapUtils; - -import javax.naming.Name; -import javax.naming.ldap.LdapName; -import java.util.Arrays; -import java.util.Iterator; - -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; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * @author Mattias Hellborg Arthursson - */ -public class SimpleLdapRepositoryTest { - - private LdapOperations ldapOperationsMock; - private ObjectDirectoryMapper odmMock; - private SimpleLdapRepository tested; - - @Before - public void prepareTestedInstance() { - ldapOperationsMock = mock(LdapOperations.class); - odmMock = mock(ObjectDirectoryMapper.class); - tested = new SimpleLdapRepository(ldapOperationsMock, odmMock, Object.class); - } - - @Test - public void testCount() { - Filter filterMock = mock(Filter.class); - when(odmMock.filterFor(Object.class, null)).thenReturn(filterMock); - ArgumentCaptor ldapQuery = ArgumentCaptor.forClass(LdapQuery.class); - doNothing().when(ldapOperationsMock).search(ldapQuery.capture(), any(CountNameClassPairCallbackHandler.class)); - - long count = tested.count(); - - assertThat(count).isEqualTo(0); - LdapQuery query = ldapQuery.getValue(); - assertThat(query.filter()).isEqualTo(filterMock); - assertThat(query.attributes()).isEqualTo(new String[]{"objectclass"}); - } - - @Test - public void testSaveNonPersistableWithIdSet() { - Object expectedEntity = new Object(); - - when(odmMock.getId(expectedEntity)).thenReturn(LdapUtils.emptyLdapName()); - when(odmMock.getCalculatedId(expectedEntity)).thenReturn(null); - - tested.save(expectedEntity); - - verify(ldapOperationsMock).update(expectedEntity); - } - - @Test - public void testSaveNonPersistableWithIdChanged() { - Object expectedEntity = new Object(); - LdapName expectedName = LdapUtils.newLdapName("ou=newlocation"); - - when(odmMock.getId(expectedEntity)).thenReturn(LdapUtils.emptyLdapName()); - when(odmMock.getCalculatedId(expectedEntity)).thenReturn(expectedName); - - tested.save(expectedEntity); - - verify(ldapOperationsMock).update(expectedEntity); - } - - @Test - public void testSaveNonPersistableWithNoIdCalculatedId() { - Object expectedEntity = new Object(); - LdapName expectedName = LdapUtils.emptyLdapName(); - - when(odmMock.getId(expectedEntity)).thenReturn(null); - when(odmMock.getCalculatedId(expectedEntity)).thenReturn(expectedName); - - tested.save(expectedEntity); - - verify(ldapOperationsMock).create(expectedEntity); - } - - @Test - public void testSavePersistableNewWithDeclaredId() { - Persistable expectedEntity = mock(Persistable.class); - - when(expectedEntity.isNew()).thenReturn(true); - when(odmMock.getId(expectedEntity)).thenReturn(LdapUtils.emptyLdapName()); - when(odmMock.getCalculatedId(expectedEntity)).thenReturn(null); - - tested.save(expectedEntity); - - verify(ldapOperationsMock).create(expectedEntity); - } - - @Test - public void testSavePersistableNewWithCalculatedId() { - Persistable expectedEntity = mock(Persistable.class); - LdapName expectedName = LdapUtils.emptyLdapName(); - - when(expectedEntity.isNew()).thenReturn(true); - when(odmMock.getId(expectedEntity)).thenReturn(null); - when(odmMock.getCalculatedId(expectedEntity)).thenReturn(expectedName); - - tested.save(expectedEntity); - - verify(ldapOperationsMock).create(expectedEntity); - } - - @Test - public void testSavePersistableNotNew() { - Persistable expectedEntity = mock(Persistable.class); - - when(expectedEntity.isNew()).thenReturn(false); - when(odmMock.getId(expectedEntity)).thenReturn(LdapUtils.emptyLdapName()); - when(odmMock.getCalculatedId(expectedEntity)).thenReturn(null); - - tested.save(expectedEntity); - - verify(ldapOperationsMock).update(expectedEntity); - } - - @Test - public void testFindOneWithName() { - LdapName expectedName = LdapUtils.emptyLdapName(); - Object expectedResult = new Object(); - - when(ldapOperationsMock.findByDn(expectedName, Object.class)).thenReturn(expectedResult); - - Object actualResult = tested.findOne(expectedName); - - assertThat(actualResult).isSameAs(expectedResult); - } - - @Test - public void verifyThatNameNotFoundInFindOneWithNameReturnsNull() { - LdapName expectedName = LdapUtils.emptyLdapName(); - - when(ldapOperationsMock.findByDn(expectedName, Object.class)).thenThrow(new NameNotFoundException("")); - - Object actualResult = tested.findOne(expectedName); - - assertThat(actualResult).isNull(); - } - - @Test - public void testFindAll() { - Name expectedName1 = LdapUtils.newLdapName("ou=aa"); - Name expectedName2 = LdapUtils.newLdapName("ou=bb"); - - Object expectedResult1 = new Object(); - Object expectedResult2 = new Object(); - - when(ldapOperationsMock.findByDn(expectedName1, Object.class)).thenReturn(expectedResult1); - when(ldapOperationsMock.findByDn(expectedName2, Object.class)).thenReturn(expectedResult2); - - Iterable actualResult = tested.findAll(Arrays.asList(expectedName1, expectedName2)); - - Iterator iterator = actualResult.iterator(); - assertThat(iterator.next()).isSameAs(expectedResult1); - assertThat(iterator.next()).isSameAs(expectedResult2); - - assertThat(iterator.hasNext()).isFalse(); - } - - @Test - public void testFindAllWhereOneEntryIsNotFound() { - Name expectedName1 = LdapUtils.newLdapName("ou=aa"); - Name expectedName2 = LdapUtils.newLdapName("ou=bb"); - - Object expectedResult2 = new Object(); - - when(ldapOperationsMock.findByDn(expectedName1, Object.class)).thenReturn(null); - when(ldapOperationsMock.findByDn(expectedName2, Object.class)).thenReturn(expectedResult2); - - Iterable actualResult = tested.findAll(Arrays.asList(expectedName1, expectedName2)); - - Iterator iterator = actualResult.iterator(); - assertThat(iterator.next()).isSameAs(expectedResult2); - - assertThat(iterator.hasNext()).isFalse(); - } - -} diff --git a/core/src/test/java/org/springframework/ldap/repository/config/AnnotationConfigTest.java b/core/src/test/java/org/springframework/ldap/repository/config/AnnotationConfigTest.java deleted file mode 100644 index 990a3758..00000000 --- a/core/src/test/java/org/springframework/ldap/repository/config/AnnotationConfigTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.springframework.ldap.repository.config; - -import org.junit.Test; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.ldap.config.DummyLdapRepository; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Mattias Hellborg Arthursson - */ -public class AnnotationConfigTest { - - @Test - public void testAnnotationConfig() { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-annotation-config.xml"); - - DummyLdapRepository repository = ctx.getBean(DummyLdapRepository.class); - assertThat(repository).isNotNull(); - } -} diff --git a/core/src/test/java/org/springframework/ldap/repository/config/SpringLdapConfiguration.java b/core/src/test/java/org/springframework/ldap/repository/config/SpringLdapConfiguration.java deleted file mode 100644 index 04164ee7..00000000 --- a/core/src/test/java/org/springframework/ldap/repository/config/SpringLdapConfiguration.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.springframework.ldap.repository.config; - -import org.springframework.context.annotation.Configuration; - -/** - * @author Mattias Hellborg Arthursson - */ -@Configuration -@EnableLdapRepositories(basePackages = "org.springframework.ldap.config") -public class SpringLdapConfiguration { -} diff --git a/core/src/test/java/org/springframework/ldap/repository/query/BaseTestPersonRepository.java b/core/src/test/java/org/springframework/ldap/repository/query/BaseTestPersonRepository.java deleted file mode 100644 index d142d3ff..00000000 --- a/core/src/test/java/org/springframework/ldap/repository/query/BaseTestPersonRepository.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2005-2015 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.springframework.ldap.odm.core.impl.BaseUnitTestPerson; -import org.springframework.ldap.odm.core.impl.UnitTestPerson; -import org.springframework.ldap.repository.LdapRepository; - -import java.util.List; - -/** - * @author Rob Winch - */ -public interface BaseTestPersonRepository extends LdapRepository { - List findByFullName(String name); -} diff --git a/core/src/test/java/org/springframework/ldap/repository/query/PartTreeLdapRepositoryQueryTest.java b/core/src/test/java/org/springframework/ldap/repository/query/PartTreeLdapRepositoryQueryTest.java deleted file mode 100644 index 71a24d0f..00000000 --- a/core/src/test/java/org/springframework/ldap/repository/query/PartTreeLdapRepositoryQueryTest.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * 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; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.projection.ProjectionFactory; -import org.springframework.data.projection.SpelAwareProxyProjectionFactory; -import org.springframework.data.repository.core.support.DefaultRepositoryMetadata; -import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.odm.core.impl.BaseUnitTestPerson; -import org.springframework.ldap.odm.core.impl.UnitTestPerson; -import org.springframework.ldap.query.LdapQuery; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; - -import java.lang.reflect.Method; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Mattias Hellborg Arthursson - * @author Eddu Melendez - */ -@ContextConfiguration("classpath:/query-test.xml") -public class PartTreeLdapRepositoryQueryTest extends AbstractJUnit4SpringContextTests { - - @Autowired - private LdapTemplate ldapTemplate; - private Class targetClass; - private Class entityClass; - private DefaultRepositoryMetadata repositoryMetadata; - private ProjectionFactory factory; - - @Before - public void prepareTest() { - entityClass = UnitTestPerson.class; - targetClass = UnitTestPersonRepository.class; - repositoryMetadata = new DefaultRepositoryMetadata(targetClass); - factory = new SpelAwareProxyProjectionFactory(); - } - - @Test - public void testFindByFullName() throws NoSuchMethodException { - assertFilterForMethod( - targetClass.getMethod("findByFullName", String.class), - "(cn=John Doe)", - "John Doe"); - } - - // LDAP-314 - @Test - public void testFindByFullNameWithBase() throws NoSuchMethodException { - entityClass = BaseUnitTestPerson.class; - targetClass = BaseTestPersonRepository.class; - repositoryMetadata = new DefaultRepositoryMetadata(targetClass); - assertFilterAndBaseForMethod( - targetClass.getMethod("findByFullName", String.class), - "(cn=John Doe)", - "ou=someOu", - "John Doe"); - } - - @Test - public void testFindByFullNameLike() throws NoSuchMethodException { - assertFilterForMethod( - targetClass.getMethod("findByFullNameLike", String.class), - "(cn=*John*)", - "*John*"); - } - - @Test - public void testFindByFullNameStartsWith() throws NoSuchMethodException { - assertFilterForMethod( - targetClass.getMethod("findByFullNameStartsWith", String.class), - "(cn=John*)", - "John"); - } - - @Test - public void testFindByFullNameEndsWith() throws NoSuchMethodException { - assertFilterForMethod( - targetClass.getMethod("findByFullNameEndsWith", String.class), - "(cn=*John)", - "John"); - } - - @Test - public void testFindByFullNameContains() throws NoSuchMethodException { - assertFilterForMethod( - targetClass.getMethod("findByFullNameContains", String.class), - "(cn=*John*)", - "John"); - } - - @Test - public void testFindByFullNameGreaterThanEqual() throws NoSuchMethodException { - assertFilterForMethod( - targetClass.getMethod("findByFullNameGreaterThanEqual", String.class), - "(cn>=John)", - "John"); - } - - @Test - public void testFindByFullNameLessThanEqual() throws NoSuchMethodException { - assertFilterForMethod( - targetClass.getMethod("findByFullNameLessThanEqual", String.class), - "(cn<=John)", - "John"); - } - - @Test - public void testFindByFullNameIsNotNull() throws NoSuchMethodException { - assertFilterForMethod( - targetClass.getMethod("findByFullNameIsNotNull"), - "(cn=*)"); - } - - @Test - public void testFindByFullNameIsNull() throws NoSuchMethodException { - assertFilterForMethod( - targetClass.getMethod("findByFullNameIsNull"), - "(!(cn=*))"); - } - - @Test - public void testFindByFullNameNot() throws NoSuchMethodException { - assertFilterForMethod( - targetClass.getMethod("findByFullNameNot", String.class), - "(!(cn=John Doe))", - "John Doe"); - } - - @Test - public void testFindByFullNameNotLike() throws NoSuchMethodException { - assertFilterForMethod( - targetClass.getMethod("findByFullNameNotLike", String.class), - "(!(cn=*John*))", - "*John*"); - } - - @Test - public void testFindByFullNameAndLastName() throws NoSuchMethodException { - assertFilterForMethod( - targetClass.getMethod("findByFullNameAndLastName", String.class, String.class), - "(&(cn=John Doe)(sn=Doe))", - "John Doe", "Doe"); - } - - @Test - public void testFindByFullNameAndLastNameNot() throws NoSuchMethodException { - assertFilterForMethod( - targetClass.getMethod("findByFullNameAndLastNameNot", String.class, String.class), - "(&(cn=John Doe)(!(sn=Doe)))", - "John Doe", "Doe"); - } - - private void assertFilterForMethod(Method targetMethod, String expectedFilter, Object... expectedParams) { - assertFilterAndBaseForMethod(targetMethod, expectedFilter, "", - expectedParams); - } - - private void assertFilterAndBaseForMethod(Method targetMethod, String expectedFilter, String expectedBase, Object... expectedParams) { - LdapQueryMethod queryMethod = new LdapQueryMethod(targetMethod, repositoryMetadata, factory); - PartTreeLdapRepositoryQuery tested = new PartTreeLdapRepositoryQuery(queryMethod, entityClass, ldapTemplate); - - LdapQuery query = tested.createQuery(expectedParams); - String base = query.base().toString(); - assertThat(base).isEqualTo(expectedBase); - assertThat(query.filter().encode()).isEqualTo(expectedFilter); - } -} diff --git a/core/src/test/java/org/springframework/ldap/repository/query/UnitTestPersonRepository.java b/core/src/test/java/org/springframework/ldap/repository/query/UnitTestPersonRepository.java deleted file mode 100644 index 04ce36b8..00000000 --- a/core/src/test/java/org/springframework/ldap/repository/query/UnitTestPersonRepository.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.repository.query; - -import org.springframework.ldap.odm.core.impl.UnitTestPerson; -import org.springframework.ldap.repository.LdapRepository; - -import java.util.List; - -/** - * @author Mattias Hellborg Arthursson - */ -public interface UnitTestPersonRepository extends LdapRepository { - List findByFullName(String name); - List findByFullNameNot(String name); - List findByFullNameLike(String name); - List findByFullNameNotLike(String name); - List findByFullNameStartsWith(String name); - List findByFullNameEndsWith(String name); - List findByFullNameContains(String name); - List findByFullNameGreaterThanEqual(String name); - List findByFullNameLessThanEqual(String name); - List findByFullNameIsNotNull(); - List findByFullNameIsNull(); - - List findByFullNameAndLastName(String fullName, String lastName); - List findByFullNameAndLastNameNot(String fullName, String lastName); - -} diff --git a/core/src/test/java/org/springframework/ldap/repository/support/QPerson.java b/core/src/test/java/org/springframework/ldap/repository/support/QPerson.java deleted file mode 100644 index b7c24f93..00000000 --- a/core/src/test/java/org/springframework/ldap/repository/support/QPerson.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.springframework.ldap.repository.support; - -import com.querydsl.core.types.Path; -import com.querydsl.core.types.PathMetadata; -import com.querydsl.core.types.dsl.EntityPathBase; -import com.querydsl.core.types.dsl.ListPath; -import com.querydsl.core.types.dsl.PathInits; -import com.querydsl.core.types.dsl.StringPath; -import org.springframework.ldap.odm.core.impl.UnitTestPerson; - -import javax.annotation.Generated; - -import static com.querydsl.core.types.PathMetadataFactory.forVariable; - - -/** - * QPerson is a Querydsl query type for Person - */ -@Generated("com.mysema.query.codegen.EntitySerializer") -public class QPerson extends EntityPathBase { - - private static final long serialVersionUID = -1526737794; - - public static final QPerson person = new QPerson("person"); - - public final StringPath fullName = createString("fullName"); - - public final ListPath description = this.createList("description", String.class, StringPath.class, PathInits.DIRECT2); - - public final StringPath lastName = createString("lastName"); - - public QPerson(String variable) { - super(UnitTestPerson.class, forVariable(variable)); - } - - public QPerson(Path path) { - super(path.getType(), path.getMetadata()); - } - - public QPerson(PathMetadata metadata) { - super(UnitTestPerson.class, metadata); - } - -} - diff --git a/core/src/test/java/org/springframework/ldap/repository/support/QueryDslFilterGeneratorTest.java b/core/src/test/java/org/springframework/ldap/repository/support/QueryDslFilterGeneratorTest.java deleted file mode 100644 index 05fc78d3..00000000 --- a/core/src/test/java/org/springframework/ldap/repository/support/QueryDslFilterGeneratorTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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; -import org.junit.Before; -import org.junit.Test; -import org.springframework.ldap.filter.Filter; -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.assertj.core.api.Assertions.assertThat; - -/** - * @author Mattias Hellborg Arthursson - * @author Eddu Melendez - */ -public class QueryDslFilterGeneratorTest { - - private LdapSerializer tested; - private QPerson person; - - @Before - public void prepareTestedInstance() { - ObjectDirectoryMapper odm = new DefaultObjectDirectoryMapper(); - tested = new LdapSerializer(odm, UnitTestPerson.class); - person = QPerson.person; - } - - @Test - public void testEqualsFilter() { - Expression expression = person.fullName.eq("John Doe"); - Filter result = tested.handle(expression); - 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); - 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); - assertThat(result.toString()).isEqualTo("(|(cn=John Doe)(sn=Doe))"); - } - - @Test - public void testOr() { - Expression expression = person.fullName.eq("John Doe") - .and(person.lastName.eq("Doe").or(person.lastName.eq("Die"))); - - Filter result = tested.handle(expression); - 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); - assertThat(result.toString()).isEqualTo("(!(cn=John Doe))"); - } - - @Test - public void testIsLike() { - Expression expression = person.fullName.like("kalle*"); - Filter result = tested.handle(expression); - assertThat(result.toString()).isEqualTo("(cn=kalle*)"); - } - - @Test - public void testStartsWith() { - Expression expression = person.fullName.startsWith("kalle"); - Filter result = tested.handle(expression); - assertThat(result.toString()).isEqualTo("(cn=kalle*)"); - } - - @Test - public void testEndsWith() { - Expression expression = person.fullName.endsWith("kalle"); - Filter result = tested.handle(expression); - assertThat(result.toString()).isEqualTo("(cn=*kalle)"); - } - - @Test - public void testContains() { - Expression expression = person.fullName.contains("kalle"); - Filter result = tested.handle(expression); - assertThat(result.toString()).isEqualTo("(cn=*kalle*)"); - } - - @Test - public void testNotNull() { - Expression expression = person.fullName.isNotNull(); - Filter result = tested.handle(expression); - assertThat(result.toString()).isEqualTo("(cn=*)"); - } - - @Test - public void testNull() { - Expression expression = person.fullName.isNull(); - Filter result = tested.handle(expression); - assertThat(result.toString()).isEqualTo("(!(cn=*))"); - } -} diff --git a/core/src/test/resources/ldap-namespace-config-with-repositories.xml b/core/src/test/resources/ldap-namespace-config-with-repositories.xml deleted file mode 100644 index 538e0bfd..00000000 --- a/core/src/test/resources/ldap-namespace-config-with-repositories.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index e6ff2793..ebfb3463 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,7 +17,6 @@ include 'test/integration-tests-sunone' include 'test/integration-tests-ad' include 'samples/plain' include 'samples/odm' -include 'samples/user-admin' rootProject.children.each { p-> diff --git a/test/integration-tests/build.gradle b/test/integration-tests/build.gradle index 5e882579..51089689 100644 --- a/test/integration-tests/build.gradle +++ b/test/integration-tests/build.gradle @@ -65,23 +65,7 @@ dependencies { } } -task generateQueryDSL(type: JavaCompile, group: 'build', description: 'Generates the QueryDSL query types') { - source = sourceSets.main.java - classpath = configurations.compile - options.compilerArgs = [ - "-proc:only", - "-processor", "org.springframework.ldap.repository.support.LdapAnnotationProcessor" - ] - destinationDir = sourceSets.generated.java.srcDirs.iterator().next() -} - -compileJava { - dependsOn generateQueryDSL - source generateQueryDSL.destinationDir -} - compileGeneratedJava { - dependsOn generateQueryDSL options.warnings = false classpath += sourceSets.main.runtimeClasspath } @@ -90,8 +74,6 @@ clean { delete sourceSets.generated.java.srcDirs } -ideaModule.dependsOn generateQueryDSL - idea { module { sourceDirs += file('build/generated-src') diff --git a/test/integration-tests/src/main/java/org/springframework/ldap/itest/config/SpringLdapConfiguration.java b/test/integration-tests/src/main/java/org/springframework/ldap/itest/config/SpringLdapConfiguration.java deleted file mode 100644 index cde84231..00000000 --- a/test/integration-tests/src/main/java/org/springframework/ldap/itest/config/SpringLdapConfiguration.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.springframework.ldap.itest.config; - -import org.springframework.context.annotation.Configuration; -import org.springframework.ldap.repository.config.EnableLdapRepositories; - -/** - * @author Mattias Hellborg Arthursson - */ -@Configuration -@EnableLdapRepositories(basePackages = "org.springframework.ldap.itest.repositories") -public class SpringLdapConfiguration { -} diff --git a/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonQueryDslRepository.java b/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonQueryDslRepository.java deleted file mode 100644 index dd78a9c1..00000000 --- a/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonQueryDslRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.springframework.ldap.itest.repositories; - -import org.springframework.data.querydsl.QueryDslPredicateExecutor; -import org.springframework.ldap.itest.odm.Person; -import org.springframework.ldap.repository.LdapRepository; - -/** - * @author Mattias Hellborg Arthursson - */ -public interface PersonQueryDslRepository extends LdapRepository, QueryDslPredicateExecutor { -} diff --git a/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonRepository.java b/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonRepository.java deleted file mode 100644 index a372ab8f..00000000 --- a/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonRepository.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.itest.repositories; - -import org.springframework.ldap.itest.odm.Person; -import org.springframework.ldap.repository.Query; -import org.springframework.ldap.repository.LdapRepository; - -/** - * @author Mattias Hellborg Arthursson - */ -public interface PersonRepository extends LdapRepository { - @Query("(sn={0})") - Iterable findByLastName(String lastName); - - @Query("(uid={0})") - Person findByUid(String uid); - - Person findByTelephoneNumber(String phoneNumber); -} diff --git a/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonWithDnAnnotationsRepository.java b/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonWithDnAnnotationsRepository.java deleted file mode 100644 index 8fe5fb7c..00000000 --- a/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonWithDnAnnotationsRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.springframework.ldap.itest.repositories; - -import org.springframework.ldap.itest.odm.PersonWithDnAnnotations; -import org.springframework.ldap.repository.LdapRepository; - -/** - * @author Mattias Hellborg Arthursson - */ -public interface PersonWithDnAnnotationsRepository extends LdapRepository { -} diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateQueryDslLdapQueryITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateQueryDslLdapQueryITest.java deleted file mode 100644 index 2c781a37..00000000 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateQueryDslLdapQueryITest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.itest.odm; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest; -import org.springframework.ldap.repository.support.QueryDslLdapQuery; -import org.springframework.test.context.ContextConfiguration; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Mattias Hellborg Arthursson - */ -@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"}) -public class LdapTemplateQueryDslLdapQueryITest extends AbstractLdapTemplateIntegrationTest { - @Autowired - private LdapTemplate tested; - private QPerson qperson; - private QueryDslLdapQuery query; - - @Before - public void prepareTestedInstance() { - qperson = QPerson.person; - query = new QueryDslLdapQuery(tested, qperson); - } - - @Test - public void testUniqueResult() { - Person person = query.where(qperson.commonName.eq("Some Person3")).uniqueResult(); - - assertThat(person).isNotNull(); - assertThat(person.getCommonName()).isEqualTo("Some Person3"); - assertThat(person.getSurname()).isEqualTo("Person3"); - assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); - assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - } - - @Test - public void testList() { - List persons = query.where(qperson.commonName.eq("Some Person3")).list(); - - Person person = persons.get(0); - assertThat(person.getCommonName()).isEqualTo("Some Person3"); - assertThat(person.getSurname()).isEqualTo("Person3"); - assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); - assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - } -} diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanAnnotationConfiguredITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanAnnotationConfiguredITest.java deleted file mode 100644 index 5918315b..00000000 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanAnnotationConfiguredITest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.itest.repository; - -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest; -import org.springframework.ldap.itest.odm.Person; -import org.springframework.ldap.itest.repositories.PersonRepository; -import org.springframework.ldap.support.LdapUtils; -import org.springframework.test.context.ContextConfiguration; - -import javax.naming.Name; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for Spring LDAP automatic repository scan functionality enabled with - * {@link org.springframework.ldap.repository.config.EnableLdapRepositories}. - * - * @author Mattias Hellborg Arthursson - */ -@ContextConfiguration(locations = {"/conf/repositoryScanAnnotationTestContext.xml"}) -public class RepositoryScanAnnotationConfiguredITest extends AbstractLdapTemplateIntegrationTest { - private static final Name PERSON3_DN = LdapUtils.newLdapName("cn=Some Person3, ou=Company1, ou=Sweden"); - - @Autowired - private PersonRepository tested; - - @Test - public void testExists() { - assertThat(tested.exists(PERSON3_DN)).isTrue(); - } - - @Test - public void testFindOneWithDn() { - Person person = tested.findOne(PERSON3_DN); - - assertThat(person).isNotNull(); - assertThat(person.getCommonName()).isEqualTo("Some Person3"); - assertThat(person.getSurname()).isEqualTo("Person3"); - assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); - assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - } -} diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanITest.java deleted file mode 100644 index 7d6894b2..00000000 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanITest.java +++ /dev/null @@ -1,261 +0,0 @@ -/* - * 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.itest.repository; - -import org.apache.commons.lang.StringUtils; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest; -import org.springframework.ldap.itest.odm.Person; -import org.springframework.ldap.itest.repositories.PersonRepository; -import org.springframework.ldap.support.LdapNameBuilder; -import org.springframework.ldap.support.LdapUtils; -import org.springframework.test.context.ContextConfiguration; - -import javax.naming.Name; -import javax.naming.ldap.LdapName; -import java.util.Arrays; -import java.util.Iterator; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; -import static org.springframework.ldap.query.LdapQueryBuilder.query; - -/** - * Tests for Spring LDAP automatic repository scan functionality. - * - * @author Mattias Hellborg Arthursson - */ -@ContextConfiguration(locations = {"/conf/repositoryScanTestContext.xml"}) -public class RepositoryScanITest extends AbstractLdapTemplateIntegrationTest { - private static final Name PERSON1_DN = LdapUtils.newLdapName("cn=Some Person, ou=Company1, ou=Sweden"); - private static final Name PERSON3_DN = LdapUtils.newLdapName("cn=Some Person3, ou=Company1, ou=Sweden"); - - @Autowired - private PersonRepository tested; - - @Test - public void testExists() { - assertThat(tested.exists(PERSON3_DN)).isTrue(); - } - - @Test - public void testFindOneWithDn() { - Person person = tested.findOne(PERSON3_DN); - - assertThat(person).isNotNull(); - assertThat(person.getCommonName()).isEqualTo("Some Person3"); - assertThat(person.getSurname()).isEqualTo("Person3"); - assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); - assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - } - - @Test - public void verifyThatFindOneWithNonexistingDnReturnsNull() { - Person person = tested.findOne(LdapUtils.newLdapName("cn=unknown")); - assertThat(person).isNull(); - } - - @Test - public void testFindOneWithQuery() { - Person person = tested.findOne(query().where("cn").is("Some Person3")); - - assertThat(person).isNotNull(); - assertThat(person.getCommonName()).isEqualTo("Some Person3"); - assertThat(person.getSurname()).isEqualTo("Person3"); - assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); - assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - } - - @Test - public void testFindAll() { - Iterable result = tested.findAll(); - assertThat(countIterable(result)).isEqualTo(5); - - for (Person person : result) { - if(StringUtils.equals(person.getCommonName(), "Some Person3")) { - assertThat(person.getCommonName()).isEqualTo("Some Person3"); - assertThat(person.getSurname()).isEqualTo("Person3"); - assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); - assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - - // Done - return; - } - } - - fail("Entry not found"); - } - - @Test - public void testFindAllWithQuery() { - Iterable persons = tested.findAll(query().where("cn").is("Some Person3")); - - assertThat(persons).isNotNull(); - Iterator iterator = persons.iterator(); - Person person = iterator.next(); - - assertThat(person.getCommonName()).isEqualTo("Some Person3"); - assertThat(person.getSurname()).isEqualTo("Person3"); - assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); - assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - - assertThat(iterator.hasNext()).isFalse(); - } - - @Test - public void testFindAllWithIterable() { - Iterable persons = tested.findAll(Arrays.asList(PERSON1_DN, PERSON3_DN)); - Iterator iterator = persons.iterator(); - Person person = iterator.next(); - - assertThat(person.getCommonName()).isEqualTo("Some Person"); - assertThat(person.getSurname()).isEqualTo("Person"); - assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person"); - assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123456"); - - person = iterator.next(); - - assertThat(person.getCommonName()).isEqualTo("Some Person3"); - assertThat(person.getSurname()).isEqualTo("Person3"); - assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); - assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - - assertThat(iterator.hasNext()).isFalse(); - } - - @Test - public void verifyThatFindAllWithIterableFiltersNotFoundEntries() { - Iterable persons = tested.findAll(Arrays.asList(LdapUtils.newLdapName("cn=unknown"), PERSON3_DN)); - Iterator iterator = persons.iterator(); - Person person = iterator.next(); - - assertThat(person.getCommonName()).isEqualTo("Some Person3"); - assertThat(person.getSurname()).isEqualTo("Person3"); - assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); - assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - - assertThat(iterator.hasNext()).isFalse(); - } - - @Test - public void testCount() { - assertThat(tested.count()).isEqualTo(5); - } - - private int countIterable(Iterable iterable) { - int count = 0; - - for (Object o : iterable) { - count++; - } - return count; - } - - @Test - public void testCreate() { - Person person = new Person(); - LdapName dn = LdapNameBuilder.newInstance("ou=company1,ou=Sweden") - .add("cn", "New Person").build(); - person.setDn(dn); - person.setCommonName("New Person"); - person.setSurname("Person"); - person.setDesc(Arrays.asList("This is the description")); - person.setTelephoneNumber("0123456"); - person.setNew(); - tested.save(person); - - assertThat(tested.count()).isEqualTo(6); - - person = tested.findOne(dn); - - assertThat(person.getCommonName()).isEqualTo("New Person"); - assertThat(person.getSurname()).isEqualTo("Person"); - assertThat(person.getDesc().get(0)).isEqualTo("This is the description"); - assertThat(person.getTelephoneNumber()).isEqualTo("0123456"); - } - - @Test(expected = IllegalArgumentException.class) - public void verifyThatCreateWithNoIdSetAndNotAbleToCalculateThrowsIllegalArgument() { - Person person = new Person(); - person.setCommonName("New Person"); - person.setSurname("Person"); - person.setDesc(Arrays.asList("This is the description")); - person.setTelephoneNumber("0123456"); - person.setNew(); - tested.save(person); - } - - @Test - public void testUpdate() { - Person person = tested.findOne(query().where("cn").is("Some Person3")); - - person.setDesc(Arrays.asList("New Description")); - tested.save(person); - - person = tested.findOne(query().where("cn").is("Some Person3")); - - assertThat(person.getCommonName()).isEqualTo("Some Person3"); - assertThat(person.getSurname()).isEqualTo("Person3"); - assertThat(person.getDesc().get(0)).isEqualTo("New Description"); - assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - } - - @Test - public void testDelete() { - Person person = tested.findOne(query().where("cn").is("Some Person3")); - tested.delete(person); - - Person found = tested.findOne(query().where("cn").is("Some Person3")); - assertThat(found).isNull(); - } - - @Test - public void testDeleteWithIterable() { - Iterable found = tested.findAll(Arrays.asList(PERSON1_DN, PERSON3_DN)); - tested.delete(found); - - assertThat(tested.count()).isEqualTo(3); - } - - @Test - public void testFindByLastName() { - Iterable found = tested.findByLastName("Person3"); - assertThat(countIterable(found)).isEqualTo(1); - } - - @Test - public void testFindByUid() { - Person person = tested.findByUid("some.person3"); - - assertThat(person.getCommonName()).isEqualTo("Some Person3"); - assertThat(person.getSurname()).isEqualTo("Person3"); - assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); - assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - } - - @Test - public void testFindByPhoneNumber() { - Person person = tested.findByTelephoneNumber("+46 555-123654"); - - assertThat(person.getCommonName()).isEqualTo("Some Person3"); - assertThat(person.getSurname()).isEqualTo("Person3"); - assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); - assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - } - -} diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanQueryDslITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanQueryDslITest.java deleted file mode 100644 index b2f6985d..00000000 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanQueryDslITest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.itest.repository; - -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest; -import org.springframework.ldap.itest.odm.Person; -import org.springframework.ldap.itest.odm.QPerson; -import org.springframework.ldap.itest.repositories.PersonQueryDslRepository; -import org.springframework.test.context.ContextConfiguration; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for Spring LDAP automatic repository scan functionality. - * - * @author Mattias Hellborg Arthursson - */ -@ContextConfiguration(locations = {"/conf/repositoryScanTestContext.xml"}) -public class RepositoryScanQueryDslITest extends AbstractLdapTemplateIntegrationTest { - - @Autowired - private PersonQueryDslRepository tested; - - @Test - public void testFindOneWithPredicate() { - QPerson person = QPerson.person; - - Person found = tested.findOne(person.commonName.eq("Some Person3")); - - assertThat(found).isNotNull(); - assertThat(found.getCommonName()).isEqualTo("Some Person3"); - assertThat(found.getSurname()).isEqualTo("Person3"); - assertThat(found.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); - assertThat(found.getTelephoneNumber()).isEqualTo("+46 555-123654"); - } - - @Test - public void testFindAllWithPredicate() { - QPerson person = QPerson.person; - - Iterable foundPersons = tested.findAll(person.commonName.eq("Some Person3")); - - Person found = foundPersons.iterator().next(); - assertThat(found.getCommonName()).isEqualTo("Some Person3"); - assertThat(found.getSurname()).isEqualTo("Person3"); - assertThat(found.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); - assertThat(found.getTelephoneNumber()).isEqualTo("+46 555-123654"); - } - - @Test - public void testCountWithPredicate() { - QPerson person = QPerson.person; - - long count = tested.count(person.commonName.eq("Some Person3")); - assertThat(count).isEqualTo(1); - } -} diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanWithDnAnnotationsITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanWithDnAnnotationsITest.java deleted file mode 100644 index cd89aca5..00000000 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanWithDnAnnotationsITest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.itest.repository; - -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest; -import org.springframework.ldap.itest.odm.PersonWithDnAnnotations; -import org.springframework.ldap.itest.repositories.PersonWithDnAnnotationsRepository; -import org.springframework.ldap.support.LdapUtils; -import org.springframework.test.context.ContextConfiguration; - -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.ldap.query.LdapQueryBuilder.query; - -/** - * Tests for Spring LDAP automatic repository scan functionality. - * - * @author Mattias Hellborg Arthursson - */ -@ContextConfiguration(locations = {"/conf/repositoryScanTestContext.xml"}) -public class RepositoryScanWithDnAnnotationsITest extends AbstractLdapTemplateIntegrationTest { - @Autowired - private PersonWithDnAnnotationsRepository tested; - - @Test - public void verifyThatCreateWithNoIdSetWillAutomaticallyCalculateDn() { - PersonWithDnAnnotations person = new PersonWithDnAnnotations(); - person.setCommonName("New Person"); - person.setSurname("Person"); - person.setDesc(Arrays.asList("This is the description")); - person.setTelephoneNumber("0123456"); - person.setCountry("Sweden"); - person.setCompany("company1"); - - assertThat(person.getDn()).isNull(); - - tested.save(person); - - assertThat(person.getDn()).isNotNull(); - - assertThat(tested.count()).isEqualTo(6); - - person = tested.findOne(query().where("cn").is("New Person")); - - assertThat(person.getCommonName()).isEqualTo("New Person"); - assertThat(person.getSurname()).isEqualTo("Person"); - assertThat(person.getDesc().get(0)).isEqualTo("This is the description"); - assertThat(person.getTelephoneNumber()).isEqualTo("0123456"); - } - - @Test - public void verifyThatMovedEntryGetsUpdatedId() { - PersonWithDnAnnotations found = tested.findOne(query().where("cn").is("Some Person3")); - assertThat(found).isNotNull(); - - assertThat(found.getDn()).isEqualTo(LdapUtils.newLdapName("cn=Some Person3,ou=company1,ou=Sweden")); - - found.setCompany("company2"); - - tested.save(found); - - assertThat(found.getDn()).isEqualTo(LdapUtils.newLdapName("cn=Some Person3,ou=company2,ou=Sweden")); - } -}