Skip to content

Commit

Permalink
Added some pending scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Sep 28, 2014
1 parent 1cabe4c commit 2f54884
Show file tree
Hide file tree
Showing 30 changed files with 340 additions and 54 deletions.
7 changes: 7 additions & 0 deletions acceptance-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ test {
systemProperty 'webdriver.base.url', baseUrl
systemProperty 'webdriver.driver', driver
systemProperty 'thucydides.resized.image.width', 1000
systemProperty 'dashboard.tag.list', 'capabilities, stories, layer'
useJUnit()
maxParallelForks = 4
}

test.shouldRunAfter clean
Expand All @@ -64,6 +66,11 @@ checkOutcomes.mustRunAfter aggregate
clean {
delete "target"
}
task verify {
println "Running acceptance tests"
}
verify.dependsOn ':acceptance-tests:clean', ':acceptance-tests:test', ':acceptance-tests:aggregate', ':acceptance-tests:checkOutcomes'


class ThucydidesPlugin implements Plugin<Project> {
void apply(Project project) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package flyinghigh.services.acceptancetests;

import net.thucydides.jbehave.ThucydidesJUnitStories;
import net.thucydides.jbehave.ThucydidesJUnitStory;

/**
* Created by john on 18/09/2014.
*/
public class EarningPoints extends ThucydidesJUnitStories {

public EarningPoints() {
this.findStoriesIn("stories/earning_points");
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package flyinghigh.services.acceptancetests;

import net.thucydides.jbehave.ThucydidesJUnitStories;

/**
* Created by john on 18/09/2014.
*/
public class ManagingAirports extends ThucydidesJUnitStories {

public ManagingAirports() {
this.findStoriesIn("stories/managing_airports");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package flyinghigh.services.acceptancetests;

import net.thucydides.jbehave.ThucydidesJUnitStories;

/**
* Created by john on 18/09/2014.
*/
public class Partners extends ThucydidesJUnitStories {

public Partners() {
this.findStoriesIn("stories/partners");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package flyinghigh.services.acceptancetests;

import net.thucydides.jbehave.ThucydidesJUnitStories;

/**
* Created by john on 18/09/2014.
*/
public class SpendingPoints extends ThucydidesJUnitStories {

public SpendingPoints() {
this.findStoriesIn("stories/spending_points");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package flyinghigh.services.acceptancetests.domain;

/**
* Created by john on 27/09/2014.
*/
public enum FrequentFlyer {
Sarah("123456");

private final String number;

FrequentFlyer(String number) {
this.number = number;
}

public String getNumber() {
return number;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package flyinghigh.services.acceptancetests.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
* Created by john on 27/09/2014.
*/
@JsonIgnoreProperties({"_links"})
public class FrequentFlyerMember {
private String id;
private String accountNumber;
private String firstName;
private String lastName;
private String homeAirportCode;
private int statusPoints;

public FrequentFlyerMember() {
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getAccountNumber() {
return accountNumber;
}

public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public int getStatusPoints() {
return statusPoints;
}

public void setStatusPoints(int statusPoints) {
this.statusPoints = statusPoints;
}

public String getHomeAirportCode() {
return homeAirportCode;
}

public void setHomeAirportCode(String homeAirportCode) {
this.homeAirportCode = homeAirportCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public List<Airport> getDisplayedAirports() {
.map(DisplayedAirport::fromWebElement)
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package flyinghigh.services.acceptancetests.pages;

import flyinghigh.services.acceptancetests.domain.Airport;
import javafx.beans.binding.MapExpression;
import net.thucydides.core.annotations.DefaultUrl;
import net.thucydides.core.pages.PageObject;

Expand All @@ -10,8 +11,6 @@
@DefaultUrl("http://localhost:9001/#/myaccount")
public class MyAccountPage extends PageObject {

private int calculatedPoints;

public void selectDepartureCity(String departure) {
$("#departure").selectByVisibleText(departure);
}
Expand All @@ -23,4 +22,8 @@ public void selectDestinationCity(String destination) {
public int getCalculatedPoints() {
return Integer.valueOf($(".requiredPoints").getText());
}

public int getPointBalance() {
return Integer.valueOf($(".status-points-balance").getText());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import com.google.common.collect.ImmutableList;
import flyinghigh.services.acceptancetests.domain.Airport;
import flyinghigh.services.acceptancetests.domain.FrequentFlyerMember;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.thucydides.core.annotations.Step;
import org.springframework.web.client.RestTemplate;

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

public class RestClient {
Expand All @@ -22,24 +28,39 @@ public String getBaseFlightUrl() {
public String getBaseAccountUrl() {
String environment = System.getProperty("webservice.environment","local");
if (environment.equals("local")) {
return "http://localhost:8090/";
return "http://localhost:8091/";
} else {
return "http://" + environment + "-" + "accounts.cfapps.io";
}
}

@Step
public List<Airport> findAllAirports() {
return findAllAirports("/rest/api/airports");
}


@Step
public List<Airport> findAllAirports(String path) {
return ImmutableList.copyOf(restTemplate.getForEntity(getBaseFlightUrl() + path, Airport[].class).getBody());
}


@Step
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);
}

@Step
public void updatePointsFor(String number, int points) throws URISyntaxException {
String url = getResultUrl(restTemplate.getForObject(getBaseAccountUrl() + "/accounts/search/findByAccountNumber?number={number}", JSONObject.class, number));
FrequentFlyerMember member = restTemplate.getForObject(url, FrequentFlyerMember.class);
member.setStatusPoints(points);
restTemplate.put(new URI(url), member);
}

private String getResultUrl(JSONObject result) {
return ((JSONObject)((JSONArray)result.get("links")).get(0)).get("href").toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
package flyinghigh.services.acceptancetests.stepdefs;

import flyinghigh.services.acceptancetests.domain.FrequentFlyer;
import flyinghigh.services.acceptancetests.rest.RestClient;
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.net.URISyntaxException;

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

RestClient restClient = new RestClient();

@Steps
MyAccountUISteps sarah;

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

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

@When("Sarah 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
@@ -1,6 +1,7 @@
package flyinghigh.services.acceptancetests.stepdefs;

import flyinghigh.services.acceptancetests.rest.RestClient;
import net.thucydides.core.annotations.Steps;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
Expand All @@ -12,7 +13,8 @@
*/
public class RouteStepDefinitions {

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

String departure;
String destination;
Expand Down
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 static org.fest.assertions.api.Assertions.assertThat;

public class MyAccountUISteps {

MyAccountPage myAccountPage;
Expand All @@ -18,4 +20,11 @@ public int calculatePointsNeededBetween(String departure, String destination) {
myAccountPage.selectDestinationCity(destination);
return myAccountPage.getCalculatedPoints();
}

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


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Earning extra points from Frequent Flyer status

Meta:
@Versions Release 2
@tag layer:webservice

Scenario Outline: Earning points on flights by Frequent Flyer status
Given a member has a status of <initialStatus>
When I fly on a flight that is worth <base> base points
Then I should earn a status bonus of <bonus>
And I should have guaranteed minimum earned points per trip of <minimum>
And I should earn <total> points in all
Examples:
| initialStatus | base | bonus | minimum | total | notes |
| Bronze | 439 | 0 | 0 | 439 | |
| Silver | 439 | 220 | 500 | 659 | minimum points |
| Silver | 148 | 111 | 500 | 500 | 50% bonus |
| Gold | 474 | 400 | 1000 | 1000 | minimum points |
| Gold | 2041 | 1531 | 1000 | 3572 | 75% bonus |



Loading

0 comments on commit 2f54884

Please sign in to comment.