Search in sources :

Example 1 with JUMPERS

use of io.confluent.examples.streams.avro.microservices.Product.JUMPERS 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)1 CREATED (io.confluent.examples.streams.avro.microservices.OrderState.CREATED)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 JUMPERS (io.confluent.examples.streams.avro.microservices.Product.JUMPERS)1 UNDERPANTS (io.confluent.examples.streams.avro.microservices.Product.UNDERPANTS)1 Schemas (io.confluent.examples.streams.microservices.domain.Schemas)1 Topics (io.confluent.examples.streams.microservices.domain.Schemas.Topics)1 OrderId.id (io.confluent.examples.streams.microservices.domain.beans.OrderId.id)1 MicroserviceTestUtils (io.confluent.examples.streams.microservices.util.MicroserviceTestUtils)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 KeyValue (org.apache.kafka.streams.KeyValue)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 After (org.junit.After)1 BeforeClass (org.junit.BeforeClass)1