Skip to content

No longer show the routing key inspection warning when the method is … #328

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

Merged
merged 2 commits into from
Mar 11, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Axon Framework plugin Changelog

## [0.9.2]
- No longer show the routing key inspection warning when the method is not annotated with a relevant handler annotation.
- Fix false positive on versions not equal to 4

## [0.9.1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ class JavaMissingRoutingKeyOnAggregateMemberInspection : AbstractBaseJavaLocalIn
?: entity.routingKey
?: return null

if (method.hasAnnotation(AxonAnnotation.EVENT_SOURCING_HANDLER) &&
entityMember.eventForwardingMode != "org.axonframework.modelling.command.ForwardMatchingInstances"
) {
val isEventSourcingHandler = method.hasAnnotation(AxonAnnotation.EVENT_SOURCING_HANDLER)
if(!isEventSourcingHandler && !method.hasAnnotation(AxonAnnotation.COMMAND_HANDLER)) {
return null
}

if (isEventSourcingHandler && entityMember.eventForwardingMode != "org.axonframework.modelling.command.ForwardMatchingInstances") {
return null
}
val payload = method.resolvePayloadType() ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ class KotlinMissingRoutingKeyOnAggregateMemberInspection : AbstractKotlinInspect
val routingKey = entityMember.routingKey
?: entity.routingKey
?: return
if (method.hasAnnotation(AxonAnnotation.EVENT_SOURCING_HANDLER) &&
entityMember.eventForwardingMode != "org.axonframework.modelling.command.ForwardMatchingInstances"
) {
val isEventSourcingHandler = method.hasAnnotation(AxonAnnotation.EVENT_SOURCING_HANDLER)
if(!isEventSourcingHandler && !method.hasAnnotation(AxonAnnotation.COMMAND_HANDLER)) {
return
}
if (isEventSourcingHandler && entityMember.eventForwardingMode != "org.axonframework.modelling.command.ForwardMatchingInstances") {
return
}
val payload = method.resolvePayloadType() ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,45 @@ class JavaMissingRoutingKeyOnAggregateMemberInspectionTest : AbstractAxonFixture
}
}

fun `test will not show problem if has no handler annotation`() {
addFile(
"MyCommand.java", """
class MyCommand {}
""".trimIndent()
)

addFile(
"MyEntity.java", """
import test.MyCommand;

class MyEntity {
@EntityId
private String myEntityId;

public void handle(MyCommand command) {}
}
""".trimIndent(), open = true
)

addFile(
"MyAggregate.java", """
import test.MyEntity;
import java.util.List;

@AggregateRoot
class MyAggregate {
@AggregateMember
List<MyEntity> entities;
""".trimIndent()
)

myFixture.enableInspections(JavaMissingRoutingKeyOnAggregateMemberInspection())
val highlights = myFixture.doHighlighting(HighlightSeverity.WARNING)
Assertions.assertThat(highlights).noneMatch {
it.text == "handle" && it.description.contains("The payload requires a myEntityId property or getter")
}
}

fun `test will not show problem when key is present`() {
addFile(
"MyCommand.java", """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,45 @@ class KotlinMissingRoutingKeyOnAggregateMemberInspectionTest : AbstractAxonFixtu
}
}

fun `test will not show problem if has no handler annotation`() {
addFile(
"MyCommand.kt", """
class MyCommand {}
""".trimIndent()
)

addFile(
"MyEntity.kt", """
import test.MyCommand

class MyEntity {
@EntityId
private lateinit var myEntityId: String

fun handle(command: MyCommand) {}
}
""".trimIndent(), open = true
)

addFile(
"MyAggregate.kt", """
import test.MyEntity
import java.util.List

@AggregateRoot
class MyAggregate {
@AggregateMember
private lateinit var entities: List<MyEntity>
""".trimIndent()
)

myFixture.enableInspections(KotlinMissingRoutingKeyOnAggregateMemberInspection())
val highlights = myFixture.doHighlighting(HighlightSeverity.WARNING)
Assertions.assertThat(highlights).noneMatch {
it.text == "handle" && it.description.contains("The payload requires a myEntityId property or getter")
}
}

fun `test will not show problem when key is present`() {
addFile(
"MyCommand.kt", """
Expand Down
Loading