use of io.confluent.examples.streams.avro.microservices.OrderState.CREATED in project kafka-streams-examples by confluentinc.
the class EmailServiceTest method shouldSendEmailWithValidContents.
@Test
public void shouldSendEmailWithValidContents() throws Exception {
// Given one order, customer and payment
String orderId = id(0L);
Order order = new Order(orderId, 15L, CREATED, UNDERPANTS, 3, 5.00d);
Customer customer = new Customer(15L, "Franz", "Kafka", "frans@thedarkside.net", "oppression street, prague, cze");
Payment payment = new Payment("Payment:1234", orderId, "CZK", 1000.00d);
emailService = new EmailService(details -> {
assertThat(details.customer).isEqualTo(customer);
assertThat(details.payment).isEqualTo(payment);
assertThat(details.order).isEqualTo(order);
complete = true;
});
send(Topics.CUSTOMERS, Collections.singleton(new KeyValue<>(customer.getId(), customer)));
send(Topics.ORDERS, Collections.singleton(new KeyValue<>(order.getId(), order)));
send(Topics.PAYMENTS, Collections.singleton(new KeyValue<>(payment.getId(), payment)));
// When
emailService.start(CLUSTER.bootstrapServers());
// Then
TestUtils.waitForCondition(() -> complete, "Email was never sent.");
}
use of io.confluent.examples.streams.avro.microservices.OrderState.CREATED in project kafka-streams-examples by confluentinc.
the class ValidationsAggregatorServiceTest method shouldAggregateRuleSuccesses.
@Test
public void shouldAggregateRuleSuccesses() throws Exception {
// Given
ordersService = new ValidationsAggregatorService();
orders = asList(new Order(id(0L), 0L, CREATED, UNDERPANTS, 3, 5.00d), new Order(id(1L), 0L, CREATED, JUMPERS, 1, 75.00d));
sendOrders(orders);
ruleResults = asList(new OrderValidation(id(0L), OrderValidationType.FRAUD_CHECK, OrderValidationResult.PASS), new OrderValidation(id(0L), OrderValidationType.ORDER_DETAILS_CHECK, OrderValidationResult.PASS), new OrderValidation(id(0L), OrderValidationType.INVENTORY_CHECK, OrderValidationResult.PASS), new OrderValidation(id(1L), OrderValidationType.FRAUD_CHECK, OrderValidationResult.PASS), new OrderValidation(id(1L), OrderValidationType.ORDER_DETAILS_CHECK, OrderValidationResult.FAIL), new OrderValidation(id(1L), OrderValidationType.INVENTORY_CHECK, OrderValidationResult.PASS));
sendOrderValuations(ruleResults);
// When
ordersService.start(CLUSTER.bootstrapServers());
// Then
List<KeyValue<String, Order>> finalOrders = MicroserviceTestUtils.readKeyValues(Topics.ORDERS, 4, CLUSTER.bootstrapServers());
assertThat(finalOrders.size()).isEqualTo(4);
// And the first order should have been validated but the second should have failed
assertThat(finalOrders.stream().map(kv -> kv.value).collect(Collectors.toList())).contains(new Order(id(0L), 0L, VALIDATED, UNDERPANTS, 3, 5.00d), new Order(id(1L), 0L, FAILED, JUMPERS, 1, 75.00d));
}
Aggregations