use of org.glassfish.jersey.examples.entityfiltering.selectable.domain.Person in project jersey by jersey.
the class PersonResource method getPerson.
@GET
@Path("{id}")
public Person getPerson() {
final Person person = new Person();
person.setGivenName("Andrew");
person.setFamilyName("Dowd");
person.setHonorificPrefix("Mr.");
person.setHonorificSuffix("PhD");
person.setRegion("1st Level Region");
final ArrayList<Address> addresses = new ArrayList<>();
person.setAddresses(addresses);
final Address address = new Address();
addresses.add(address);
address.setRegion("2nd Level Region");
address.setStreetAddress("1234 fake st.");
address.setPhoneNumber(new PhoneNumber());
address.getPhoneNumber().setNumber("867-5309");
address.getPhoneNumber().setAreaCode("540");
person.setPhoneNumbers(new HashMap<String, PhoneNumber>());
final PhoneNumber number = new PhoneNumber();
number.setAreaCode("804");
number.setNumber("867-5309");
person.getPhoneNumbers().put("HOME", number);
return person;
}
use of org.glassfish.jersey.examples.entityfiltering.selectable.domain.Person in project jersey by jersey.
the class PersonResourceTest method testSubFilters.
/**
* Test 2nd and 3rd level filters.
*/
@Test
public void testSubFilters() throws Exception {
final Person entity = target("people").path("1234").queryParam("select", "familyName,givenName,addresses.streetAddress,addresses.phoneNumber.areaCode").request().get(Person.class);
// Not null values.
assertThat(entity.getFamilyName(), notNullValue());
assertThat(entity.getGivenName(), notNullValue());
assertThat(entity.getAddresses().get(0).getStreetAddress(), notNullValue());
assertThat(entity.getAddresses().get(0).getPhoneNumber().getAreaCode(), notNullValue());
// Null values.
assertThat(entity.getRegion(), nullValue());
assertThat(entity.getAddresses().get(0).getPhoneNumber().getNumber(), nullValue());
}
use of org.glassfish.jersey.examples.entityfiltering.selectable.domain.Person in project jersey by jersey.
the class PersonResourceTest method testNoFilter.
@Test
public void testNoFilter() throws Exception {
final Person entity = target("people").path("1234").request().get(Person.class);
// Not null values.
assertThat(entity.getFamilyName(), notNullValue());
assertThat(entity.getGivenName(), notNullValue());
assertThat(entity.getHonorificPrefix(), notNullValue());
assertThat(entity.getHonorificSuffix(), notNullValue());
assertThat(entity.getRegion(), notNullValue());
final List<Address> addresses = entity.getAddresses();
assertThat(addresses, notNullValue());
final Address address = addresses.get(0);
assertThat(address, notNullValue());
assertThat(address.getRegion(), notNullValue());
assertThat(address.getStreetAddress(), notNullValue());
PhoneNumber phoneNumber = address.getPhoneNumber();
assertThat(phoneNumber, notNullValue());
assertThat(phoneNumber.getAreaCode(), notNullValue());
assertThat(phoneNumber.getNumber(), notNullValue());
final Map<String, PhoneNumber> phoneNumbers = entity.getPhoneNumbers();
assertThat(phoneNumbers, notNullValue());
// TODO: enable for MOXy as well when JERSEY-2751 gets fixed.
if (JacksonFeature.class.isAssignableFrom(filteringProvider)) {
phoneNumber = phoneNumbers.get("HOME");
assertThat(phoneNumber, notNullValue());
assertThat(phoneNumber.getAreaCode(), notNullValue());
assertThat(phoneNumber.getNumber(), notNullValue());
}
}
use of org.glassfish.jersey.examples.entityfiltering.selectable.domain.Person in project jersey by jersey.
the class PersonResourceTest method testInvalidFilter.
@Test
public void testInvalidFilter() throws Exception {
final Person entity = target("people").path("1234").queryParam("select", "invalid").request().get(Person.class);
// All null values.
assertThat(entity.getFamilyName(), nullValue());
assertThat(entity.getGivenName(), nullValue());
assertThat(entity.getHonorificPrefix(), nullValue());
assertThat(entity.getHonorificSuffix(), nullValue());
assertThat(entity.getRegion(), nullValue());
assertThat(entity.getAddresses(), nullValue());
assertThat(entity.getPhoneNumbers(), nullValue());
}
use of org.glassfish.jersey.examples.entityfiltering.selectable.domain.Person in project jersey by jersey.
the class PersonResourceTest method testFilters.
/**
* Test first level filters.
*/
@Test
public void testFilters() throws Exception {
final Person entity = target("people").path("1234").queryParam("select", "familyName,givenName").request().get(Person.class);
// Not null values.
assertThat(entity.getFamilyName(), notNullValue());
assertThat(entity.getGivenName(), notNullValue());
// Null values.
assertThat(entity.getAddresses(), nullValue());
assertThat(entity.getPhoneNumbers(), nullValue());
assertThat(entity.getRegion(), nullValue());
}
Aggregations