use of org.glassfish.jersey.examples.flight.model.Aircraft in project jersey by jersey.
the class DataStore method selectAvailableAircrafts.
public static List<Aircraft> selectAvailableAircrafts() {
final ArrayList<Aircraft> result = new ArrayList<>(aircrafts.values());
final Iterator<Aircraft> it = result.iterator();
while (it.hasNext()) {
Aircraft a = it.next();
if (!a.isAvailable()) {
it.remove();
}
}
Collections.sort(result, AIRCRAFT_COMPARATOR);
return result;
}
use of org.glassfish.jersey.examples.flight.model.Aircraft in project jersey by jersey.
the class FlightsDemoAppTest method _testAvailableAircrafts.
public void _testAvailableAircrafts(String acceptType) {
final List<Aircraft> aircrafts = target("aircrafts/available").request(acceptType).get(new GenericType<List<Aircraft>>() {
});
for (Aircraft aircraft : aircrafts) {
assertNotNull("Aircraft id", aircraft.getId());
assertNotNull("Aircraft type", aircraft.getType());
assertTrue("Aircraft not available", aircraft.isAvailable());
}
}
use of org.glassfish.jersey.examples.flight.model.Aircraft in project jersey by jersey.
the class FlightsDemoAppTest method _testCreateAircraftWithLocation.
public void _testCreateAircraftWithLocation(String acceptType) {
Form form = new Form("manufacturer", "Cesna").param("type", "750").param("capacity", "12").param("x-pos", "100").param("y-pos", "200");
Aircraft aircraft = target("aircrafts").queryParam("user", "admin").request(acceptType).post(Entity.form(form), Aircraft.class);
assertNotNull("Aircraft", aircraft);
assertNotNull("Aircraft id", aircraft.getId());
assertNotNull("Aircraft type", aircraft.getType());
assertNotNull("Aircraft location", aircraft.getLocation());
assertEquals("Aircraft location x pos.", 100, aircraft.getLocation().getX());
assertEquals("Aircraft location y pos.", 200, aircraft.getLocation().getY());
assertTrue("Aircraft not available", aircraft.isAvailable());
final List<Aircraft> availableAircrafts = target("aircrafts/available").request(acceptType).get(new GenericType<List<Aircraft>>() {
});
for (Aircraft a : availableAircrafts) {
if (aircraft.getId().equals(a.getId())) {
// passed
return;
}
}
fail("New aircraft not found in the list of available aircrafts.");
}
use of org.glassfish.jersey.examples.flight.model.Aircraft in project jersey by jersey.
the class FlightsDemoAppTest method _testCreateFlight.
public void _testCreateFlight(String acceptType) {
final List<Aircraft> availableAircrafts = target("aircrafts/available").request(acceptType).get(new GenericType<List<Aircraft>>() {
});
final Aircraft aircraft = availableAircrafts.get(0);
final Form flightForm = new Form("aircraftId", aircraft.getId().toString());
Flight flight = target("flights").queryParam("user", "admin").request(acceptType).post(Entity.form(flightForm), Flight.class);
assertNotNull("Flight", flight);
assertNotNull("Flight.id", flight.getId());
assertNotNull("Flight.aircraft", flight.getAircraft());
assertEquals("Aircraft IDs do not match", aircraft.getId(), flight.getAircraft().getId());
assertFalse("Aircraft not assigned", flight.getAircraft().isAvailable());
}
use of org.glassfish.jersey.examples.flight.model.Aircraft in project jersey by jersey.
the class DataStore method generateData.
public static void generateData() {
flights.clear();
aircrafts.clear();
LinkedList<Aircraft> planes = new LinkedList<>();
while (planes.size() < MAX_GEN_AIRCRAFTS) {
Aircraft a = generateAircraft();
if (addAircraft(a)) {
planes.add(a);
}
}
int count = 0;
while (count < MAX_GEN_FLIGHTS) {
final Flight flight = generateFlight();
if (addFlight(flight)) {
count++;
final Aircraft aircraft = planes.remove(rnd.nextInt(planes.size()));
aircraft.marAssigned();
flight.setAircraft(aircraft);
}
}
}
Aggregations