Search in sources :

Example 1 with Aircraft

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;
}
Also used : ArrayList(java.util.ArrayList) Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft)

Example 2 with Aircraft

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());
    }
}
Also used : List(java.util.List) Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft)

Example 3 with Aircraft

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.");
}
Also used : Form(javax.ws.rs.core.Form) List(java.util.List) Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft)

Example 4 with Aircraft

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());
}
Also used : Form(javax.ws.rs.core.Form) Flight(org.glassfish.jersey.examples.flight.model.Flight) List(java.util.List) Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft)

Example 5 with Aircraft

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);
        }
    }
}
Also used : Flight(org.glassfish.jersey.examples.flight.model.Flight) Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft) LinkedList(java.util.LinkedList)

Aggregations

Aircraft (org.glassfish.jersey.examples.flight.model.Aircraft)11 List (java.util.List)5 Flight (org.glassfish.jersey.examples.flight.model.Flight)4 RolesAllowed (javax.annotation.security.RolesAllowed)3 BadRequestException (javax.ws.rs.BadRequestException)3 Form (javax.ws.rs.core.Form)3 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Detail (org.glassfish.jersey.examples.flight.filtering.Detail)2 AircraftType (org.glassfish.jersey.examples.flight.model.AircraftType)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 DELETE (javax.ws.rs.DELETE)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Location (org.glassfish.jersey.examples.flight.model.Location)1