forked from asyncapi/jasyncapi
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(3.0.0): check correctness of realisation by reading AsyncAPI exa…
…mple - RPC Server AsyncAPI example
- Loading branch information
Showing
3 changed files
with
227 additions
and
1 deletion.
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
157 changes: 157 additions & 0 deletions
157
asyncapi-core/src/test/kotlin/com/asyncapi/examples/v3/_0_0/RpcServerAsyncAPI.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,157 @@ | ||
package com.asyncapi.examples.v3._0_0 | ||
|
||
import com.asyncapi.v3.Reference | ||
import com.asyncapi.v3._0_0.model.channel.Channel | ||
import com.asyncapi.v3._0_0.model.channel.Parameter | ||
import com.asyncapi.v3._0_0.model.channel.message.CorrelationId | ||
import com.asyncapi.v3._0_0.model.channel.message.Message | ||
import com.asyncapi.v3._0_0.model.component.Components | ||
import com.asyncapi.v3._0_0.model.info.Info | ||
import com.asyncapi.v3._0_0.model.operation.Operation | ||
import com.asyncapi.v3._0_0.model.operation.OperationAction | ||
import com.asyncapi.v3._0_0.model.server.Server | ||
import com.asyncapi.v3.binding.channel.amqp.AMQPChannelBinding | ||
import com.asyncapi.v3.binding.channel.amqp.AMQPChannelType | ||
import com.asyncapi.v3.binding.channel.amqp.queue.AMQPChannelQueueProperties | ||
import com.asyncapi.v3.binding.operation.amqp.AMQPOperationBinding | ||
import com.asyncapi.v3.schema.Schema | ||
|
||
class RpcServerAsyncAPI: AbstractExampleValidationTest() { | ||
|
||
override fun specificationLocation(): String = "/examples/v3.0.0/rpc-server-asyncapi.yml" | ||
|
||
override fun expectedId(): String = "urn:example:rpcserver" | ||
|
||
override fun expectedInfo(): Info { | ||
return Info.builder() | ||
.title("RPC Server Example") | ||
.version("1.0.0") | ||
.description("This example demonstrates how to define an RPC server.") | ||
.build() | ||
} | ||
|
||
override fun expectedDefaultContentType(): String = "application/json" | ||
|
||
override fun expectedServers(): Map<String, Any> { | ||
return mapOf( | ||
Pair("production", Server.builder() | ||
.host("rabbitmq.example.org") | ||
.protocol("amqp") | ||
.build() | ||
) | ||
) | ||
} | ||
|
||
override fun expectedChannels(): Map<String, Any> { | ||
return mapOf( | ||
Pair("queue", | ||
Channel.builder() | ||
.address("{queue}") | ||
.messages(mapOf( | ||
Pair("sendSumResult", | ||
Message.builder() | ||
.correlationId(CorrelationId(null, "\$message.header#/correlation_id")) | ||
.payload(Schema.builder() | ||
.type("object") | ||
.properties(mapOf( | ||
Pair("result", Schema.builder() | ||
.type("number") | ||
.examples(listOf(7)) | ||
.build() | ||
) | ||
)) | ||
.build() | ||
) | ||
.build() | ||
) | ||
)) | ||
.parameters(mapOf( | ||
Pair("queue", Parameter()) | ||
)) | ||
.bindings(mapOf( | ||
Pair("amqp", | ||
AMQPChannelBinding.builder() | ||
.`is`(AMQPChannelType.QUEUE) | ||
.queue(AMQPChannelQueueProperties.builder() | ||
.exclusive(true) | ||
.build() | ||
) | ||
.build() | ||
) | ||
)) | ||
.build() | ||
), | ||
Pair("rpc_queue", | ||
Channel.builder() | ||
.address("rpc_queue") | ||
.messages(mapOf( | ||
Pair("sum", | ||
Message.builder() | ||
.correlationId(CorrelationId(null, "\$message.header#/correlation_id")) | ||
.payload(Schema.builder() | ||
.type("object") | ||
.properties(mapOf( | ||
Pair("numbers", Schema.builder() | ||
.type("array") | ||
.items(Schema.builder() | ||
.type("number") | ||
.build() | ||
) | ||
.examples(listOf(listOf(4, 3))) | ||
.build() | ||
) | ||
)) | ||
.build() | ||
) | ||
.build() | ||
) | ||
)) | ||
.bindings(mapOf( | ||
Pair("amqp", | ||
AMQPChannelBinding.builder() | ||
.`is`(AMQPChannelType.QUEUE) | ||
.queue(AMQPChannelQueueProperties.builder() | ||
.durable(false) | ||
.build() | ||
) | ||
.build() | ||
) | ||
)) | ||
.build() | ||
) | ||
) | ||
} | ||
|
||
override fun expectedOperations(): Map<String, Any> { | ||
return mapOf( | ||
Pair("sendSumResult", | ||
Operation.builder() | ||
.action(OperationAction.SEND) | ||
.channel(Reference("#/channels/queue")) | ||
.bindings(mapOf( | ||
Pair("amqp", | ||
AMQPOperationBinding.builder() | ||
.ack(true) | ||
.build() | ||
) | ||
)) | ||
.messages(listOf( | ||
Reference("#/channels/queue/messages/sendSumResult") | ||
)) | ||
.build() | ||
), | ||
Pair("sum", | ||
Operation.builder() | ||
.action(OperationAction.RECEIVE) | ||
.channel(Reference("#/channels/rpc_queue")) | ||
.messages(listOf( | ||
Reference("#/channels/rpc_queue/messages/sum") | ||
)) | ||
.build() | ||
) | ||
) | ||
} | ||
|
||
override fun expectedComponents(): Components? = null | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
asyncapi-core/src/test/resources/examples/v3.0.0/rpc-server-asyncapi.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,69 @@ | ||
asyncapi: 3.0.0 | ||
id: 'urn:example:rpcserver' | ||
info: | ||
title: RPC Server Example | ||
version: 1.0.0 | ||
description: This example demonstrates how to define an RPC server. | ||
defaultContentType: application/json | ||
servers: | ||
production: | ||
host: rabbitmq.example.org | ||
protocol: amqp | ||
channels: | ||
queue: | ||
address: '{queue}' | ||
messages: | ||
sendSumResult: | ||
correlationId: | ||
location: $message.header#/correlation_id | ||
payload: | ||
type: object | ||
properties: | ||
result: | ||
type: number | ||
examples: | ||
- 7 | ||
parameters: | ||
queue: {} | ||
bindings: | ||
amqp: | ||
is: queue | ||
queue: | ||
exclusive: true | ||
rpc_queue: | ||
address: rpc_queue | ||
messages: | ||
sum: | ||
correlationId: | ||
location: $message.header#/correlation_id | ||
payload: | ||
type: object | ||
properties: | ||
numbers: | ||
type: array | ||
items: | ||
type: number | ||
examples: | ||
- - 4 | ||
- 3 | ||
bindings: | ||
amqp: | ||
is: queue | ||
queue: | ||
durable: false | ||
operations: | ||
sendSumResult: | ||
action: send | ||
channel: | ||
$ref: '#/channels/queue' | ||
bindings: | ||
amqp: | ||
ack: true | ||
messages: | ||
- $ref: '#/channels/queue/messages/sendSumResult' | ||
sum: | ||
action: receive | ||
channel: | ||
$ref: '#/channels/rpc_queue' | ||
messages: | ||
- $ref: '#/channels/rpc_queue/messages/sum' |