Search in sources :

Example 11 with Aircraft

use of org.glassfish.jersey.examples.flight.model.Aircraft in project jersey by jersey.

the class FlightsDemoAppTest method _testCreateAircraft.

public void _testCreateAircraft(String acceptType) {
    Form form = new Form("manufacturer", "Cesna").param("type", "680").param("capacity", "9");
    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.", 0, aircraft.getLocation().getX());
    assertEquals("Aircraft location y pos.", 0, 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)

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