Skip to content

Commit

Permalink
Prepared demo
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Oct 1, 2014
1 parent df4fe5a commit 40a074e
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import flyinghigh.services.acceptancetests.steps.MyAccountUISteps;
import net.thucydides.core.annotations.Steps;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Pending;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.core.model.ExamplesTable;
Expand Down Expand Up @@ -44,21 +45,27 @@ public class AirportStepDefinitions {
public void givenAFrequentFlyer() {
}

@Pending
@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);
// TODO
// FrequentFlyer frequentFlyer = FrequentFlyer.valueOf(name);
// restClient.updatePointsFor(frequentFlyer.getNumber(), points);
}


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

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

@Given("I need to know what cities I can fly to")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void seeListOfPossibleDestinations() {

@Then("the following destination airports: $airports")
public void shouldSeeAirports(ExamplesTable airports) {
sarah.shouldSeePossibleDestinations(airportNamesFrom(airports));
// TODO
// sarah.shouldSeePossibleDestinations(airportNamesFrom(airports));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import flyinghigh.services.acceptancetests.steps.MyAccountUISteps;
import net.thucydides.core.annotations.Steps;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Pending;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.core.model.ExamplesTable;
Expand All @@ -26,13 +27,13 @@ public class FrequentFlyerStepDefinitions {
MyAccountUISteps sarah;

@Given("$frequentFlyer is a Frequent Flyer member")
public void giveSarahSomePoints(String name) throws URISyntaxException {
FrequentFlyer frequentFlyer = FrequentFlyer.valueOf(name);
}
public void giveSarahSomePoints(FrequentFlyer frequentFlyer) {}

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ public void openMyAccountPage() {

@When("I calculate the points needed to go from <departure> to <destination>")
public void calculatePointsNeeded(String departure, String destination) {
calculatedPoints = myAccountSteps.calculatePointsNeededBetween(departure,
destination);
// TODO
// calculatedPoints = myAccountSteps.calculatePointsNeededBetween(departure,
// destination);
}

@Then("I should see <requiredPoints> points")
public void shouldSeeRequiredPoints(int requiredPoints) {
assertThat(calculatedPoints).isEqualTo(requiredPoints);
// TODO
// assertThat(calculatedPoints).isEqualTo(requiredPoints);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public void setDepartureAndDestination(String departure, String destination) {
}
@When("I calculate the number of required points")
public void calculateRequiredPoints() {
calculatedPoints = restClient.calculateRequiredPoints(departure, destination);
// TODO
// calculatedPoints = restClient.calculateRequiredPoints(departure, destination);
}

@Then("I should obtain <requiredPoints>")
public void checkCalculatedPoints(int requiredPoints) {
assertThat(calculatedPoints).isEqualTo(requiredPoints);
// TODO
// assertThat(calculatedPoints).isEqualTo(requiredPoints);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ public int calculatePointsNeededBetween(String departure,

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

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

@Step
public void shouldSeePossibleDestinations(List<String> expectedAirports) {
assertThat(myAccountPage.getPossibleDestinations()).containsAll(expectedAirports);
// TODO
// assertThat(myAccountPage.getPossibleDestinations()).containsAll(expectedAirports);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public List<Airport> listAirports() {

@RequestMapping("/rest/api/airports/search/findByCode")
public Airport findByCode(@RequestParam("code") String code) {
return airportRepository.findByCode(code).get(0);
List<Airport> matchingAirports = airportRepository.findByCode(code);
if (matchingAirports.isEmpty()) {
throw new UnknownAirportException(code);
}
return matchingAirports.get(0);
}

@RequestMapping(method = RequestMethod.GET, value = "/rest/api/airports/reset")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package flyinghigh.services.flights.web;

/**
* Created by john on 30/09/2014.
*/
public class UnknownAirportException extends RuntimeException {
public UnknownAirportException(String code) {
super(code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mongodb.util.Hash;
import flyinghigh.services.flights.domain.Airport;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -42,18 +43,20 @@ public void configureBaseUrl() {
}

@Test
public void should_find_airports_with_flights_to_a_given_destination() {
List<HashMap> destinations = restTemplate.getForObject(baseUrl + "/rest/api/routes/to?destinationCode={destinationCode}", List.class, "SYD");
@Ignore
public void should_find_airports_based_on_return_routes() {
List<HashMap> destinations = restTemplate.getForObject(baseUrl + "/rest/api/routes/from?departureCode={departureCode}", List.class, "WLG");

assertThat(destinations).isNotEmpty();
destinations.stream().forEach(
destination -> assertThat(destination.get("code")).isNotEqualTo("SYD")
destination -> assertThat(destination.get("code")).isNotEqualTo("WLG")
);
}

@Test
public void should_find_airports_with_flights_from_a_given_destination() {
List<HashMap> destinations = restTemplate.getForObject(baseUrl + "/rest/api/routes/from?departureCode={departureCode}", List.class, "SYD");
List<HashMap> destinations = restTemplate.getForObject(
baseUrl + "/rest/api/routes/from?departureCode={departureCode}", List.class, "SYD");

assertThat(destinations).isNotEmpty();
destinations.stream().forEach(
Expand All @@ -62,15 +65,14 @@ public void should_find_airports_with_flights_from_a_given_destination() {
}

@Test
public void should_find_airports_based_on_return_routes() {
List<HashMap> destinations = restTemplate.getForObject(baseUrl + "/rest/api/routes/from?departureCode={departureCode}", List.class, "WLG");
public void should_find_airports_with_flights_to_a_given_destination() {
List<HashMap> destinations = restTemplate.getForObject(baseUrl + "/rest/api/routes/to?destinationCode={destinationCode}", List.class, "SYD");

assertThat(destinations).isNotEmpty();
destinations.stream().forEach(
destination -> assertThat(destination.get("code")).isNotEqualTo("WEL")
destination -> assertThat(destination.get("code")).isNotEqualTo("SYD")
);
}



}

0 comments on commit 40a074e

Please sign in to comment.