Skip to content

Commit 56adb40

Browse files
authored
chore(core): replace code based integration test with artifact base (#1509)
1 parent 100caee commit 56adb40

File tree

13 files changed

+1065
-181
lines changed

13 files changed

+1065
-181
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Contributing follows mostly the following steps:
4343
- Add/Adapt tests as necessary
4444
4. Run the tests
4545
- Run tests locally via `./gradlew test` (includes `unitTest` and `integrationTest` targets, which executes faster)
46+
- In case there are expected changes to the generated asyncapi artifacts, run `./gradlew test updateAsyncApiJson` to update them using the current (actual) files
4647
5. Run the code formatter
4748
- We use the palantir code style and disallow wildcard imports
4849
- Run `./gradlew spotlessApply` to fix most things automatically

springwolf-core/src/test/java/io/github/springwolf/core/integrationtests/AsyncApiDocumentIntegrationTest.java renamed to springwolf-core/src/test/java/io/github/springwolf/core/integrationtests/application/ApplicationIntegrationTest.java

Lines changed: 81 additions & 176 deletions
Large diffs are not rendered by default.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
package io.github.springwolf.core.integrationtests.application;
3+
4+
import io.github.springwolf.asyncapi.v3.model.AsyncAPI;
5+
import io.github.springwolf.asyncapi.v3.model.channel.message.MessageObject;
6+
import io.github.springwolf.asyncapi.v3.model.schema.SchemaReference;
7+
import io.github.springwolf.core.asyncapi.AsyncApiService;
8+
import io.github.springwolf.core.fixtures.MinimalIntegrationTestContextConfiguration;
9+
import io.github.springwolf.core.integrationtests.application.listener.ListenerApplication;
10+
import org.junit.jupiter.api.Nested;
11+
import org.junit.jupiter.api.Test;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.boot.test.context.SpringBootTest;
14+
import org.springframework.test.context.TestPropertySource;
15+
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
18+
@Nested
19+
@SpringBootTest(classes = ListenerApplication.class)
20+
@MinimalIntegrationTestContextConfiguration
21+
@TestPropertySource(
22+
properties = {
23+
"springwolf.docket.base-package=io.github.springwolf.core.integrationtests.application.listener",
24+
"springwolf.docket.group-configs[0].group=FooMessage",
25+
"springwolf.docket.group-configs[0].action-to-match=",
26+
"springwolf.docket.group-configs[0].channel-name-to-match=",
27+
"springwolf.docket.group-configs[0].message-name-to-match=.*Foo",
28+
"springwolf.docket.group-configs[1].group=all & everything",
29+
"springwolf.docket.group-configs[1].action-to-match=",
30+
"springwolf.docket.group-configs[1].channel-name-to-match=.*",
31+
"springwolf.docket.group-configs[1].message-name-to-match=",
32+
})
33+
class GroupingIntegrationTest {
34+
@Autowired
35+
private AsyncApiService asyncApiService;
36+
37+
@Test
38+
void shouldFindOnlyForGroupFoo() {
39+
AsyncAPI asyncAPI = asyncApiService.getForGroupName("FooMessage").get();
40+
41+
assertThat(asyncAPI.getChannels().keySet()).containsExactlyInAnyOrder("listener-channel");
42+
assertThat(asyncAPI.getChannels().get("listener-channel").getMessages())
43+
.containsOnlyKeys(
44+
"io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
45+
assertThat(asyncAPI.getOperations())
46+
.containsOnlyKeys("listener-channel_receive_listen3", "listener-channel_receive_listen4");
47+
assertThat(asyncAPI.getComponents().getMessages())
48+
.containsOnlyKeys(
49+
"io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
50+
assertThat(asyncAPI.getComponents().getSchemas())
51+
.containsOnlyKeys(
52+
"HeadersNotDocumented",
53+
"io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Bar",
54+
"io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
55+
56+
MessageObject fooMessage = (MessageObject) asyncAPI.getComponents()
57+
.getMessages()
58+
.get("io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
59+
assertThat(fooMessage.getPayload().getMultiFormatSchema().getSchema()).isInstanceOf(SchemaReference.class);
60+
SchemaReference fooSchemaRef =
61+
(SchemaReference) fooMessage.getPayload().getMultiFormatSchema().getSchema();
62+
assertThat(fooSchemaRef.getRef())
63+
.isEqualTo(
64+
"#/components/schemas/io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
65+
}
66+
67+
@Test
68+
void shouldFindAllForGroupAll() {
69+
// given
70+
AsyncAPI fullApi = asyncApiService.getAsyncAPI();
71+
72+
// when
73+
AsyncAPI asyncAPIOpt =
74+
asyncApiService.getForGroupName("all & everything").get();
75+
76+
// then
77+
78+
// String and Integer get filtered.
79+
// Question: Why are they in the fullApi in the first place, if not referenced? (inline schema)
80+
fullApi.getComponents().getSchemas().remove(String.class.getName());
81+
fullApi.getComponents().getSchemas().remove(Integer.class.getName());
82+
83+
assertThat(asyncAPIOpt).isEqualTo(fullApi);
84+
}
85+
}

springwolf-core/src/test/java/io/github/springwolf/core/integrationtests/application/schema/SchemaEnumAsRefApplication.java renamed to springwolf-core/src/test/java/io/github/springwolf/core/integrationtests/application/ref/SchemaEnumAsRefApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
package io.github.springwolf.core.integrationtests.application.schema;
2+
package io.github.springwolf.core.integrationtests.application.ref;
33

44
import io.github.springwolf.core.asyncapi.annotations.AsyncListener;
55
import io.github.springwolf.core.asyncapi.annotations.AsyncOperation;

springwolf-core/src/test/java/io/github/springwolf/core/standalone/DefaultStandaloneApplicationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void shouldCreateStandaloneFactoryForBasicApplicationWithProfile() {
6262
.getAsyncAPI()
6363
.getInfo()
6464
.getTitle())
65-
.isEqualTo("Springwolf-core-properties");
65+
.isEqualTo("Springwolf-core-standalone");
6666
}
6767

6868
@Test

springwolf-core/src/test/java/io/github/springwolf/core/standalone/StandaloneEnvironmentLoaderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ void shouldLoadStandaloneProfileIncludingPropertyFile() {
2727

2828
// then
2929
assertThat(environment.getActiveProfiles()).containsExactly("standalone");
30-
assertThat(environment.getProperty("spring.application.name")).isEqualTo("Springwolf-core-properties");
30+
assertThat(environment.getProperty("spring.application.name")).isEqualTo("Springwolf-core-standalone");
3131
}
3232
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
spring.application.name=Springwolf-core-properties
1+
spring.application.name=Springwolf-core-standalone

springwolf-core/src/test/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ springwolf.enabled=true
33
springwolf.docket.base-package=io.github.springwolf.core.integrationtests
44
springwolf.docket.info.title=${spring.application.name}
55
springwolf.docket.info.version=1.0.0
6-
springwolf.docket.info.description=Springwolf example project to demonstrate springwolfs abilities
6+
springwolf.docket.info.description=Springwolf core integration test
77
springwolf.docket.servers.test-protocol.protocol=property-protocol
88
springwolf.docket.servers.test-protocol.host=some-property-server:1234
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
{
2+
"asyncapi": "3.0.0",
3+
"id": "urn:io:github:springwolf:example",
4+
"info": {
5+
"title": "Info title was loaded from spring properties",
6+
"version": "1.0.0",
7+
"description": "Springwolf core integration test",
8+
"x-generator": "springwolf"
9+
},
10+
"defaultContentType": "application/json",
11+
"servers": {
12+
"test-protocol": {
13+
"host": "some-server:1234",
14+
"protocol": "test"
15+
}
16+
},
17+
"channels": {
18+
"listener-channel": {
19+
"address": "listener-channel",
20+
"messages": {
21+
"Foo": {
22+
"$ref": "#/components/messages/Foo"
23+
},
24+
"integer": {
25+
"$ref": "#/components/messages/integer"
26+
},
27+
"string": {
28+
"$ref": "#/components/messages/string"
29+
}
30+
},
31+
"bindings": { }
32+
}
33+
},
34+
"components": {
35+
"schemas": {
36+
"Bar": {
37+
"title": "Bar",
38+
"type": "object",
39+
"properties": {
40+
"aFieldInBarRecord": {
41+
"type": "string"
42+
}
43+
},
44+
"examples": [
45+
{
46+
"aFieldInBarRecord": "string"
47+
}
48+
]
49+
},
50+
"Foo": {
51+
"title": "Foo",
52+
"type": "object",
53+
"properties": {
54+
"aFieldInFooRecord": {
55+
"$ref": "#/components/schemas/Bar"
56+
}
57+
},
58+
"examples": [
59+
{
60+
"aFieldInFooRecord": {
61+
"aFieldInBarRecord": "string"
62+
}
63+
}
64+
]
65+
},
66+
"HeadersNotDocumented": {
67+
"title": "HeadersNotDocumented",
68+
"type": "object",
69+
"properties": { },
70+
"description": "There can be headers, but they are not explicitly documented.",
71+
"examples": [
72+
{ }
73+
]
74+
},
75+
"integer": {
76+
"type": "integer",
77+
"format": "int32",
78+
"examples": [
79+
0
80+
]
81+
},
82+
"string": {
83+
"type": "string",
84+
"examples": [
85+
"\"string\""
86+
]
87+
}
88+
},
89+
"messages": {
90+
"Foo": {
91+
"headers": {
92+
"$ref": "#/components/schemas/HeadersNotDocumented"
93+
},
94+
"payload": {
95+
"schemaFormat": "application/vnd.aai.asyncapi+json;version=3.0.0",
96+
"schema": {
97+
"$ref": "#/components/schemas/Foo"
98+
}
99+
},
100+
"name": "Foo",
101+
"title": "Foo",
102+
"bindings": { }
103+
},
104+
"integer": {
105+
"headers": {
106+
"$ref": "#/components/schemas/HeadersNotDocumented"
107+
},
108+
"payload": {
109+
"schemaFormat": "application/vnd.aai.asyncapi+json;version=3.0.0",
110+
"schema": {
111+
"type": "integer",
112+
"format": "int32",
113+
"examples": [
114+
0
115+
]
116+
}
117+
},
118+
"name": "integer",
119+
"title": "integer",
120+
"bindings": { }
121+
},
122+
"string": {
123+
"headers": {
124+
"$ref": "#/components/schemas/HeadersNotDocumented"
125+
},
126+
"payload": {
127+
"schemaFormat": "application/vnd.aai.asyncapi+json;version=3.0.0",
128+
"schema": {
129+
"type": "string",
130+
"examples": [
131+
"\"string\""
132+
]
133+
}
134+
},
135+
"name": "string",
136+
"title": "string",
137+
"bindings": { }
138+
}
139+
}
140+
},
141+
"operations": {
142+
"listener-channel_receive_listen": {
143+
"action": "receive",
144+
"channel": {
145+
"$ref": "#/channels/listener-channel"
146+
},
147+
"title": "listener-channel_receive",
148+
"description": "Auto-generated description",
149+
"bindings": { },
150+
"messages": [
151+
{
152+
"$ref": "#/channels/listener-channel/messages/string"
153+
}
154+
]
155+
},
156+
"listener-channel_receive_listen2": {
157+
"action": "receive",
158+
"channel": {
159+
"$ref": "#/channels/listener-channel"
160+
},
161+
"title": "listener-channel_receive",
162+
"description": "Auto-generated description",
163+
"bindings": { },
164+
"messages": [
165+
{
166+
"$ref": "#/channels/listener-channel/messages/string"
167+
}
168+
]
169+
},
170+
"listener-channel_receive_listen3": {
171+
"action": "receive",
172+
"channel": {
173+
"$ref": "#/channels/listener-channel"
174+
},
175+
"title": "listener-channel_receive",
176+
"description": "Auto-generated description",
177+
"bindings": { },
178+
"messages": [
179+
{
180+
"$ref": "#/channels/listener-channel/messages/Foo"
181+
}
182+
]
183+
},
184+
"listener-channel_receive_listen4": {
185+
"action": "receive",
186+
"channel": {
187+
"$ref": "#/channels/listener-channel"
188+
},
189+
"title": "listener-channel_receive",
190+
"description": "Auto-generated description",
191+
"bindings": { },
192+
"messages": [
193+
{
194+
"$ref": "#/channels/listener-channel/messages/integer"
195+
}
196+
]
197+
}
198+
}
199+
}

0 commit comments

Comments
 (0)