DATALDAP-45 - Introduced usage of nullable annotations for API validation.
Mark all packages with Spring Frameworks @NonNullApi. Add Spring's @Nullable to methods, parameters and fields that take or produce null values. Adapt using code to make sure the IDE can evaluate the null flow properly. Introduce methods that return required (non-null) values.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 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.
|
||||
@@ -34,7 +34,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link EnableLdapRepositories#repositoryBaseClass()}.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 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.
|
||||
@@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.ldap.repository.support.BaseUnitTestPerson;
|
||||
@@ -35,23 +34,17 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Eddu Melendez
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@ContextConfiguration
|
||||
public class PartTreeLdapRepositoryQueryTests 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();
|
||||
}
|
||||
private Class<?> entityClass = UnitTestPerson.class;
|
||||
private Class<?> targetClass = UnitTestPersonRepository.class;
|
||||
private DefaultRepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(targetClass);
|
||||
private ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
|
||||
|
||||
@Test
|
||||
public void testFindByFullName() throws NoSuchMethodException {
|
||||
@@ -61,9 +54,11 @@ public class PartTreeLdapRepositoryQueryTests extends AbstractJUnit4SpringContex
|
||||
// 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");
|
||||
}
|
||||
@@ -136,6 +131,7 @@ public class PartTreeLdapRepositoryQueryTests extends AbstractJUnit4SpringContex
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 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.
|
||||
@@ -17,7 +17,6 @@ package org.springframework.data.ldap.repository.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.ldap.filter.Filter;
|
||||
import org.springframework.ldap.odm.core.ObjectDirectoryMapper;
|
||||
@@ -31,92 +30,108 @@ import com.querydsl.core.types.Expression;
|
||||
*/
|
||||
public class QuerydslFilterGeneratorTests {
|
||||
|
||||
private LdapSerializer tested;
|
||||
private QPerson person;
|
||||
|
||||
@Before
|
||||
public void prepareTestedInstance() {
|
||||
ObjectDirectoryMapper odm = new DefaultObjectDirectoryMapper();
|
||||
tested = new LdapSerializer(odm, UnitTestPerson.class);
|
||||
person = QPerson.person;
|
||||
}
|
||||
private ObjectDirectoryMapper odm = new DefaultObjectDirectoryMapper();
|
||||
private LdapSerializer tested = new LdapSerializer(odm, UnitTestPerson.class);
|
||||
private QPerson 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=*))");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user