-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildDwellingRestApiTest.kt
More file actions
82 lines (75 loc) · 3.06 KB
/
BuildDwellingRestApiTest.kt
File metadata and controls
82 lines (75 loc) · 3.06 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
75
76
77
78
79
80
81
82
package com.dddheroes.heroesofddd.creaturerecruitment.write.builddwelling
import com.dddheroes.extensions.webmvc.test.RestAssuredMockMvcTest
import com.dddheroes.heroesofddd.shared.domain.identifiers.DwellingId
import com.dddheroes.heroesofddd.shared.domain.identifiers.GameId
import com.dddheroes.heroesofddd.shared.domain.identifiers.PlayerId
import com.dddheroes.heroesofddd.shared.restapi.Headers
import com.dddheroes.sdk.application.CommandHandlerResult.Failure
import com.dddheroes.sdk.application.CommandHandlerResult.Success
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.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.creaturerecruitment.write.builddwelling.enabled=true"])
internal class BuildDwellingRestApiTest @Autowired constructor(val gateways: AxonGatewaysMock) {
private val gameId = GameId.random()
private val playerId = PlayerId.random()
private val dwellingId = DwellingId.random()
private val creatureId = "angel"
private val costGold = 3000
@Test
fun `command success - returns 204 No Content`() {
gateways.assumeCommandReturns<BuildDwelling>(Success)
Given {
pathParam("gameId", gameId.raw)
pathParam("dwellingId", dwellingId.raw)
header(Headers.PLAYER_ID, playerId.raw)
contentType(ContentType.JSON)
body(
"""
{
"creatureId": "$creatureId",
"costPerTroop": {"gold": $costGold}
}
"""
)
} When {
async().put("/games/{gameId}/dwellings/{dwellingId}")
} Then {
statusCode(HttpStatus.NO_CONTENT.value())
}
}
@Test
fun `command failure - returns 400 Bad Request`() {
gateways.assumeCommandReturns<BuildDwelling>(Failure("Dwelling already built"))
Given {
pathParam("gameId", gameId.raw)
pathParam("dwellingId", dwellingId.raw)
header(Headers.PLAYER_ID, playerId.raw)
contentType(ContentType.JSON)
body(
"""
{
"creatureId": "$creatureId",
"costPerTroop": {"gold": $costGold}
}
"""
)
} When {
async().put("/games/{gameId}/dwellings/{dwellingId}")
} Then {
statusCode(HttpStatus.BAD_REQUEST.value())
contentType(ContentType.JSON)
body("message", equalTo("Dwelling already built"))
}
}
}