Search in sources :

Example 1 with CREATED

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.");
}
Also used : Order(io.confluent.examples.streams.avro.microservices.Order) Payment(io.confluent.examples.streams.avro.microservices.Payment) MicroserviceTestUtils(io.confluent.examples.streams.microservices.util.MicroserviceTestUtils) BeforeClass(org.junit.BeforeClass) TestUtils(org.apache.kafka.test.TestUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) KeyValue(org.apache.kafka.streams.KeyValue) OrderId.id(io.confluent.examples.streams.microservices.domain.beans.OrderId.id) Test(org.junit.Test) Customer(io.confluent.examples.streams.avro.microservices.Customer) UNDERPANTS(io.confluent.examples.streams.avro.microservices.Product.UNDERPANTS) Topics(io.confluent.examples.streams.microservices.domain.Schemas.Topics) Schemas(io.confluent.examples.streams.microservices.domain.Schemas) After(org.junit.After) Order(io.confluent.examples.streams.avro.microservices.Order) Collections(java.util.Collections) CREATED(io.confluent.examples.streams.avro.microservices.OrderState.CREATED) Payment(io.confluent.examples.streams.avro.microservices.Payment) KeyValue(org.apache.kafka.streams.KeyValue) Customer(io.confluent.examples.streams.avro.microservices.Customer) Test(org.junit.Test)

Example 2 with CREATED

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));
}
Also used : Order(io.confluent.examples.streams.avro.microservices.Order) MicroserviceTestUtils(io.confluent.examples.streams.microservices.util.MicroserviceTestUtils) OrderValidationResult(io.confluent.examples.streams.avro.microservices.OrderValidationResult) OrderValidationType(io.confluent.examples.streams.avro.microservices.OrderValidationType) JUMPERS(io.confluent.examples.streams.avro.microservices.Product.JUMPERS) BeforeClass(org.junit.BeforeClass) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) KeyValue(org.apache.kafka.streams.KeyValue) OrderId.id(io.confluent.examples.streams.microservices.domain.beans.OrderId.id) FAILED(io.confluent.examples.streams.avro.microservices.OrderState.FAILED) Test(org.junit.Test) Collectors(java.util.stream.Collectors) UNDERPANTS(io.confluent.examples.streams.avro.microservices.Product.UNDERPANTS) Topics(io.confluent.examples.streams.microservices.domain.Schemas.Topics) Schemas(io.confluent.examples.streams.microservices.domain.Schemas) List(java.util.List) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) VALIDATED(io.confluent.examples.streams.avro.microservices.OrderState.VALIDATED) OrderValidation(io.confluent.examples.streams.avro.microservices.OrderValidation) CREATED(io.confluent.examples.streams.avro.microservices.OrderState.CREATED) Order(io.confluent.examples.streams.avro.microservices.Order) KeyValue(org.apache.kafka.streams.KeyValue) OrderValidation(io.confluent.examples.streams.avro.microservices.OrderValidation) Test(org.junit.Test)

Aggregations

Order (io.confluent.examples.streams.avro.microservices.Order)2 CREATED (io.confluent.examples.streams.avro.microservices.OrderState.CREATED)2 UNDERPANTS (io.confluent.examples.streams.avro.microservices.Product.UNDERPANTS)2 Schemas (io.confluent.examples.streams.microservices.domain.Schemas)2 Topics (io.confluent.examples.streams.microservices.domain.Schemas.Topics)2 OrderId.id (io.confluent.examples.streams.microservices.domain.beans.OrderId.id)2 MicroserviceTestUtils (io.confluent.examples.streams.microservices.util.MicroserviceTestUtils)2 KeyValue (org.apache.kafka.streams.KeyValue)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 After (org.junit.After)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 Customer (io.confluent.examples.streams.avro.microservices.Customer)1 FAILED (io.confluent.examples.streams.avro.microservices.OrderState.FAILED)1 VALIDATED (io.confluent.examples.streams.avro.microservices.OrderState.VALIDATED)1 OrderValidation (io.confluent.examples.streams.avro.microservices.OrderValidation)1 OrderValidationResult (io.confluent.examples.streams.avro.microservices.OrderValidationResult)1 OrderValidationType (io.confluent.examples.streams.avro.microservices.OrderValidationType)1 Payment (io.confluent.examples.streams.avro.microservices.Payment)1 JUMPERS (io.confluent.examples.streams.avro.microservices.Product.JUMPERS)1