From 1cabe4c65a1b6b145a522bce57b3e5d389d8d541 Mon Sep 17 00:00:00 2001 From: John Smart Date: Sat, 27 Sep 2014 02:31:37 -0700 Subject: [PATCH] Demo-worthy version --- acceptance-tests/build.gradle | 5 +- acceptance-tests/gradle.properties | 2 +- .../CalculatePointsFromPurchases.java | 9 +++ .../CalculatingRequiredPoints.java | 9 +++ .../acceptancetests/pages/MyAccountPage.java | 26 +++++++++ .../acceptancetests/rest/RestClient.java | 4 ++ .../stepdefs/AirportStepUIDefinitions.java | 2 + .../stepdefs/MyAccountStepUIDefinitions.java | 45 ++++++++++++++ .../stepdefs/RouteStepDefinitions.java | 35 +++++++++++ .../steps/MyAccountUISteps.java | 21 +++++++ .../stories/earning_points/narrative.txt | 3 + .../managing_airports/listing_airports.story | 2 +- .../stories/managing_airports/narrative.txt | 3 + .../partners/listing_affiliated_hotels.story | 2 +- .../resources/stories/partners/narrative.txt | 1 + .../calculating_required_points.story | 34 +++++++++++ .../stories/spending_points/narrative.txt | 3 + accounts-web-service/build.gradle | 2 + .../accounts/domain/FrequentFlyerAccount.java | 8 ++- .../services/{ => database}/Bootstrap.java | 2 +- .../{ => database}/DatabaseSetup.java | 2 +- .../{ => database}/DatabaseSetupImpl.java | 8 +-- .../DestinationsCalculatorService.java | 14 +++++ .../accounts/web/AccountsController.java | 10 +++- .../flights/InitializingTheDatabasessIT.java | 2 +- .../services/flights/LookingUpAccountsIT.java | 2 +- .../services/flights/StackSpec.java | 32 ++++++++++ build.gradle | 5 ++ .../services/flights/domain/Airport.java | 14 ++--- .../flights/repositories/RouteRepository.java | 2 + .../services/{ => database}/Bootstrap.java | 2 +- .../{ => database}/DatabaseSetup.java | 2 +- .../{ => database}/DatabaseSetupImpl.java | 37 +++++++++--- .../services/points/NoSuchRouteException.java | 10 ++++ .../services/points/PointsCalculator.java | 42 ++++++++++++++ .../flights/web/AirportsController.java | 2 +- .../flights/web/RoutesController.java | 29 ++++++---- .../WhenCalculatingRequiredPoints.groovy | 51 ++++++++++++++++ .../flights/CalculatingRequiredPointsIT.java | 58 +++++++++++++++++++ .../CheckingTheApplicationVersionIT.java | 5 -- .../flights/InitializingTheAirportsIT.java | 2 +- .../services/flights/LookingUpAirportsIT.java | 2 +- .../services/flights/LookingUpRoutesIT.java | 2 +- .../src/test/resources/application.properties | 8 +++ 44 files changed, 506 insertions(+), 55 deletions(-) create mode 100644 acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/CalculatePointsFromPurchases.java create mode 100644 acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/CalculatingRequiredPoints.java create mode 100644 acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/pages/MyAccountPage.java create mode 100644 acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/stepdefs/MyAccountStepUIDefinitions.java create mode 100644 acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/stepdefs/RouteStepDefinitions.java create mode 100644 acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/steps/MyAccountUISteps.java create mode 100644 acceptance-tests/src/test/resources/stories/earning_points/narrative.txt create mode 100644 acceptance-tests/src/test/resources/stories/managing_airports/narrative.txt create mode 100644 acceptance-tests/src/test/resources/stories/spending_points/calculating_required_points.story create mode 100644 acceptance-tests/src/test/resources/stories/spending_points/narrative.txt rename accounts-web-service/src/main/java/flyinghigh/services/accounts/services/{ => database}/Bootstrap.java (88%) rename accounts-web-service/src/main/java/flyinghigh/services/accounts/services/{ => database}/DatabaseSetup.java (67%) rename accounts-web-service/src/main/java/flyinghigh/services/accounts/services/{ => database}/DatabaseSetupImpl.java (91%) create mode 100644 accounts-web-service/src/main/java/flyinghigh/services/accounts/services/destinations/DestinationsCalculatorService.java create mode 100644 accounts-web-service/src/test/java/flyinghigh/services/flights/StackSpec.java rename flights-web-service/src/main/java/flyinghigh/services/flights/services/{ => database}/Bootstrap.java (89%) rename flights-web-service/src/main/java/flyinghigh/services/flights/services/{ => database}/DatabaseSetup.java (68%) rename flights-web-service/src/main/java/flyinghigh/services/flights/services/{ => database}/DatabaseSetupImpl.java (62%) create mode 100644 flights-web-service/src/main/java/flyinghigh/services/flights/services/points/NoSuchRouteException.java create mode 100644 flights-web-service/src/main/java/flyinghigh/services/flights/services/points/PointsCalculator.java create mode 100644 flights-web-service/src/test/groovy/flyinghigh/services/flights/domain/WhenCalculatingRequiredPoints.groovy create mode 100644 flights-web-service/src/test/java/flyinghigh/services/flights/CalculatingRequiredPointsIT.java create mode 100644 flights-web-service/src/test/resources/application.properties diff --git a/acceptance-tests/build.gradle b/acceptance-tests/build.gradle index d77005b..883425a 100644 --- a/acceptance-tests/build.gradle +++ b/acceptance-tests/build.gradle @@ -29,7 +29,7 @@ dependencies { testCompile "org.codehaus.groovy.modules.http-builder:http-builder:0.7" testCompile 'org.easytesting:fest-assert-core:2.0M10' testCompile 'net.thucydides:thucydides-core:0.9.271' - testCompile 'net.thucydides:thucydides-jbehave-plugin:0.9.271' + testCompile 'net.thucydides:thucydides-jbehave-plugin:0.9.272-SNAPSHOT' } @@ -53,10 +53,13 @@ test { systemProperty 'webservice.environment', webserviceEnvironment systemProperty 'webdriver.base.url', baseUrl systemProperty 'webdriver.driver', driver + systemProperty 'thucydides.resized.image.width', 1000 useJUnit() } +test.shouldRunAfter clean aggregate.mustRunAfter test +checkOutcomes.mustRunAfter aggregate clean { delete "target" diff --git a/acceptance-tests/gradle.properties b/acceptance-tests/gradle.properties index df86648..92f1786 100644 --- a/acceptance-tests/gradle.properties +++ b/acceptance-tests/gradle.properties @@ -1,3 +1,3 @@ webserviceEnvironment=local -baseUrl = 'http://localhost:9001' +baseUrl = http://localhost:9001 driver=chrome \ No newline at end of file diff --git a/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/CalculatePointsFromPurchases.java b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/CalculatePointsFromPurchases.java new file mode 100644 index 0000000..6bdbdbe --- /dev/null +++ b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/CalculatePointsFromPurchases.java @@ -0,0 +1,9 @@ +package flyinghigh.services.acceptancetests; + +import net.thucydides.jbehave.ThucydidesJUnitStory; + +/** + * Created by john on 18/09/2014. + */ +public class CalculatePointsFromPurchases extends ThucydidesJUnitStory { +} diff --git a/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/CalculatingRequiredPoints.java b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/CalculatingRequiredPoints.java new file mode 100644 index 0000000..cce051f --- /dev/null +++ b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/CalculatingRequiredPoints.java @@ -0,0 +1,9 @@ +package flyinghigh.services.acceptancetests; + +import net.thucydides.jbehave.ThucydidesJUnitStory; + +/** + * Created by john on 18/09/2014. + */ +public class CalculatingRequiredPoints extends ThucydidesJUnitStory { +} diff --git a/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/pages/MyAccountPage.java b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/pages/MyAccountPage.java new file mode 100644 index 0000000..2eb2393 --- /dev/null +++ b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/pages/MyAccountPage.java @@ -0,0 +1,26 @@ +package flyinghigh.services.acceptancetests.pages; + +import flyinghigh.services.acceptancetests.domain.Airport; +import net.thucydides.core.annotations.DefaultUrl; +import net.thucydides.core.pages.PageObject; + +import java.util.List; +import java.util.stream.Collectors; + +@DefaultUrl("http://localhost:9001/#/myaccount") +public class MyAccountPage extends PageObject { + + private int calculatedPoints; + + public void selectDepartureCity(String departure) { + $("#departure").selectByVisibleText(departure); + } + + public void selectDestinationCity(String destination) { + $("#destination").selectByVisibleText(destination); + } + + public int getCalculatedPoints() { + return Integer.valueOf($(".requiredPoints").getText()); + } +} diff --git a/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/rest/RestClient.java b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/rest/RestClient.java index c33f072..48e9637 100644 --- a/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/rest/RestClient.java +++ b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/rest/RestClient.java @@ -38,4 +38,8 @@ public List findAllAirports(String path) { } + public int calculateRequiredPoints(String departureCode, String destinationCode) { + String points = restTemplate.getForObject(getBaseFlightUrl() + "/rest/api/routes/calculatePoints?departureCode={departure}&destinationCode={destination}", String.class,departureCode,destinationCode); + return Integer.valueOf(points); + } } diff --git a/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/stepdefs/AirportStepUIDefinitions.java b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/stepdefs/AirportStepUIDefinitions.java index 90bc0f2..3b53ce8 100644 --- a/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/stepdefs/AirportStepUIDefinitions.java +++ b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/stepdefs/AirportStepUIDefinitions.java @@ -3,6 +3,7 @@ import com.google.common.collect.Lists; import flyinghigh.services.acceptancetests.domain.Airport; import flyinghigh.services.acceptancetests.pages.HomePage; +import flyinghigh.services.acceptancetests.pages.MyAccountPage; import flyinghigh.services.acceptancetests.rest.RestClient; import flyinghigh.services.acceptancetests.steps.AirportClientSteps; import net.thucydides.core.annotations.Steps; @@ -28,6 +29,7 @@ public class AirportStepUIDefinitions { AirportClientSteps airportClientSteps; HomePage homePage; + MyAccountPage myAccountPage; @When("I go to the home page") public void openHomePage() { diff --git a/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/stepdefs/MyAccountStepUIDefinitions.java b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/stepdefs/MyAccountStepUIDefinitions.java new file mode 100644 index 0000000..32e2b08 --- /dev/null +++ b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/stepdefs/MyAccountStepUIDefinitions.java @@ -0,0 +1,45 @@ +package flyinghigh.services.acceptancetests.stepdefs; + +import flyinghigh.services.acceptancetests.domain.Airport; +import flyinghigh.services.acceptancetests.pages.HomePage; +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; +import org.jbehave.core.annotations.When; + +import java.util.List; + +import static org.fest.assertions.api.Assertions.assertThat; + + +/** + * Created by john on 17/09/2014. + */ +public class MyAccountStepUIDefinitions { + + @Steps + MyAccountUISteps myAccountSteps; + + @Given("I am on the My Account page") + public void openMyAccountPage() { + myAccountSteps.openAccountPage(); + } + + int calculatedPoints; + + @When("I calculate the points needed to go from to ") + public void calculatePointsNeeded(String departure, String destination) { + calculatedPoints = myAccountSteps.calculatePointsNeededBetween(departure,destination); + } + + @Then("I should see points") + public void shouldSeeRequiredPoints(int requiredPoints) { + assertThat(calculatedPoints).isEqualTo(requiredPoints); + } + + +} diff --git a/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/stepdefs/RouteStepDefinitions.java b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/stepdefs/RouteStepDefinitions.java new file mode 100644 index 0000000..2ab4e43 --- /dev/null +++ b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/stepdefs/RouteStepDefinitions.java @@ -0,0 +1,35 @@ +package flyinghigh.services.acceptancetests.stepdefs; + +import flyinghigh.services.acceptancetests.rest.RestClient; +import org.jbehave.core.annotations.Given; +import org.jbehave.core.annotations.Then; +import org.jbehave.core.annotations.When; + +import static org.fest.assertions.api.Assertions.assertThat; + +/** + * Created by john on 27/09/2014. + */ +public class RouteStepDefinitions { + + RestClient restClient = new RestClient(); + + String departure; + String destination; + int calculatedPoints; + + @Given("I want to go from to ") + public void setDepartureAndDestination(String departure, String destination) { + this.departure = departure; + this.destination = destination; + } + @When("I calculate the number of required points") + public void calculateRequiredPoints() { + calculatedPoints = restClient.calculateRequiredPoints(departure, destination); + } + + @Then("I should obtain ") + public void checkCalculatedPoints(int requiredPoints) { + assertThat(calculatedPoints).isEqualTo(requiredPoints); + } +} diff --git a/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/steps/MyAccountUISteps.java b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/steps/MyAccountUISteps.java new file mode 100644 index 0000000..cab2aa6 --- /dev/null +++ b/acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/steps/MyAccountUISteps.java @@ -0,0 +1,21 @@ +package flyinghigh.services.acceptancetests.steps; + +import flyinghigh.services.acceptancetests.pages.MyAccountPage; +import net.thucydides.core.annotations.Step; + +public class MyAccountUISteps { + + MyAccountPage myAccountPage; + + @Step + public void openAccountPage() { + myAccountPage.open(); + } + + @Step + public int calculatePointsNeededBetween(String departure, String destination) { + myAccountPage.selectDepartureCity(departure); + myAccountPage.selectDestinationCity(destination); + return myAccountPage.getCalculatedPoints(); + } +} diff --git a/acceptance-tests/src/test/resources/stories/earning_points/narrative.txt b/acceptance-tests/src/test/resources/stories/earning_points/narrative.txt new file mode 100644 index 0000000..e812bb7 --- /dev/null +++ b/acceptance-tests/src/test/resources/stories/earning_points/narrative.txt @@ -0,0 +1,3 @@ +Earning Points +In order to encourage clients to book flights more often +We want clients to be able to book flights using points they earn through flights or partner purchases. \ No newline at end of file diff --git a/acceptance-tests/src/test/resources/stories/managing_airports/listing_airports.story b/acceptance-tests/src/test/resources/stories/managing_airports/listing_airports.story index fcaac98..e13f0d4 100644 --- a/acceptance-tests/src/test/resources/stories/managing_airports/listing_airports.story +++ b/acceptance-tests/src/test/resources/stories/managing_airports/listing_airports.story @@ -13,7 +13,7 @@ When I ask for a list of airports Then I should obtain at least the following: | country | name | code | | Australia | Sydney | SYD | -| Australia | Melbourne | MLB | +| Australia | Melbourne | MEL | | Australia | Brisbane | BNE | | USA | San Francisco | SFO | | USA | Los Angeles | LAX | diff --git a/acceptance-tests/src/test/resources/stories/managing_airports/narrative.txt b/acceptance-tests/src/test/resources/stories/managing_airports/narrative.txt new file mode 100644 index 0000000..1ca9bf3 --- /dev/null +++ b/acceptance-tests/src/test/resources/stories/managing_airports/narrative.txt @@ -0,0 +1,3 @@ +Airports +In order to encourage clients to book flights more often +We want to make clients aware of all the possible destinations they can fly to with Flying High Airlines \ No newline at end of file diff --git a/acceptance-tests/src/test/resources/stories/partners/listing_affiliated_hotels.story b/acceptance-tests/src/test/resources/stories/partners/listing_affiliated_hotels.story index 31b5d5b..f84c590 100644 --- a/acceptance-tests/src/test/resources/stories/partners/listing_affiliated_hotels.story +++ b/acceptance-tests/src/test/resources/stories/partners/listing_affiliated_hotels.story @@ -4,7 +4,7 @@ Meta: Narrative: In order to earn the most points possible As a traveller -I want to know what hotels will let me earn poitns +I want to know what hotels will let me earn points Scenario: List partner hotels diff --git a/acceptance-tests/src/test/resources/stories/partners/narrative.txt b/acceptance-tests/src/test/resources/stories/partners/narrative.txt index bc43437..21c4cc9 100644 --- a/acceptance-tests/src/test/resources/stories/partners/narrative.txt +++ b/acceptance-tests/src/test/resources/stories/partners/narrative.txt @@ -1,2 +1,3 @@ +Frequent Flyer Partners In order to attract more clients We want members to be able to earn points by spending with partner organizations \ No newline at end of file diff --git a/acceptance-tests/src/test/resources/stories/spending_points/calculating_required_points.story b/acceptance-tests/src/test/resources/stories/spending_points/calculating_required_points.story new file mode 100644 index 0000000..6ce4e4a --- /dev/null +++ b/acceptance-tests/src/test/resources/stories/spending_points/calculating_required_points.story @@ -0,0 +1,34 @@ +Meta: +@Versions Release 1, Iteration 1.1 + +Narrative: +As a traveller +I want to know how many points I need to go to a given destination +So that I can plan my next trip with Flying High Airlines + +Notes: 2 points required per km + +Scenario: Calculate required points +Given I am a frequent flyer +And I am on the My Account page +When I calculate the points needed to go from to +Then I should see points +Examples: +|departure |destination |requiredPoints| +|Sydney |Melbourne |1700 | +|Melbourne |Wellington |4400 | + +Scenario: Required points between different destinations +Given I want to go from to +When I calculate the number of required points +Then I should obtain +Examples: +|departure |destination |requiredPoints| +|SYD |MEL |1700 | +|MEL |SYD |1700 | +|SYD |SFO |13000 | +|MEL |WLG |4400 | +|MEL |LAX |12400 | +|BNE |SYD |1700 | +|BNE |LAX |12400 | +|LAX |BNE |12400 | diff --git a/acceptance-tests/src/test/resources/stories/spending_points/narrative.txt b/acceptance-tests/src/test/resources/stories/spending_points/narrative.txt new file mode 100644 index 0000000..13eae9f --- /dev/null +++ b/acceptance-tests/src/test/resources/stories/spending_points/narrative.txt @@ -0,0 +1,3 @@ +Spending Frequent Flyer points +In order to encourage clients to book flights more often +We want to let clients spend the points they earn when booking flights \ No newline at end of file diff --git a/accounts-web-service/build.gradle b/accounts-web-service/build.gradle index 371064a..49c34da 100644 --- a/accounts-web-service/build.gradle +++ b/accounts-web-service/build.gradle @@ -30,6 +30,8 @@ dependencies { compile("org.codehaus.groovy:groovy-all:2.3.6") compile("com.google.guava:guava:18.0") + compile project(":flights-web-service") + testCompile("org.spockframework:spock-core:0.7-groovy-2.0") testCompile("junit:junit") testCompile 'org.springframework.boot:spring-boot-starter-test' diff --git a/accounts-web-service/src/main/java/flyinghigh/services/accounts/domain/FrequentFlyerAccount.java b/accounts-web-service/src/main/java/flyinghigh/services/accounts/domain/FrequentFlyerAccount.java index 45fd1f3..9b5f2f8 100644 --- a/accounts-web-service/src/main/java/flyinghigh/services/accounts/domain/FrequentFlyerAccount.java +++ b/accounts-web-service/src/main/java/flyinghigh/services/accounts/domain/FrequentFlyerAccount.java @@ -10,6 +10,7 @@ public class FrequentFlyerAccount { private String accountNumber; private String firstName; private String lastName; + private String homeAirportCode; private int statusPoints; public FrequentFlyerAccount() { @@ -30,11 +31,12 @@ public FrequentFlyerAccount(String accountNumber, String firstName, String lastN this.statusPoints = 0; } - public FrequentFlyerAccount(String accountNumber, String firstName, String lastName, int statusPoints) { + public FrequentFlyerAccount(String accountNumber, String firstName, String lastName, int statusPoints, String homeAirportCode) { this.accountNumber = accountNumber; this.firstName = firstName; this.lastName = lastName; this.statusPoints = statusPoints; + this.homeAirportCode = homeAirportCode; } public String getId() { @@ -61,6 +63,10 @@ public String getFirstName() { return firstName; } + public String getHomeAirportCode() { + return homeAirportCode; + } + public Earner earns(int amount) { return new Earner(amount, this); } diff --git a/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/Bootstrap.java b/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/database/Bootstrap.java similarity index 88% rename from accounts-web-service/src/main/java/flyinghigh/services/accounts/services/Bootstrap.java rename to accounts-web-service/src/main/java/flyinghigh/services/accounts/services/database/Bootstrap.java index 3a45f37..86d7b94 100644 --- a/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/Bootstrap.java +++ b/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/database/Bootstrap.java @@ -1,4 +1,4 @@ -package flyinghigh.services.accounts.services; +package flyinghigh.services.accounts.services.database; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationListener; diff --git a/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/DatabaseSetup.java b/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/database/DatabaseSetup.java similarity index 67% rename from accounts-web-service/src/main/java/flyinghigh/services/accounts/services/DatabaseSetup.java rename to accounts-web-service/src/main/java/flyinghigh/services/accounts/services/database/DatabaseSetup.java index fc99135..3b560a9 100644 --- a/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/DatabaseSetup.java +++ b/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/database/DatabaseSetup.java @@ -1,4 +1,4 @@ -package flyinghigh.services.accounts.services; +package flyinghigh.services.accounts.services.database; /** * Created by john on 17/09/2014. diff --git a/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/DatabaseSetupImpl.java b/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/database/DatabaseSetupImpl.java similarity index 91% rename from accounts-web-service/src/main/java/flyinghigh/services/accounts/services/DatabaseSetupImpl.java rename to accounts-web-service/src/main/java/flyinghigh/services/accounts/services/database/DatabaseSetupImpl.java index e2a1e83..3bddeca 100644 --- a/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/DatabaseSetupImpl.java +++ b/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/database/DatabaseSetupImpl.java @@ -1,4 +1,4 @@ -package flyinghigh.services.accounts.services; +package flyinghigh.services.accounts.services.database; import com.google.common.collect.ImmutableList; import flyinghigh.services.accounts.domain.FrequentFlyerAccount; @@ -12,9 +12,9 @@ public class DatabaseSetupImpl implements DatabaseSetup { private final static List DEFAULT_ACCOUNTS = ImmutableList.of( - new FrequentFlyerAccount("123456","Sarah-Jane","Smith",500), - new FrequentFlyerAccount("123457","Harry","Sullivan",1000), - new FrequentFlyerAccount("123458","Jo","Grant", 2000) + new FrequentFlyerAccount("123456","Sarah-Jane","Smith",500,"SYD"), + new FrequentFlyerAccount("123457","Harry","Sullivan",1000,"SYD"), + new FrequentFlyerAccount("123458","Jo","Grant", 2000,"SYD") ); private final AccountRepository accountRepository; diff --git a/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/destinations/DestinationsCalculatorService.java b/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/destinations/DestinationsCalculatorService.java new file mode 100644 index 0000000..dc7a225 --- /dev/null +++ b/accounts-web-service/src/main/java/flyinghigh/services/accounts/services/destinations/DestinationsCalculatorService.java @@ -0,0 +1,14 @@ +package flyinghigh.services.accounts.services.destinations; + +import com.google.common.collect.ImmutableList; +import flyinghigh.services.flights.domain.Route; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class DestinationsCalculatorService { + public List findPossibleDestinations(String homeAirportCode, int statusPoints) { + return ImmutableList.of("Melbourne", "Brisbane"); + } +} diff --git a/accounts-web-service/src/main/java/flyinghigh/services/accounts/web/AccountsController.java b/accounts-web-service/src/main/java/flyinghigh/services/accounts/web/AccountsController.java index 766b380..4f9f4cb 100644 --- a/accounts-web-service/src/main/java/flyinghigh/services/accounts/web/AccountsController.java +++ b/accounts-web-service/src/main/java/flyinghigh/services/accounts/web/AccountsController.java @@ -3,8 +3,8 @@ import com.google.common.collect.ImmutableList; import flyinghigh.services.accounts.domain.FrequentFlyerAccount; import flyinghigh.services.accounts.repositories.AccountRepository; -import flyinghigh.services.accounts.services.DatabaseSetup; -import groovy.transform.Immutable; +import flyinghigh.services.accounts.services.database.DatabaseSetup; +import flyinghigh.services.accounts.services.destinations.DestinationsCalculatorService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -23,6 +23,9 @@ public class AccountsController { @Autowired private DatabaseSetup databaseSetup; + @Autowired + private DestinationsCalculatorService destinationsCalculatorService; + @RequestMapping(method = RequestMethod.GET, value = "/{number}") public FrequentFlyerAccount viewAccount(@PathVariable String number) { return accountRepository.findByAccountNumber(number); @@ -40,7 +43,8 @@ public void initializeAccounts() { @RequestMapping(method = RequestMethod.GET, value = "/{number}/possibleDestinations") public List findPossibleDestinations(@PathVariable String number) { - return ImmutableList.of("Paris","London"); + FrequentFlyerAccount currentAccount = accountRepository.findByAccountNumber(number); + return destinationsCalculatorService.findPossibleDestinations(currentAccount.getHomeAirportCode(), currentAccount.getStatusPoints()); } } diff --git a/accounts-web-service/src/test/java/flyinghigh/services/flights/InitializingTheDatabasessIT.java b/accounts-web-service/src/test/java/flyinghigh/services/flights/InitializingTheDatabasessIT.java index ba40953..aeeedbf 100644 --- a/accounts-web-service/src/test/java/flyinghigh/services/flights/InitializingTheDatabasessIT.java +++ b/accounts-web-service/src/test/java/flyinghigh/services/flights/InitializingTheDatabasessIT.java @@ -3,7 +3,7 @@ import flyinghigh.services.accounts.AccountsApp; import flyinghigh.services.accounts.domain.FrequentFlyerAccount; import flyinghigh.services.accounts.repositories.AccountRepository; -import flyinghigh.services.accounts.services.DatabaseSetup; +import flyinghigh.services.accounts.services.database.DatabaseSetup; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/accounts-web-service/src/test/java/flyinghigh/services/flights/LookingUpAccountsIT.java b/accounts-web-service/src/test/java/flyinghigh/services/flights/LookingUpAccountsIT.java index 2f5bc4f..cfd289d 100644 --- a/accounts-web-service/src/test/java/flyinghigh/services/flights/LookingUpAccountsIT.java +++ b/accounts-web-service/src/test/java/flyinghigh/services/flights/LookingUpAccountsIT.java @@ -3,7 +3,7 @@ import flyinghigh.services.accounts.AccountsApp; import flyinghigh.services.accounts.domain.FrequentFlyerAccount; import flyinghigh.services.accounts.repositories.AccountRepository; -import flyinghigh.services.accounts.services.DatabaseSetup; +import flyinghigh.services.accounts.services.database.DatabaseSetup; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/accounts-web-service/src/test/java/flyinghigh/services/flights/StackSpec.java b/accounts-web-service/src/test/java/flyinghigh/services/flights/StackSpec.java new file mode 100644 index 0000000..2af55e3 --- /dev/null +++ b/accounts-web-service/src/test/java/flyinghigh/services/flights/StackSpec.java @@ -0,0 +1,32 @@ +package flyinghigh.services.flights; + +import com.insightfullogic.lambdabehave.JunitSuiteRunner; +import org.junit.runner.RunWith; + +import java.util.Stack; + +import static com.insightfullogic.lambdabehave.Suite.describe; + +/** + * Created by john on 26/09/2014. + */ +@RunWith(JunitSuiteRunner.class) +public class StackSpec { + { + + Stack stack = new Stack<>(); + + describe("a stack", it -> { + + it.isSetupWith(stack::clear); + + it.isConcludedWith(stack::clear); + + it.should("be empty when created", expect -> { + expect.that(stack).isEmpty(); + }); + }); + } +} + + diff --git a/build.gradle b/build.gradle index 15fb00d..2bd5c27 100644 --- a/build.gradle +++ b/build.gradle @@ -35,4 +35,9 @@ allprojects { } +task verify { + println "Running acceptance tests" +} +verify.dependsOn ':acceptance-tests:clean', ':acceptance-tests:test', ':acceptance-tests:aggregate', ':acceptance-tests:checkOutcomes' + diff --git a/flights-web-service/src/main/java/flyinghigh/services/flights/domain/Airport.java b/flights-web-service/src/main/java/flyinghigh/services/flights/domain/Airport.java index ddd55a4..4035a1c 100644 --- a/flights-web-service/src/main/java/flyinghigh/services/flights/domain/Airport.java +++ b/flights-web-service/src/main/java/flyinghigh/services/flights/domain/Airport.java @@ -62,6 +62,11 @@ public boolean equals(Object o) { return true; } + @Override + public String toString() { + return name + "(" + code + ")"; + } + @Override public int hashCode() { int result = code != null ? code.hashCode() : 0; @@ -70,15 +75,6 @@ public int hashCode() { return result; } - @Override - public String toString() { - return "Airport{" + - "code='" + code + '\'' + - ", name='" + name + '\'' + - ", country='" + country + '\'' + - '}'; - } - public static class AirportBuilder { public String name; diff --git a/flights-web-service/src/main/java/flyinghigh/services/flights/repositories/RouteRepository.java b/flights-web-service/src/main/java/flyinghigh/services/flights/repositories/RouteRepository.java index 2ed8a0b..4606c39 100644 --- a/flights-web-service/src/main/java/flyinghigh/services/flights/repositories/RouteRepository.java +++ b/flights-web-service/src/main/java/flyinghigh/services/flights/repositories/RouteRepository.java @@ -10,4 +10,6 @@ @RepositoryRestResource(collectionResourceRel = "routes", path = "routes") public interface RouteRepository extends MongoRepository { List findByDepartureCode(@Param("departureCode") String departureCode); + List findByDepartureCodeAndDestinationCode(@Param("departureCode") String departureCode, + @Param("destinationCode") String destinationCode); } \ No newline at end of file diff --git a/flights-web-service/src/main/java/flyinghigh/services/flights/services/Bootstrap.java b/flights-web-service/src/main/java/flyinghigh/services/flights/services/database/Bootstrap.java similarity index 89% rename from flights-web-service/src/main/java/flyinghigh/services/flights/services/Bootstrap.java rename to flights-web-service/src/main/java/flyinghigh/services/flights/services/database/Bootstrap.java index 94de67e..3d2bc4f 100644 --- a/flights-web-service/src/main/java/flyinghigh/services/flights/services/Bootstrap.java +++ b/flights-web-service/src/main/java/flyinghigh/services/flights/services/database/Bootstrap.java @@ -1,4 +1,4 @@ -package flyinghigh.services.flights.services; +package flyinghigh.services.flights.services.database; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationListener; diff --git a/flights-web-service/src/main/java/flyinghigh/services/flights/services/DatabaseSetup.java b/flights-web-service/src/main/java/flyinghigh/services/flights/services/database/DatabaseSetup.java similarity index 68% rename from flights-web-service/src/main/java/flyinghigh/services/flights/services/DatabaseSetup.java rename to flights-web-service/src/main/java/flyinghigh/services/flights/services/database/DatabaseSetup.java index cefd447..463b2ec 100644 --- a/flights-web-service/src/main/java/flyinghigh/services/flights/services/DatabaseSetup.java +++ b/flights-web-service/src/main/java/flyinghigh/services/flights/services/database/DatabaseSetup.java @@ -1,4 +1,4 @@ -package flyinghigh.services.flights.services; +package flyinghigh.services.flights.services.database; /** * Created by john on 17/09/2014. diff --git a/flights-web-service/src/main/java/flyinghigh/services/flights/services/DatabaseSetupImpl.java b/flights-web-service/src/main/java/flyinghigh/services/flights/services/database/DatabaseSetupImpl.java similarity index 62% rename from flights-web-service/src/main/java/flyinghigh/services/flights/services/DatabaseSetupImpl.java rename to flights-web-service/src/main/java/flyinghigh/services/flights/services/database/DatabaseSetupImpl.java index b3a0b2a..af04bf9 100644 --- a/flights-web-service/src/main/java/flyinghigh/services/flights/services/DatabaseSetupImpl.java +++ b/flights-web-service/src/main/java/flyinghigh/services/flights/services/database/DatabaseSetupImpl.java @@ -1,4 +1,4 @@ -package flyinghigh.services.flights.services; +package flyinghigh.services.flights.services.database; import com.google.common.collect.ImmutableList; import flyinghigh.services.flights.domain.Airport; @@ -14,19 +14,17 @@ public class DatabaseSetupImpl implements DatabaseSetup { private final static Airport sydney = Airport.called("Sydney").inCountry("Australia").withCode("SYD"); - private final static Airport melbourne = Airport.called("Melbourne").inCountry("Australia").withCode("MLB"); + private final static Airport melbourne = Airport.called("Melbourne").inCountry("Australia").withCode("MEL"); private final static Airport brisbane = Airport.called("Brisbane").inCountry("Australia").withCode("BNE"); private final static Airport perth = Airport.called("Perth").inCountry("Australia").withCode("PER"); private final static Airport sanfrancisco = Airport.called("San Francisco").inCountry("USA").withCode("SFO"); private final static Airport losangeles = Airport.called("Los Angeles").inCountry("USA").withCode("LAX"); - private final static Airport hongkong = Airport.called("Hong Kong").inCountry("Hong Kong").withCode("HKG"); - private final static Airport singapore = Airport.called("Singapore").inCountry("Singapore").withCode("SIN"); private final static Airport auckland = Airport.called("Auckland").inCountry("New Zealand").withCode("AKL"); private final static Airport wellington = Airport.called("Wellington").inCountry("New Zealand").withCode("WLG"); private final static Airport christchurch = Airport.called("Christchurch").inCountry("New Zealand").withCode("CHC"); private final static List DEFAULT_AIRPORTS = ImmutableList.of( - sydney, melbourne, brisbane, sanfrancisco, losangeles, hongkong, singapore, auckland, wellington, christchurch + sydney, melbourne, brisbane, perth, auckland, wellington, christchurch, sanfrancisco, losangeles ); @@ -36,14 +34,37 @@ public class DatabaseSetupImpl implements DatabaseSetup { Route.from(sydney).to(perth).withDistanceOf(3000).km(), Route.from(sydney).to(auckland).withDistanceOf(1800).km(), Route.from(sydney).to(wellington).withDistanceOf(2000).km(), - Route.from(sydney).to(sanfrancisco).withDistanceOf(6000).km(), + Route.from(sydney).to(christchurch).withDistanceOf(2500).km(), + Route.from(sydney).to(sanfrancisco).withDistanceOf(6500).km(), + Route.from(sydney).to(losangeles).withDistanceOf(6000).km(), + Route.from(melbourne).to(sydney).withDistanceOf(850).km(), Route.from(melbourne).to(brisbane).withDistanceOf(2000).km(), Route.from(melbourne).to(perth).withDistanceOf(2700).km(), Route.from(melbourne).to(auckland).withDistanceOf(2500).km(), Route.from(melbourne).to(wellington).withDistanceOf(2200).km(), - Route.from(melbourne).to(sanfrancisco).withDistanceOf(6800).km() - ); + Route.from(melbourne).to(christchurch).withDistanceOf(2800).km(), + Route.from(melbourne).to(sanfrancisco).withDistanceOf(6800).km(), + Route.from(melbourne).to(losangeles).withDistanceOf(6200).km(), + + Route.from(brisbane).to(sydney).withDistanceOf(850).km(), + Route.from(brisbane).to(melbourne).withDistanceOf(2000).km(), + Route.from(brisbane).to(perth).withDistanceOf(2700).km(), + Route.from(brisbane).to(auckland).withDistanceOf(2500).km(), + Route.from(brisbane).to(wellington).withDistanceOf(2200).km(), + Route.from(brisbane).to(christchurch).withDistanceOf(2800).km(), + Route.from(brisbane).to(sanfrancisco).withDistanceOf(6800).km(), + Route.from(brisbane).to(losangeles).withDistanceOf(6200).km(), + + Route.from(perth).to(sydney).withDistanceOf(850).km(), + Route.from(perth).to(melbourne).withDistanceOf(2000).km(), + Route.from(perth).to(brisbane).withDistanceOf(2700).km(), + Route.from(perth).to(auckland).withDistanceOf(2500).km(), + Route.from(perth).to(wellington).withDistanceOf(2200).km(), + Route.from(perth).to(christchurch).withDistanceOf(2800).km(), + Route.from(perth).to(sanfrancisco).withDistanceOf(6800).km(), + Route.from(perth).to(losangeles).withDistanceOf(6200).km() + ); private @Autowired diff --git a/flights-web-service/src/main/java/flyinghigh/services/flights/services/points/NoSuchRouteException.java b/flights-web-service/src/main/java/flyinghigh/services/flights/services/points/NoSuchRouteException.java new file mode 100644 index 0000000..3266b85 --- /dev/null +++ b/flights-web-service/src/main/java/flyinghigh/services/flights/services/points/NoSuchRouteException.java @@ -0,0 +1,10 @@ +package flyinghigh.services.flights.services.points; + +/** + * Created by john on 27/09/2014. + */ +public class NoSuchRouteException extends Exception { + public NoSuchRouteException(String message) { + super(message); + } +} diff --git a/flights-web-service/src/main/java/flyinghigh/services/flights/services/points/PointsCalculator.java b/flights-web-service/src/main/java/flyinghigh/services/flights/services/points/PointsCalculator.java new file mode 100644 index 0000000..d8b05d2 --- /dev/null +++ b/flights-web-service/src/main/java/flyinghigh/services/flights/services/points/PointsCalculator.java @@ -0,0 +1,42 @@ +package flyinghigh.services.flights.services.points; + +import flyinghigh.services.flights.domain.Airport; +import flyinghigh.services.flights.domain.Route; +import flyinghigh.services.flights.repositories.RouteRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class PointsCalculator { + + private final RouteRepository routeRepository; + + private final int POINTS_PER_KM = 2; + + @Autowired + public PointsCalculator(RouteRepository routeRepository) { + this.routeRepository = routeRepository; + } + + public int calculatePointsRequiredBetween(String departureCode, String destinationCode) throws NoSuchRouteException { + List routes = routeRepository.findByDepartureCodeAndDestinationCode(departureCode, destinationCode); + + if (noAvailable(routes)) { + routes = routeRepository.findByDepartureCodeAndDestinationCode(destinationCode, departureCode); + + if (noAvailable(routes)) { + throw new NoSuchRouteException("No route between " + departureCode + " and " + destinationCode); + } + } + + return routes.get(0).getDistance() * POINTS_PER_KM; + } + + private boolean noAvailable(List routes) { + return (routes.isEmpty()); + } + + +} diff --git a/flights-web-service/src/main/java/flyinghigh/services/flights/web/AirportsController.java b/flights-web-service/src/main/java/flyinghigh/services/flights/web/AirportsController.java index 06622c1..75236f2 100644 --- a/flights-web-service/src/main/java/flyinghigh/services/flights/web/AirportsController.java +++ b/flights-web-service/src/main/java/flyinghigh/services/flights/web/AirportsController.java @@ -2,7 +2,7 @@ import flyinghigh.services.flights.domain.Airport; import flyinghigh.services.flights.repositories.AirportRepository; -import flyinghigh.services.flights.services.DatabaseSetup; +import flyinghigh.services.flights.services.database.DatabaseSetup; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/flights-web-service/src/main/java/flyinghigh/services/flights/web/RoutesController.java b/flights-web-service/src/main/java/flyinghigh/services/flights/web/RoutesController.java index c472a42..7944c0f 100644 --- a/flights-web-service/src/main/java/flyinghigh/services/flights/web/RoutesController.java +++ b/flights-web-service/src/main/java/flyinghigh/services/flights/web/RoutesController.java @@ -1,34 +1,41 @@ package flyinghigh.services.flights.web; import flyinghigh.services.flights.domain.Airport; -import flyinghigh.services.flights.repositories.AirportRepository; import flyinghigh.services.flights.repositories.RouteRepository; -import flyinghigh.services.flights.services.DatabaseSetup; +import flyinghigh.services.flights.services.database.DatabaseSetup; +import flyinghigh.services.flights.services.points.NoSuchRouteException; +import flyinghigh.services.flights.services.points.PointsCalculator; import org.springframework.beans.factory.annotation.Autowired; -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; - @RestController public class RoutesController { - @Autowired private RouteRepository routeRepository; + @Autowired + private RouteRepository routeRepository; @Autowired private DatabaseSetup databaseSetup; -// @RequestMapping("/rest/api/routes/departingFrom") -// public List listAirports() { -// return routeRepository.findByDepartureCode()); -// } + @Autowired + private PointsCalculator pointsCalculator; @RequestMapping(method = RequestMethod.GET, value = "/rest/api/routes/reset") public void initializeAccounts() { - databaseSetup.initializeReferenceData();; + databaseSetup.initializeReferenceData(); } + @RequestMapping(method = RequestMethod.GET, value = "/rest/api/routes/calculatePoints") + public int calculateRequiredPoints(@RequestParam("departureCode") String departureCode, + @RequestParam("destinationCode") String destinationCode) throws NoSuchRouteException { + if (!departureCode.equals(destinationCode)) { + return pointsCalculator.calculatePointsRequiredBetween(departureCode, destinationCode); + } else { + return 0; + } + } } diff --git a/flights-web-service/src/test/groovy/flyinghigh/services/flights/domain/WhenCalculatingRequiredPoints.groovy b/flights-web-service/src/test/groovy/flyinghigh/services/flights/domain/WhenCalculatingRequiredPoints.groovy new file mode 100644 index 0000000..2205e4e --- /dev/null +++ b/flights-web-service/src/test/groovy/flyinghigh/services/flights/domain/WhenCalculatingRequiredPoints.groovy @@ -0,0 +1,51 @@ +package flyinghigh.services.flights.domain + +import flyinghigh.services.flights.repositories.RouteRepository +import flyinghigh.services.flights.services.points.NoSuchRouteException +import spock.lang.Specification +import flyinghigh.services.flights.services.points.PointsCalculator + +class WhenCalculatingRequiredPoints extends Specification { + + def routeRepository = Mock(RouteRepository); + + def DISTANCE = 1000 + def REQUIRED_POINTS = DISTANCE * 2 + + def sydney = new Airport("Australia","Sydney","SYD") + def melbourne = new Airport("Australia","Melbourne","MEL") + + def "Required points should be calculated based on route distance"() { + given: + routeRepository.findByDepartureCodeAndDestinationCode("SYD","MEL") >> [Route.from(sydney).to(melbourne).withDistanceOf(DISTANCE).km()] + + def pointsCalculator = new PointsCalculator(routeRepository) + when: + int calculatedPoints = pointsCalculator.calculatePointsRequiredBetween("SYD", "MEL"); + then: + calculatedPoints == REQUIRED_POINTS + } + + def "Required points should be calculated in both directions"() { + given: + routeRepository.findByDepartureCodeAndDestinationCode("SYD","MEL") >> [] + routeRepository.findByDepartureCodeAndDestinationCode("MEL","SYD") >> [Route.from(sydney).to(melbourne).withDistanceOf(DISTANCE).km()] + + def pointsCalculator = new PointsCalculator(routeRepository) + when: + int calculatedPoints = pointsCalculator.calculatePointsRequiredBetween("SYD", "MEL"); + then: + calculatedPoints == REQUIRED_POINTS + } + + def "Should throw NoSuchRouteException if no routes are available"() { + given: + routeRepository.findByDepartureCodeAndDestinationCode("MEL","SYD") >> [] + routeRepository.findByDepartureCodeAndDestinationCode("SYD","MEL") >> [] + def pointsCalculator = new PointsCalculator(routeRepository) + when: + pointsCalculator.calculatePointsRequiredBetween("SYD", "MEL"); + then: + thrown(NoSuchRouteException) + } +} \ No newline at end of file diff --git a/flights-web-service/src/test/java/flyinghigh/services/flights/CalculatingRequiredPointsIT.java b/flights-web-service/src/test/java/flyinghigh/services/flights/CalculatingRequiredPointsIT.java new file mode 100644 index 0000000..e9d0dc0 --- /dev/null +++ b/flights-web-service/src/test/java/flyinghigh/services/flights/CalculatingRequiredPointsIT.java @@ -0,0 +1,58 @@ +package flyinghigh.services.flights; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.web.client.RestTemplate; + +import static org.fest.assertions.api.Assertions.assertThat; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = FlightsApp.class) +@WebAppConfiguration +@IntegrationTest({"server.port=0", "management.port=0"}) +public class CalculatingRequiredPointsIT { + + @Autowired + private EmbeddedWebApplicationContext server; + + @Value("${local.server.port}") + private int port; + + private RestTemplate restTemplate = new RestTemplate(); + + private String baseUrl; + + @Before + public void configureBaseUrl() { + baseUrl = "http://localhost:" + port; + restTemplate = new RestTemplate(); + } + + @Test + public void should_calculate_the_points_required_for_a_given_route() { + String points = restTemplate.getForObject(baseUrl + "/rest/api/routes/calculatePoints?departureCode={departure}&destinationCode={destination}", String.class,"SYD","SFO"); + assertThat(points).isEqualTo("13000"); + } + + @Test + public void should_calculate_the_points_required_for_a_trip_back() { + String points = restTemplate.getForObject(baseUrl + "/rest/api/routes/calculatePoints?departureCode={departure}&destinationCode={destination}", String.class,"SFO","SYD"); + assertThat(points).isEqualTo("13000"); + } + + + @Test + public void should_calculate_zero_for_points_between_the_same_cities() { + String points = restTemplate.getForObject(baseUrl + "/rest/api/routes/calculatePoints?departureCode={departure}&destinationCode={destination}", String.class,"SYD","SYD"); + assertThat(points).isEqualTo("0"); + } + +} diff --git a/flights-web-service/src/test/java/flyinghigh/services/flights/CheckingTheApplicationVersionIT.java b/flights-web-service/src/test/java/flyinghigh/services/flights/CheckingTheApplicationVersionIT.java index a86b72f..2f9126e 100644 --- a/flights-web-service/src/test/java/flyinghigh/services/flights/CheckingTheApplicationVersionIT.java +++ b/flights-web-service/src/test/java/flyinghigh/services/flights/CheckingTheApplicationVersionIT.java @@ -1,8 +1,5 @@ package flyinghigh.services.flights; -import flyinghigh.services.flights.domain.Airport; -import flyinghigh.services.flights.repositories.AirportRepository; -import flyinghigh.services.flights.services.DatabaseSetup; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -15,8 +12,6 @@ import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.client.RestTemplate; -import java.util.List; - import static org.fest.assertions.api.Assertions.assertThat; // diff --git a/flights-web-service/src/test/java/flyinghigh/services/flights/InitializingTheAirportsIT.java b/flights-web-service/src/test/java/flyinghigh/services/flights/InitializingTheAirportsIT.java index d6e0dc6..8f3e943 100644 --- a/flights-web-service/src/test/java/flyinghigh/services/flights/InitializingTheAirportsIT.java +++ b/flights-web-service/src/test/java/flyinghigh/services/flights/InitializingTheAirportsIT.java @@ -2,7 +2,7 @@ import flyinghigh.services.flights.domain.Airport; import flyinghigh.services.flights.repositories.AirportRepository; -import flyinghigh.services.flights.services.DatabaseSetup; +import flyinghigh.services.flights.services.database.DatabaseSetup; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/flights-web-service/src/test/java/flyinghigh/services/flights/LookingUpAirportsIT.java b/flights-web-service/src/test/java/flyinghigh/services/flights/LookingUpAirportsIT.java index 3f93cc5..be4e00c 100644 --- a/flights-web-service/src/test/java/flyinghigh/services/flights/LookingUpAirportsIT.java +++ b/flights-web-service/src/test/java/flyinghigh/services/flights/LookingUpAirportsIT.java @@ -2,7 +2,7 @@ import flyinghigh.services.flights.domain.Airport; import flyinghigh.services.flights.repositories.AirportRepository; -import flyinghigh.services.flights.services.DatabaseSetup; +import flyinghigh.services.flights.services.database.DatabaseSetup; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/flights-web-service/src/test/java/flyinghigh/services/flights/LookingUpRoutesIT.java b/flights-web-service/src/test/java/flyinghigh/services/flights/LookingUpRoutesIT.java index 126dc34..9a6c064 100644 --- a/flights-web-service/src/test/java/flyinghigh/services/flights/LookingUpRoutesIT.java +++ b/flights-web-service/src/test/java/flyinghigh/services/flights/LookingUpRoutesIT.java @@ -3,7 +3,7 @@ import flyinghigh.services.flights.domain.Route; import flyinghigh.services.flights.repositories.AirportRepository; import flyinghigh.services.flights.repositories.RouteRepository; -import flyinghigh.services.flights.services.DatabaseSetup; +import flyinghigh.services.flights.services.database.DatabaseSetup; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/flights-web-service/src/test/resources/application.properties b/flights-web-service/src/test/resources/application.properties new file mode 100644 index 0000000..572899f --- /dev/null +++ b/flights-web-service/src/test/resources/application.properties @@ -0,0 +1,8 @@ +server.port=8090 +application.version=@application.version@-@build.number@ + +mongodb.host=localhost +mongodb.port=27017 +mongodb.database=flyinghigh +mongodb.username= +mongodb.password= \ No newline at end of file