-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(2.0.0): check correctness of realisation by reading AsyncAPI exa…
…mple - OneOf Example #187
- Loading branch information
Showing
2 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_0_0/OneOf.kt
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,93 @@ | ||
package com.asyncapi.examples.v2._0_0 | ||
|
||
import com.asyncapi.v2.Reference | ||
import com.asyncapi.v2._0_0.model.channel.ChannelItem | ||
import com.asyncapi.v2._0_0.model.channel.message.Message | ||
import com.asyncapi.v2._0_0.model.channel.operation.Operation | ||
import com.asyncapi.v2._0_0.model.component.Components | ||
import com.asyncapi.v2._0_0.model.info.Info | ||
import com.asyncapi.v2.schema.Schema | ||
|
||
class OneOf: AbstractExampleValidationTest() { | ||
|
||
override fun specificationLocation(): String = "/examples/v2.0.0/oneof.yml" | ||
|
||
override fun expectedInfo(): Info { | ||
return Info.builder() | ||
.title("OneOf example") | ||
.version("1.0.0") | ||
.build() | ||
} | ||
|
||
override fun expectedServers(): Map<String, Any>? = null | ||
|
||
override fun expectedChannels(): Map<String, Any> { | ||
return mapOf( | ||
Pair("test", ChannelItem.builder() | ||
.publish(Operation.builder() | ||
.message(Reference("#/components/messages/testMessages")) | ||
.build() | ||
) | ||
.build() | ||
), | ||
Pair("test2", ChannelItem.builder() | ||
.subscribe(Operation.builder() | ||
// TODO: add OneOfMessage to 2.0.0 | ||
.message(Message.builder() | ||
.payload(Schema.builder().ref("#/components/schemas/objectWithKey").build()) | ||
.build()) | ||
.build() | ||
) | ||
.build() | ||
) | ||
) | ||
} | ||
|
||
override fun expectedComponents(): Components? { | ||
return Components.builder() | ||
.messages(mapOf( | ||
Pair("testMessages", Message.builder() | ||
.payload(Schema.builder() | ||
.oneOf(listOf( | ||
Schema.builder().ref("#/components/schemas/objectWithKey").build(), | ||
Schema.builder().ref("#/components/schemas/objectWithKey2").build() | ||
)) | ||
.build() | ||
) | ||
.build() | ||
), | ||
Pair("testMessage1", Message.builder() | ||
.payload(Schema.builder().ref("#/components/schemas/objectWithKey").build()) | ||
.build() | ||
), | ||
Pair("testMessage2", Message.builder() | ||
.payload(Schema.builder().ref("#/components/schemas/objectWithKey2").build()) | ||
.build() | ||
) | ||
)) | ||
.schemas(mapOf( | ||
Pair("objectWithKey", Schema.builder() | ||
.type("object") | ||
.properties(mapOf( | ||
Pair("key", Schema.builder() | ||
.type("string") | ||
.build() | ||
) | ||
)) | ||
.build() | ||
), | ||
Pair("objectWithKey2", Schema.builder() | ||
.type("object") | ||
.properties(mapOf( | ||
Pair("key2", Schema.builder() | ||
.type("string") | ||
.build() | ||
) | ||
)) | ||
.build() | ||
) | ||
)) | ||
.build() | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
asyncapi-core/src/test/resources/examples/v2.0.0/oneof.yml
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,42 @@ | ||
asyncapi: "2.0.0" | ||
info: | ||
title: OneOf example | ||
version: '1.0.0' | ||
|
||
channels: | ||
test: | ||
publish: | ||
message: | ||
$ref: '#/components/messages/testMessages' | ||
|
||
test2: | ||
subscribe: | ||
message: | ||
payload: | ||
$ref: "#/components/schemas/objectWithKey" | ||
|
||
components: | ||
messages: | ||
testMessages: | ||
payload: | ||
oneOf: # oneOf in payload schema | ||
- $ref: "#/components/schemas/objectWithKey" | ||
- $ref: "#/components/schemas/objectWithKey2" | ||
testMessage1: | ||
payload: | ||
$ref: "#/components/schemas/objectWithKey" | ||
testMessage2: | ||
payload: | ||
$ref: "#/components/schemas/objectWithKey2" | ||
|
||
schemas: | ||
objectWithKey: | ||
type: object | ||
properties: | ||
key: | ||
type: string | ||
objectWithKey2: | ||
type: object | ||
properties: | ||
key2: | ||
type: string |