Search in sources :

Example 6 with Person

use of gov.ca.cwds.rest.api.domain.Person in project API by ca-cwds.

the class PersonServiceTest method findReturnsNullWhenNotFound.

@Test
public void findReturnsNullWhenNotFound() throws Exception {
    when(personDao.find(new Long(-1))).thenReturn(null);
    Person found = personService.find(new Long(-1));
    assertThat(found, is(nullValue()));
}
Also used : Person(gov.ca.cwds.rest.api.domain.Person) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) Test(org.junit.Test)

Example 7 with Person

use of gov.ca.cwds.rest.api.domain.Person in project API by ca-cwds.

the class PersonServiceTest method createReturnsNonNull.

@Test
public void createReturnsNonNull() throws Exception {
    gov.ca.cwds.data.persistence.ns.Address toCreateAddress = new gov.ca.cwds.data.persistence.ns.Address(1L, "742 Evergreen Terrace", "Springfield", "WA", new Integer(98700), "Home");
    Set<PersonAddress> personAddresses = new HashSet<>();
    PersonAddress personAddress = new PersonAddress();
    personAddress.setAddress(toCreateAddress);
    personAddresses.add(personAddress);
    gov.ca.cwds.data.persistence.ns.Person toCreate = new gov.ca.cwds.data.persistence.ns.Person(2L, "Bart", "Simpson", "M", DomainChef.uncookDateString("2016-10-31"), "1234556789", personAddresses, null, null, null, null);
    Person request = new Person(toCreate);
    when(personDao.create(any(gov.ca.cwds.data.persistence.ns.Person.class))).thenReturn(toCreate);
    when(personDao.find(any(gov.ca.cwds.data.persistence.ns.Person.class))).thenReturn(toCreate);
    PostedPerson postedPerson = personService.create(request);
    assertThat(postedPerson, is(notNullValue()));
}
Also used : PersonAddress(gov.ca.cwds.data.persistence.ns.PersonAddress) Address(gov.ca.cwds.rest.api.domain.Address) PersonAddress(gov.ca.cwds.data.persistence.ns.PersonAddress) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) Person(gov.ca.cwds.rest.api.domain.Person) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with Person

use of gov.ca.cwds.rest.api.domain.Person in project API by ca-cwds.

the class PersonServiceTest method updateThrowsNullPointeException.

/*
   * update tests
   */
@Test
public void updateThrowsNullPointeException() throws Exception {
    thrown.expect(NullPointerException.class);
    Address address = new Address("", "", "742 Evergreen Terrace", "Springfield", "WA", 98700, "Home");
    Set<Address> addresses = new HashSet<>();
    addresses.add(address);
    Person toUpdate = new Person("Bart", "Simpson", "M", "2013-10-31", "1234556789", addresses, null, null, null, null);
    personService.update(1L, toUpdate);
}
Also used : PersonAddress(gov.ca.cwds.data.persistence.ns.PersonAddress) Address(gov.ca.cwds.rest.api.domain.Address) Person(gov.ca.cwds.rest.api.domain.Person) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Person

use of gov.ca.cwds.rest.api.domain.Person in project API by ca-cwds.

the class PersonResourceTest method createDelegatesToCrudsResource.

/**
   * Create Tests
   * 
   * @throws Exception required for test compilation
   */
@Test
public void createDelegatesToCrudsResource() throws Exception {
    Person person = new Person("firstname", "last", "M", "1990-11-22", "000000000", null, null, null, null, null);
    inMemoryResource.client().target(ROOT_RESOURCE).request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(person, MediaType.APPLICATION_JSON));
    verify(resourceDelegate, atLeastOnce()).create(eq(person));
}
Also used : Person(gov.ca.cwds.rest.api.domain.Person) Test(org.junit.Test)

Example 10 with Person

use of gov.ca.cwds.rest.api.domain.Person in project API by ca-cwds.

the class PersonService method update.

/**
   * <strong>NOT IMPLEMENTED! REQUIRED BY {@link CrudsService}!</strong> {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#update(java.io.Serializable,
   *      gov.ca.cwds.rest.api.Request)
   */
@Override
public Response update(final Serializable primaryKey, Request request) {
    assert primaryKey instanceof Long;
    assert request instanceof Person;
    Person person = (Person) request;
    gov.ca.cwds.data.persistence.ns.Person managedPerson = new gov.ca.cwds.data.persistence.ns.Person(person, null, null);
    managedPerson = personDao.update(managedPerson);
    populatePersonDetails(person, managedPerson);
    managedPerson = personDao.find(managedPerson.getId());
    PostedPerson postedPerson = new PostedPerson(managedPerson);
    return postedPerson;
}
Also used : Person(gov.ca.cwds.rest.api.domain.Person) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson)

Aggregations

Person (gov.ca.cwds.rest.api.domain.Person)10 PostedPerson (gov.ca.cwds.rest.api.domain.PostedPerson)7 Test (org.junit.Test)7 PersonAddress (gov.ca.cwds.data.persistence.ns.PersonAddress)4 Address (gov.ca.cwds.rest.api.domain.Address)4 HashSet (java.util.HashSet)4 ApiException (gov.ca.cwds.rest.api.ApiException)1 Response (gov.ca.cwds.rest.api.Response)1 Ethnicity (gov.ca.cwds.rest.api.domain.Ethnicity)1 Language (gov.ca.cwds.rest.api.domain.Language)1 Participant (gov.ca.cwds.rest.api.domain.Participant)1 PhoneNumber (gov.ca.cwds.rest.api.domain.PhoneNumber)1 Race (gov.ca.cwds.rest.api.domain.Race)1 UnitOfWork (io.dropwizard.hibernate.UnitOfWork)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1