Search in sources :

Example 1 with Address

use of org.glassfish.jersey.examples.entityfiltering.selectable.domain.Address 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 Address

use of org.glassfish.jersey.examples.entityfiltering.selectable.domain.Address 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)

Aggregations

Address (org.glassfish.jersey.examples.entityfiltering.selectable.domain.Address)2 Person (org.glassfish.jersey.examples.entityfiltering.selectable.domain.Person)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 JerseyTest (org.glassfish.jersey.test.JerseyTest)1 Test (org.junit.Test)1