Skip to content

Commit

Permalink
Change tests to use Routes().
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Mar 25, 2024
1 parent 42b07a8 commit 6946e42
Show file tree
Hide file tree
Showing 14 changed files with 426 additions and 213 deletions.
68 changes: 45 additions & 23 deletions aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ var _ = Describe("func FromAggregate()", func() {
handler = &fixtures.AggregateMessageHandler{
ConfigureFunc: func(c dogma.AggregateConfigurer) {
c.Identity("<name>", aggregateKey)
c.ConsumesCommandType(fixtures.MessageA{})
c.ConsumesCommandType(fixtures.MessageB{})
c.ProducesEventType(fixtures.MessageE{})
c.Routes(
dogma.HandlesCommand[fixtures.MessageA](),
dogma.HandlesCommand[fixtures.MessageB](),
dogma.RecordsEvent[fixtures.MessageE](),
)
},
}
})
Expand Down Expand Up @@ -157,8 +159,10 @@ var _ = Describe("func FromAggregate()", func() {
"when the handler does not configure an identity",
`*fixtures.AggregateMessageHandler is configured without an identity, Identity() must be called exactly once within Configure()`,
func(c dogma.AggregateConfigurer) {
c.ConsumesCommandType(fixtures.MessageA{})
c.ProducesEventType(fixtures.MessageE{})
c.Routes(
dogma.HandlesCommand[fixtures.MessageA](),
dogma.RecordsEvent[fixtures.MessageE](),
)
},
),
Entry(
Expand All @@ -167,79 +171,97 @@ var _ = Describe("func FromAggregate()", func() {
func(c dogma.AggregateConfigurer) {
c.Identity("<name>", aggregateKey)
c.Identity("<other>", aggregateKey)
c.ConsumesCommandType(fixtures.MessageA{})
c.ProducesEventType(fixtures.MessageE{})
c.Routes(
dogma.HandlesCommand[fixtures.MessageA](),
dogma.RecordsEvent[fixtures.MessageE](),
)
},
),
Entry(
"when the handler configures an invalid name",
`*fixtures.AggregateMessageHandler is configured with an invalid identity, invalid name "\t \n", names must be non-empty, printable UTF-8 strings with no whitespace`,
func(c dogma.AggregateConfigurer) {
c.Identity("\t \n", appKey)
c.ConsumesCommandType(fixtures.MessageA{})
c.ProducesEventType(fixtures.MessageE{})
c.Routes(
dogma.HandlesCommand[fixtures.MessageA](),
dogma.RecordsEvent[fixtures.MessageE](),
)
},
),
Entry(
"when the handler configures an invalid key",
`*fixtures.AggregateMessageHandler is configured with an invalid identity, invalid key "\t \n", keys must be RFC 4122 UUIDs`,
func(c dogma.AggregateConfigurer) {
c.Identity("<name>", "\t \n")
c.ConsumesCommandType(fixtures.MessageA{})
c.ProducesEventType(fixtures.MessageE{})
c.Routes(
dogma.HandlesCommand[fixtures.MessageA](),
dogma.RecordsEvent[fixtures.MessageE](),
)
},
),
Entry(
"when the handler does not configure any consumed command types",
`*fixtures.AggregateMessageHandler (<name>) is not configured to consume any commands, ConsumesCommandType() must be called at least once within Configure()`,
func(c dogma.AggregateConfigurer) {
c.Identity("<name>", aggregateKey)
c.ProducesEventType(fixtures.MessageE{})
c.Routes(
dogma.RecordsEvent[fixtures.MessageE](),
)
},
),
Entry(
"when the handler configures the same consumed command type multiple times",
`*fixtures.AggregateMessageHandler (<name>) is configured to consume the fixtures.MessageA command more than once, should this refer to different message types?`,
func(c dogma.AggregateConfigurer) {
c.Identity("<name>", aggregateKey)
c.ConsumesCommandType(fixtures.MessageA{})
c.ConsumesCommandType(fixtures.MessageA{})
c.ProducesEventType(fixtures.MessageE{})
c.Routes(
dogma.HandlesCommand[fixtures.MessageA](),
dogma.HandlesCommand[fixtures.MessageA](),
dogma.RecordsEvent[fixtures.MessageE](),
)
},
),
Entry(
"when the handler does not configure any produced events",
`*fixtures.AggregateMessageHandler (<name>) is not configured to produce any events, ProducesEventType() must be called at least once within Configure()`,
func(c dogma.AggregateConfigurer) {
c.Identity("<name>", aggregateKey)
c.ConsumesCommandType(fixtures.MessageA{})
c.Routes(
dogma.HandlesCommand[fixtures.MessageA](),
)
},
),
Entry(
"when the handler configures the same produced event type multiple times",
`*fixtures.AggregateMessageHandler (<name>) is configured to produce the fixtures.MessageE event more than once, should this refer to different message types?`,
func(c dogma.AggregateConfigurer) {
c.Identity("<name>", aggregateKey)
c.ConsumesCommandType(fixtures.MessageA{})
c.ProducesEventType(fixtures.MessageE{})
c.ProducesEventType(fixtures.MessageE{})
c.Routes(
dogma.HandlesCommand[fixtures.MessageA](),
dogma.RecordsEvent[fixtures.MessageE](),
dogma.RecordsEvent[fixtures.MessageE](),
)
},
),
Entry(
"when the handler configures the same message type with different roles",
`*fixtures.AggregateMessageHandler (<name>) is configured to use fixtures.MessageA as both a command and an event`,
func(c dogma.AggregateConfigurer) {
c.Identity("<name>", aggregateKey)
c.ConsumesCommandType(fixtures.MessageA{})
c.ProducesEventType(fixtures.MessageA{})
c.Routes(
dogma.HandlesCommand[fixtures.MessageA](),
dogma.RecordsEvent[fixtures.MessageA](),
)
},
),
Entry(
"when an error occurs before the identity is configured it omits the handler name",
`*fixtures.AggregateMessageHandler is configured to consume the fixtures.MessageA command more than once, should this refer to different message types?`,
func(c dogma.AggregateConfigurer) {
c.ConsumesCommandType(fixtures.MessageA{})
c.ConsumesCommandType(fixtures.MessageA{})
c.Routes(
dogma.HandlesCommand[fixtures.MessageA](),
dogma.HandlesCommand[fixtures.MessageA](),
)
},
),
)
Expand Down
26 changes: 17 additions & 9 deletions api/blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ var _ = Context("end-to-end tests", func() {
c.RegisterAggregate(&AggregateMessageHandler{
ConfigureFunc: func(c dogma.AggregateConfigurer) {
c.Identity("<aggregate>", "938b829d-e4d7-4780-bf06-ea349453ba8f")
c.ConsumesCommandType(MessageC{})
c.ProducesEventType(MessageE{})
c.Routes(
dogma.HandlesCommand[MessageC](),
dogma.RecordsEvent[MessageE](),
)
},
})

c.RegisterProcess(&ProcessMessageHandler{
ConfigureFunc: func(c dogma.ProcessConfigurer) {
c.Identity("<process>", "2a87972b-547d-416b-b6e5-4dddb1187658")
c.ConsumesEventType(MessageE{})
c.ProducesCommandType(MessageC{})
c.SchedulesTimeoutType(MessageT{})
c.Routes(
dogma.HandlesEvent[MessageE](),
dogma.ExecutesCommand[MessageC](),
dogma.SchedulesTimeout[MessageT](),
)
},
})
},
Expand All @@ -59,16 +63,20 @@ var _ = Context("end-to-end tests", func() {
c.RegisterIntegration(&IntegrationMessageHandler{
ConfigureFunc: func(c dogma.IntegrationConfigurer) {
c.Identity("<integration>", "e6f0ad02-d301-4f46-a03d-4f9d0d20f5cf")
c.ConsumesCommandType(MessageI{})
c.ProducesEventType(MessageJ{})
c.Routes(
dogma.HandlesCommand[MessageI](),
dogma.RecordsEvent[MessageJ](),
)
},
})

c.RegisterProjection(&ProjectionMessageHandler{
ConfigureFunc: func(c dogma.ProjectionConfigurer) {
c.Identity("<projection>", "280a58bd-f154-46d7-863b-23ce70e49d2a")
c.ConsumesEventType(MessageE{})
c.ConsumesEventType(MessageJ{})
c.Routes(
dogma.HandlesEvent[MessageE](),
dogma.HandlesEvent[MessageJ](),
)
},
})
},
Expand Down
Loading

0 comments on commit 6946e42

Please sign in to comment.