Search in sources :

Example 31 with Response

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

the class ChildClientServiceTest method deleteReturnsNullWhenNotFount.

@SuppressWarnings("javadoc")
@Test
public void deleteReturnsNullWhenNotFount() throws Exception {
    Response found = childClientService.delete("ABC1234567");
    assertThat(found, is(nullValue()));
}
Also used : Response(gov.ca.cwds.rest.api.Response) Test(org.junit.Test)

Example 32 with Response

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

the class AllegationServiceTest method testCreateReturnsPostedClass.

// create test
@Override
@Test
public void testCreateReturnsPostedClass() throws Exception {
    String id = "Aaeae9r0F4";
    Allegation allegationDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Allegation/valid/valid.json"), Allegation.class);
    gov.ca.cwds.data.persistence.cms.Allegation toCreate = new gov.ca.cwds.data.persistence.cms.Allegation(id, allegationDomain, "ABC");
    Allegation request = new Allegation(toCreate);
    when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(toCreate);
    Response response = allegationService.create(request);
    assertThat(response.getClass(), is(PostedAllegation.class));
}
Also used : Response(gov.ca.cwds.rest.api.Response) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation) Test(org.junit.Test)

Example 33 with Response

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

the class CmsNSHelper method handleResponse.

@SuppressWarnings("javadoc")
public Map<String, Map<CrudsService, Response>> handleResponse(Map<CrudsService, Request> cmsRequests, Map<CrudsService, Request> nsRequests) {
    Map<CrudsService, Response> cmsResponse = new HashMap<>();
    Map<CrudsService, Response> nsResponse = new HashMap<>();
    Map<String, Map<CrudsService, Response>> response = new HashMap<>();
    Response referral = null;
    Response person;
    org.hibernate.Session sessionCMS = cmsSessionFactory.openSession();
    org.hibernate.Session sessionNS = nsSessionFactory.openSession();
    try {
        // NOSONAR
        ManagedSessionContext.bind(sessionCMS);
        Transaction transactionCMS = sessionCMS.beginTransaction();
        for (CrudsService service : cmsRequests.keySet()) {
            try {
                referral = service.create(cmsRequests.get(service));
                cmsResponse.put(service, referral);
                sessionCMS.flush();
            } catch (Exception e) {
                transactionCMS.rollback();
                throw e;
            }
        }
        // NOSONAR
        ManagedSessionContext.bind(sessionNS);
        Transaction transactionNS = sessionNS.beginTransaction();
        for (CrudsService service : nsRequests.keySet()) {
            try {
                person = service.create(nsRequests.get(service));
                nsResponse.put(service, person);
                sessionNS.flush();
            } catch (Exception e) {
                transactionNS.rollback();
                transactionCMS.rollback();
                throw e;
            }
            try {
                transactionCMS.commit();
                transactionNS.commit();
            } catch (Exception e) {
                throw e;
            }
        }
    } finally {
        sessionCMS.close();
        sessionNS.close();
        // NOSONAR
        ManagedSessionContext.unbind(cmsSessionFactory);
        // NOSONAR
        ManagedSessionContext.unbind(nsSessionFactory);
    }
    response.put("cms", cmsResponse);
    response.put("ns", nsResponse);
    return response;
}
Also used : Response(gov.ca.cwds.rest.api.Response) Transaction(org.hibernate.Transaction) HashMap(java.util.HashMap) CrudsService(gov.ca.cwds.rest.services.CrudsService) Map(java.util.Map) HashMap(java.util.HashMap)

Example 34 with Response

use of gov.ca.cwds.rest.api.Response 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()));
}
Also used : Response(gov.ca.cwds.rest.api.Response) ScreeningResponse(gov.ca.cwds.rest.api.domain.ScreeningResponse) Test(org.junit.Test)

Example 35 with Response

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

the class CmsReferralServiceTest method createReturnsPostedCmsReferralWithIdenticalReferralIds.

@Test
public void createReturnsPostedCmsReferralWithIdenticalReferralIds() throws Exception {
    Response response = cmsReferralServiceResponse();
    PostedCmsReferral postedCmsReferral = (PostedCmsReferral) response;
    String referralId = ((CrossReport) postedCmsReferral.getCrossReport().toArray()[0]).getReferralId();
    assertThat(((ReferralClient) postedCmsReferral.getReferralClient().toArray()[0]).getReferralId(), is(referralId));
    assertThat(postedCmsReferral.getReporter().getReferralId(), is(referralId));
    assertThat(((Allegation) postedCmsReferral.getAllegation().toArray()[0]).getReferralId(), is(referralId));
}
Also used : Response(gov.ca.cwds.rest.api.Response) CrossReport(gov.ca.cwds.rest.api.domain.cms.CrossReport) PostedCmsReferral(gov.ca.cwds.rest.api.domain.cms.PostedCmsReferral) Test(org.junit.Test)

Aggregations

Response (gov.ca.cwds.rest.api.Response)83 Test (org.junit.Test)80 ReferralClient (gov.ca.cwds.rest.api.domain.cms.ReferralClient)46 CrossReport (gov.ca.cwds.rest.api.domain.cms.CrossReport)45 Allegation (gov.ca.cwds.rest.api.domain.cms.Allegation)44 Client (gov.ca.cwds.rest.api.domain.cms.Client)44 Referral (gov.ca.cwds.rest.api.domain.cms.Referral)44 PostedScreeningToReferral (gov.ca.cwds.rest.api.domain.PostedScreeningToReferral)43 ChildClient (gov.ca.cwds.rest.api.domain.cms.ChildClient)43 CmsReferral (gov.ca.cwds.rest.api.domain.cms.CmsReferral)43 LongText (gov.ca.cwds.rest.api.domain.cms.LongText)43 Reporter (gov.ca.cwds.rest.api.domain.cms.Reporter)43 LinkedHashSet (java.util.LinkedHashSet)43 Set (java.util.Set)43 ScreeningToReferral (gov.ca.cwds.rest.api.domain.ScreeningToReferral)42 Address (gov.ca.cwds.rest.api.domain.cms.Address)42 ClientAddress (gov.ca.cwds.rest.api.domain.cms.ClientAddress)42 ErrorMessage (gov.ca.cwds.rest.api.domain.error.ErrorMessage)22 ExpectedException (org.junit.rules.ExpectedException)16 PostedCmsReferral (gov.ca.cwds.rest.api.domain.cms.PostedCmsReferral)3