-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add discriminator field support + better integration tests in core (#600
) * test(core): add AsyncListener and AsyncPublisher integration test * feat(asyncapi): handle discriminator field * chore(core): formatting
- Loading branch information
Showing
12 changed files
with
234 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...ava/io/github/stavshamir/springwolf/integrationtests/AsyncApiDocumentIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf.integrationtests; | ||
|
||
import io.github.stavshamir.springwolf.asyncapi.AsyncApiService; | ||
import io.github.stavshamir.springwolf.asyncapi.v3.model.AsyncAPI; | ||
import io.github.stavshamir.springwolf.asyncapi.v3.model.channel.message.Message; | ||
import io.github.stavshamir.springwolf.asyncapi.v3.model.schema.SchemaObject; | ||
import io.github.stavshamir.springwolf.fixtures.MinimalIntegrationTestContextConfiguration; | ||
import io.github.stavshamir.springwolf.integrationtests.application.listener.ListenerApplication; | ||
import io.github.stavshamir.springwolf.integrationtests.application.polymorphic.PolymorphicPayloadApplication; | ||
import io.github.stavshamir.springwolf.integrationtests.application.publisher.PublisherApplication; | ||
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 java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class AsyncApiDocumentIntegrationTest { | ||
|
||
@Nested | ||
@SpringBootTest(classes = ListenerApplication.class) | ||
@MinimalIntegrationTestContextConfiguration | ||
@TestPropertySource( | ||
properties = { | ||
"springwolf.docket.base-package=io.github.stavshamir.springwolf.integrationtests.application.listener", | ||
}) | ||
class ListenerAnnotationTest { | ||
@Autowired | ||
private AsyncApiService asyncApiService; | ||
|
||
@Test | ||
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.getComponents().getMessages()).containsOnlyKeys("java.lang.String"); | ||
assertThat(asyncAPI.getComponents().getSchemas()).containsOnlyKeys("HeadersNotDocumented", "String"); | ||
} | ||
} | ||
|
||
@Nested | ||
@SpringBootTest(classes = PublisherApplication.class) | ||
@MinimalIntegrationTestContextConfiguration | ||
@TestPropertySource( | ||
properties = { | ||
"springwolf.docket.base-package=io.github.stavshamir.springwolf.integrationtests.application.publisher", | ||
}) | ||
class PublisherAnnotationTest { | ||
@Autowired | ||
private AsyncApiService asyncApiService; | ||
|
||
@Test | ||
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.getComponents().getMessages()).containsOnlyKeys("java.lang.String"); | ||
assertThat(asyncAPI.getComponents().getSchemas()).containsOnlyKeys("HeadersNotDocumented", "String"); | ||
} | ||
} | ||
|
||
@Nested | ||
@SpringBootTest(classes = PolymorphicPayloadApplication.class) | ||
@MinimalIntegrationTestContextConfiguration | ||
@TestPropertySource( | ||
properties = { | ||
"springwolf.docket.base-package=io.github.stavshamir.springwolf.integrationtests.application.polymorphic", | ||
}) | ||
class PolymorphicPayloadTest { | ||
@Autowired | ||
private AsyncApiService asyncApiService; | ||
|
||
@Test | ||
void polymorphicDiscriminatorFieldIsHandled() { | ||
// when | ||
AsyncAPI asyncAPI = asyncApiService.getAsyncAPI(); | ||
|
||
// then | ||
Map<String, Message> messages = asyncAPI.getComponents().getMessages(); | ||
assertThat(messages) | ||
.containsOnlyKeys( | ||
"io.github.stavshamir.springwolf.integrationtests.application.polymorphic.PolymorphicPayloadApplication$Payload"); | ||
Map<String, SchemaObject> schemas = asyncAPI.getComponents().getSchemas(); | ||
assertThat(schemas).containsOnlyKeys("HeadersNotDocumented", "Payload", "Pet", "Cat", "Dog"); | ||
|
||
assertThat(schemas.get("Pet").getDiscriminator()).isEqualTo("type"); | ||
assertThat(schemas.get("Cat").getAllOf().get(0).getReference().getRef()) | ||
.isEqualTo("#/components/schemas/Pet"); | ||
assertThat(schemas.get("Cat").getAllOf().get(1).getSchema().getProperties()) | ||
.containsOnlyKeys("catSpecificField"); | ||
assertThat(schemas.get("Dog").getAllOf().get(0).getReference().getRef()) | ||
.isEqualTo("#/components/schemas/Pet"); | ||
assertThat(schemas.get("Dog").getAllOf().get(1).getSchema().getProperties()) | ||
.containsOnlyKeys("dogSpecificField"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...olf/integrationtests/TestApplication.java → ...ts/application/basic/TestApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf.integrationtests; | ||
package io.github.stavshamir.springwolf.integrationtests.application.basic; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
class TestApplication {} | ||
public class TestApplication {} |
20 changes: 20 additions & 0 deletions
20
...thub/stavshamir/springwolf/integrationtests/application/listener/ListenerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf.integrationtests.application.listener; | ||
|
||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncListener; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncOperation; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@SpringBootApplication | ||
public class ListenerApplication { | ||
@Bean | ||
public Listener listener() { | ||
return new Listener(); | ||
} | ||
|
||
class Listener { | ||
@AsyncListener(operation = @AsyncOperation(channelName = "listener-channel")) | ||
public void listen(String payload) {} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...ir/springwolf/integrationtests/application/polymorphic/PolymorphicPayloadApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf.integrationtests.application.polymorphic; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncListener; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncOperation; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@SpringBootApplication | ||
public class PolymorphicPayloadApplication { | ||
@Bean | ||
public Listener listener() { | ||
return new Listener(); | ||
} | ||
|
||
class Listener { | ||
@AsyncListener(operation = @AsyncOperation(channelName = "listener-channel")) | ||
public void listen(Payload payload) {} | ||
} | ||
|
||
public record Payload(Pet pet) {} | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") | ||
@JsonSubTypes( | ||
value = { | ||
@JsonSubTypes.Type(value = Dog.class, name = "dog"), | ||
@JsonSubTypes.Type(value = Cat.class, name = "cat"), | ||
}) | ||
public interface Pet { | ||
public String getType(); | ||
} | ||
|
||
public record Dog() implements Pet { | ||
@Override | ||
public String getType() { | ||
return "dog"; | ||
} | ||
|
||
public String getDogSpecificField() { | ||
return "dog-specific-field"; | ||
} | ||
} | ||
|
||
public record Cat() implements Pet { | ||
@Override | ||
public String getType() { | ||
return "cat"; | ||
} | ||
|
||
public String getCatSpecificField() { | ||
return "cat-specific-field"; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ub/stavshamir/springwolf/integrationtests/application/publisher/PublisherApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf.integrationtests.application.publisher; | ||
|
||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncOperation; | ||
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncPublisher; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@SpringBootApplication | ||
public class PublisherApplication { | ||
@Bean | ||
public Publisher publisher() { | ||
return new Publisher(); | ||
} | ||
|
||
class Publisher { | ||
@AsyncPublisher(operation = @AsyncOperation(channelName = "publisher-channel")) | ||
public void publish(String payload) {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters