Created
October 25, 2020 21:49
-
-
Save danielsiwiec/7282e62599574d6b662d04374775e3c7 to your computer and use it in GitHub Desktop.
Service Test (event-driven)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SpringBootTest | |
@EmbeddedKafka(topics = {"orders", "payments"}) | |
public class PaymentServiceTest { | |
@Autowired | |
private Producer<Order> orderProducer; | |
@Autowired | |
private Consumer<Payment> paymentConsumer; | |
@Test | |
public void shouldProcessPaymentForValidOrder() { | |
var validOrder = Order | |
.withCustomerId(123) | |
.withItems(Item.withId("af12da")); | |
orderProducer.send(validOrder); | |
var payment = paymentConsumer.poll(); | |
assertThat(payment.getPaymentStatus()).isEqualTo("OK"); | |
assertThat(payment.getPaymentTransactionId()).isNotNull(); | |
} | |
@Test | |
public void shouldRejectPaymentForOrderWithMissingCustomer() { | |
var validOrder = Order | |
.withItems(Item.withId("af12da")); | |
orderProducer.send(validOrder); | |
var payment = paymentConsumer.poll(); | |
assertThat(payment.getPaymentStatus()).isEqualTo("ORDER_INVALID"); | |
assertThat(payment.getPaymentTransactionId()).isNull(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment