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 - Mercure AsyncAPI example
- Loading branch information
Showing
3 changed files
with
190 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
131 changes: 131 additions & 0 deletions
131
asyncapi-core/src/test/kotlin/com/asyncapi/examples/v3/_0_0/MercureAsyncAPI.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,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() | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
asyncapi-core/src/test/resources/examples/v3.0.0/mercure-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,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 |