@@ -44,10 +44,72 @@ import org.junit.jupiter.api.assertDoesNotThrow
44
44
@DisplayName(VALIDATION_SHOULD + " validate an entity ID" )
45
45
internal class EntityIdSpec : ValidationOfConstraintTest () {
46
46
47
+ @Nested inner class
48
+ `in a command file and ` {
49
+
50
+ @Test
51
+ fun `find out that non-default message is valid` () {
52
+ val state = assertDoesNotThrow {
53
+ entityIdMsgFieldValue {
54
+ value = newStringValue()
55
+ }
56
+ }
57
+ assertValid(state)
58
+ }
59
+
60
+ @Test
61
+ fun `find out that default message is NOT valid` () {
62
+ val msg = EntityIdMsgFieldValue .getDefaultInstance()
63
+ assertNotValid(msg)
64
+ }
65
+
47
66
@Test
48
67
fun `find out that empty string is NOT valid` () {
49
68
val msg = EntityIdStringFieldValue .getDefaultInstance()
50
69
assertNotValid(msg)
51
70
}
52
71
72
+ @Test
73
+ fun `find out that non-empty string is valid` () {
74
+ val state = assertDoesNotThrow {
75
+ entityIdStringFieldValue {
76
+ value = Identifier .newUuid()
77
+ }
78
+ }
79
+ assertValid(state)
80
+ }
81
+
82
+ @Test
83
+ fun `provide a violation if is not valid` () {
84
+ val msg = EntityIdMsgFieldValue .getDefaultInstance()
85
+ assertSingleViolation(msg, MessageValidatorTestEnv .VALUE )
86
+ }
87
+ }
88
+
89
+ @Nested inner class
90
+ `in a state and ` {
91
+
92
+ @Test
93
+ fun `consider it required by default` () {
94
+ val stateWithDefaultId = AggregateState .getDefaultInstance()
95
+ assertNotValid(stateWithDefaultId)
96
+ }
97
+
98
+ @Test
99
+ fun `match only the first field named 'id' or ending with '_id'` () {
100
+ val onlyEntityIdSet = assertDoesNotThrow {
101
+ // Only ID set.
102
+ aggregateState {
103
+ entityId = Identifier .newUuid()
104
+ }
105
+ }
106
+ assertValid(onlyEntityIdSet)
107
+ }
108
+
109
+ @Test
110
+ fun `not consider it '(required)' if the option is set explicitly to false` () {
111
+ val stateWithDefaultId = ProjectionState .getDefaultInstance()
112
+ assertValid(stateWithDefaultId)
113
+ }
114
+ }
53
115
}
0 commit comments