-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
252 additions
and
26 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...ance-tests/src/test/java/flyinghigh/services/acceptancetests/ListingAffiliatedHotels.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ListingAffiliatedHotels extends ThucydidesJUnitStory { | ||
} |
23 changes: 23 additions & 0 deletions
23
...tance-tests/src/test/java/flyinghigh/services/acceptancetests/pages/DisplayedAirport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package flyinghigh.services.acceptancetests.pages; | ||
|
||
import flyinghigh.services.acceptancetests.domain.Airport; | ||
import net.thucydides.core.pages.WebElementFacade; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Created by john on 24/09/2014. | ||
*/ | ||
public class DisplayedAirport { | ||
public static Airport fromWebElement(final WebElementFacade airportElement) { | ||
return new Airport(airportElement.findBy(".airport-name").getText(), | ||
airportElement.findBy(".airport-code").getText(), | ||
airportElement.findBy(".airport-country").getText()); | ||
} | ||
|
||
public static Airport fromMapValues(final Map<String, String> airportFields) { | ||
return new Airport(airportFields.get("name"), | ||
airportFields.get("code"), | ||
airportFields.get("country")); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/pages/HomePage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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/#/home") | ||
public class HomePage extends PageObject { | ||
public List<Airport> getDisplayedAirports() { | ||
return findAll(".airport") | ||
.stream() | ||
.map(DisplayedAirport::fromWebElement) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
acceptance-tests/src/test/java/flyinghigh/services/acceptancetests/rest/RestClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package flyinghigh.services.acceptancetests.rest; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import flyinghigh.services.acceptancetests.domain.Airport; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.List; | ||
|
||
public class RestClient { | ||
|
||
private RestTemplate restTemplate = new RestTemplate(); | ||
|
||
public String getBaseFlightUrl() { | ||
String environment = System.getProperty("webservice.environment","local"); | ||
if (environment.equals("local")) { | ||
return "http://localhost:8090/"; | ||
} else { | ||
return "http://" + environment + "-" + "flights.cfapps.io"; | ||
} | ||
} | ||
|
||
public List<Airport> findAllAirports() { | ||
return findAllAirports("/rest/api/airports"); | ||
} | ||
|
||
|
||
public List<Airport> findAllAirports(String path) { | ||
return ImmutableList.copyOf(restTemplate.getForEntity(getBaseFlightUrl() + path, Airport[].class).getBody()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
.../src/test/java/flyinghigh/services/acceptancetests/stepdefs/AirportStepUIDefinitions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package flyinghigh.services.acceptancetests.stepdefs; | ||
|
||
import com.google.common.collect.Lists; | ||
import flyinghigh.services.acceptancetests.domain.Airport; | ||
import flyinghigh.services.acceptancetests.pages.HomePage; | ||
import flyinghigh.services.acceptancetests.rest.RestClient; | ||
import flyinghigh.services.acceptancetests.steps.AirportClientSteps; | ||
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 org.jbehave.core.model.ExamplesTable; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.fest.assertions.api.Assertions.assertThat; | ||
|
||
|
||
/** | ||
* Created by john on 17/09/2014. | ||
*/ | ||
public class AirportStepUIDefinitions { | ||
|
||
RestClient restClient = new RestClient(); | ||
|
||
@Steps | ||
AirportClientSteps airportClientSteps; | ||
|
||
HomePage homePage; | ||
|
||
@When("I go to the home page") | ||
public void openHomePage() { | ||
homePage.open(); | ||
} | ||
|
||
@Then("I should see the list of possibile destinations") | ||
public void seeListOfPossibleDestinations() { | ||
List<Airport> expectedAirports = restClient.findAllAirports(); | ||
|
||
List<Airport> displayedAirports = homePage.getDisplayedAirports(); | ||
|
||
assertThat(displayedAirports.size()).isEqualTo(expectedAirports.size()); | ||
assertThat(displayedAirports).containsAll(expectedAirports); | ||
} | ||
|
||
|
||
|
||
} |
15 changes: 15 additions & 0 deletions
15
.../test/java/flyinghigh/services/acceptancetests/stepdefs/FrequentFlyerStepDefinitions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package flyinghigh.services.acceptancetests.stepdefs; | ||
|
||
import org.jbehave.core.annotations.Given; | ||
|
||
/** | ||
* Created by john on 24/09/2014. | ||
*/ | ||
public class FrequentFlyerStepDefinitions { | ||
|
||
@Given("I am a frequent flyer") | ||
public void givenAFrequentFlyer() { | ||
// TODO | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
acceptance-tests/src/test/resources/stories/partners/listing_affiliated_hotels.story
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Meta: | ||
@Versions Release 1, Iteration 1.1 | ||
|
||
Narrative: | ||
In order to earn the most points possible | ||
As a traveller | ||
I want to know what hotels will let me earn poitns | ||
|
||
|
||
Scenario: List partner hotels | ||
Given I am a frequent flyer | ||
When I ask to see what hotels I should go to to earn more points | ||
Then I should see the list of partner hotels |
25 changes: 25 additions & 0 deletions
25
flights-web-service/src/main/java/flyinghigh/services/flights/filters/SimpleCORSFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package flyinghigh.services.flights.filters; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import javax.servlet.*; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
@Component | ||
public class SimpleCORSFilter implements Filter { | ||
|
||
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { | ||
HttpServletResponse response = (HttpServletResponse) res; | ||
response.setHeader("Access-Control-Allow-Origin", "*"); | ||
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); | ||
response.setHeader("Access-Control-Max-Age", "3600"); | ||
response.setHeader("Access-Control-Allow-Headers", "x-requested-with"); | ||
chain.doFilter(req, res); | ||
} | ||
|
||
public void init(FilterConfig filterConfig) {} | ||
|
||
public void destroy() {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
flights-web-service/src/test/java/flyinghigh/services/flights/InitializingTheAirportsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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; | ||
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 java.util.List; | ||
|
||
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 InitializingTheAirportsIT { | ||
|
||
@Autowired | ||
private DatabaseSetup databaseSetup; | ||
|
||
@Autowired | ||
private AirportRepository airportRepository; | ||
|
||
@Test | ||
public void should_instantiate_database_with_standard_airports() { | ||
databaseSetup.initializeAirports(); | ||
List<Airport> airports = airportRepository.findAll(); | ||
assertThat(airports).isNotEmpty(); | ||
} | ||
|
||
} |