From 1f56baddab986629db2609e437fbf1c223d2edc4 Mon Sep 17 00:00:00 2001 From: Adam Klinkosz Date: Thu, 15 Apr 2021 17:35:21 +0200 Subject: [PATCH 01/13] Introduced Cucumber with Selenium for a QA assignment --- pom.xml | 43 ++++++++++++++++ .../petclinic/integration/Browser.java | 43 ++++++++++++++++ .../petclinic/integration/CucumberRunner.java | 16 ++++++ .../integration/SpringIntegrationTest.java | 10 ++++ .../petclinic/integration/StepDefinition.java | 51 +++++++++++++++++++ .../resources/scenarios/AddOwners.feature | 3 ++ .../resources/scenarios/FindOwners.feature | 14 +++++ src/test/resources/scenarios/MainPage.feature | 5 ++ 8 files changed, 185 insertions(+) create mode 100644 src/test/java/org/springframework/samples/petclinic/integration/Browser.java create mode 100644 src/test/java/org/springframework/samples/petclinic/integration/CucumberRunner.java create mode 100644 src/test/java/org/springframework/samples/petclinic/integration/SpringIntegrationTest.java create mode 100644 src/test/java/org/springframework/samples/petclinic/integration/StepDefinition.java create mode 100644 src/test/resources/scenarios/AddOwners.feature create mode 100644 src/test/resources/scenarios/FindOwners.feature create mode 100644 src/test/resources/scenarios/MainPage.feature diff --git a/pom.xml b/pom.xml index cdd6c4522..4cca338b3 100644 --- a/pom.xml +++ b/pom.xml @@ -119,6 +119,49 @@ spring-boot-devtools true + + + + io.cucumber + cucumber-java + 6.10.3 + test + + + io.cucumber + cucumber-junit + 6.10.3 + test + + + io.cucumber + cucumber-spring + 6.10.3 + test + + + org.seleniumhq.selenium + selenium-java + 3.141.59 + + + org.junit.vintage + junit-vintage-engine + ${junit-jupiter.version} + test + + + io.github.bonigarcia + webdrivermanager + 4.4.0 + test + + + org.assertj + assertj-core + 3.19.0 + test + diff --git a/src/test/java/org/springframework/samples/petclinic/integration/Browser.java b/src/test/java/org/springframework/samples/petclinic/integration/Browser.java new file mode 100644 index 000000000..54882b0f1 --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/integration/Browser.java @@ -0,0 +1,43 @@ +package org.springframework.samples.petclinic.integration; + +import java.util.concurrent.TimeUnit; + +import org.openqa.selenium.Dimension; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeDriverService; +import org.openqa.selenium.chrome.ChromeOptions; + +import io.github.bonigarcia.wdm.WebDriverManager; + +public class Browser { + public final static WebDriver webDriver = createDriver(); + + private static WebDriver createDriver() { + setupDriver(); + ChromeDriver chromeDriver = new ChromeDriver( + new ChromeDriverService.Builder().withSilent(true).build(), + chromeOptions() + ); + chromeDriver.manage().window().setSize(new Dimension(1024, 768)); + chromeDriver.manage().timeouts().implicitlyWait(0L, TimeUnit.SECONDS); + return chromeDriver; + } + + private static void setupDriver() { + WebDriverManager + .chromedriver() + .timeout(60) + .setup(); + } + + private static ChromeOptions chromeOptions() { + final ChromeOptions chromeOptions = new ChromeOptions(); + chromeOptions.addArguments("enable-automation"); + chromeOptions.addArguments("--no-sandbox"); + chromeOptions.addArguments("--disable-infobars"); + chromeOptions.addArguments("--disable-dev-shm-usage"); + chromeOptions.addArguments("--disable-browser-side-navigation"); + return chromeOptions; + } +} diff --git a/src/test/java/org/springframework/samples/petclinic/integration/CucumberRunner.java b/src/test/java/org/springframework/samples/petclinic/integration/CucumberRunner.java new file mode 100644 index 000000000..6b28fc7db --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/integration/CucumberRunner.java @@ -0,0 +1,16 @@ +package org.springframework.samples.petclinic.integration; + +import org.junit.runner.RunWith; + +import io.cucumber.junit.Cucumber; +import io.cucumber.junit.CucumberOptions; + + +@RunWith(Cucumber.class) +@CucumberOptions( + plugin = { "pretty", "html:target/cucumber-html-report" }, + glue = { "org.springframework.samples.petclinic.integration" }, + features = "classpath:scenarios" +) +public class CucumberRunner { +} diff --git a/src/test/java/org/springframework/samples/petclinic/integration/SpringIntegrationTest.java b/src/test/java/org/springframework/samples/petclinic/integration/SpringIntegrationTest.java new file mode 100644 index 000000000..a59c16b26 --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/integration/SpringIntegrationTest.java @@ -0,0 +1,10 @@ +package org.springframework.samples.petclinic.integration; + +import org.springframework.boot.test.context.SpringBootTest; + +import io.cucumber.spring.CucumberContextConfiguration; + +@CucumberContextConfiguration +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class SpringIntegrationTest { +} diff --git a/src/test/java/org/springframework/samples/petclinic/integration/StepDefinition.java b/src/test/java/org/springframework/samples/petclinic/integration/StepDefinition.java new file mode 100644 index 000000000..db06aaefd --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/integration/StepDefinition.java @@ -0,0 +1,51 @@ +package org.springframework.samples.petclinic.integration; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.WebDriverWait; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +public class StepDefinition extends SpringIntegrationTest { + private final WebDriver webDriver = Browser.webDriver; + + @Given("^I go to the main page$") + public void mainPage() { + webDriver.navigate().to("http://localhost:8080"); + } + + @When("^I click on the link with title \"([^\"]*)\"$") + public void clickOnLinkWithTitle(String linkTitle) { + By elementSelector = By.xpath(String.format("//*[@title='%s']", linkTitle)); + new WebDriverWait(webDriver, 60L).until(driver -> driver.findElement(elementSelector).isDisplayed()); + WebElement webElement = webDriver.findElement(elementSelector); + webElement.click(); + } + + @Then("^I should see the \"([^\"]*)\" page$") + public void shouldSeeThePage(String pageTitle) { + By elementSelector = By.tagName("h2"); + new WebDriverWait(webDriver, 60L).until(driver -> driver.findElement(elementSelector).isDisplayed()); + WebElement webElement = webDriver.findElement(elementSelector); + assertThat(webElement.getText()).isEqualTo(pageTitle); + } + + @When("^I fill the field named \"([^\"]*)\" with value \"([^\"]*)\"$") + public void fillInputBoxWithValue(String name, String value) { + By elementSelector = By.name(name); + WebElement webElement = webDriver.findElement(elementSelector); + webElement.sendKeys(value); + } + + @When("^I submit the form \"([^\"]*)\"$") + public void submitForm(String id) { + By elementSelector = By.id(id); + WebElement webElement = webDriver.findElement(elementSelector); + webElement.submit(); + } +} diff --git a/src/test/resources/scenarios/AddOwners.feature b/src/test/resources/scenarios/AddOwners.feature new file mode 100644 index 000000000..e69f35b0a --- /dev/null +++ b/src/test/resources/scenarios/AddOwners.feature @@ -0,0 +1,3 @@ +Feature: Add owners + + # Add scenarios covering all cases. diff --git a/src/test/resources/scenarios/FindOwners.feature b/src/test/resources/scenarios/FindOwners.feature new file mode 100644 index 000000000..1ca6624b6 --- /dev/null +++ b/src/test/resources/scenarios/FindOwners.feature @@ -0,0 +1,14 @@ +Feature: Find owners + + Scenario: Find owners page + When I click on the link with title "find owners" + Then I should see the "Find Owners" page + + Scenario: Should find an owner + When I fill the field named "lastName" with value "Franklin" + Then I should see the "Owner Information" page + + Scenario: Should find multiple owners + When I fill the field named "lastName" with value "Davis" + Then I should see the "Owners" page + # Add additional checks here. diff --git a/src/test/resources/scenarios/MainPage.feature b/src/test/resources/scenarios/MainPage.feature new file mode 100644 index 000000000..eebeae133 --- /dev/null +++ b/src/test/resources/scenarios/MainPage.feature @@ -0,0 +1,5 @@ +Feature: Main page + + Scenario: Main page + When I go to the main page + Then I should see the "Welcome" page From 3e9cdaad38a96c9971e7190406e323120a669220 Mon Sep 17 00:00:00 2001 From: Adam Klinkosz Date: Thu, 15 Apr 2021 17:59:55 +0200 Subject: [PATCH 02/13] Fixed code formatting --- ASSIGNMENT.md | 14 ++++++++++++++ readme.md | 2 +- .../samples/petclinic/integration/Browser.java | 13 +++++-------- .../petclinic/integration/CucumberRunner.java | 9 +++------ .../integration/SpringIntegrationTest.java | 1 + .../petclinic/integration/StepDefinition.java | 2 ++ 6 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 ASSIGNMENT.md diff --git a/ASSIGNMENT.md b/ASSIGNMENT.md new file mode 100644 index 000000000..d507e6f88 --- /dev/null +++ b/ASSIGNMENT.md @@ -0,0 +1,14 @@ +# QA Assignment + +## Finding owners +The scenarios for this feature are incomplete or even naive. Please cover more cases in more reliable way. + +## Adding owners +Open `src/test/resources/scenarios/AddOwners.feature` and follow instructions given in the comments. + + +## Bonus tasks +1. The browser is not closing after all tests were run. Fix it. +2. There is something wrong with the way the HTML elements are selected. + Prepare a suggestion of how to improve it or even implement such a change. +3. diff --git a/readme.md b/readme.md index ff6d2be15..f8e8dd8b0 100644 --- a/readme.md +++ b/readme.md @@ -8,7 +8,7 @@ Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) applicatio ``` -git clone https://github.com/spring-projects/spring-petclinic.git +git clone https://github.com/cleankod/spring-petclinic cd spring-petclinic ./mvnw package java -jar target/*.jar diff --git a/src/test/java/org/springframework/samples/petclinic/integration/Browser.java b/src/test/java/org/springframework/samples/petclinic/integration/Browser.java index 54882b0f1..a45925949 100644 --- a/src/test/java/org/springframework/samples/petclinic/integration/Browser.java +++ b/src/test/java/org/springframework/samples/petclinic/integration/Browser.java @@ -11,24 +11,20 @@ import org.openqa.selenium.chrome.ChromeOptions; import io.github.bonigarcia.wdm.WebDriverManager; public class Browser { + public final static WebDriver webDriver = createDriver(); private static WebDriver createDriver() { setupDriver(); - ChromeDriver chromeDriver = new ChromeDriver( - new ChromeDriverService.Builder().withSilent(true).build(), - chromeOptions() - ); + ChromeDriver chromeDriver = new ChromeDriver(new ChromeDriverService.Builder().withSilent(true).build(), + chromeOptions()); chromeDriver.manage().window().setSize(new Dimension(1024, 768)); chromeDriver.manage().timeouts().implicitlyWait(0L, TimeUnit.SECONDS); return chromeDriver; } private static void setupDriver() { - WebDriverManager - .chromedriver() - .timeout(60) - .setup(); + WebDriverManager.chromedriver().timeout(60).setup(); } private static ChromeOptions chromeOptions() { @@ -40,4 +36,5 @@ public class Browser { chromeOptions.addArguments("--disable-browser-side-navigation"); return chromeOptions; } + } diff --git a/src/test/java/org/springframework/samples/petclinic/integration/CucumberRunner.java b/src/test/java/org/springframework/samples/petclinic/integration/CucumberRunner.java index 6b28fc7db..7714ffddb 100644 --- a/src/test/java/org/springframework/samples/petclinic/integration/CucumberRunner.java +++ b/src/test/java/org/springframework/samples/petclinic/integration/CucumberRunner.java @@ -5,12 +5,9 @@ import org.junit.runner.RunWith; import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; - @RunWith(Cucumber.class) -@CucumberOptions( - plugin = { "pretty", "html:target/cucumber-html-report" }, - glue = { "org.springframework.samples.petclinic.integration" }, - features = "classpath:scenarios" -) +@CucumberOptions(plugin = { "pretty", "html:target/cucumber-html-report" }, + glue = { "org.springframework.samples.petclinic.integration" }, features = "classpath:scenarios") public class CucumberRunner { + } diff --git a/src/test/java/org/springframework/samples/petclinic/integration/SpringIntegrationTest.java b/src/test/java/org/springframework/samples/petclinic/integration/SpringIntegrationTest.java index a59c16b26..90ea71c81 100644 --- a/src/test/java/org/springframework/samples/petclinic/integration/SpringIntegrationTest.java +++ b/src/test/java/org/springframework/samples/petclinic/integration/SpringIntegrationTest.java @@ -7,4 +7,5 @@ import io.cucumber.spring.CucumberContextConfiguration; @CucumberContextConfiguration @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) public class SpringIntegrationTest { + } diff --git a/src/test/java/org/springframework/samples/petclinic/integration/StepDefinition.java b/src/test/java/org/springframework/samples/petclinic/integration/StepDefinition.java index db06aaefd..de20de94d 100644 --- a/src/test/java/org/springframework/samples/petclinic/integration/StepDefinition.java +++ b/src/test/java/org/springframework/samples/petclinic/integration/StepDefinition.java @@ -12,6 +12,7 @@ import io.cucumber.java.en.Then; import io.cucumber.java.en.When; public class StepDefinition extends SpringIntegrationTest { + private final WebDriver webDriver = Browser.webDriver; @Given("^I go to the main page$") @@ -48,4 +49,5 @@ public class StepDefinition extends SpringIntegrationTest { WebElement webElement = webDriver.findElement(elementSelector); webElement.submit(); } + } From 03cff1a308aacad32047f0879c81ccdd3e930d2c Mon Sep 17 00:00:00 2001 From: Adam Klinkosz Date: Thu, 15 Apr 2021 18:38:28 +0200 Subject: [PATCH 03/13] Tests execution with maven --- ASSIGNMENT.md | 6 ++++++ pom.xml | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/ASSIGNMENT.md b/ASSIGNMENT.md index d507e6f88..248612ec2 100644 --- a/ASSIGNMENT.md +++ b/ASSIGNMENT.md @@ -1,5 +1,11 @@ # QA Assignment +## Running tests +You can run the Cucumber features from your IDE or via the command line: +```shell +./mvnw -P itest integration-test +``` + ## Finding owners The scenarios for this feature are incomplete or even naive. Please cover more cases in more reliable way. diff --git a/pom.xml b/pom.xml index 4cca338b3..8707d3248 100644 --- a/pom.xml +++ b/pom.xml @@ -411,6 +411,41 @@ + + itest + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.22.2 + + test/integration + + **/CucumberRunner.java + + + **/*Tests.java + + + + + integration-test + + integration-test + + + + verify + + verify + + + + + + + From 54792e17e3f516c2d428ac2b22b57803f824d4b2 Mon Sep 17 00:00:00 2001 From: Adam Klinkosz Date: Thu, 15 Apr 2021 18:38:40 +0200 Subject: [PATCH 04/13] Fix tests --- .../samples/petclinic/integration/StepDefinition.java | 9 ++++++++- src/test/resources/scenarios/FindOwners.feature | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/springframework/samples/petclinic/integration/StepDefinition.java b/src/test/java/org/springframework/samples/petclinic/integration/StepDefinition.java index de20de94d..f6273d083 100644 --- a/src/test/java/org/springframework/samples/petclinic/integration/StepDefinition.java +++ b/src/test/java/org/springframework/samples/petclinic/integration/StepDefinition.java @@ -13,11 +13,18 @@ import io.cucumber.java.en.When; public class StepDefinition extends SpringIntegrationTest { + public static final String BASE_URL = "http://localhost:8080"; + private final WebDriver webDriver = Browser.webDriver; @Given("^I go to the main page$") public void mainPage() { - webDriver.navigate().to("http://localhost:8080"); + webDriver.navigate().to(BASE_URL); + } + + @Given("^I go to the find-owners page$") + public void findOwnersPage() { + webDriver.navigate().to(BASE_URL + "/owners/find"); } @When("^I click on the link with title \"([^\"]*)\"$") diff --git a/src/test/resources/scenarios/FindOwners.feature b/src/test/resources/scenarios/FindOwners.feature index 1ca6624b6..9a3525cb0 100644 --- a/src/test/resources/scenarios/FindOwners.feature +++ b/src/test/resources/scenarios/FindOwners.feature @@ -1,14 +1,18 @@ Feature: Find owners Scenario: Find owners page + Given I go to the main page When I click on the link with title "find owners" Then I should see the "Find Owners" page Scenario: Should find an owner When I fill the field named "lastName" with value "Franklin" + And I submit the form "search-owner-form" Then I should see the "Owner Information" page Scenario: Should find multiple owners + Given I go to the find-owners page When I fill the field named "lastName" with value "Davis" + And I submit the form "search-owner-form" Then I should see the "Owners" page # Add additional checks here. From ccef226160fd6fad8da607b9f3bcd974c02bdcea Mon Sep 17 00:00:00 2001 From: Adam Klinkosz Date: Thu, 15 Apr 2021 18:39:34 +0200 Subject: [PATCH 05/13] Improve assignment instructions --- ASSIGNMENT.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ASSIGNMENT.md b/ASSIGNMENT.md index 248612ec2..a13c21e89 100644 --- a/ASSIGNMENT.md +++ b/ASSIGNMENT.md @@ -8,13 +8,12 @@ You can run the Cucumber features from your IDE or via the command line: ## Finding owners The scenarios for this feature are incomplete or even naive. Please cover more cases in more reliable way. +Open the `src/test/resources/scenarios/FindOwners.feature` and follow instructions given in the comments. ## Adding owners Open `src/test/resources/scenarios/AddOwners.feature` and follow instructions given in the comments. - ## Bonus tasks 1. The browser is not closing after all tests were run. Fix it. 2. There is something wrong with the way the HTML elements are selected. Prepare a suggestion of how to improve it or even implement such a change. -3. From 93f9644b8c855108c198139454aeb5cb8481f2b6 Mon Sep 17 00:00:00 2001 From: Adam Klinkosz Date: Thu, 15 Apr 2021 18:40:51 +0200 Subject: [PATCH 06/13] Improve assignment instructions --- ASSIGNMENT.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ASSIGNMENT.md b/ASSIGNMENT.md index a13c21e89..df0429d98 100644 --- a/ASSIGNMENT.md +++ b/ASSIGNMENT.md @@ -14,6 +14,7 @@ Open the `src/test/resources/scenarios/FindOwners.feature` and follow instructio Open `src/test/resources/scenarios/AddOwners.feature` and follow instructions given in the comments. ## Bonus tasks -1. The browser is not closing after all tests were run. Fix it. +1. The browser doesn't close after all tests. Fix it. 2. There is something wrong with the way the HTML elements are selected. Prepare a suggestion of how to improve it or even implement such a change. +3. Suggest a replacement for Selenium. From cc7339160119dc99f61416f1302a217df6250285 Mon Sep 17 00:00:00 2001 From: Adam Klinkosz Date: Thu, 15 Apr 2021 18:43:13 +0200 Subject: [PATCH 07/13] Base spring test is abstract since it does not contain any tests itself --- .../samples/petclinic/integration/SpringIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/springframework/samples/petclinic/integration/SpringIntegrationTest.java b/src/test/java/org/springframework/samples/petclinic/integration/SpringIntegrationTest.java index 90ea71c81..0f09c88f3 100644 --- a/src/test/java/org/springframework/samples/petclinic/integration/SpringIntegrationTest.java +++ b/src/test/java/org/springframework/samples/petclinic/integration/SpringIntegrationTest.java @@ -6,6 +6,6 @@ import io.cucumber.spring.CucumberContextConfiguration; @CucumberContextConfiguration @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class SpringIntegrationTest { +public abstract class SpringIntegrationTest { } From add090c15dea1cc1e7bee4a7595f6ef1aba1a320 Mon Sep 17 00:00:00 2001 From: Adam Klinkosz Date: Thu, 15 Apr 2021 18:43:26 +0200 Subject: [PATCH 08/13] Improve assignment instructions --- ASSIGNMENT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ASSIGNMENT.md b/ASSIGNMENT.md index df0429d98..c2fb56a6d 100644 --- a/ASSIGNMENT.md +++ b/ASSIGNMENT.md @@ -14,7 +14,7 @@ Open the `src/test/resources/scenarios/FindOwners.feature` and follow instructio Open `src/test/resources/scenarios/AddOwners.feature` and follow instructions given in the comments. ## Bonus tasks -1. The browser doesn't close after all tests. Fix it. +1. The browser doesn't close after all tests. Please fix it. 2. There is something wrong with the way the HTML elements are selected. Prepare a suggestion of how to improve it or even implement such a change. 3. Suggest a replacement for Selenium. From 2ef05dc3c1b92cbadf5966a52fb642cba792bd24 Mon Sep 17 00:00:00 2001 From: Adam Klinkosz Date: Fri, 16 Apr 2021 10:16:29 +0200 Subject: [PATCH 09/13] Improve assignment instructions --- ASSIGNMENT.md | 11 ++++-- readme.md | 94 ++++----------------------------------------------- 2 files changed, 14 insertions(+), 91 deletions(-) diff --git a/ASSIGNMENT.md b/ASSIGNMENT.md index c2fb56a6d..db0eb1ea4 100644 --- a/ASSIGNMENT.md +++ b/ASSIGNMENT.md @@ -1,19 +1,24 @@ # QA Assignment +## How to start? +Follow the instructions in the [readme](readme.md) file. + ## Running tests You can run the Cucumber features from your IDE or via the command line: ```shell ./mvnw -P itest integration-test ``` -## Finding owners +## Assignment + +### Finding owners The scenarios for this feature are incomplete or even naive. Please cover more cases in more reliable way. Open the `src/test/resources/scenarios/FindOwners.feature` and follow instructions given in the comments. -## Adding owners +### Adding owners Open `src/test/resources/scenarios/AddOwners.feature` and follow instructions given in the comments. -## Bonus tasks +### Bonus tasks 1. The browser doesn't close after all tests. Please fix it. 2. There is something wrong with the way the HTML elements are selected. Prepare a suggestion of how to improve it or even implement such a change. diff --git a/readme.md b/readme.md index f8e8dd8b0..cdabba806 100644 --- a/readme.md +++ b/readme.md @@ -24,110 +24,28 @@ Or you can run it from Maven directly using the Spring Boot Maven plugin. If you ./mvnw spring-boot:run ``` -## In case you find a bug/suggested improvement for Spring Petclinic -Our issue tracker is available here: https://github.com/spring-projects/spring-petclinic/issues - - -## Database configuration - -In its default configuration, Petclinic uses an in-memory database (H2) which -gets populated at startup with data. The h2 console is automatically exposed at `http://localhost:8080/h2-console` -and it is possible to inspect the content of the database using the `jdbc:h2:mem:testdb` url. - -A similar setup is provided for MySql in case a persistent database configuration is needed. Note that whenever the database type is changed, the app needs to be run with a different profile: `spring.profiles.active=mysql` for MySql. - -You could start MySql locally with whatever installer works for your OS, or with docker: - -``` -docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8 -``` - -Further documentation is provided [here](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt). - ## Working with Petclinic in your IDE ### Prerequisites The following items should be installed in your system: -* Java 8 or newer. -* git command line tool (https://help.github.com/articles/set-up-git) -* Your preferred IDE +* JDK 11 or newer. +* `git` command line tool (https://help.github.com/articles/set-up-git) +* Your preferred IDE + * IntelliJ IDEA * Eclipse with the m2e plugin. Note: when m2e is available, there is an m2 icon in `Help -> About` dialog. If m2e is not there, just follow the install process here: https://www.eclipse.org/m2e/ * [Spring Tools Suite](https://spring.io/tools) (STS) - * IntelliJ IDEA * [VS Code](https://code.visualstudio.com) ### Steps: -1) On the command line - ``` - git clone https://github.com/spring-projects/spring-petclinic.git - ``` -2) Inside Eclipse or STS - ``` - File -> Import -> Maven -> Existing Maven project - ``` - - Then either build on the command line `./mvnw generate-resources` or using the Eclipse launcher (right click on project and `Run As -> Maven install`) to generate the css. Run the application main method by right clicking on it and choosing `Run As -> Java Application`. - -3) Inside IntelliJ IDEA +1) Inside IntelliJ IDEA In the main menu, choose `File -> Open` and select the Petclinic [pom.xml](pom.xml). Click on the `Open` button. CSS files are generated from the Maven build. You can either build them on the command line `./mvnw generate-resources` or right click on the `spring-petclinic` project then `Maven -> Generates sources and Update Folders`. A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application by right clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`. -4) Navigate to Petclinic +2) Navigate to Petclinic Visit [http://localhost:8080](http://localhost:8080) in your browser. - - -## Looking for something in particular? - -|Spring Boot Configuration | Class or Java property files | -|--------------------------|---| -|The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) | -|Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources) | -|Caching | [CacheConfiguration](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) | - -## Interesting Spring Petclinic branches and forks - -The Spring Petclinic "main" branch in the [spring-projects](https://github.com/spring-projects/spring-petclinic) -GitHub org is the "canonical" implementation, currently based on Spring Boot and Thymeleaf. There are -[quite a few forks](https://spring-petclinic.github.io/docs/forks.html) in a special GitHub org -[spring-petclinic](https://github.com/spring-petclinic). If you have a special interest in a different technology stack -that could be used to implement the Pet Clinic then please join the community there. - - -## Interaction with other open source projects - -One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found some bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they've been fixed/implemented in just a few days. -Here is a list of them: - -| Name | Issue | -|------|-------| -| Spring JDBC: simplify usage of NamedParameterJdbcTemplate | [SPR-10256](https://jira.springsource.org/browse/SPR-10256) and [SPR-10257](https://jira.springsource.org/browse/SPR-10257) | -| Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility |[HV-790](https://hibernate.atlassian.net/browse/HV-790) and [HV-792](https://hibernate.atlassian.net/browse/HV-792) | -| Spring Data: provide more flexibility when working with JPQL queries | [DATAJPA-292](https://jira.springsource.org/browse/DATAJPA-292) | - - -# Contributing - -The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, features requests and submitting pull requests. - -For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at . If you have not previously done so, please fill out and submit the [Contributor License Agreement](https://cla.pivotal.io/sign/spring). - -# License - -The Spring PetClinic sample application is released under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0). - -[spring-petclinic]: https://github.com/spring-projects/spring-petclinic -[spring-framework-petclinic]: https://github.com/spring-petclinic/spring-framework-petclinic -[spring-petclinic-angularjs]: https://github.com/spring-petclinic/spring-petclinic-angularjs -[javaconfig branch]: https://github.com/spring-petclinic/spring-framework-petclinic/tree/javaconfig -[spring-petclinic-angular]: https://github.com/spring-petclinic/spring-petclinic-angular -[spring-petclinic-microservices]: https://github.com/spring-petclinic/spring-petclinic-microservices -[spring-petclinic-reactjs]: https://github.com/spring-petclinic/spring-petclinic-reactjs -[spring-petclinic-graphql]: https://github.com/spring-petclinic/spring-petclinic-graphql -[spring-petclinic-kotlin]: https://github.com/spring-petclinic/spring-petclinic-kotlin -[spring-petclinic-rest]: https://github.com/spring-petclinic/spring-petclinic-rest From a7f262cddc0d835f3a68ed792ccffb873ca6bfd7 Mon Sep 17 00:00:00 2001 From: Adam Klinkosz Date: Fri, 16 Apr 2021 10:18:37 +0200 Subject: [PATCH 10/13] Improve readme --- readme.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index cdabba806..55e7b2e41 100644 --- a/readme.md +++ b/readme.md @@ -1,10 +1,8 @@ -# Spring PetClinic Sample Application [![Build Status](https://travis-ci.org/spring-projects/spring-petclinic.png?branch=main)](https://travis-ci.org/spring-projects/spring-petclinic/) - -## Understanding the Spring Petclinic application with a few diagrams -See the presentation here +# PetClinic Sample Application [![Build Status](https://travis-ci.org/spring-projects/spring-petclinic.png?branch=main)](https://travis-ci.org/spring-projects/spring-petclinic/) ## Running petclinic locally -Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/). You can build a jar file and run it from the command line: +Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/). +You can build a jar file and run it from the command line: ``` @@ -40,7 +38,7 @@ The following items should be installed in your system: ### Steps: 1) Inside IntelliJ IDEA - In the main menu, choose `File -> Open` and select the Petclinic [pom.xml](pom.xml). Click on the `Open` button. + In the main menu, choose `File -> Open` and select the Petclinic's [pom.xml](pom.xml). Click on the `Open` button. CSS files are generated from the Maven build. You can either build them on the command line `./mvnw generate-resources` or right click on the `spring-petclinic` project then `Maven -> Generates sources and Update Folders`. From d85e2fa39aa9c6dc8fde9086b60ed8c5ba71e73c Mon Sep 17 00:00:00 2001 From: Adam Klinkosz Date: Fri, 16 Apr 2021 10:20:54 +0200 Subject: [PATCH 11/13] Improve assignment instructions --- ASSIGNMENT.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ASSIGNMENT.md b/ASSIGNMENT.md index db0eb1ea4..4d63222ba 100644 --- a/ASSIGNMENT.md +++ b/ASSIGNMENT.md @@ -1,7 +1,9 @@ # QA Assignment ## How to start? -Follow the instructions in the [readme](readme.md) file. +1. Follow the instructions in the [readme](readme.md) file. +2. Switch the branch to `cucumber`. +3. Create a pull request with your changes. ## Running tests You can run the Cucumber features from your IDE or via the command line: From 30933a6d67c405f10b6accc10bbf65b170ffde6c Mon Sep 17 00:00:00 2001 From: Adam Klinkosz Date: Tue, 20 Apr 2021 12:02:08 +0200 Subject: [PATCH 12/13] Improve assignment and readme instructions --- ASSIGNMENT.md | 10 +++++++--- readme.md | 51 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/ASSIGNMENT.md b/ASSIGNMENT.md index 4d63222ba..d7023e0cb 100644 --- a/ASSIGNMENT.md +++ b/ASSIGNMENT.md @@ -1,9 +1,10 @@ # QA Assignment ## How to start? -1. Follow the instructions in the [readme](readme.md) file. -2. Switch the branch to `cucumber`. -3. Create a pull request with your changes. +1. Fork the project's repository. +2. Follow the instructions in the [readme](readme.md) file. +3. Switch the branch to `cucumber`. +4. Create a pull request with your changes. ## Running tests You can run the Cucumber features from your IDE or via the command line: @@ -20,6 +21,9 @@ Open the `src/test/resources/scenarios/FindOwners.feature` and follow instructio ### Adding owners Open `src/test/resources/scenarios/AddOwners.feature` and follow instructions given in the comments. +### Report bugs +Report any found bugs in the best possible format you can think of. + ### Bonus tasks 1. The browser doesn't close after all tests. Please fix it. 2. There is something wrong with the way the HTML elements are selected. diff --git a/readme.md b/readme.md index 55e7b2e41..21d36e315 100644 --- a/readme.md +++ b/readme.md @@ -1,48 +1,57 @@ # PetClinic Sample Application [![Build Status](https://travis-ci.org/spring-projects/spring-petclinic.png?branch=main)](https://travis-ci.org/spring-projects/spring-petclinic/) -## Running petclinic locally +## About Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/). + +## Prerequisites +The following items should be installed in your system: +* JDK 11 or newer. +* `git` command line tool (https://help.github.com/articles/set-up-git) +* Your preferred IDE + * IntelliJ IDEA + * Eclipse with the m2e plugin. Note: when m2e is available, there is an m2 icon in `Help -> About` dialog. If m2e is + not there, just follow the install process here: https://www.eclipse.org/m2e/ + * [Spring Tools Suite](https://spring.io/tools) (STS) + * [VS Code](https://code.visualstudio.com) + +## Running petclinic locally You can build a jar file and run it from the command line: - ``` -git clone https://github.com/cleankod/spring-petclinic +# Clone the repository (remember to change the URL to your forked one): +git clone git@github.com:cleankod/spring-petclinic.git + +# Change working directory to inside the project: cd spring-petclinic + +# Build: ./mvnw package + +# Run: java -jar target/*.jar ``` -You can then access petclinic here: http://localhost:8080/ +You can then access the application here: http://localhost:8080/ petclinic-screenshot -Or you can run it from Maven directly using the Spring Boot Maven plugin. If you do this it will pick up changes that you make in the project immediately (changes to Java source files require a compile as well - most people use an IDE for this): +Or you can run it from Maven directly using the Spring Boot Maven plugin. If you do this it will pick up changes that you make in the project immediately +(changes to Java source files require a compilation as well - most people use an IDE for this): ``` ./mvnw spring-boot:run ``` ## Working with Petclinic in your IDE - -### Prerequisites -The following items should be installed in your system: -* JDK 11 or newer. -* `git` command line tool (https://help.github.com/articles/set-up-git) -* Your preferred IDE - * IntelliJ IDEA - * Eclipse with the m2e plugin. Note: when m2e is available, there is an m2 icon in `Help -> About` dialog. If m2e is - not there, just follow the install process here: https://www.eclipse.org/m2e/ - * [Spring Tools Suite](https://spring.io/tools) (STS) - * [VS Code](https://code.visualstudio.com) - ### Steps: -1) Inside IntelliJ IDEA - In the main menu, choose `File -> Open` and select the Petclinic's [pom.xml](pom.xml). Click on the `Open` button. +1) Inside IntelliJ IDEA, in the main menu, choose `File -> Open` and select the Petclinic's [pom.xml](pom.xml). Click on the `Open` button. - CSS files are generated from the Maven build. You can either build them on the command line `./mvnw generate-resources` or right click on the `spring-petclinic` project then `Maven -> Generates sources and Update Folders`. + CSS files are generated from the Maven build. You can either build them on the command line `./mvnw generate-resources` or right click on the + `spring-petclinic` project then `Maven -> Generates sources and Update Folders`. - A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application by right clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`. + A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application + by right clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`. 2) Navigate to Petclinic From 1f3ce08a47af9a3bbe882f34df2f338f7836eb68 Mon Sep 17 00:00:00 2001 From: Adam Klinkosz Date: Tue, 20 Apr 2021 12:06:15 +0200 Subject: [PATCH 13/13] Improve assignment and readme instructions --- ASSIGNMENT.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ASSIGNMENT.md b/ASSIGNMENT.md index d7023e0cb..4404c803d 100644 --- a/ASSIGNMENT.md +++ b/ASSIGNMENT.md @@ -3,14 +3,15 @@ ## How to start? 1. Fork the project's repository. 2. Follow the instructions in the [readme](readme.md) file. -3. Switch the branch to `cucumber`. -4. Create a pull request with your changes. +3. Create a pull request with your changes. ## Running tests You can run the Cucumber features from your IDE or via the command line: ```shell ./mvnw -P itest integration-test ``` +Make sure the application is not started elsewhere. If it is, the `8080` port used by the application will already be occupied, +and therefore the tests will fail. ## Assignment