Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Service Test (point-to-point)
@SpringBootTest
public class PaymentServiceTest {
@Autowired
private RestTemplate restTemplate;
@Test
public void shouldProcessPaymentForValidOrder() {
var validOrder = Order
.withCustomerId(123)
.withItems(Item.withId("af12da"));
var response = restTemplate.postForEntity("/payment", validOrder);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody().getPaymentTransactionId()).isNotNull();
}
@Test
public void shouldRejectPaymentForOrderWithMissingCustomer() {
var validOrder = Order
.withItems(Item.withId("af12da"));
var response = restTemplate.postForEntity("/payment", validOrder);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(response.getBody().getPaymentTransactionId()).isNull();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment