-
-
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.6.0): check correctness of realisation by reading AsyncAPI exa…
…mple - RPC Client Example #165
- Loading branch information
Showing
2 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_6_0/RpcClient.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,135 @@ | ||
package com.asyncapi.examples.v2._6_0 | ||
|
||
import com.asyncapi.v2._6_0.model.channel.ChannelItem | ||
import com.asyncapi.v2._6_0.model.channel.Parameter | ||
import com.asyncapi.v2._6_0.model.channel.message.CorrelationId | ||
import com.asyncapi.v2._6_0.model.channel.message.Message | ||
import com.asyncapi.v2._6_0.model.channel.operation.Operation | ||
import com.asyncapi.v2._6_0.model.component.Components | ||
import com.asyncapi.v2._6_0.model.info.Info | ||
import com.asyncapi.v2._6_0.model.server.Server | ||
import com.asyncapi.v2.binding.channel.amqp.AMQPChannelBinding | ||
import com.asyncapi.v2.binding.channel.amqp.AMQPChannelType | ||
import com.asyncapi.v2.binding.channel.amqp.queue.AMQPChannelQueueProperties | ||
import com.asyncapi.v2.binding.operation.amqp.AMQPOperationBinding | ||
import com.asyncapi.v2.schema.Schema | ||
|
||
class RpcClient: AbstractExampleValidationTest() { | ||
|
||
override fun specificationLocation(): String = "/examples/v2.6.0/rpc-client.yml" | ||
|
||
override fun expectedId(): String = "urn:example:rpcclient" | ||
|
||
override fun expectedDefaultContentType(): String = "application/json" | ||
|
||
override fun expectedInfo(): Info { | ||
return Info.builder() | ||
.title("RPC Client Example") | ||
.version("1.0.0") | ||
.description("This example demonstrates how to define an RPC client." | ||
) | ||
.build() | ||
} | ||
|
||
override fun expectedServers(): Map<String, Any> { | ||
return mapOf( | ||
Pair("production", Server.builder() | ||
.url("rabbitmq.example.org") | ||
.protocol("amqp") | ||
.build() | ||
) | ||
) | ||
} | ||
|
||
override fun expectedChannels(): Map<String, Any> { | ||
return mapOf( | ||
Pair("{queue}", ChannelItem.builder() | ||
.parameters(mapOf( | ||
Pair("queue", Parameter.builder() | ||
.schema(Schema.builder() | ||
.type("string") | ||
.pattern("^amq\\\\.gen\\\\-.+\$") | ||
.build()) | ||
.build() | ||
), | ||
)) | ||
.bindings(mapOf( | ||
Pair("amqp", AMQPChannelBinding.builder() | ||
.`is`(AMQPChannelType.QUEUE) | ||
.queue(AMQPChannelQueueProperties.builder() | ||
.exclusive(true) | ||
.build() | ||
) | ||
.build() | ||
) | ||
)) | ||
.publish(Operation.builder() | ||
.operationId("receiveSumResult") | ||
.bindings(mapOf( | ||
Pair("amqp", AMQPOperationBinding.builder() | ||
.ack(false) | ||
.build() | ||
) | ||
)) | ||
.message(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() | ||
) | ||
.build() | ||
) | ||
.build() | ||
), | ||
Pair("rpc_queue", ChannelItem.builder() | ||
.bindings(mapOf( | ||
Pair("amqp", AMQPChannelBinding.builder() | ||
.`is`(AMQPChannelType.QUEUE) | ||
.queue(AMQPChannelQueueProperties.builder() | ||
.durable(false) | ||
.build() | ||
) | ||
.build() | ||
) | ||
)) | ||
.subscribe(Operation.builder() | ||
.operationId("requestSum") | ||
.bindings(mapOf( | ||
Pair("amqp", AMQPOperationBinding.builder() | ||
.ack(true) | ||
.build() | ||
) | ||
)) | ||
.message(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() | ||
) | ||
.build() | ||
) | ||
.build() | ||
) | ||
) | ||
} | ||
|
||
override fun expectedComponents(): Components? = null | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
asyncapi-core/src/test/resources/examples/v2.6.0/rpc-client.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,65 @@ | ||
asyncapi: "2.6.0" | ||
id: 'urn:example:rpcclient' | ||
defaultContentType: application/json | ||
|
||
info: | ||
title: RPC Client Example | ||
description: This example demonstrates how to define an RPC client. | ||
version: '1.0.0' | ||
|
||
servers: | ||
production: | ||
url: rabbitmq.example.org | ||
protocol: amqp | ||
|
||
channels: | ||
'{queue}': | ||
parameters: | ||
queue: | ||
schema: | ||
type: string | ||
pattern: '^amq\\.gen\\-.+$' | ||
bindings: | ||
amqp: | ||
is: queue | ||
queue: | ||
exclusive: true | ||
publish: | ||
operationId: receiveSumResult | ||
bindings: | ||
amqp: | ||
ack: false | ||
message: | ||
correlationId: | ||
location: $message.header#/correlation_id | ||
payload: | ||
type: object | ||
properties: | ||
result: | ||
type: number | ||
examples: | ||
- 7 | ||
|
||
rpc_queue: | ||
bindings: | ||
amqp: | ||
is: queue | ||
queue: | ||
durable: false | ||
subscribe: | ||
operationId: requestSum | ||
bindings: | ||
amqp: | ||
ack: true | ||
message: | ||
correlationId: | ||
location: $message.header#/correlation_id | ||
payload: | ||
type: object | ||
properties: | ||
numbers: | ||
type: array | ||
items: | ||
type: number | ||
examples: | ||
- [4,3] |