Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add _id postfix to channelId
Browse files Browse the repository at this point in the history
timonback committed Aug 28, 2024
1 parent 5c27763 commit c8831d7
Showing 16 changed files with 300 additions and 295 deletions.
Original file line number Diff line number Diff line change
@@ -7,6 +7,6 @@ public class ReferenceUtil {
private static final String FORBIDDEN_ID_CHARACTER = "/";

public static String toValidId(String name) {
return name.replaceAll(FORBIDDEN_ID_CHARACTER, "_"); // TODO: easier to verify correct usage +"_id";
return name.replaceAll(FORBIDDEN_ID_CHARACTER, "_") + ID_POSTFIX;
}
}
Original file line number Diff line number Diff line change
@@ -10,6 +10,6 @@ class ReferenceUtilTest {
void shouldCorrectIllegalCharacter() {
String name = "users/{userId}";

assertThat(ReferenceUtil.toValidId(name)).isEqualTo("users_{userId}");
assertThat(ReferenceUtil.toValidId(name)).isEqualTo("users_{userId}_id");
}
}
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@
import java.util.Map;
import java.util.Set;

import static io.github.springwolf.asyncapi.v3.model.ReferenceUtil.ID_POSTFIX;
import static java.util.Collections.EMPTY_MAP;
import static java.util.Collections.emptyList;
import static java.util.Collections.singleton;
@@ -187,7 +188,7 @@ void scan_componentHasListenerMethodWithUnknownServer() {
assertThatThrownBy(channelScanner::scan)
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(
"Operation 'test_channel_send' defines unknown server ref 'server3'. This AsyncApi defines these server(s): [server1, server2]");
"Operation 'test_channel_id_send' defines unknown server ref 'server3'. This AsyncApi defines these server(s): [server1, server2]");
}

@Test
@@ -249,23 +250,23 @@ void scan_componentHasMultipleListenerAnnotations() {
.build();

ChannelObject expectedChannel1 = ChannelObject.builder()
.channelId("test-channel-1")
.channelId("test-channel-1" + ID_POSTFIX)
.address("test-channel-1")
.messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message)))
.bindings(null)
.build();

ChannelObject expectedChannel2 = ChannelObject.builder()
.channelId("test-channel-2")
.channelId("test-channel-2" + ID_POSTFIX)
.address("test-channel-2")
.messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message)))
.bindings(null)
.build();

assertThat(actualChannels)
.containsExactlyInAnyOrderEntriesOf(Map.of(
"test-channel-1", expectedChannel1,
"test-channel-2", expectedChannel2));
"test-channel-1_id", expectedChannel1,
"test-channel-2_id", expectedChannel2));
}

@Test
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@
import java.util.Map;
import java.util.Set;

import static io.github.springwolf.asyncapi.v3.model.ReferenceUtil.ID_POSTFIX;
import static java.util.Collections.EMPTY_MAP;
import static java.util.Collections.emptyList;
import static java.util.Collections.singleton;
@@ -169,16 +170,16 @@ void scan_componentOperationHasListenerMethod() {
.build();

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

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

@Test
@@ -206,15 +207,15 @@ void scan_componentHasListenerMethodWithAllAttributes() {

Operation expectedOperation = Operation.builder()
.action(OperationAction.SEND)
.title("test-channel_send")
.channel(ChannelReference.fromChannel("test-channel"))
.title("test-channel_id_send")
.channel(ChannelReference.fromChannel("test-channel" + ID_POSTFIX))
.description("description")
.bindings(Map.of(TestOperationBindingProcessor.TYPE, TestOperationBindingProcessor.BINDING))
.messages(List.of(MessageReference.toChannelMessage("test-channel", message)))
.messages(List.of(MessageReference.toChannelMessage("test-channel" + ID_POSTFIX, message)))
.build();

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

@Test
@@ -243,26 +244,26 @@ void scan_componentHasMultipleListenerAnnotations() {

Operation expectedOperation1 = Operation.builder()
.action(OperationAction.SEND)
.channel(ChannelReference.fromChannel("test-channel-1"))
.channel(ChannelReference.fromChannel("test-channel-1" + ID_POSTFIX))
.description("test-channel-1-description")
.title("test-channel-1_send")
.title("test-channel-1_id_send")
.bindings(EMPTY_MAP)
.messages(List.of(MessageReference.toChannelMessage("test-channel-1", message)))
.messages(List.of(MessageReference.toChannelMessage("test-channel-1" + ID_POSTFIX, message)))
.build();

Operation expectedOperation2 = Operation.builder()
.action(OperationAction.SEND)
.channel(ChannelReference.fromChannel("test-channel-2"))
.channel(ChannelReference.fromChannel("test-channel-2" + ID_POSTFIX))
.description("test-channel-2-description")
.title("test-channel-2_send")
.title("test-channel-2_id_send")
.bindings(EMPTY_MAP)
.messages(List.of(MessageReference.toChannelMessage("test-channel-2", message)))
.messages(List.of(MessageReference.toChannelMessage("test-channel-2" + ID_POSTFIX, message)))
.build();

assertThat(actualOperations)
.containsExactlyInAnyOrderEntriesOf(Map.of(
"test-channel-1_send_methodWithMultipleAnnotation", expectedOperation1,
"test-channel-2_send_methodWithMultipleAnnotation", expectedOperation2));
"test-channel-1_id_send_methodWithMultipleAnnotation", expectedOperation1,
"test-channel-2_id_send_methodWithMultipleAnnotation", expectedOperation2));
}

