use of gov.ca.cwds.rest.api.domain.ScreeningResponse in project API by ca-cwds.
the class ScreeningServiceTest method findReturnsNullWhenNotFound.
/*
* find tests
*/
// @Test
// public void findReturnsCorrectScreeningWhenFoundAndParticipantListIsNotNull() throws Exception
// {
// roles.add("victim");
// gov.ca.cwds.rest.api.domain.Address domainAddress = new gov.ca.cwds.rest.api.domain.Address(
// "742 Evergreen Terrace", "Springfield", "WA", 98700, "home", 3);
// addresses.add(domainAddress);
// Participant bart = new Participant(1, "Bart", "Simpson", "male", "123456789", "2016-10-31",
// 1234, 1234, roles, addresses);
// Participant maggie = new Participant(2, "Maggie", "Simpson", "female", "123456789",
// "2016-10-31", 1234, 1234, roles, addresses);
//
// Address address = new Address(1L, "742 Evergreen Terrace", "Springfield", "WA", 98700, "home");
// Date date = DomainChef.uncookDateString("2016-10-31");
// ImmutableSet.Builder<gov.ca.cwds.data.persistence.ns.Participant> persistentPersonSetBuilder =
// ImmutableSet.builder();
// persistentPersonSetBuilder
// .add(new gov.ca.cwds.data.persistence.ns.Participant(bart, null, null,
// new gov.ca.cwds.data.persistence.ns.Person(new Person("Bart", "Simpson", "M",
// "2016-10-31", "123456789", null, null, null, null, null), null, null)))
// .add(new gov.ca.cwds.data.persistence.ns.Participant(maggie, null, null,
// new gov.ca.cwds.data.persistence.ns.Person(new Person("Maggie", "Simpson", "M",
// "2016-10-31", "123456789", null, null, null, null, null), null, null)));
//
// Screening screening = new Screening("X5HNJK", date, "Amador", date, "Home", "email",
// "First screening", "immediate", "accept_for_investigation", date, "first narrative",
// address, persistentPersonSetBuilder.build());
//
// ImmutableSet.Builder<Participant> domainParticipantSetBuilder = ImmutableSet.builder();
// domainParticipantSetBuilder.add(bart).add(maggie);
//
// when(screeningDao.find(new Long(123))).thenReturn(screening);
//
// ScreeningResponse expected = new ScreeningResponse("X5HNJK", "2016-10-31", "Amador",
// "2016-10-31", "Home", "email", "First screening", "immediate", "accept_for_investigation",
// "2016-10-31", "first narrative", domainAddress, domainParticipantSetBuilder.build());
//
// Response found = screeningService.find(123L);
// assertThat(found.getClass(), is(ScreeningResponse.class));
// assertThat(found, is(expected));
// }
// @Test
// public void findReturnsCorrectScreeningWhenFoundAndParticipantListIsNull() throws Exception {
// Address address = new Address(1L, "742 Evergreen Terrace", "Springfield", "WA", 98700, "home");
// Date date = DomainChef.uncookDateString("2016-10-31");
// Screening screening =
// new Screening("X5HNJK", date, "Amador", date, "Home", "email", "First screening",
// "accept_for_investigation", "immediate", date, "first narrative", address, null);
//
// gov.ca.cwds.rest.api.domain.Address domainAddress = new gov.ca.cwds.rest.api.domain.Address(
// "742 Evergreen Terrace", "Springfield", "WA", 98700, "home", 3);
//
// when(screeningDao.find(new Long(123))).thenReturn(screening);
//
// ImmutableSet.Builder<Participant> setbuilder = ImmutableSet.builder();
// ScreeningResponse expected = new ScreeningResponse("X5HNJK", "10/13/2016", "Amador",
// "10/13/2016", "Home", "email", "First screening", null, "accept_for_investigation",
// "10/13/2016", "first narrative", domainAddress, setbuilder.build());
//
// Response found = screeningService.find(123L);
// assertThat(found.getClass(), is(ScreeningResponse.class));
// assertThat(found, is(expected));
// }
@Test
public void findReturnsNullWhenNotFound() throws Exception {
Response found = screeningService.find(33L);
assertThat(found, is(nullValue()));
}
use of gov.ca.cwds.rest.api.domain.ScreeningResponse in project API by ca-cwds.
the class ScreeningService method update.
/**
* {@inheritDoc}
*
* @see gov.ca.cwds.rest.services.CrudsService#update(java.io.Serializable,
* gov.ca.cwds.rest.api.Request)
*/
@Override
public ScreeningResponse update(Serializable primaryKey, Request request) {
assert primaryKey instanceof Long;
assert request instanceof ScreeningRequest;
ScreeningRequest screeningRequest = (ScreeningRequest) request;
Set<gov.ca.cwds.data.persistence.ns.Participant> participants = new HashSet<>();
Address address = new Address(screeningRequest.getAddress(), null, null);
gov.ca.cwds.data.persistence.ns.Screening screening = new gov.ca.cwds.data.persistence.ns.Screening((Long) primaryKey, screeningRequest, address, participants, null, null);
screening = screeningDao.update(screening);
if (screeningDao.getSessionFactory() != null) {
screeningDao.getSessionFactory().getCurrentSession().flush();
screeningDao.getSessionFactory().getCurrentSession().refresh(screening);
}
return new ScreeningResponse(screening, screening.getParticipants());
}
use of gov.ca.cwds.rest.api.domain.ScreeningResponse in project API by ca-cwds.
the class ScreeningServiceTest method updateReturnsCorrectScreeningResponseOnSuccess.
@Test
public void updateReturnsCorrectScreeningResponseOnSuccess() throws Exception {
roles.add("victim");
gov.ca.cwds.rest.api.domain.Address domainAddress = new gov.ca.cwds.rest.api.domain.Address("", "", "742 Evergreen Terrace", "Springfield", "WA", 98700, "home");
addresses.add(domainAddress);
ScreeningRequest screeningRequest = new ScreeningRequest("ref", "2016-10-31", "Sac", "2016-10-31", "loc", "comm", "name", "now", "sure", "2016-10-31", "narrative", domainAddress);
Participant bart = new Participant(1, "", "", "Bart", "Simpson", "male", "123456789", "2016-10-31", 1234, 1234, roles, addresses);
Participant maggie = new Participant(2, "", "", "Maggie", "Simpson", "female", "123456789", "2016-10-31", 1234, 1234, roles, addresses);
// Participant bart = new Participant(1, 123, "Bart", "Simpson", "M", "2016-10-31",
// "123456789");
// Participant maggie = new Participant(2, 1, "Maggie", "Simpson", "M", "2016-10-31",
// "123456789");
ImmutableSet.Builder<gov.ca.cwds.data.persistence.ns.Participant> peopleListBuilder = ImmutableSet.builder();
ImmutableSet<gov.ca.cwds.data.persistence.ns.Participant> people = peopleListBuilder.add(new gov.ca.cwds.data.persistence.ns.Participant(bart, null, null)).add(new gov.ca.cwds.data.persistence.ns.Participant(maggie, null, null)).build();
gov.ca.cwds.data.persistence.ns.Screening screening = new gov.ca.cwds.data.persistence.ns.Screening(1L, screeningRequest, new Address(domainAddress, null, null), people, null, null);
when(screeningDao.find(new Long(123))).thenReturn(screening);
when(screeningDao.update(any())).thenReturn(screening);
ScreeningResponse expected = new ScreeningResponse(screening, people);
ScreeningResponse updated = screeningService.update(1L, screeningRequest);
assertThat(updated, is(expected));
}
use of gov.ca.cwds.rest.api.domain.ScreeningResponse in project API by ca-cwds.
the class ScreeningService method find.
/**
* {@inheritDoc}
*
* @see gov.ca.cwds.rest.services.CrudsService#find(java.io.Serializable)
*/
@Override
public Response find(Serializable primaryKey) {
if (primaryKey instanceof Long) {
gov.ca.cwds.data.persistence.ns.Screening screening = screeningDao.find(primaryKey);
if (screening != null) {
return new ScreeningResponse(screening, screening.getParticipants());
}
return null;
} else {
List<gov.ca.cwds.data.persistence.ns.Screening> screenings = findByCriteria(primaryKey);
ImmutableSet.Builder<ScreeningResponse> builder = ImmutableSet.builder();
for (gov.ca.cwds.data.persistence.ns.Screening screening : screenings) {
if (screening != null) {
builder.add(new ScreeningResponse(screening, screening.getParticipants()));
}
}
return new ScreeningListResponse(builder.build());
}
}
Aggregations