Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) Add support to parse Annotations from super classes #731

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.StringValueResolver;

Expand Down Expand Up @@ -58,7 +59,7 @@ protected Stream<MethodAndAnnotation<A>> getAnnotatedMethods(Class<?> type) {
Class<A> annotationClass = this.asyncAnnotationProvider.getAnnotation();
log.debug("Scanning class \"{}\" for @\"{}\" annotated methods", type.getName(), annotationClass.getName());

return Arrays.stream(type.getDeclaredMethods())
return Arrays.stream(ReflectionUtils.getAllDeclaredMethods(type))
.filter(method -> !method.isBridge())
.filter(method -> AnnotationScannerUtil.findAnnotation(annotationClass, method) != null)
.peek(method -> log.debug("Mapping method \"{}\" to channels", method.getName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,43 @@ void scan_componentHasAsyncMethodAnnotation() {
.containsExactly(Map.entry("test-channel_send_methodWithAnnotation", expectedOperation));
}

@Test
void scan_componentHasAsyncMethodAnnotationInAbstractClass() {
// Given a class with methods annotated with AsyncListener, where only the channel-name is set
setClassToScan(ClassExtendsFromAbstractWithListenerAnnotation.class);

// When scan is called
Map<String, Operation> actualOperations = operationsScanner.scan();

// Then the returned collection contains the channel
MessagePayload payload = MessagePayload.of(MultiFormatSchema.builder()
.schema(SchemaReference.fromSchema(SimpleFoo.class.getSimpleName()))
.build());

MessageObject message = MessageObject.builder()
.messageId("simpleFoo")
.name("SimpleFooPayLoad")
.title("Message Title")
.description("Message description")
.payload(payload)
.headers(MessageHeaders.of(
MessageReference.toSchema(AsyncHeadersNotDocumented.NOT_DOCUMENTED.getTitle())))
.bindings(EMPTY_MAP)
.build();

Operation expectedOperation = Operation.builder()
.action(OperationAction.SEND)
.channel(ChannelReference.fromChannel("abstract-test-channel"))
.description("test abstract channel operation description")
.title("abstract-test-channel_send")
.bindings(EMPTY_MAP)
.messages(List.of(MessageReference.toChannelMessage("abstract-test-channel", message)))
.build();

assertThat(actualOperations)
.containsExactly(Map.entry("abstract-test-channel_send_methodWithAnnotation", expectedOperation));
}

private static class ClassWithoutListenerAnnotation {

private void methodWithoutAnnotation() {}
Expand Down Expand Up @@ -370,6 +407,25 @@ private void methodWithAnnotation(SimpleFoo payload) {}
private void methodWithoutAnnotation() {}
}

private static class ClassExtendsFromAbstractWithListenerAnnotation extends AbstractClassWithListenerAnnotation {}

private abstract static class AbstractClassWithListenerAnnotation {

@AsyncListener(
operation =
@AsyncOperation(
channelName = "abstract-test-channel",
description = "test abstract channel operation description",
message =
@AsyncMessage(
description = "Message description",
messageId = "simpleFooAbstract",
name = "SimpleFooPayLoad",
contentType = "application/json",
title = "Message Title")))
protected void methodWithAnnotation(SimpleFoo payload) {}
}

@Nested
class ImplementingInterface {
@ParameterizedTest
Expand Down