Skip to content

Commit

Permalink
More refining
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Oct 1, 2014
1 parent 922dadc commit df4fe5a
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 18 deletions.
2 changes: 2 additions & 0 deletions acceptance-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ dependencies {
testCompile 'org.easytesting:fest-assert-core:2.0M10'
testCompile 'net.thucydides:thucydides-core:0.9.273'
testCompile 'net.thucydides:thucydides-jbehave-plugin:0.9.273'
testCompile 'org.jbehave:jbehave:3.9.4'
testCompile 'com.thoughtworks.paranamer:paranamer:2.7'

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Created by john on 27/09/2014.
*/
public enum FrequentFlyer {

Sarah("123456");

private final String number;
Expand All @@ -15,4 +16,6 @@ public enum FrequentFlyer {
public String getNumber() {
return number;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import net.thucydides.core.annotations.DefaultUrl;
import net.thucydides.core.annotations.findby.By;
import net.thucydides.core.pages.PageObject;
import org.openqa.selenium.WebElement;

import java.util.List;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;

@DefaultUrl("http://localhost:9001/#/myaccount")
public class MyAccountPage extends PageObject {

Expand Down Expand Up @@ -39,4 +42,15 @@ public void waitForCalulationResult() {
waitFor(".requiredPoints");
waitFor(250).milliseconds();
}

public String getHomeCity() {
return $("#home-city").getText();
}

public List<String> getPossibleDestinations() {
return findAll(".possible-destination-name")
.stream()
.map(WebElement::getText)
.collect(toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import flyinghigh.services.acceptancetests.domain.Airport;
import flyinghigh.services.acceptancetests.domain.FrequentFlyer;
import flyinghigh.services.acceptancetests.pages.DisplayedAirport;
import flyinghigh.services.acceptancetests.rest.RestClient;
import flyinghigh.services.acceptancetests.steps.AirportClientSteps;
import flyinghigh.services.acceptancetests.steps.MyAccountUISteps;
import net.thucydides.core.annotations.Steps;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.core.model.ExamplesTable;

import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collector;
Expand All @@ -29,6 +33,34 @@ public class AirportStepDefinitions {
@Steps
AirportClientSteps airportClientSteps;


@Steps
RestClient restClient;

@Steps
MyAccountUISteps sarah;

@Given("I am a frequent flyer")
public void givenAFrequentFlyer() {
}

@Given("$frequentFlyer is a Frequent Flyer member with $points points")
public void giveSarahSomePoints(String name, int points) throws URISyntaxException {
FrequentFlyer frequentFlyer = FrequentFlyer.valueOf(name);
restClient.updatePointsFor(frequentFlyer.getNumber(), points);
}


@Then("she should see an account balance of $expectedPoints points")
public void shouldSeePointBalanceOf(int expectedPoints) {
sarah.shouldSeeAccountBalanceOf(expectedPoints);
}

@Then("she should see a home city of $homeCity")
public void shouldSeeHomeCityOf(String homeCity) {
sarah.shouldSeeHomeCity(homeCity);
}

@Given("I need to know what cities I can fly to")
public void givenINeedToKnowWhatCitiesICanFlyTo() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import flyinghigh.services.acceptancetests.pages.MyAccountPage;
import flyinghigh.services.acceptancetests.rest.RestClient;
import flyinghigh.services.acceptancetests.steps.AirportClientSteps;
import flyinghigh.services.acceptancetests.steps.MyAccountUISteps;
import net.thucydides.core.annotations.Steps;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
Expand All @@ -15,6 +16,8 @@
import java.util.List;
import java.util.Map;

import static flyinghigh.services.acceptancetests.stepdefs.AirportTableUtils.airportNamesFrom;
import static java.util.stream.Collectors.toList;
import static org.fest.assertions.api.Assertions.assertThat;


Expand All @@ -28,6 +31,9 @@ public class AirportStepUIDefinitions {
@Steps
AirportClientSteps airportClientSteps;

@Steps
MyAccountUISteps sarah;

HomePage homePage;
MyAccountPage myAccountPage;

Expand All @@ -46,6 +52,8 @@ public void seeListOfPossibleDestinations() {
assertThat(displayedAirports).containsAll(expectedAirports);
}



@Then("the following destination airports: $airports")
public void shouldSeeAirports(ExamplesTable airports) {
sarah.shouldSeePossibleDestinations(airportNamesFrom(airports));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package flyinghigh.services.acceptancetests.stepdefs;

import org.jbehave.core.model.ExamplesTable;

import java.util.List;

import static java.util.stream.Collectors.toList;

/**
* Created by john on 30/09/2014.
*/
public class AirportTableUtils {
public static List<String> airportNamesFrom(ExamplesTable airports) {
return airports.getRows()
.stream()
.map(row -> row.get("airport"))
.collect(toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,33 @@
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.core.model.ExamplesTable;

import java.net.URISyntaxException;
import java.util.List;

import static java.util.stream.Collectors.toList;

/**
* Created by john on 24/09/2014.
*/
public class FrequentFlyerStepDefinitions {

RestClient restClient = new RestClient();
@Steps
RestClient restClient;

@Steps
MyAccountUISteps sarah;

@Given("I am a frequent flyer")
public void givenAFrequentFlyer() {
}

@Given("$frequentFlyer is a Frequent Flyer member with $points points")
public void giveSarahSomePoints(FrequentFlyer frequentFlyer, int points) throws URISyntaxException {
restClient.updatePointsFor(frequentFlyer.getNumber(), points);
@Given("$frequentFlyer is a Frequent Flyer member")
public void giveSarahSomePoints(String name) throws URISyntaxException {
FrequentFlyer frequentFlyer = FrequentFlyer.valueOf(name);
}

@When("Sarah views her account details")
@When("she views her account details")
public void viewAccountDetails() {
sarah.openAccountPage();
}

@Then("she should see an account balance of $expectedPoints points")
public void shouldSeePointBalanceOf(int expectedPoints) {
sarah.shouldSeeAccountBalanceOf(expectedPoints);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import flyinghigh.services.acceptancetests.pages.MyAccountPage;
import net.thucydides.core.annotations.Step;

import java.util.List;

import static org.fest.assertions.api.Assertions.assertThat;

public class MyAccountUISteps {
Expand All @@ -27,8 +29,16 @@ public int calculatePointsNeededBetween(String departure,

@Step
public void shouldSeeAccountBalanceOf(int expectedPoints) {
// assertThat(myAccountPage.getPointBalance()).isEqualTo(expectedPoints);
assertThat(myAccountPage.getPointBalance()).isEqualTo(expectedPoints);
}

@Step
public void shouldSeeHomeCity(String expectedHomeCity) {
assertThat(myAccountPage.getHomeCity()).isEqualTo(expectedHomeCity);
}

@Step
public void shouldSeePossibleDestinations(List<String> expectedAirports) {
assertThat(myAccountPage.getPossibleDestinations()).containsAll(expectedAirports);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ I want to see my total points

Scenario: View point balance
Given Sarah is a Frequent Flyer member with 800 points
When Sarah views her account details
When she views her account details
Then she should see an account balance of 800 points
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Meta:
@Versions Release 1, Iteration 1.0
@tag layer:web

Narrative:
In order to plan my holidays
As a traveller
I want to see where I can fly with Flying High airlines

Scenario: View possible destinations
Given Sarah is a Frequent Flyer member
When she views her account details
Then she should see a home city of Sydney
And the following destination airports:
| airport |
| Melbourne |
| Brisbane |
| Perth |
| Auckland |
| Wellington |
| Christchurch |
| San Francisco|
| Los Angeles |
| Melbourne |
| Brisbane |
| Perth |
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Meta:
@Versions Release 1, Iteration 1.0
@tag layer:webservice

Narrative:
In order to know where I can fly
Expand All @@ -9,6 +8,9 @@ I want to know what airports are served by Flying High flights


Scenario: List serviced airports
Meta:
@tag layer:webservice

Given I need to know what cities I can fly to
When I ask for a list of airports
Then I should obtain at least the following:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
@RepositoryRestResource(collectionResourceRel = "airports", path = "airports")
public interface AirportRepository extends MongoRepository<Airport, String> {
List<Airport> findByName(@Param("name") String name);
List<Airport> findByCode(@Param("code") String code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
Expand All @@ -24,6 +25,11 @@ public List<Airport> listAirports() {
return airportRepository.findAll(new Sort("name"));
}

@RequestMapping("/rest/api/airports/search/findByCode")
public Airport findByCode(@RequestParam("code") String code) {
return airportRepository.findByCode(code).get(0);
}

@RequestMapping(method = RequestMethod.GET, value = "/rest/api/airports/reset")
public void initializeAccounts() {
databaseSetup.initializeReferenceData();;
Expand Down

0 comments on commit df4fe5a

Please sign in to comment.