Search in sources :

Example 1 with Person

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

the class PersonResourceTest method udpateReturns501.

/**
   * Update Tests
   * 
   * @throws Exception required for test compilation
   */
@Test
public void udpateReturns501() throws Exception {
    Person person = new Person("firstname", "last", "M", "1973-11-22", "000000000", null, null, null, null, null);
    int status = inMemoryResource.client().target(FOUND_RESOURCE).request().accept(MediaType.APPLICATION_JSON).put(Entity.entity(person, MediaType.APPLICATION_JSON)).getStatus();
    assertThat(status, is(501));
}
Also used : Person(gov.ca.cwds.rest.api.domain.Person) Test(org.junit.Test)

Example 2 with Person

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

the class PersonServiceTest method testFindReturnsCorrectPersonWhenFound.

/*
   * find tests
   */
@Test
public void testFindReturnsCorrectPersonWhenFound() throws Exception {
    Address address = new Address("", "", "742 Evergreen Terrace", "Springfield", "WA", 98700, "Home");
    PhoneNumber phoneNumber = new PhoneNumber("408-277-4778", "cell");
    Language language = new Language("English");
    Race race = new Race("White", "European");
    Ethnicity ethnicity = new Ethnicity("Unknown", "South American");
    Set<Address> addresses = new HashSet<Address>();
    addresses.add(address);
    Set<PhoneNumber> phoneNumbers = new HashSet<PhoneNumber>();
    phoneNumbers.add(phoneNumber);
    Set<Language> languages = new HashSet<Language>();
    languages.add(language);
    Set<Race> races = new HashSet<Race>();
    races.add(race);
    Set<Ethnicity> ethnicities = new HashSet<Ethnicity>();
    ethnicities.add(ethnicity);
    Person expected = new Person("Bart", "Simpson", "M", "2016-10-31", "1234556789", addresses, phoneNumbers, languages, races, ethnicities);
    gov.ca.cwds.data.persistence.ns.Person person = new gov.ca.cwds.data.persistence.ns.Person(expected, null, null);
    when(personDao.find(123L)).thenReturn(person);
    Person found = personService.find(123L);
    assertThat(found, is(expected));
}
Also used : PersonAddress(gov.ca.cwds.data.persistence.ns.PersonAddress) Address(gov.ca.cwds.rest.api.domain.Address) Ethnicity(gov.ca.cwds.rest.api.domain.Ethnicity) Language(gov.ca.cwds.rest.api.domain.Language) Race(gov.ca.cwds.rest.api.domain.Race) PhoneNumber(gov.ca.cwds.rest.api.domain.PhoneNumber) 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 3 with Person

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

the class ParticipantService method create.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
   */
@Override
public Response create(Request request) {
    assert request instanceof Participant;
    Participant participant = (Participant) request;
    gov.ca.cwds.data.persistence.ns.Participant managed = new gov.ca.cwds.data.persistence.ns.Participant(participant, null, null);
    Person person = personService.find(managed.getPersonId());
    managed = participantDao.create(managed);
    return new Participant(managed, person);
}
Also used : Participant(gov.ca.cwds.rest.api.domain.Participant) Person(gov.ca.cwds.rest.api.domain.Person)

Example 4 with Person

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

the class PersonService method create.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
   */
@Override
@UnitOfWork(value = "ns")
public PostedPerson create(Request request) {
    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.create(managedPerson);
    populatePersonDetails(person, managedPerson);
    managedPerson = personDao.find(managedPerson.getId());
    PostedPerson postedPerson = new PostedPerson(managedPerson);
    try {
        final gov.ca.cwds.rest.api.domain.es.Person esPerson = new gov.ca.cwds.rest.api.domain.es.Person(managedPerson.getId().toString(), managedPerson.getFirstName(), managedPerson.getLastName(), managedPerson.getGender(), DomainChef.cookDate(managedPerson.getDateOfBirth()), managedPerson.getSsn(), managedPerson.getClass().getName(), MAPPER.writeValueAsString(managedPerson));
        final String document = MAPPER.writeValueAsString(esPerson);
        // If the people index is missing, create it.
        elasticsearchDao.createIndexIfNeeded(elasticsearchDao.getDefaultAlias());
    // The ES Dao manages its own connections. No need to manually start or stop.
    // elasticsearchDao.index(elasticsearchDao.getDefaultAlias(),
    // elasticsearchDao.getDefaultDocType(), document, esPerson.getId());
    } catch (Exception e) {
        LOGGER.error("Unable to Index Person in ElasticSearch", e);
        throw new ApiException("Unable to Index Person in ElasticSearch", e);
    }
    return postedPerson;
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) ApiException(gov.ca.cwds.rest.api.ApiException) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) Person(gov.ca.cwds.rest.api.domain.Person) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) ApiException(gov.ca.cwds.rest.api.ApiException) UnitOfWork(io.dropwizard.hibernate.UnitOfWork)

Example 5 with Person

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

the class PersonServiceTest method createReturnsPostedPerson.

/*
   * create tests
   */
@Test
public void createReturnsPostedPerson() 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("2013-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);
    Response response = personService.create(request);
    assertThat(response.getClass(), is(PostedPerson.class));
}
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) Response(gov.ca.cwds.rest.api.Response) Person(gov.ca.cwds.rest.api.domain.Person) PostedPerson(gov.ca.cwds.rest.api.domain.PostedPerson) HashSet(java.util.HashSet) Test(org.junit.Test)

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