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));
}
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));
}
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);
}
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;
}
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));
}
Aggregations