70 likes | 86 Views
Enterprise System Integration. Practical Session 3. Manuel Camargo manuel.camargo@ut.ee. Source code. https://bitbucket.org/orlenyslp/esi-2019/src/master /. http://kodu.ut.ee/~chavez85/esi/. Practice aim. BDD / cucumber ( acceptance testing ) Gherkin --Specification language.
E N D
Enterprise System Integration PracticalSession 3 Manuel Camargo manuel.camargo@ut.ee
Sourcecode https://bitbucket.org/orlenyslp/esi-2019/src/master/ http://kodu.ut.ee/~chavez85/esi/
Practice aim • BDD / cucumber (acceptance testing) • Gherkin --Specification language Web UI adaptor on top of a domain model using Spring Boot
Test structure \features/sales/creation_of_purchase_order.feature User story com/example/demo/sales/CreationOfPurchaseOrderSteps.java CreationOfPurchaseOrderSteps.java @ContextConfiguration(classes = DemoApplication.class) @WebAppConfiguration public class CreationOfPurchaseOrderSteps { @Autowired private WebApplicationContextwac; private WebClientcustomerBrowser; HtmlPagecustomerPage; @Autowired PlantInventoryEntryRepositoryplantInventoryEntryRepository; @Autowired PlantInventoryItemRepositoryplantInventoryItemRepository; @Autowired PurchaseOrderRepositoryPurchaseOrderRepository; @Before // Use `Before` from Cucumber library public void setUp() { … Implementationsteps
Test structure public class CreationOfPurchaseOrderSteps {@Autowiredprivate WebApplicationContextwac;private WebClientcustomerBrowser;HtmlPagecustomerPage;@AutowiredPlantInventoryEntryRepositoryplantInventoryEntryRepository;@AutowiredPlantInventoryItemRepositoryplantInventoryItemRepository;@AutowiredPurchaseOrderRepositorypurchaseOrderRepository;@Before // Use `Before` from Cucumber librarypublic void setUp() {customerBrowser= MockMvcWebClientBuilder.webAppContextSetup(wac).build(); }@After // Use `After` from Cucumber librarypublic void tearOff() {purchaseOrderRepository.deleteAll();plantInventoryItemRepository.deleteAll();plantInventoryEntryRepository.deleteAll(); } Setup Creation of relationships Customerbrowsercreation Cleansingafter test execution
Test structure Setup @Given("^the following plant catalog$")public void the_following_plant_catalog(List<PlantInventoryEntry> entries) throws Throwable {plantInventoryEntryRepository.saveAll(entries);}@Given("^the following inventory$")public void the_following_inventory(DataTable table) throws Throwable {for (Map<String, String> row: table.asMaps(String.class, String.class))plantInventoryItemRepository.save(PlantInventoryItem.of(Long.parseLong(row.get("id")),row.get("serialNumber"),EquipmentCondition.valueOf(row.get("equipmentCondition")),plantInventoryEntryRepository.findById(Long.parseLong(row.get("plantInfo"))).orElse(null) ) );}@Given("^a customer is in the \"([^\"]*)\" web page$")public void a_customer_is_in_the_web_page(String arg1) throws Throwable {customerPage= customerBrowser.getPage("http://localhost/dashboard/catalog/form");}@Given("^no purchase order exists in the system$")public void no_purchase_order_exists_in_the_system() throws Throwable {assertThat(purchaseOrderRepository.findAll().size()).isZero();} Tablespopulation Simulatethecustomer interaction with the application Validation of no order existance
Test structure Scenarios @When("^the customer queries the plant catalog for an \"([^\"]*)\" available from \"([^\"]*)\" to \"([^\"]*)\"$")public void the_customer_queries_the_plant_catalog_for_an_available_from_to(String plantName, String startDate, String endDate) throws Throwable {// The following elements are selected by their identifierHtmlTextInputnameInput = (HtmlTextInput)customerPage.getElementById("name");HtmlDateInputstartDateInput = (HtmlDateInput)customerPage.getElementById("rental-start-date");HtmlDateInputendDateInput = (HtmlDateInput)customerPage.getElementById("rental-end-date");HtmlButton submit = (HtmlButton)customerPage.getElementById("submit-button");nameInput.setValueAttribute(plantName);startDateInput.setValueAttribute(startDate);endDateInput.setValueAttribute(endDate);customerPage= submit.click();}@Then("^(\\d+) plants are shown$")public void plants_are_shown(int arg1) throws Throwable { List<?> rows = customerPage.getByXPath("//tr[contains(@class, 'table-row')]");assertThat(rows.size()).isEqualTo(arg1);}