Skip to content

Commit

Permalink
Demo-worthy version
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Sep 27, 2014
1 parent 983b2f6 commit 1cabe4c
Show file tree
Hide file tree
Showing 44 changed files with 506 additions and 55 deletions.
5 changes: 4 additions & 1 deletion acceptance-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

}

Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
webserviceEnvironment=local
baseUrl = 'http://localhost:9001'
baseUrl = http://localhost:9001
driver=chrome
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ public List<Airport> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +29,7 @@ public class AirportStepUIDefinitions {
AirportClientSteps airportClientSteps;

HomePage homePage;
MyAccountPage myAccountPage;

@When("I go to the home page")
public void openHomePage() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <departure> to <destination>")
public void calculatePointsNeeded(String departure, String destination) {
calculatedPoints = myAccountSteps.calculatePointsNeededBetween(departure,destination);
}

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


}
Original file line number Diff line number Diff line change
@@ -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 <departure> to <destination>")
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 <requiredPoints>")
public void checkCalculatedPoints(int requiredPoints) {
assertThat(calculatedPoints).isEqualTo(requiredPoints);
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 <departure> to <destination>
Then I should see <requiredPoints> points
Examples:
|departure |destination |requiredPoints|
|Sydney |Melbourne |1700 |
|Melbourne |Wellington |4400 |

Scenario: Required points between different destinations
Given I want to go from <departure> to <destination>
When I calculate the number of required points
Then I should obtain <requiredPoints>
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 |
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions accounts-web-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class FrequentFlyerAccount {
private String accountNumber;
private String firstName;
private String lastName;
private String homeAirportCode;
private int statusPoints;

public FrequentFlyerAccount() {
Expand All @@ -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() {
Expand All @@ -61,6 +63,10 @@ public String getFirstName() {
return firstName;
}

public String getHomeAirportCode() {
return homeAirportCode;
}

public Earner earns(int amount) {
return new Earner(amount, this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package flyinghigh.services.accounts.services;
package flyinghigh.services.accounts.services.database;

/**
* Created by john on 17/09/2014.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,9 +12,9 @@
public class DatabaseSetupImpl implements DatabaseSetup {

private final static List<FrequentFlyerAccount> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> findPossibleDestinations(String homeAirportCode, int statusPoints) {
return ImmutableList.of("Melbourne", "Brisbane");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -40,7 +43,8 @@ public void initializeAccounts() {

@RequestMapping(method = RequestMethod.GET, value = "/{number}/possibleDestinations")
public List<String> findPossibleDestinations(@PathVariable String number) {
return ImmutableList.of("Paris","London");
FrequentFlyerAccount currentAccount = accountRepository.findByAccountNumber(number);
return destinationsCalculatorService.findPossibleDestinations(currentAccount.getHomeAirportCode(), currentAccount.getStatusPoints());
}

}
Loading

0 comments on commit 1cabe4c

Please sign in to comment.