@Test
@@ -291,15 +292,15 @@ void scan_componentHasAsyncMethodAnnotation() {

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

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

@Test
@@ -328,15 +329,15 @@ void scan_componentHasAsyncMethodAnnotationInAbstractClass() {

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

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

@Test
@@ -471,11 +472,11 @@ void scan_componentHasOnlyDeclaredMethods(Class<?> clazz) {

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

ChannelObject expectedChannel = ChannelObject.builder()
@@ -484,7 +485,7 @@ void scan_componentHasOnlyDeclaredMethods(Class<?> clazz) {
.build();

assertThat(actualOperations)
.containsExactly(Map.entry("test-channel_send_methodFromInterface", expectedOperation));
.containsExactly(Map.entry("test-channel_id_send_methodFromInterface", expectedOperation));
}

private static class ClassImplementingInterface implements ClassInterface<String> {
@@ -546,11 +547,11 @@ void scan_componentHasListenerMethodWithMetaAnnotation() {

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

ChannelObject expectedChannel = ChannelObject.builder()
@@ -559,7 +560,7 @@ void scan_componentHasListenerMethodWithMetaAnnotation() {
.build();

assertThat(actualOperations)
.containsExactly(Map.entry("test-channel_send_methodFromInterface", expectedOperation));
.containsExactly(Map.entry("test-channel_id_send_methodFromInterface", expectedOperation));
}

public static class ClassWithMetaAnnotation {
Original file line number Diff line number Diff line change
@@ -37,8 +37,8 @@ void asyncListenerAnnotationIsFound() {
AsyncAPI asyncAPI = asyncApiService.getAsyncAPI();
assertThat(asyncAPI).isNotNull();

assertThat(asyncAPI.getChannels()).containsOnlyKeys("listener-channel");
assertThat(asyncAPI.getOperations()).containsOnlyKeys("listener-channel_receive_listen");
assertThat(asyncAPI.getChannels()).containsOnlyKeys("listener-channel_id");
assertThat(asyncAPI.getOperations()).containsOnlyKeys("listener-channel_id_receive_listen");
assertThat(asyncAPI.getComponents().getMessages()).containsOnlyKeys("java.lang.String");
assertThat(asyncAPI.getComponents().getSchemas())
.containsOnlyKeys("HeadersNotDocumented", "java.lang.String");
@@ -61,8 +61,8 @@ void asyncPublisherAnnotationIsFound() {
AsyncAPI asyncAPI = asyncApiService.getAsyncAPI();
assertThat(asyncAPI).isNotNull();

assertThat(asyncAPI.getChannels()).containsOnlyKeys("publisher-channel");
assertThat(asyncAPI.getOperations()).containsOnlyKeys("publisher-channel_send_publish");
assertThat(asyncAPI.getChannels()).containsOnlyKeys("publisher-channel_id");
assertThat(asyncAPI.getOperations()).containsOnlyKeys("publisher-channel_id_send_publish");
assertThat(asyncAPI.getComponents().getMessages()).containsOnlyKeys("java.lang.String");
assertThat(asyncAPI.getComponents().getSchemas())
.containsOnlyKeys("HeadersNotDocumented", "java.lang.String");
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@
}
}
},
"example-topic-exchange": {
"example-topic-exchange_id": {
"address": "example-topic-exchange",
"messages": {
"io.github.springwolf.examples.amqp.dtos.AnotherPayloadDto": {
@@ -491,12 +491,12 @@
}
]
},
"example-topic-exchange_send_sendMessage": {
"example-topic-exchange_id_send_sendMessage": {
"action": "send",
"channel": {
"$ref": "#/channels/example-topic-exchange"
"$ref": "#/channels/example-topic-exchange_id"
},
"title": "example-topic-exchange_send",
"title": "example-topic-exchange_id_send",
"description": "Custom, optional description defined in the AsyncPublisher annotation",
"bindings": {
"amqp": {
@@ -512,7 +512,7 @@
},
"messages": [
{
"$ref": "#/channels/example-topic-exchange/messages/io.github.springwolf.examples.amqp.dtos.AnotherPayloadDto"
"$ref": "#/channels/example-topic-exchange_id/messages/io.github.springwolf.examples.amqp.dtos.AnotherPayloadDto"
}
]
},
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ channels:
autoDelete: false
vhost: /
bindingVersion: 0.4.0
example-topic-exchange:
example-topic-exchange_id:
address: example-topic-exchange
messages:
io.github.springwolf.examples.amqp.dtos.AnotherPayloadDto:
@@ -341,11 +341,11 @@ operations:
bindingVersion: 0.4.0
messages:
- $ref: "#/channels/example-queue_id/messages/io.github.springwolf.examples.amqp.dtos.ExamplePayloadDto"
example-topic-exchange_send_sendMessage:
example-topic-exchange_id_send_sendMessage:
action: send
channel:
$ref: "#/channels/example-topic-exchange"
title: example-topic-exchange_send
$ref: "#/channels/example-topic-exchange_id"
title: example-topic-exchange_id_send
description: "Custom, optional description defined in the AsyncPublisher annotation"
bindings:
amqp:
@@ -358,7 +358,7 @@ operations:
ack: false
bindingVersion: 0.4.0
messages:
- $ref: "#/channels/example-topic-exchange/messages/io.github.springwolf.examples.amqp.dtos.AnotherPayloadDto"
- $ref: "#/channels/example-topic-exchange_id/messages/io.github.springwolf.examples.amqp.dtos.AnotherPayloadDto"
multi-payload-queue_id_receive_bindingsBeanExample:
action: receive
channel:
Loading

0 comments on commit c8831d7

Please sign in to comment.