Skip to content

Commit 9ab6712

Browse files
authored
test: Add annotation integration test (#52)
test - Add annotation integration test
1 parent 77c80d8 commit 9ab6712

File tree

3 files changed

+110
-2
lines changed

3 files changed

+110
-2
lines changed

kotlin-asyncapi-spring-web/src/main/kotlin/org/openfolder/kotlinasyncapi/springweb/context/AnnotationProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ internal class AnnotationProvider(
4141

4242
override val asyncApi: AsyncApi? by lazy {
4343
AsyncApi().apply {
44-
channels {
44+
components {
4545
bind(this)
4646
}
47-
components {
47+
channels {
4848
bind(this)
4949
}
5050
}

kotlin-asyncapi-spring-web/src/test/kotlin/org/openfolder/kotlinasyncapi/springweb/controller/AsyncApiControllerIntegrationTest.kt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.openfolder.kotlinasyncapi.springweb.controller
22

33
import org.junit.jupiter.api.Test
4+
import org.openfolder.kotlinasyncapi.annotation.channel.Channel
5+
import org.openfolder.kotlinasyncapi.annotation.channel.Message
6+
import org.openfolder.kotlinasyncapi.annotation.channel.Publish
47
import org.openfolder.kotlinasyncapi.springweb.EnableAsyncApi
58
import org.openfolder.kotlinasyncapi.springweb.TestUtils
69
import org.openfolder.kotlinasyncapi.springweb.service.AsyncApiExtension
@@ -161,3 +164,51 @@ internal class AsyncApiControllerIntegrationTest {
161164
}
162165
}
163166
}
167+
168+
@SpringBootTest
169+
@AutoConfigureMockMvc
170+
internal class AsyncApiControllerAnnotationIntegrationTest {
171+
172+
@Autowired
173+
lateinit var mockMvc: MockMvc
174+
175+
@Test
176+
fun `should return AsyncApi document`() {
177+
val expected = TestUtils.json("async_api_annotation_integration.json")
178+
179+
mockMvc.perform(get("/docs/asyncapi"))
180+
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful)
181+
.andExpect(content().json(expected))
182+
}
183+
184+
@SpringBootConfiguration
185+
@EnableAutoConfiguration
186+
@EnableAsyncApi
187+
open class TestConfig {
188+
189+
@Bean
190+
open fun asyncApiExtension() =
191+
AsyncApiExtension.builder {
192+
info {
193+
title("testTitle")
194+
version("testVersion")
195+
}
196+
}
197+
}
198+
199+
@Channel("my/channel")
200+
class TestChannel {
201+
202+
@Publish(
203+
description = "testDescription",
204+
message = Message(TestMessage::class)
205+
)
206+
fun testOperation() {}
207+
}
208+
209+
@Message
210+
data class TestMessage(
211+
val value: String,
212+
val optionalValue: Boolean?
213+
)
214+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"asyncapi": "2.4.0",
3+
"info": {
4+
"title": "testTitle",
5+
"version": "testVersion"
6+
},
7+
"channels": {
8+
"my/channel": {
9+
"$ref": "#/components/channels/TestChannel"
10+
}
11+
},
12+
"components": {
13+
"schemas": {
14+
"TestMessage": {
15+
"required": [
16+
"value"
17+
],
18+
"type": "object",
19+
"properties": {
20+
"value": {
21+
"type": "string",
22+
"exampleSetFlag": false,
23+
"types": [
24+
"string"
25+
]
26+
},
27+
"optionalValue": {
28+
"type": "boolean",
29+
"exampleSetFlag": false,
30+
"types": [
31+
"boolean"
32+
]
33+
}
34+
},
35+
"exampleSetFlag": false
36+
}
37+
},
38+
"channels": {
39+
"TestChannel": {
40+
"publish": {
41+
"description": "testDescription",
42+
"message": {
43+
"$ref": "#/components/messages/TestMessage"
44+
}
45+
}
46+
}
47+
},
48+
"messages": {
49+
"TestMessage": {
50+
"payload": {
51+
"$ref": "#/components/schemas/TestMessage"
52+
},
53+
"schemaFormat": "application/schema+json;version=draft-07"
54+
}
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)