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(2.6.0): check correctness of realisation by reading AsyncAPI exa…
…mple - Mercure Example asyncapi#165
- Loading branch information
Showing
2 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
asyncapi-core/src/test/kotlin/com/asyncapi/examples/v2/_6_0/Mercure.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,112 @@ | ||
package com.asyncapi.examples.v2._6_0 | ||
|
||
import com.asyncapi.v2.Reference | ||
import com.asyncapi.v2._6_0.model.ExternalDocumentation | ||
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.Message | ||
import com.asyncapi.v2._6_0.model.channel.message.OneOfMessages | ||
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.message.http.HTTPMessageBinding | ||
import com.asyncapi.v2.binding.operation.http.HTTPOperationBinding | ||
import com.asyncapi.v2.binding.operation.http.HTTPOperationType | ||
import com.asyncapi.v2.schema.Schema | ||
import com.asyncapi.v2.security_scheme.http.HttpSecurityScheme | ||
|
||
class Mercure: AbstractExampleValidationTest() { | ||
|
||
override fun specificationLocation(): String = "/examples/v2.6.0/mercure.yml" | ||
|
||
override fun expectedDefaultContentType(): String = "application/ld+json" | ||
|
||
override fun expectedInfo(): Info { | ||
return Info.builder() | ||
.title("Mercure Hub Example") | ||
.description("This example demonstrates how to define a Mercure hub.") | ||
.version("1.0.0") | ||
.build() | ||
} | ||
|
||
override fun expectedServers(): Map<String, Any> { | ||
return mapOf( | ||
Pair("production", Server.builder() | ||
.url("https://demo.mercure.rocks/.well-known/mercure") | ||
.protocol("mercure") | ||
.build() | ||
) | ||
) | ||
} | ||
|
||
override fun expectedChannels(): Map<String, Any> { | ||
return mapOf( | ||
Pair("https://example.com/books/{id}", ChannelItem.builder() | ||
.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() | ||
.schema(Schema.builder() | ||
.type("integer") | ||
.build() | ||
) | ||
.build() | ||
) | ||
)) | ||
.subscribe(Operation.builder() | ||
.message(Reference("#/components/messages/book")) | ||
.build() | ||
) | ||
.publish(Operation.builder() | ||
.message(Reference("#/components/messages/book")) | ||
.build() | ||
) | ||
.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() | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
asyncapi-core/src/test/resources/examples/v2.6.0/mercure.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,49 @@ | ||
asyncapi: "2.6.0" | ||
info: | ||
title: Mercure Hub Example | ||
version: '1.0.0' | ||
description: This example demonstrates how to define a Mercure hub. | ||
|
||
# While not mandatory, it's a best practice to use formats with hypermedia capabilities such as JSON-LD, Atom or HTML with the Mercure protocol | ||
defaultContentType: application/ld+json | ||
|
||
servers: | ||
production: | ||
url: https://demo.mercure.rocks/.well-known/mercure | ||
protocol: mercure | ||
|
||
channels: | ||
'https://example.com/books/{id}': | ||
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: | ||
schema: | ||
type: integer | ||
subscribe: | ||
message: | ||
$ref: '#/components/messages/book' | ||
publish: | ||
message: | ||
$ref: '#/components/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 |