|
|
|
@ -15,7 +15,12 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.springframework.data.util; |
|
|
|
package org.springframework.data.util; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.*; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatNoException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.net.URLClassLoader; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.springframework.aot.generate.ClassNameGenerator; |
|
|
|
import org.springframework.aot.generate.ClassNameGenerator; |
|
|
|
@ -26,7 +31,6 @@ import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; |
|
|
|
import org.springframework.data.aot.sample.ConfigWithQuerydslPredicateExecutor.Person; |
|
|
|
import org.springframework.data.aot.sample.ConfigWithQuerydslPredicateExecutor.Person; |
|
|
|
import org.springframework.data.aot.sample.QConfigWithQuerydslPredicateExecutor_Person; |
|
|
|
import org.springframework.data.aot.sample.QConfigWithQuerydslPredicateExecutor_Person; |
|
|
|
import org.springframework.data.classloadersupport.HidingClassLoader; |
|
|
|
import org.springframework.data.classloadersupport.HidingClassLoader; |
|
|
|
import org.springframework.data.querydsl.User; |
|
|
|
|
|
|
|
import org.springframework.javapoet.ClassName; |
|
|
|
import org.springframework.javapoet.ClassName; |
|
|
|
|
|
|
|
|
|
|
|
import com.querydsl.core.types.EntityPath; |
|
|
|
import com.querydsl.core.types.EntityPath; |
|
|
|
@ -34,6 +38,7 @@ import com.querydsl.core.types.EntityPath; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Unit tests for {@link QTypeContributor}. |
|
|
|
* Unit tests for {@link QTypeContributor}. |
|
|
|
* |
|
|
|
* |
|
|
|
|
|
|
|
* @author Christoph Strobl |
|
|
|
* @author ckdgus08 |
|
|
|
* @author ckdgus08 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class QTypeContributorUnitTests { |
|
|
|
class QTypeContributorUnitTests { |
|
|
|
@ -75,58 +80,52 @@ class QTypeContributorUnitTests { |
|
|
|
RuntimeHintsPredicates.reflection().onType(QConfigWithQuerydslPredicateExecutor_Person.class).negate()); |
|
|
|
RuntimeHintsPredicates.reflection().onType(QConfigWithQuerydslPredicateExecutor_Person.class).negate()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-4958
|
|
|
|
@Test // GH-3284
|
|
|
|
void doesNotAddQTypeHintForArrayType() { |
|
|
|
void doesNotFailForArrayType() { |
|
|
|
|
|
|
|
|
|
|
|
GenerationContext generationContext = new DefaultGenerationContext( |
|
|
|
GenerationContext generationContext = new DefaultGenerationContext( |
|
|
|
new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles()); |
|
|
|
new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles()); |
|
|
|
|
|
|
|
|
|
|
|
QTypeContributor.contributeEntityPath(Person[].class, generationContext, HidingClassLoader.hideTypes()); |
|
|
|
assertThatNoException().isThrownBy( |
|
|
|
|
|
|
|
() -> QTypeContributor.contributeEntityPath(Person[].class, generationContext, HidingClassLoader.hideTypes())); |
|
|
|
assertThat(generationContext.getRuntimeHints()).matches( |
|
|
|
|
|
|
|
RuntimeHintsPredicates.reflection().onType(QConfigWithQuerydslPredicateExecutor_Person.class).negate()); |
|
|
|
|
|
|
|
assertThat(generationContext.getRuntimeHints()).matches( |
|
|
|
|
|
|
|
RuntimeHintsPredicates.reflection().onType(QConfigWithQuerydslPredicateExecutor_Person[].class).negate()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-4958
|
|
|
|
@Test // GH-3284
|
|
|
|
void addsQTypeHintForQUserType() { |
|
|
|
void doesNotFailForPrimitiveType() { |
|
|
|
|
|
|
|
|
|
|
|
GenerationContext generationContext = new DefaultGenerationContext( |
|
|
|
GenerationContext generationContext = new DefaultGenerationContext( |
|
|
|
new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles()); |
|
|
|
new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles()); |
|
|
|
|
|
|
|
|
|
|
|
QTypeContributor.contributeEntityPath(User.class, generationContext, getClass().getClassLoader()); |
|
|
|
assertThatNoException().isThrownBy( |
|
|
|
|
|
|
|
() -> QTypeContributor.contributeEntityPath(int.class, generationContext, getClass().getClassLoader())); |
|
|
|
var qUserHintCount = generationContext.getRuntimeHints().reflection().typeHints() |
|
|
|
|
|
|
|
.filter(hint -> hint.getType().getName().equals("org.springframework.data.querydsl.QUser")) |
|
|
|
|
|
|
|
.count(); |
|
|
|
|
|
|
|
assertThat(qUserHintCount).isEqualTo(1); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-4958
|
|
|
|
@Test // GH-3284
|
|
|
|
void doesNotAddQTypeHintForQUserArrayType() { |
|
|
|
void doesNotFailForTypeInDefaultPackage() throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
GenerationContext generationContext = new DefaultGenerationContext( |
|
|
|
GenerationContext generationContext = new DefaultGenerationContext( |
|
|
|
new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles()); |
|
|
|
new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles()); |
|
|
|
var classLoader = getClass().getClassLoader(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QTypeContributor.contributeEntityPath(User[].class, generationContext, classLoader); |
|
|
|
class CapturingClassLoader extends ClassLoader { |
|
|
|
|
|
|
|
|
|
|
|
assertThat(generationContext.getRuntimeHints().reflection().typeHints()).isEmpty(); |
|
|
|
final Set<String> lookups = new HashSet<>(10); |
|
|
|
var qUserHintCount = generationContext.getRuntimeHints().reflection().typeHints() |
|
|
|
|
|
|
|
.filter(hint -> hint.getType().getName().equals("org.springframework.data.querydsl.QUser")) |
|
|
|
|
|
|
|
.count(); |
|
|
|
|
|
|
|
assertThat(qUserHintCount).isEqualTo(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-4958
|
|
|
|
CapturingClassLoader() { |
|
|
|
void doesNotAddQTypeHintForPrimitiveType() { |
|
|
|
super(URLClassLoader.getSystemClassLoader()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GenerationContext generationContext = new DefaultGenerationContext( |
|
|
|
@Override |
|
|
|
new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles()); |
|
|
|
public Class<?> loadClass(String name) throws ClassNotFoundException { |
|
|
|
|
|
|
|
lookups.add(name); |
|
|
|
|
|
|
|
return super.loadClass(name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QTypeContributor.contributeEntityPath(int.class, generationContext, getClass().getClassLoader()); |
|
|
|
CapturingClassLoader classLoaderToUse = new CapturingClassLoader(); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(generationContext.getRuntimeHints().reflection().typeHints()).isEmpty(); |
|
|
|
var typeInDefaultPackage = Class.forName("TypeInDefaultPackage"); |
|
|
|
|
|
|
|
assertThatNoException().isThrownBy( |
|
|
|
|
|
|
|
() -> QTypeContributor.contributeEntityPath(typeInDefaultPackage, generationContext, classLoaderToUse)); |
|
|
|
|
|
|
|
assertThat(classLoaderToUse.lookups).contains("QTypeInDefaultPackage"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|