Polishing
This commit is contained in:
@@ -16,16 +16,14 @@
|
||||
|
||||
package org.springframework.messaging.rsocket.service;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aop.SpringProxy;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aot.generate.GenerationContext;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.test.generate.TestGenerationContext;
|
||||
import org.springframework.beans.factory.aot.BeanRegistrationAotContribution;
|
||||
import org.springframework.beans.factory.aot.BeanRegistrationCode;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.RegisteredBean;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
@@ -35,50 +33,52 @@ import org.springframework.messaging.handler.annotation.Payload;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.proxies;
|
||||
|
||||
/**
|
||||
* Tests for {@link RSocketExchangeBeanRegistrationAotProcessor}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @author Olga Maciaszek-Sharma
|
||||
* @since 6.0.5
|
||||
*/
|
||||
class RSocketExchangeBeanRegistrationAotProcessorTests {
|
||||
|
||||
private final RSocketExchangeBeanRegistrationAotProcessor processor =
|
||||
new RSocketExchangeBeanRegistrationAotProcessor();
|
||||
|
||||
private final GenerationContext generationContext = new TestGenerationContext();
|
||||
|
||||
private final RuntimeHints runtimeHints = this.generationContext.getRuntimeHints();
|
||||
|
||||
|
||||
@Test
|
||||
void shouldProcessesAnnotatedInterface() {
|
||||
process(AnnotatedInterface.class);
|
||||
assertThat(RuntimeHintsPredicates.proxies().forInterfaces(AnnotatedInterface.class,
|
||||
SpringProxy.class, Advised.class, DecoratingProxy.class))
|
||||
.accepts(this.generationContext.getRuntimeHints());
|
||||
assertThat(proxies().forInterfaces(AnnotatedInterface.class, SpringProxy.class, Advised.class, DecoratingProxy.class))
|
||||
.accepts(this.runtimeHints);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSkipNonAnnotatedInterface() {
|
||||
process(NonAnnotatedInterface.class);
|
||||
assertThat(this.generationContext.getRuntimeHints().proxies().jdkProxyHints()).isEmpty();
|
||||
assertThat(this.runtimeHints.proxies().jdkProxyHints()).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
void process(Class<?> beanClass) {
|
||||
BeanRegistrationAotContribution contribution = createContribution(beanClass);
|
||||
if (contribution != null) {
|
||||
contribution.applyTo(this.generationContext, mock(BeanRegistrationCode.class));
|
||||
contribution.applyTo(this.generationContext, mock());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private BeanRegistrationAotContribution createContribution(Class<?> beanClass) {
|
||||
private static BeanRegistrationAotContribution createContribution(Class<?> beanClass) {
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerBeanDefinition(beanClass.getName(), new RootBeanDefinition(beanClass));
|
||||
return this.processor.processAheadOfTime(RegisteredBean.of(beanFactory, beanClass.getName()));
|
||||
|
||||
return new RSocketExchangeBeanRegistrationAotProcessor()
|
||||
.processAheadOfTime(RegisteredBean.of(beanFactory, beanClass.getName()));
|
||||
}
|
||||
|
||||
|
||||
interface NonAnnotatedInterface {
|
||||
|
||||
void notExchange();
|
||||
@@ -91,5 +91,3 @@ class RSocketExchangeBeanRegistrationAotProcessorTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,18 +21,19 @@ import java.lang.reflect.Method;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.messaging.handler.annotation.DestinationVariable;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.util.MimeType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.reflection;
|
||||
|
||||
/**
|
||||
* Tests for {@link RSocketExchangeReflectiveProcessor}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @author Olga Maciaszek-Sharma
|
||||
* @since 6.0.5
|
||||
*/
|
||||
class RSocketExchangeReflectiveProcessorTests {
|
||||
|
||||
@@ -40,6 +41,7 @@ class RSocketExchangeReflectiveProcessorTests {
|
||||
|
||||
private final RuntimeHints hints = new RuntimeHints();
|
||||
|
||||
|
||||
@Test
|
||||
void shouldRegisterReflectionHintsForMethod() throws NoSuchMethodException {
|
||||
Method method = SampleService.class.getDeclaredMethod("get", Request.class, Variable.class,
|
||||
@@ -47,36 +49,23 @@ class RSocketExchangeReflectiveProcessorTests {
|
||||
|
||||
processor.registerReflectionHints(hints.reflection(), method);
|
||||
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(SampleService.class))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleService.class, "get"))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(Response.class))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(Response.class, "getMessage"))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(Response.class, "setMessage"))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(Request.class))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(Request.class, "getMessage"))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(Request.class, "setMessage"))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(Variable.class))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(Variable.class, "getValue"))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(Variable.class, "setValue"))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(Metadata.class))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(Metadata.class, "getValue"))
|
||||
.accepts(hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(Metadata.class, "setValue"))
|
||||
.accepts(hints);
|
||||
assertThat(reflection().onType(SampleService.class)).accepts(hints);
|
||||
assertThat(reflection().onMethod(SampleService.class, "get")).accepts(hints);
|
||||
assertThat(reflection().onType(Response.class)).accepts(hints);
|
||||
assertThat(reflection().onMethod(Response.class, "getMessage")).accepts(hints);
|
||||
assertThat(reflection().onMethod(Response.class, "setMessage")).accepts(hints);
|
||||
assertThat(reflection().onType(Request.class)).accepts(hints);
|
||||
assertThat(reflection().onMethod(Request.class, "getMessage")).accepts(hints);
|
||||
assertThat(reflection().onMethod(Request.class, "setMessage")).accepts(hints);
|
||||
assertThat(reflection().onType(Variable.class)).accepts(hints);
|
||||
assertThat(reflection().onMethod(Variable.class, "getValue")).accepts(hints);
|
||||
assertThat(reflection().onMethod(Variable.class, "setValue")).accepts(hints);
|
||||
assertThat(reflection().onType(Metadata.class)).accepts(hints);
|
||||
assertThat(reflection().onMethod(Metadata.class, "getValue")).accepts(hints);
|
||||
assertThat(reflection().onMethod(Metadata.class, "setValue")).accepts(hints);
|
||||
}
|
||||
|
||||
|
||||
interface SampleService {
|
||||
|
||||
@RSocketExchange
|
||||
@@ -148,4 +137,5 @@ class RSocketExchangeReflectiveProcessorTests {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user