Skip to content

Commit

Permalink
test(3.0.0): check correctness of realisation by reading AsyncAPI exa…
Browse files Browse the repository at this point in the history
…mple - RPC Server AsyncAPI example
  • Loading branch information
Pakisan committed Feb 6, 2024
1 parent 31f15fe commit 3d74156
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Hints:
- [x] [oneof-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/oneof-asyncapi.yml)
- [ ] [operation-security-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/operation-security-asyncapi.yml)
- [x] [rpc-client-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/rpc-client-asyncapi.yml)
- [ ] [rpc-server-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/rpc-server-asyncapi.yml)
- [x] [rpc-server-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/rpc-server-asyncapi.yml)
- [x] [simple-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/simple-asyncapi.yml)
- [ ] [slack-rtm-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/slack-rtm-asyncapi.yml)
- [ ] [streetlights-kafka-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/streetlights-kafka-asyncapi.yml)
Expand Down
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

}
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'

0 comments on commit 3d74156

Please sign in to comment.