Skip to content

Commit

Permalink
Include a service to display the current version
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Sep 22, 2014
1 parent f2ceb08 commit 96143bc
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 31 deletions.
18 changes: 12 additions & 6 deletions flights-web-service/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import org.apache.tools.ant.filters.ReplaceTokens

apply plugin: 'spring-boot'
apply plugin: 'cloudfoundry'

jar {
baseName = 'flights-web-service'
version = '1.0.0'
version = '1.0.0'
}
group = "com.wakaleo.flying-high"

Expand Down Expand Up @@ -42,12 +44,11 @@ test {
exclude '**/*IT.class'

testLogging {
events "passed","skipped","failed"
events "passed", "skipped", "failed"
}
}

task integrationTests(type: Test) {
// reports.html.destination = file("$buildDir/reports/integration-tests")

if (project.hasProperty('localhost')) {
systemProperty 'mongodb.host', 'localhost'
Expand All @@ -63,16 +64,21 @@ task integrationTests(type: Test) {
systemProperty 'mongodb.password', 'flyinghigh'
}


include '**/*IT.class'
testLogging {
events "passed", "skipped", "failed"
}
}

integrationTests.mustRunAfter test
integrationTests.dependsOn test
check.dependsOn integrationTests

processResources {
filter ReplaceTokens, tokens: [
"application.version": project.jar.version,
"build.number": buildNumber
]
}

if (project.hasProperty('production')) {
cloudfoundry {
space = 'production'
Expand Down
1 change: 1 addition & 0 deletions flights-web-service/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
buildNumber=DEV
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public Airport(String country, String name, String code) {
this.code = code;
}

public static AirportBuilder called(String name) {
return new AirportBuilder(name);
}



public String getId() {
return id;
}
Expand Down Expand Up @@ -72,4 +78,33 @@ public String toString() {
", country='" + country + '\'' +
'}';
}

public static class AirportBuilder {
public String name;

public AirportBuilder(String name) {
this.name = name;
}

public FinalizedAirportBuilder inCountry(String country) {
return new FinalizedAirportBuilder(name, country);
}


}

public static class FinalizedAirportBuilder {
public String name;
public String country;

public FinalizedAirportBuilder(String name, String country) {
this.name = name;
this.country = country;
}


public Airport withCode(String code) {
return new Airport(country, name, code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
public class DatabaseSetupImpl implements DatabaseSetup {

private final static List<Airport> DEFAULT_AIRPORTS = ImmutableList.of(
new Airport("Australia", "Sydney", "SYD"),
new Airport("Australia", "Melbourne", "MLB"),
new Airport("Australia", "Brisbane", "BNE"),
new Airport("USA", "San Francisco", "SFO"),
new Airport("USA", "Los Angeles", "LAX"),
new Airport("Hong Kong", "Hong Kong", "HKG"),
new Airport("Singapore", "Singapore", "SIN"),
new Airport("China", "Beijing", "PEK"),
new Airport("New Zealand", "Auckland", "AKL"),
new Airport("New Zealand", "Wellington", "WLG"),
new Airport("New Zealand", "Christchurch", "CHC"),
new Airport("UK", "London", "LHR"),
new Airport("France", "Paris", "CDG"),
new Airport("Italy", "Rome", "FCO"),
new Airport("UAE", "Dubai", "DXB")
Airport.called("Sydney").inCountry("Australia").withCode("SYD"),
Airport.called("Sydney").inCountry("Melbourne").withCode("MLB"),
Airport.called("San Francisco").inCountry("USA").withCode("SFO"),
Airport.called("Los Angeles").inCountry("USA").withCode("LAX"),
Airport.called("Hong Kong").inCountry("Hong Kong").withCode("HKG"),
Airport.called("Singapore").inCountry("Singapore").withCode("SIN"),
Airport.called("Beijing").inCountry("China").withCode("PEK"),
Airport.called("Auckland").inCountry("New Zealand").withCode("AKL"),
Airport.called("Wellington").inCountry("New Zealand").withCode("WLG"),
Airport.called("Christchurch").inCountry("New Zealand").withCode("LHR"),
Airport.called("Christchurch").inCountry("New Zealand").withCode("LHR"),
Airport.called("Paris").inCountry("France").withCode("CDG"),
Airport.called("Nice").inCountry("France").withCode("NIC"),
Airport.called("Rome").inCountry("Italy").withCode("FCO"),
Airport.called("Dubai").inCountry("UAE").withCode("DXB")
);

private final AirportRepository airportRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package flyinghigh.services.flights.web;

import flyinghigh.services.flights.domain.Airport;
import flyinghigh.services.flights.repositories.AirportRepository;
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.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Properties;

@RestController
public class AboutController {

@RequestMapping("/about")
public String displayVersionDetails() throws IOException {
final Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("/application.properties"));
String version = properties.getProperty("application.version");
StringBuilder about = new StringBuilder();
about.append("FLIGHTS WEB SERVICE VERSION ");
about.append(version);

return about.toString();
}

}
11 changes: 2 additions & 9 deletions flights-web-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
server.port=8090

#mongodb.host=ds039020.mongolab.com
#mongodb.port=39020
#mongodb.database=flyinghigh-integration
#mongodb.username=flyinghigh
#mongodb.password=flyinghigh
application.version=@application.version@-@build.number@

mongodb.host=localhost
mongodb.port=27017
mongodb.database=flyinghigh
mongodb.username=
mongodb.password=

-Pmongodb.host=ds039020.mongolab.com -Pmongodb.port=39020 -Pmongodb.database=flyinghigh-integration -Pmongodb.username=flyinghigh -Pmongodb.password=flyinghigh
mongodb.password=
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package flyinghigh.services.flights.domain

import spock.lang.Specification
import flyinghigh.services.flights.domain.Airport

class WhenManagingAirports extends Specification {
def "Airports have a name and a code"() {
Expand All @@ -12,4 +11,13 @@ class WhenManagingAirports extends Specification {
and:
airport.code == "SYD"
}

def "Should be able to create airports easily"() {
when:
def airport = Airport.called("Sydney").inCountry("Australia").withCode("SYD")
then:
airport.name == "Sydney"
airport.code == "SYD"
airport.country == "Australia"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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 CheckingTheApplicationVersionIT {

@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_display_the_current_application_version() {
String about = restTemplate.getForObject(baseUrl + "/about", String.class);
assertThat(about).contains("FLIGHTS WEB SERVICE VERSION");
}

}

0 comments on commit 96143bc

Please sign in to comment.