Skip to content

Commit 2b75a2e

Browse files
committed
test(core): minor cleanup and adding reference to verifying collections
1 parent 87a3b55 commit 2b75a2e

File tree

3 files changed

+36
-106
lines changed

3 files changed

+36
-106
lines changed

springwolf-core/src/test/java/io/github/springwolf/core/integrationtests/application/GroupingIntegrationTest.java

Lines changed: 0 additions & 84 deletions
This file was deleted.

springwolf-core/src/test/java/io/github/springwolf/core/integrationtests/application/GroupingWithComplexSchemaIntegrationTest.java

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
import io.github.springwolf.asyncapi.v3.model.AsyncAPI;
55
import io.github.springwolf.asyncapi.v3.model.channel.message.MessageObject;
6+
import io.github.springwolf.asyncapi.v3.model.components.ComponentSchema;
67
import io.github.springwolf.asyncapi.v3.model.schema.SchemaReference;
78
import io.github.springwolf.core.asyncapi.AsyncApiService;
89
import io.github.springwolf.core.fixtures.SpringwolfIntegrationTest;
9-
import io.github.springwolf.core.integrationtests.application.complexSchema.PublisherGroupingComplexSchemaApplication;
10+
import io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication;
1011
import org.junit.jupiter.api.Nested;
1112
import org.junit.jupiter.api.Test;
1213
import org.springframework.beans.factory.annotation.Autowired;
@@ -16,7 +17,7 @@
1617
import static org.assertj.core.api.Assertions.assertThat;
1718

1819
@Nested
19-
@SpringBootTest(classes = PublisherGroupingComplexSchemaApplication.class)
20+
@SpringBootTest(classes = ComplexSchemaApplication.class)
2021
@SpringwolfIntegrationTest
2122
@TestPropertySource(
2223
properties = {
@@ -34,36 +35,48 @@ class GroupingWithComplexSchemaIntegrationTest {
3435
private AsyncApiService asyncApiService;
3536

3637
@Test
37-
void shouldFindOnlyForGroupFoo() {
38+
void shouldFindOnlyForGroupUserMessage() {
3839
AsyncAPI asyncAPI = asyncApiService.getForGroupName("UserMessage").get();
3940

40-
assertThat(asyncAPI.getChannels().keySet()).containsExactlyInAnyOrder("publisher-channel");
41-
assertThat(asyncAPI.getChannels().get("publisher-channel").getMessages())
41+
assertThat(asyncAPI.getChannels().keySet()).containsExactlyInAnyOrder("publisher-channel2");
42+
assertThat(asyncAPI.getChannels().get("publisher-channel2").getMessages())
4243
.containsOnlyKeys(
43-
"io.github.springwolf.core.integrationtests.application.complexSchema.PublisherGroupingComplexSchemaApplication.ComplexPublisher.User");
44+
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.User");
4445
assertThat(asyncAPI.getOperations())
45-
.containsOnlyKeys("publisher-channel_send_publish1", "publisher-channel_send_publish2");
46+
.containsOnlyKeys("publisher-channel2_send_publish1", "publisher-channel2_send_publish2");
4647
assertThat(asyncAPI.getComponents().getMessages())
4748
.containsOnlyKeys(
48-
"io.github.springwolf.core.integrationtests.application.complexSchema.PublisherGroupingComplexSchemaApplication.ComplexPublisher.User");
49+
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.User");
4950
assertThat(asyncAPI.getComponents().getSchemas())
5051
.containsOnlyKeys(
5152
"HeadersNotDocumented",
52-
"io.github.springwolf.core.integrationtests.application.complexSchema.PublisherGroupingComplexSchemaApplication.ComplexPublisher.User",
53-
"io.github.springwolf.core.integrationtests.application.complexSchema.PublisherGroupingComplexSchemaApplication.ComplexPublisher.Address",
54-
"io.github.springwolf.core.integrationtests.application.complexSchema.PublisherGroupingComplexSchemaApplication.ComplexPublisher.City");
53+
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.User",
54+
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.Address",
55+
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.City");
5556

5657
MessageObject userMessage = (MessageObject)
5758
asyncAPI.getComponents()
5859
.getMessages()
5960
.get(
60-
"io.github.springwolf.core.integrationtests.application.complexSchema.PublisherGroupingComplexSchemaApplication.ComplexPublisher.User");
61+
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.User");
6162
assertThat(userMessage.getPayload().getMultiFormatSchema().getSchema()).isInstanceOf(SchemaReference.class);
62-
SchemaReference fooSchemaRef = (SchemaReference)
63+
SchemaReference userMessageToSchemaRef = (SchemaReference)
6364
userMessage.getPayload().getMultiFormatSchema().getSchema();
64-
assertThat(fooSchemaRef.getRef())
65+
assertThat(userMessageToSchemaRef.getRef())
6566
.isEqualTo(
66-
"#/components/schemas/io.github.springwolf.core.integrationtests.application.complexSchema.PublisherGroupingComplexSchemaApplication.ComplexPublisher.User");
67+
"#/components/schemas/io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.User");
68+
69+
// Verify that collection property is correctly represented using `items`
70+
ComponentSchema addressesSchema = (ComponentSchema) asyncAPI.getComponents()
71+
.getSchemas()
72+
.get(
73+
"io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.User")
74+
.getSchema()
75+
.getProperties()
76+
.get("addresses");
77+
assertThat(addressesSchema.getSchema().getItems().getReference().getRef())
78+
.isEqualTo(
79+
"#/components/schemas/io.github.springwolf.core.integrationtests.application.complexSchema.ComplexSchemaApplication.ComplexPublisher.Address");
6780
}
6881

6982
@Test

springwolf-core/src/test/java/io/github/springwolf/core/integrationtests/application/complexSchema/PublisherGroupingComplexSchemaApplication.java renamed to springwolf-core/src/test/java/io/github/springwolf/core/integrationtests/application/complexSchema/ComplexSchemaApplication.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@
1010
import java.util.List;
1111

1212
@SpringBootApplication
13-
public class PublisherGroupingComplexSchemaApplication {
13+
public class ComplexSchemaApplication {
14+
15+
@AsyncPublisher(operation = @AsyncOperation(channelName = "publisher-channel"))
16+
public void publish(List<String> payload) {}
17+
1418
@Bean
1519
public ComplexPublisher complexPublisher() {
1620
return new ComplexPublisher();
1721
}
1822

19-
static class ComplexPublisher {
20-
@AsyncPublisher(operation = @AsyncOperation(channelName = "publisher-channel"))
23+
public static class ComplexPublisher {
24+
@AsyncPublisher(operation = @AsyncOperation(channelName = "publisher-channel2"))
2125
public void publish1(User payload) {}
2226

23-
@AsyncPublisher(operation = @AsyncOperation(channelName = "publisher-channel"))
27+
@AsyncPublisher(operation = @AsyncOperation(channelName = "publisher-channel2"))
2428
public void publish2(List<User> payload) {}
2529

2630
public record User(String name, Integer age, Collection<Address> addresses) {}
@@ -29,7 +33,4 @@ public record Address(String streetName, String addition, City city) {}
2933

3034
public record City(String zipCode, String name) {}
3135
}
32-
33-
@AsyncPublisher(operation = @AsyncOperation(channelName = "publisher-channel2"))
34-
public void publish2(List<String> payload) {}
3536
}

0 commit comments

Comments
 (0)