Search in sources :

Example 1 with Person

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;
}
Also used : Address(org.glassfish.jersey.examples.entityfiltering.selectable.domain.Address) ArrayList(java.util.ArrayList) PhoneNumber(org.glassfish.jersey.examples.entityfiltering.selectable.domain.PhoneNumber) Person(org.glassfish.jersey.examples.entityfiltering.selectable.domain.Person) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with 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());
}
Also used : Person(org.glassfish.jersey.examples.entityfiltering.selectable.domain.Person) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 3 with Person

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());
    }
}
Also used : Address(org.glassfish.jersey.examples.entityfiltering.selectable.domain.Address) PhoneNumber(org.glassfish.jersey.examples.entityfiltering.selectable.domain.PhoneNumber) Person(org.glassfish.jersey.examples.entityfiltering.selectable.domain.Person) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 4 with Person

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());
}
Also used : Person(org.glassfish.jersey.examples.entityfiltering.selectable.domain.Person) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 5 with Person

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());
}
Also used : Person(org.glassfish.jersey.examples.entityfiltering.selectable.domain.Person) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Aggregations

Person (org.glassfish.jersey.examples.entityfiltering.selectable.domain.Person)6 JerseyTest (org.glassfish.jersey.test.JerseyTest)5 Test (org.junit.Test)5 Address (org.glassfish.jersey.examples.entityfiltering.selectable.domain.Address)2 PhoneNumber (org.glassfish.jersey.examples.entityfiltering.selectable.domain.PhoneNumber)2 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1