-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
CreateOrderSagaTest.java
119 lines (109 loc) · 4.56 KB
/
CreateOrderSagaTest.java
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package net.chrisrichardson.ftgo.orderservice.sagas.createorder;
import net.chrisrichardson.ftgo.accountservice.api.AccountingServiceChannels;
import net.chrisrichardson.ftgo.accountservice.api.AuthorizeCommand;
import net.chrisrichardson.ftgo.common.CommonJsonMapperInitializer;
import net.chrisrichardson.ftgo.consumerservice.api.ConsumerServiceChannels;
import net.chrisrichardson.ftgo.consumerservice.api.ValidateOrderByConsumer;
import net.chrisrichardson.ftgo.kitchenservice.api.CancelCreateTicket;
import net.chrisrichardson.ftgo.kitchenservice.api.ConfirmCreateTicket;
import net.chrisrichardson.ftgo.kitchenservice.api.CreateTicket;
import net.chrisrichardson.ftgo.kitchenservice.api.KitchenServiceChannels;
import net.chrisrichardson.ftgo.orderservice.api.OrderServiceChannels;
import net.chrisrichardson.ftgo.orderservice.sagaparticipants.*;
import org.jetbrains.annotations.NotNull;
import org.junit.BeforeClass;
import org.junit.Test;
import static io.eventuate.tram.sagas.testing.SagaUnitTestSupport.given;
import static net.chrisrichardson.ftgo.orderservice.OrderDetailsMother.*;
import static net.chrisrichardson.ftgo.orderservice.RestaurantMother.AJANTA_ID;
public class CreateOrderSagaTest {
private OrderServiceProxy orderServiceProxy = new OrderServiceProxy();
private KitchenServiceProxy kitchenServiceProxy = new KitchenServiceProxy();
private ConsumerServiceProxy consumerServiceProxy = new ConsumerServiceProxy();
private AccountingServiceProxy accountingServiceProxy = new AccountingServiceProxy();
@BeforeClass
public static void initialize() {
CommonJsonMapperInitializer.registerMoneyModule();
}
private CreateOrderSaga makeCreateOrderSaga() {
return new CreateOrderSaga(orderServiceProxy, consumerServiceProxy, kitchenServiceProxy, accountingServiceProxy);
}
@Test
public void shouldCreateOrder() {
given()
.saga(makeCreateOrderSaga(),
new CreateOrderSagaState(ORDER_ID, CHICKEN_VINDALOO_ORDER_DETAILS)).
expect().
command(makeValidateOrderByConsumer()).
to(ConsumerServiceChannels.consumerServiceChannel).
andGiven().
successReply().
expect().
command(new CreateTicket(AJANTA_ID, ORDER_ID, null /* FIXME */)).
to(KitchenServiceChannels.COMMAND_CHANNEL).
andGiven().
successReply().
expect().
command(new AuthorizeCommand().withConsumerId(CONSUMER_ID).withOrderId(ORDER_ID).withOrderTotal(CHICKEN_VINDALOO_ORDER_TOTAL.asString())).
to(AccountingServiceChannels.accountingServiceChannel).
andGiven().
successReply().
expect().
command(new ConfirmCreateTicket(ORDER_ID)).
to(KitchenServiceChannels.COMMAND_CHANNEL).
andGiven().
successReply().
expect().
command(new ApproveOrderCommand(ORDER_ID)).
to(OrderServiceChannels.COMMAND_CHANNEL)
;
}
@NotNull
private ValidateOrderByConsumer makeValidateOrderByConsumer() {
return new ValidateOrderByConsumer().withConsumerId(CONSUMER_ID).withOrderId(ORDER_ID).withOrderTotal(CHICKEN_VINDALOO_ORDER_TOTAL.asString());
}
@Test
public void shouldRejectOrderDueToConsumerVerificationFailed() {
given()
.saga(makeCreateOrderSaga(),
new CreateOrderSagaState(ORDER_ID, CHICKEN_VINDALOO_ORDER_DETAILS)).
expect().
command(makeValidateOrderByConsumer()).
to(ConsumerServiceChannels.consumerServiceChannel).
andGiven().
failureReply().
expect().
command(new RejectOrderCommand(ORDER_ID)).
to(OrderServiceChannels.COMMAND_CHANNEL);
}
@Test
public void shouldRejectDueToFailedAuthorizxation() {
given()
.saga(makeCreateOrderSaga(),
new CreateOrderSagaState(ORDER_ID, CHICKEN_VINDALOO_ORDER_DETAILS)).
expect().
command(makeValidateOrderByConsumer()).
to(ConsumerServiceChannels.consumerServiceChannel).
andGiven().
successReply().
expect().
command(new CreateTicket(AJANTA_ID, ORDER_ID, null /* FIXME */)).
to(KitchenServiceChannels.COMMAND_CHANNEL).
andGiven().
successReply().
expect().
command(new AuthorizeCommand().withConsumerId(CONSUMER_ID).withOrderId(ORDER_ID).withOrderTotal(CHICKEN_VINDALOO_ORDER_TOTAL.asString())).
to(AccountingServiceChannels.accountingServiceChannel).
andGiven().
failureReply().
expect().
command(new CancelCreateTicket(ORDER_ID)).
to(KitchenServiceChannels.COMMAND_CHANNEL).
andGiven().
successReply().
expect().
command(new RejectOrderCommand(ORDER_ID)).
to(OrderServiceChannels.COMMAND_CHANNEL)
;
}
}