Skip to content
Open
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 CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Contributing follows mostly the following steps:
- Add/Adapt tests as necessary
4. Run the tests
- Run tests locally via `./gradlew test` (includes `unitTest` and `integrationTest` targets, which executes faster)
- In case there are expected changes to the generated asyncapi artifacts, run `./gradlew test updateAsyncApiJson` to update them using the current (actual) files
5. Run the code formatter
- We use the palantir code style and disallow wildcard imports
- Run `./gradlew spotlessApply` to fix most things automatically
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.springwolf.core.integrationtests.application;

import io.github.springwolf.asyncapi.v3.model.AsyncAPI;
import io.github.springwolf.asyncapi.v3.model.channel.message.MessageObject;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaReference;
import io.github.springwolf.core.asyncapi.AsyncApiService;
import io.github.springwolf.core.fixtures.MinimalIntegrationTestContextConfiguration;
import io.github.springwolf.core.integrationtests.application.listener.ListenerApplication;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;

import static org.assertj.core.api.Assertions.assertThat;

@Nested
@SpringBootTest(classes = ListenerApplication.class)
@MinimalIntegrationTestContextConfiguration
@TestPropertySource(
properties = {
"springwolf.docket.base-package=io.github.springwolf.core.integrationtests.application.listener",
"springwolf.docket.group-configs[0].group=FooMessage",
"springwolf.docket.group-configs[0].action-to-match=",
"springwolf.docket.group-configs[0].channel-name-to-match=",
"springwolf.docket.group-configs[0].message-name-to-match=.*Foo",
"springwolf.docket.group-configs[1].group=all & everything",
"springwolf.docket.group-configs[1].action-to-match=",
"springwolf.docket.group-configs[1].channel-name-to-match=.*",
"springwolf.docket.group-configs[1].message-name-to-match=",
})
class GroupingIntegrationTest {
@Autowired
private AsyncApiService asyncApiService;

@Test
void shouldFindOnlyForGroupFoo() {
AsyncAPI asyncAPI = asyncApiService.getForGroupName("FooMessage").get();

assertThat(asyncAPI.getChannels().keySet()).containsExactlyInAnyOrder("listener-channel");
assertThat(asyncAPI.getChannels().get("listener-channel").getMessages())
.containsOnlyKeys(
"io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
assertThat(asyncAPI.getOperations())
.containsOnlyKeys("listener-channel_receive_listen3", "listener-channel_receive_listen4");
assertThat(asyncAPI.getComponents().getMessages())
.containsOnlyKeys(
"io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
assertThat(asyncAPI.getComponents().getSchemas())
.containsOnlyKeys(
"HeadersNotDocumented",
"io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Bar",
"io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");

MessageObject fooMessage = (MessageObject) asyncAPI.getComponents()
.getMessages()
.get("io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
assertThat(fooMessage.getPayload().getMultiFormatSchema().getSchema()).isInstanceOf(SchemaReference.class);
SchemaReference fooSchemaRef =
(SchemaReference) fooMessage.getPayload().getMultiFormatSchema().getSchema();
assertThat(fooSchemaRef.getRef())
.isEqualTo(
"#/components/schemas/io.github.springwolf.core.integrationtests.application.listener.ListenerApplication.Foo");
}

@Test
void shouldFindAllForGroupAll() {
// given
AsyncAPI fullApi = asyncApiService.getAsyncAPI();

// when
AsyncAPI asyncAPIOpt =
asyncApiService.getForGroupName("all & everything").get();

// then

// String and Integer get filtered.
// Question: Why are they in the fullApi in the first place, if not referenced? (inline schema)
fullApi.getComponents().getSchemas().remove(String.class.getName());
fullApi.getComponents().getSchemas().remove(Integer.class.getName());

assertThat(asyncAPIOpt).isEqualTo(fullApi);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.springwolf.core.integrationtests.application.schema;
package io.github.springwolf.core.integrationtests.application.ref;

import io.github.springwolf.core.asyncapi.annotations.AsyncListener;
import io.github.springwolf.core.asyncapi.annotations.AsyncOperation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void shouldCreateStandaloneFactoryForBasicApplicationWithProfile() {
.getAsyncAPI()
.getInfo()
.getTitle())
.isEqualTo("Springwolf-core-properties");
.isEqualTo("Springwolf-core-standalone");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ void shouldLoadStandaloneProfileIncludingPropertyFile() {

// then
assertThat(environment.getActiveProfiles()).containsExactly("standalone");
assertThat(environment.getProperty("spring.application.name")).isEqualTo("Springwolf-core-properties");
assertThat(environment.getProperty("spring.application.name")).isEqualTo("Springwolf-core-standalone");
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spring.application.name=Springwolf-core-properties
spring.application.name=Springwolf-core-standalone
2 changes: 1 addition & 1 deletion springwolf-core/src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ springwolf.enabled=true
springwolf.docket.base-package=io.github.springwolf.core.integrationtests
springwolf.docket.info.title=${spring.application.name}
springwolf.docket.info.version=1.0.0
springwolf.docket.info.description=Springwolf example project to demonstrate springwolfs abilities
springwolf.docket.info.description=Springwolf core integration test
springwolf.docket.servers.test-protocol.protocol=property-protocol
springwolf.docket.servers.test-protocol.host=some-property-server:1234
199 changes: 199 additions & 0 deletions springwolf-core/src/test/resources/application/asyncapi.fqn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
{
"asyncapi": "3.0.0",
"id": "urn:io:github:springwolf:example",
"info": {
"title": "Info title was loaded from spring properties",
"version": "1.0.0",
"description": "Springwolf core integration test",
"x-generator": "springwolf"
},
"defaultContentType": "application/json",
"servers": {
"test-protocol": {
"host": "some-server:1234",
"protocol": "test"
}
},
"channels": {
"listener-channel": {
"address": "listener-channel",
"messages": {
"Foo": {
"$ref": "#/components/messages/Foo"
},
"integer": {
"$ref": "#/components/messages/integer"
},
"string": {
"$ref": "#/components/messages/string"
}
},
"bindings": { }
}
},
"components": {
"schemas": {
"Bar": {
"title": "Bar",
"type": "object",
"properties": {
"aFieldInBarRecord": {
"type": "string"
}
},
"examples": [
{
"aFieldInBarRecord": "string"
}
]
},
"Foo": {
"title": "Foo",
"type": "object",
"properties": {
"aFieldInFooRecord": {
"$ref": "#/components/schemas/Bar"
}
},
"examples": [
{
"aFieldInFooRecord": {
"aFieldInBarRecord": "string"
}
}
]
},
"HeadersNotDocumented": {
"title": "HeadersNotDocumented",
"type": "object",
"properties": { },
"description": "There can be headers, but they are not explicitly documented.",
"examples": [
{ }
]
},
"integer": {
"type": "integer",
"format": "int32",
"examples": [
0
]
},
"string": {
"type": "string",
"examples": [
"\"string\""
]
}
},
"messages": {
"Foo": {
"headers": {
"$ref": "#/components/schemas/HeadersNotDocumented"
},
"payload": {
"schemaFormat": "application/vnd.aai.asyncapi+json;version=3.0.0",
"schema": {
"$ref": "#/components/schemas/Foo"
}
},
"name": "Foo",
"title": "Foo",
"bindings": { }
},
"integer": {
"headers": {
"$ref": "#/components/schemas/HeadersNotDocumented"
},
"payload": {
"schemaFormat": "application/vnd.aai.asyncapi+json;version=3.0.0",
"schema": {
"type": "integer",
"format": "int32",
"examples": [
0
]
}
},
"name": "integer",
"title": "integer",
"bindings": { }
},
"string": {
"headers": {
"$ref": "#/components/schemas/HeadersNotDocumented"
},
"payload": {
"schemaFormat": "application/vnd.aai.asyncapi+json;version=3.0.0",
"schema": {
"type": "string",
"examples": [
"\"string\""
]
}
},
"name": "string",
"title": "string",
"bindings": { }
}
}
},
"operations": {
"listener-channel_receive_listen": {
"action": "receive",
"channel": {
"$ref": "#/channels/listener-channel"
},
"title": "listener-channel_receive",
"description": "Auto-generated description",
"bindings": { },
"messages": [
{
"$ref": "#/channels/listener-channel/messages/string"
}
]
},
"listener-channel_receive_listen2": {
"action": "receive",
"channel": {
"$ref": "#/channels/listener-channel"
},
"title": "listener-channel_receive",
"description": "Auto-generated description",
"bindings": { },
"messages": [
{
"$ref": "#/channels/listener-channel/messages/string"
}
]
},
"listener-channel_receive_listen3": {
"action": "receive",
"channel": {
"$ref": "#/channels/listener-channel"
},
"title": "listener-channel_receive",
"description": "Auto-generated description",
"bindings": { },
"messages": [
{
"$ref": "#/channels/listener-channel/messages/Foo"
}
]
},
"listener-channel_receive_listen4": {
"action": "receive",
"channel": {
"$ref": "#/channels/listener-channel"
},
"title": "listener-channel_receive",
"description": "Auto-generated description",
"bindings": { },
"messages": [
{
"$ref": "#/channels/listener-channel/messages/integer"
}
]
}
}
}
Loading
Loading