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 - Mercure AsyncAPI example
  • Loading branch information
Pakisan committed Feb 6, 2024
1 parent e891b99 commit e9e0824
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Hints:
- [ ] [gitter-streaming-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/gitter-streaming-asyncapi.yml)
- [ ] [kraken-websocket-request-reply-message-filter-in-reply-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/kraken-websocket-request-reply-message-filter-in-reply-asyncapi.yml)
- [ ] [kraken-websocket-request-reply-multiple-channels-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/kraken-websocket-request-reply-multiple-channels-asyncapi.yml)
- [ ] [mercure-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/mercure-asyncapi.yml)
- [x] [mercure-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/mercure-asyncapi.yml)
- [x] [not-asyncapi.yml](https://github.com/asyncapi/spec/blob/master/examples/not-asyncapi.yml)
- [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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package com.asyncapi.examples.v3._0_0

import com.asyncapi.v3.Reference
import com.asyncapi.v3._0_0.model.ExternalDocumentation
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.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.schema.Schema

class MercureAsyncAPI: AbstractExampleValidationTest() {

override fun specificationLocation(): String = "/examples/v3.0.0/mercure-asyncapi.yml"

override fun expectedDefaultContentType(): String = "application/ld+json"

override fun expectedInfo(): Info {
return Info.builder()
.title("Mercure Hub Example")
.version("1.0.0")
.description("This example demonstrates how to define a Mercure hub.")
.build()
}

override fun expectedServers(): Map<String, Any> {
return mapOf(
Pair("production",
Server.builder()
.host("demo.mercure.rocks")
.pathname("/.well-known/mercure")
.protocol("mercure")
.build()
)
)
}

override fun expectedChannels(): Map<String, Any> {
return mapOf(
Pair("books",
Channel.builder()
.address("https://example.com/books/{id}")
.messages(mapOf(
Pair("book", Reference("#/components/messages/book"))
))
.description(
"Every time a resource of type `http://schema.org/Book` is created or " +
"modified, a JSON-LD representation of the new version of this resource " +
"must be pushed in this Mercure topic."
)
.parameters(mapOf(
Pair("id", Parameter.builder().description("ID of the book").build())
))
.build()
)
)
}

override fun expectedOperations(): Map<String, Any> {
return mapOf(
Pair("ReceiveBooksInfo",
Operation.builder()
.action(OperationAction.RECEIVE)
.channel(Reference("#/channels/books"))
.messages(listOf(
Reference("#/channels/books/messages/book")
))
.build()
),
Pair("SendBooksInfo",
Operation.builder()
.action(OperationAction.SEND)
.channel(Reference("#/channels/books"))
.messages(listOf(
Reference("#/channels/books/messages/book")
))
.build()
)
)
}

override fun expectedComponents(): Components {
return Components.builder()
.messages(mapOf(
Pair("book",
Message.builder()
.summary("The content of a book resource.")
.externalDocs(ExternalDocumentation(null, "https://schema.org/Book"))
.payload(Schema.builder()
.type("object")
.properties(mapOf(
Pair("@id",
Schema.builder()
.type("string")
.format("iri-reference")
.build()
),
Pair("@type",
Schema.builder()
.type("string")
.format("iri-reference")
.build()
),
Pair("name",
Schema.builder()
.type("string")
.build()
),
Pair("isbn",
Schema.builder()
.type("string")
.build()
),
Pair("abstract",
Schema.builder()
.type("string")
.build()
)
))
.build()
)
.build()
)
))
.build()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
asyncapi: 3.0.0
info:
title: Mercure Hub Example
version: 1.0.0
description: This example demonstrates how to define a Mercure hub.
defaultContentType: application/ld+json
servers:
production:
host: demo.mercure.rocks
pathname: /.well-known/mercure
protocol: mercure
channels:
books:
address: 'https://example.com/books/{id}'
messages:
book:
$ref: '#/components/messages/book'
description: >-
Every time a resource of type `http://schema.org/Book` is created or
modified, a JSON-LD representation of the new version of this resource
must be pushed in this Mercure topic.
parameters:
id:
description: ID of the book
operations:
ReceiveBooksInfo:
action: receive
channel:
$ref: '#/channels/books'
messages:
- $ref: '#/channels/books/messages/book'
SendBooksInfo:
action: send
channel:
$ref: '#/channels/books'
messages:
- $ref: '#/channels/books/messages/book'
components:
messages:
book:
summary: The content of a book resource.
externalDocs:
url: 'https://schema.org/Book'
payload:
type: object
properties:
'@id':
type: string
format: iri-reference
'@type':
type: string
format: iri-reference
name:
type: string
isbn:
type: string
abstract:
type: string

0 comments on commit e9e0824

Please sign in to comment.