Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
End to End Test (asynchronous)
public class OrderProcessingTest {
@Autowired
RestTemplate restTemplate;
@Test
public void shouldProcessValidOrder() {
var validOrder = Order.withItems(Item.id("2fa2ac")).withCustomerId("123");
// submit Order
var response = restTemplate.postForEntity("/processOrder", validOrder);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody().getStatus()).isEqualTo("QUEUED");
// await until Order fully processed
var orderId = response.getBody().getId();
await().until(() -> restTemplate.getForEntity("orderStatus/" + orderId).getBody().getStatus(), equalTo("PROCESSED"));
var processedOrder = restTemplate.getForEntity("orderStatus/" + orderId).getBody();
// validate Payment
var paymentTransactionId = processedOrder.getPaymentTranscationId();
var paymentStatus = restTemplate.getForEntity("http://externalPaymentGateway/paymentStatus/" + paymentTransactionId);
assertThat(paymentStatus).isEqualTo("PAYMENT_PROCESSED");
// validate Shipment
var shipmentId = processedOrder.getShipmentId();
var shipmentStatus = restTemplate.getForEntity("http://externalShipmentService/shipmentStatus/" + shipmentId);
assertThat(shipmentStatus).isEqualTo("QUEUED_FOR_SHIPMENT");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment