Created
October 25, 2020 21:25
-
-
Save danielsiwiec/f1b9507ed576c812a27b01e6341fd2a8 to your computer and use it in GitHub Desktop.
Service Test (point-to-point)
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 | |
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