Created
January 7, 2022 02:43
-
-
Save wenqiglantz/0def7fb0b07ba94cd73ed2e5c90463d8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| @Slf4j | |
| public class CustomerSteps extends CucumberBootstrap { | |
| @Autowired | |
| private CustomerRepository customerRepository; | |
| //this method executes after every scenario | |
| @After | |
| public void cleanUp() { | |
| log.info(">>> cleaning up after scenario!"); | |
| customerRepository.deleteAll(); | |
| } | |
| //this method executes after every step | |
| @AfterStep | |
| public void afterStep() { | |
| log.info(">>> AfterStep!"); | |
| //placeholder for after step logic | |
| } | |
| //this method executes before every scenario | |
| @Before | |
| public void before() { | |
| log.info(">>> Before scenario!"); | |
| //placeholder for before scenario logic | |
| } | |
| //this method executes before every step | |
| @BeforeStep | |
| public void beforeStep() { | |
| log.info(">>> BeforeStep!"); | |
| //placeholder for before step logic | |
| } | |
| @Given("^the collection of customers:$") | |
| public void collection_of_customers(DataTable dataTable) { | |
| dataTable.asList(CustomerInfo.class).forEach(customerInfo -> { | |
| saveCustomer((CustomerInfo)customerInfo); | |
| }); | |
| } | |
| @When("^customerId (.+) is passed in to retrieve the customer details$") | |
| public void get_customer_details_by_id(String customerId) { | |
| ResponseEntity<CustomerInfo> response = testRestTemplate.getForEntity( | |
| "/customers/" + customerId, CustomerInfo.class, customerId); | |
| assertThat(response.getBody(), is(notNullValue())); | |
| assertThat(response.getBody().getCustomerId(), is(equalTo(customerId))); | |
| } | |
| @Then("^The customer detail is retrieved$") | |
| public void customer_detail_retrieved(DataTable dataTable) { | |
| dataTable.asList(CustomerInfo.class).forEach(customerInfo -> { | |
| Optional<Customer> customerOptional = | |
| customerRepository.findByCustomerId(((CustomerInfo)customerInfo).getCustomerId()); | |
| if (customerOptional.isPresent()){ | |
| assertThat(customerOptional.get().getFirstName(), is(equalTo(((CustomerInfo)customerInfo).getFirstName()))); | |
| assertThat(customerOptional.get().getLastName(), is(equalTo(((CustomerInfo)customerInfo).getLastName()))); | |
| } | |
| }); | |
| } | |
| private void saveCustomer(CustomerInfo customerInfo) { | |
| customerRepository.save(Customer.builder() | |
| .customerId(customerInfo.getCustomerId()) | |
| .firstName(customerInfo.getFirstName()) | |
| .lastName(customerInfo.getLastName()) | |
| .build()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment