Remove Spring Data
Fixes gh-436
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
package org.springframework.ldap.config;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class DummyEntity {
|
||||
}
|
||||
@@ -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<DummyEntity, Name> {
|
||||
}
|
||||
@@ -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<String, BeanDefinitionParser> parsers = WhiteboxImpl.getInternalState(handler, "parsers");
|
||||
assertFalse(parsers.containsKey(Elements.REPOSITORIES));
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -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<Object> tested;
|
||||
|
||||
@Before
|
||||
public void prepareTestedInstance() {
|
||||
ldapOperationsMock = mock(LdapOperations.class);
|
||||
odmMock = mock(ObjectDirectoryMapper.class);
|
||||
tested = new SimpleLdapRepository<Object>(ldapOperationsMock, odmMock, Object.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCount() {
|
||||
Filter filterMock = mock(Filter.class);
|
||||
when(odmMock.filterFor(Object.class, null)).thenReturn(filterMock);
|
||||
ArgumentCaptor<LdapQuery> 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<Object> actualResult = tested.findAll(Arrays.asList(expectedName1, expectedName2));
|
||||
|
||||
Iterator<Object> 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<Object> actualResult = tested.findAll(Arrays.asList(expectedName1, expectedName2));
|
||||
|
||||
Iterator<Object> iterator = actualResult.iterator();
|
||||
assertThat(iterator.next()).isSameAs(expectedResult2);
|
||||
|
||||
assertThat(iterator.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -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<UnitTestPerson> {
|
||||
List<BaseUnitTestPerson> findByFullName(String name);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<UnitTestPerson> {
|
||||
List<UnitTestPerson> findByFullName(String name);
|
||||
List<UnitTestPerson> findByFullNameNot(String name);
|
||||
List<UnitTestPerson> findByFullNameLike(String name);
|
||||
List<UnitTestPerson> findByFullNameNotLike(String name);
|
||||
List<UnitTestPerson> findByFullNameStartsWith(String name);
|
||||
List<UnitTestPerson> findByFullNameEndsWith(String name);
|
||||
List<UnitTestPerson> findByFullNameContains(String name);
|
||||
List<UnitTestPerson> findByFullNameGreaterThanEqual(String name);
|
||||
List<UnitTestPerson> findByFullNameLessThanEqual(String name);
|
||||
List<UnitTestPerson> findByFullNameIsNotNull();
|
||||
List<UnitTestPerson> findByFullNameIsNull();
|
||||
|
||||
List<UnitTestPerson> findByFullNameAndLastName(String fullName, String lastName);
|
||||
List<UnitTestPerson> findByFullNameAndLastNameNot(String fullName, String lastName);
|
||||
|
||||
}
|
||||
@@ -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<UnitTestPerson> {
|
||||
|
||||
private static final long serialVersionUID = -1526737794;
|
||||
|
||||
public static final QPerson person = new QPerson("person");
|
||||
|
||||
public final StringPath fullName = createString("fullName");
|
||||
|
||||
public final ListPath<String, StringPath> description = this.<String, StringPath>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<? extends UnitTestPerson> path) {
|
||||
super(path.getType(), path.getMetadata());
|
||||
}
|
||||
|
||||
public QPerson(PathMetadata metadata) {
|
||||
super(UnitTestPerson.class, metadata);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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=*))");
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:ldap="http://www.springframework.org/schema/ldap"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
|
||||
|
||||
<ldap:context-source password="apassword" url="ldap://localhost:389" username="uid=admin"/>
|
||||
<ldap:ldap-template />
|
||||
|
||||
<ldap:repositories base-package="org.springframework.ldap.config" />
|
||||
</beans>
|
||||
Reference in New Issue
Block a user