AirportLoader { public void upload(InputStream airportDataStream) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(airportDataStream)); String line = null; List<Airport> airports = new ArrayList<>(); while ((line = reader.readLine()) != null) { List<String> tokens = tokenize(line); double longitude = Double.parseDouble(tokens.get(7)); double latitude = Double.parseDouble(tokens.get(6)); Airport airport = new Airport(tokens.get(4), latitude, longitude); airport.setName(tokens.get(1)); Integer altitude = tokens.get(8).isEmpty()?null:Integer.parseInt(tokens.get(8)); airport.setAltitudeFt(altitude); airport.setCity(tokens.get(2)); airport.setCountry(tokens.get(3)); DST dst = DST.valueOf(tokens.get(10)); airport.setDst(dst); airport.setIcao(tokens.get(5)); TimeZone timeZone = tokens.get(9).isEmpty()?null:TimeZone.getTimeZone("GMT"+tokens.get(9)); airport.setTimeZone(timeZone); airports.add(airport); } for (Airport airport : airports) { Response response = collect.path("/airport").request().post(Entity.entity(airport, MediaType.APPLICATION_JSON)); System.out.println("Uploaded airport "+airport.getIata()+": " + (response.getStatus()==200?"OK":"FAILED")); } } AirportLoader(String baseEndpoint); void upload(InputStream airportDataStream); List<String> tokenize(String line); static void main(String args[]);  }
@Test public void endToEndTest() throws IOException { target.upload(AirportLoaderTest.class.getResourceAsStream("/airports-test.txt")); for (String iata:IMPORTED_IATA_CODES) { Response response = collect.path("/airport/"+iata).request().get(); assertEquals(200, response.getStatus()); } }