Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Sep 29, 2014
1 parent 1b22386 commit fbc9fa5
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 65 deletions.
12 changes: 6 additions & 6 deletions acceptance-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
classpath("net.thucydides:thucydides-core:0.9.271")
classpath("net.thucydides:thucydides-core:0.9.272-SNAPSHOT")
}
}

Expand All @@ -28,8 +28,8 @@ dependencies {
compile("org.springframework.data:spring-data-rest-webmvc:2.2.0.RELEASE")
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.272'
testCompile 'net.thucydides:thucydides-core:0.9.272-SNAPSHOT'
testCompile 'net.thucydides:thucydides-jbehave-plugin:0.9.273-SNAPSHOT'

}

Expand All @@ -53,10 +53,10 @@ test {
systemProperty 'webservice.environment', webserviceEnvironment
systemProperty 'webdriver.base.url', baseUrl
systemProperty 'webdriver.driver', driver
systemProperty 'thucydides.resized.image.width', 1000
systemProperty 'dashboard.tag.list', 'capabilities, stories, layer'
systemProperty 'thucydides.browser.width', 1000
// systemProperty 'thucydides.resized.image.width', 1000
systemProperty 'dashboard.tag.list', 'capability, layer'
useJUnit()
maxParallelForks = 4
}

test.shouldRunAfter clean
Expand Down
4 changes: 2 additions & 2 deletions acceptance-tests/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
webserviceEnvironment=local
baseUrl = http://localhost:9001
driver=chrome
baseUrl = http://localhost:9001
driver=chrome
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RestClient {
private RestTemplate restTemplate = new RestTemplate();

public String getBaseFlightUrl() {
String environment = System.getProperty("webservice.environment","local");
String environment = "dev";//System.getProperty("webservice.environment","local");
if (environment.equals("local")) {
return "http://localhost:8090/";
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Earning extra points from Frequent Flyer status

Meta:
@Versions Release 2
@tag layer:webservice
@tag layer:web

Scenario Outline: Earning points on flights by Frequent Flyer status
Scenario: 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>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ In order to encourage travellers to book with Flying High Airlines more frequent
As the Flying High sales manager
I want travellers to earn Frequent Flyer points when they fly with us

Scenario: Earning standard points from an Economy flight
Given the flying distance between Sydney and Melbourne is 878 km
And I am a Bronze Frequent Flyer member
When I fly from Sydney to Melbourne on 10/10/2014
Then I should earn 439 points
Scenario: Earning points when I buy something in a supermarket
Given I am shopping at Woolworths
And Woolworths is a partner organisation
When I purchase a box of sardines for 5.00
Then I should earn 5 points

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ Meta:
@tag layer:web

Narrative:
In order to know how many points I have earnd
In order to know how many points I have earned
As a traveller
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Notes: 2 points required per km
Scenario: Calculate required points
Meta:
@tag layer:web
2 points required per km

Given I am a frequent flyer
And I am on the My Account page
Expand Down
2 changes: 2 additions & 0 deletions acceptance-tests/src/test/resources/thucydides.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dashboard.excluded.tag.list=story
webservice.environment=dev
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.6.RELEASE")
classpath group: 'org.cloudfoundry', name: 'cf-gradle-plugin', version: '1.0.4'
classpath("net.thucydides:thucydides-core:0.9.271")
classpath("net.thucydides:thucydides-core:0.9.272-SNAPSHOT")
}
}

Expand Down
2 changes: 2 additions & 0 deletions flights-web-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ dependencies {
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile "org.codehaus.groovy.modules.http-builder:http-builder:0.7"
testCompile 'org.easytesting:fest-assert-core:2.0M10'
testCompile 'com.insightfullogic:lambda-behave:0.3'
testCompile 'org.mockito:mockito-all:1.9.5'
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ 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 setup() {
}
def DISTANCE = 1000
def REQUIRED_POINTS = DISTANCE * 2

def "Required points should be calculated based on route distance"() {
given:
Expand All @@ -33,7 +30,8 @@ class WhenCalculatingRequiredPoints extends Specification {
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()]
routeRepository.findByDepartureCodeAndDestinationCode("MEL","SYD") >>
[Route.from(sydney).to(melbourne).withDistanceOf(DISTANCE).km()]

def pointsCalculator = new PointsCalculator(routeRepository)
when:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package flyinghigh.services.flights;

import com.google.common.collect.ImmutableList;
import com.insightfullogic.lambdabehave.JunitSuiteRunner;
import flyinghigh.services.flights.domain.Airport;
import flyinghigh.services.flights.domain.Route;
import flyinghigh.services.flights.repositories.RouteRepository;
import flyinghigh.services.flights.services.points.PointsCalculator;
import org.junit.runner.RunWith;

import java.util.List;

import static com.insightfullogic.lambdabehave.Suite.describe;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@RunWith(JunitSuiteRunner.class)
public class CalculatingEarnedPointsSpecification {
{

Airport sydney = new Airport("Australia", "Sydney", "SYD");
Airport melbourne = new Airport("Australia", "Melbourne", "MEL");

RouteRepository routeRepository = mock(RouteRepository.class);
PointsCalculator pointsCalculator = new PointsCalculator(routeRepository);

describe("calcuating points earned for a given route", it -> {

it.uses(6000, 12000)
.and(5000, 10000)
.toShow("2 points should be earned per km travelled",
(expect, distance, expectedPoints) -> {
List<Route> routes = ImmutableList.of(Route.from(sydney)
.to(melbourne)
.withDistanceOf(distance).km());
when(routeRepository.findByDepartureCodeAndDestinationCode("SYD", "MEL"))
.thenReturn(routes);

int calculatedPoints
= pointsCalculator.calculatePointsRequiredBetween("SYD", "MEL");

expect.that(calculatedPoints).isEqualTo(expectedPoints);
});
});
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

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

//
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = FlightsApp.class)
@WebAppConfiguration
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package flyinghigh.services.flights;

import flyinghigh.services.flights.domain.Airport;

import com.insightfullogic.lambdabehave.JunitSuiteRunner;
import org.junit.runner.RunWith;

import java.util.Stack;

import static com.insightfullogic.lambdabehave.Suite.describe;
import static org.hamcrest.Matchers.equalTo;

@RunWith(JunitSuiteRunner.class)
public class CreatingAnAirportSpecification {{

Airport airport = Airport.called("Sydney").inCountry("Australia").withCode("SYD");

describe("an airport", it -> {

it.should("be created with the correct values", expect -> {
expect.that(airport).hasProperty("name", equalTo("Sydney"));
expect.that(airport).hasProperty("code", equalTo("SYD"));
expect.that(airport).hasProperty("country", equalTo("Australia"));
});
});


}}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

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

//
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = FlightsApp.class)
@WebAppConfiguration
Expand All @@ -34,5 +33,4 @@ public void should_instantiate_database_with_standard_airports() {
List<Airport> airports = airportRepository.findAll();
assertThat(airports).isNotEmpty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,8 @@ public class LookingUpAirportsIT {
@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();
databaseSetup.initializeReferenceData();
}

Expand Down

0 comments on commit fbc9fa5

Please sign in to comment.