-
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
5 changed files
with
137 additions
and
9 deletions.
There are no files selected for viewing
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
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
76 changes: 76 additions & 0 deletions
76
...ice/src/test/java/flyinghigh/services/flights/FindingDestinationAndDepartureAirports.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,76 @@ | ||
package flyinghigh.services.flights; | ||
|
||
import com.mongodb.util.Hash; | ||
import flyinghigh.services.flights.domain.Airport; | ||
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.HashMap; | ||
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 FindingDestinationAndDepartureAirports { | ||
|
||
@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_find_airports_with_flights_to_a_given_destination() { | ||
List<HashMap> destinations = restTemplate.getForObject(baseUrl + "/rest/api/routes/to?destinationCode={destinationCode}", List.class, "SYD"); | ||
|
||
assertThat(destinations).isNotEmpty(); | ||
destinations.stream().forEach( | ||
destination -> assertThat(destination.get("code")).isNotEqualTo("SYD") | ||
); | ||
} | ||
|
||
@Test | ||
public void should_find_airports_with_flights_from_a_given_destination() { | ||
List<HashMap> destinations = restTemplate.getForObject(baseUrl + "/rest/api/routes/from?departureCode={departureCode}", List.class, "SYD"); | ||
|
||
assertThat(destinations).isNotEmpty(); | ||
destinations.stream().forEach( | ||
destination -> assertThat(destination.get("code")).isNotEqualTo("SYD") | ||
); | ||
} | ||
|
||
@Test | ||
public void should_find_airports_based_on_return_routes() { | ||
List<HashMap> destinations = restTemplate.getForObject(baseUrl + "/rest/api/routes/from?departureCode={departureCode}", List.class, "WLG"); | ||
|
||
assertThat(destinations).isNotEmpty(); | ||
destinations.stream().forEach( | ||
destination -> assertThat(destination.get("code")).isNotEqualTo("WEL") | ||
); | ||
} | ||
|
||
|
||
|
||
} |