-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetArmyCreaturesRestApiTest.kt
More file actions
74 lines (67 loc) · 2.81 KB
/
GetArmyCreaturesRestApiTest.kt
File metadata and controls
74 lines (67 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.dddheroes.heroesofddd.armies.read.getarmycreatures
import com.dddheroes.extensions.webmvc.test.RestAssuredMockMvcTest
import com.dddheroes.heroesofddd.shared.domain.identifiers.ArmyId
import com.dddheroes.heroesofddd.shared.domain.identifiers.GameId
import io.restassured.http.ContentType
import io.restassured.module.mockmvc.kotlin.extensions.Given
import io.restassured.module.mockmvc.kotlin.extensions.Then
import io.restassured.module.mockmvc.kotlin.extensions.When
import org.axonframework.extensions.spring.test.AxonGatewaysMock
import org.axonframework.extensions.spring.test.AxonGatewaysMockTest
import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.hasSize
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.test.context.TestPropertySource
@RestAssuredMockMvcTest
@AxonGatewaysMockTest
@TestPropertySource(properties = ["slices.armies.read.getarmycreatures.enabled=true"])
internal class GetArmyCreaturesRestApiTest @Autowired constructor(val gateways: AxonGatewaysMock) {
private val gameId = GameId.random()
private val armyId = ArmyId("hero-catherine-army")
@Test
fun `returns army creatures`() {
val query = GetArmyCreatures(gameId, armyId)
val result = GetArmyCreatures.Result(
armyId.raw,
listOf(
GetArmyCreatures.CreatureStack("angel", 5),
GetArmyCreatures.CreatureStack("bowman", 3)
)
)
gateways.assumeQueryReturns(query, result)
Given {
pathParam("gameId", gameId.raw)
pathParam("armyId", armyId.raw)
} When {
async().get("/games/{gameId}/armies/{armyId}/creatures")
} Then {
statusCode(HttpStatus.OK.value())
contentType(ContentType.JSON)
body("armyId", equalTo(armyId.raw))
body("stacks", hasSize<Int>(2))
body("stacks[0].creatureId", equalTo("angel"))
body("stacks[0].quantity", equalTo(5))
body("stacks[1].creatureId", equalTo("bowman"))
body("stacks[1].quantity", equalTo(3))
}
}
@Test
fun `returns empty stacks when no creatures`() {
val query = GetArmyCreatures(gameId, armyId)
val result = GetArmyCreatures.Result(armyId.raw, emptyList())
gateways.assumeQueryReturns(query, result)
Given {
pathParam("gameId", gameId.raw)
pathParam("armyId", armyId.raw)
} When {
async().get("/games/{gameId}/armies/{armyId}/creatures")
} Then {
statusCode(HttpStatus.OK.value())
contentType(ContentType.JSON)
body("armyId", equalTo(armyId.raw))
body("stacks", hasSize<Int>(0))
}
}
}