Search in sources :

Example 31 with ReferralClient

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

the class CmsReferralServiceTest method createReturnsNonNull.

@Test
public void createReturnsNonNull() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/cms/CmsReferral/valid/referralCmsReferral.json"), Referral.class);
    gov.ca.cwds.data.persistence.cms.Referral referralToCreate = new gov.ca.cwds.data.persistence.cms.Referral("ABC1234567", referralDomain, "2016-10-31");
    Set<Client> clientDomain = MAPPER.readValue(fixture("fixtures/domain/cms/CmsReferral/valid/clientCmsReferral.json"), new TypeReference<Set<Client>>() {
    });
    gov.ca.cwds.data.persistence.cms.Client clientToCreate = new gov.ca.cwds.data.persistence.cms.Client("ABC1234567", (Client) clientDomain.toArray()[0], "2016-10-31");
    Set<ReferralClient> referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/cms/CmsReferral/valid/referralClientCmsReferral.json"), new TypeReference<Set<ReferralClient>>() {
    });
    gov.ca.cwds.data.persistence.cms.ReferralClient referralClientToCreate = new gov.ca.cwds.data.persistence.cms.ReferralClient((ReferralClient) referralClientDomain.toArray()[0], "2016-10-31");
    Set<Allegation> allegationDomain = MAPPER.readValue(fixture("fixtures/domain/cms/CmsReferral/valid/allegationCmsReferral.json"), new TypeReference<Set<Allegation>>() {
    });
    gov.ca.cwds.data.persistence.cms.Allegation allegationToCreate = new gov.ca.cwds.data.persistence.cms.Allegation("ABC1234567", (Allegation) allegationDomain.toArray()[0], "2016-10-31");
    Set<CrossReport> crossReportDomain = MAPPER.readValue(fixture("fixtures/domain/cms/CmsReferral/valid/crossReportCmsReferral.json"), new TypeReference<Set<CrossReport>>() {
    });
    gov.ca.cwds.data.persistence.cms.CrossReport crossReportToCreate = new gov.ca.cwds.data.persistence.cms.CrossReport("1234ABC123", (CrossReport) crossReportDomain.toArray()[0], "2016-10-31");
    Reporter reporterDomain = MAPPER.readValue(fixture("fixtures/domain/cms/CmsReferral/valid/reporterCmsReferral.json"), Reporter.class);
    gov.ca.cwds.data.persistence.cms.Reporter reporterToCreate = new gov.ca.cwds.data.persistence.cms.Reporter(reporterDomain, "2016-10-31");
    Referral referralRequest = new Referral(referralToCreate);
    ReferralClient referralClientRequest = new ReferralClient(referralClientToCreate);
    Set<ReferralClient> referralClientRequestSet = new LinkedHashSet<>();
    referralClientRequestSet.add(referralClientRequest);
    Client clientRequest = new Client(clientToCreate, false);
    Set<Client> clientRequestSet = new LinkedHashSet<>();
    clientRequestSet.add(clientRequest);
    Allegation allegationRequest = new Allegation(allegationToCreate);
    Set<Allegation> allegationRequestSet = new LinkedHashSet<>();
    allegationRequestSet.add(allegationRequest);
    CrossReport crossReportRequest = new CrossReport(crossReportToCreate);
    Set<CrossReport> crossReportRequestSet = new LinkedHashSet<>();
    crossReportRequestSet.add(crossReportRequest);
    Reporter reporterRequest = new Reporter(reporterToCreate);
    CmsReferral cmsReferralToCreate = new CmsReferral(referralRequest, clientRequestSet, allegationRequestSet, crossReportRequestSet, referralClientRequestSet, reporterRequest);
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(referralToCreate);
    when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(clientToCreate);
    when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(referralClientToCreate);
    when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(allegationToCreate);
    when(crossReportDao.create(any(gov.ca.cwds.data.persistence.cms.CrossReport.class))).thenReturn(crossReportToCreate);
    when(reporterDao.create(any(gov.ca.cwds.data.persistence.cms.Reporter.class))).thenReturn(reporterToCreate);
    CmsReferralService cmsReferralRequest = new CmsReferralService(referralService, clientService, allegationService, crossReportService, referralClientService, reporterService, clientUcService);
    PostedCmsReferral returned = (PostedCmsReferral) cmsReferralRequest.create(cmsReferralToCreate);
    assertThat(returned, is(notNullValue()));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PostedCmsReferral(gov.ca.cwds.rest.api.domain.cms.PostedCmsReferral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) PostedCmsReferral(gov.ca.cwds.rest.api.domain.cms.PostedCmsReferral) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) Client(gov.ca.cwds.rest.api.domain.cms.Client) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) PostedClient(gov.ca.cwds.rest.api.domain.cms.PostedClient) PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) Reporter(gov.ca.cwds.rest.api.domain.cms.Reporter) CrossReport(gov.ca.cwds.rest.api.domain.cms.CrossReport) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) PostedCmsReferral(gov.ca.cwds.rest.api.domain.cms.PostedCmsReferral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 32 with ReferralClient

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

the class ReferralClientServiceTest method findReturnsNullWhenNotFound.

@SuppressWarnings("javadoc")
@Test
public void findReturnsNullWhenNotFound() throws Exception {
    ReferralClient expected = MAPPER.readValue(fixture("fixtures/domain/legacy/ReferralClient/valid/valid.json"), ReferralClient.class);
    gov.ca.cwds.data.persistence.cms.ReferralClient referralClient = new gov.ca.cwds.data.persistence.cms.ReferralClient(expected, "ABC");
    Response found = referralClientService.find(referralClient.getPrimaryKey().toString());
    assertThat(found, is(nullValue()));
}
Also used : Response(gov.ca.cwds.rest.api.Response) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 33 with ReferralClient

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

the class ReferralClientServiceTest method findReturnsCorrectReferralClientWhenFound.

// find test
// TODO: Story #136701343: Tech debt: exception handling in service layer.
@SuppressWarnings("javadoc")
@Test
public void findReturnsCorrectReferralClientWhenFound() throws Exception {
    ReferralClient expected = MAPPER.readValue(fixture("fixtures/domain/legacy/ReferralClient/valid/valid.json"), ReferralClient.class);
    gov.ca.cwds.data.persistence.cms.ReferralClient referralClient = new gov.ca.cwds.data.persistence.cms.ReferralClient(expected, "ABC");
    when(referralClientDao.find(referralClient.getPrimaryKey())).thenReturn(referralClient);
    ReferralClient found = referralClientService.find(referralClient.getPrimaryKey().toString());
    assertThat(found, is(expected));
}
Also used : ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 34 with ReferralClient

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

the class ReferralClientServiceTest method deleteDelegatesToCrudsService.

@SuppressWarnings("javadoc")
@Test
public void deleteDelegatesToCrudsService() throws Exception {
    ReferralClient expected = MAPPER.readValue(fixture("fixtures/domain/legacy/ReferralClient/valid/valid.json"), ReferralClient.class);
    gov.ca.cwds.data.persistence.cms.ReferralClient referralClient = new gov.ca.cwds.data.persistence.cms.ReferralClient(expected, "ABC");
    referralClientService.delete(referralClient.getPrimaryKey().toString());
    verify(referralClientDao, times(1)).delete(referralClient.getPrimaryKey());
}
Also used : ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 35 with ReferralClient

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

the class ReferralClientServiceTest method createCountyTriggerForLACounty.

/*
   * Test for checking the staffperson county Code
   */
@SuppressWarnings("javadoc")
@Test
public void createCountyTriggerForLACounty() throws Exception {
    ReferralClient referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/ReferralClient/valid/valid.json"), ReferralClient.class);
    gov.ca.cwds.data.persistence.cms.ReferralClient toCreate = new gov.ca.cwds.data.persistence.cms.ReferralClient(referralClientDomain, "BTr");
    ReferralClient request = new ReferralClient(toCreate);
    when(triggerTablesDao.getLaCountySpecificCode()).thenReturn("19");
    StaffPerson staffPerson = new StaffPerson("BTr", null, "External Interface", "external interface", "SCXCIN7", " ", "", BigDecimal.valueOf(9165672100L), 0, null, "    ", "N", "MIZN02k00E", "  ", "    ", "19", "N", "3XPCP92q38", null);
    when(staffpersonDao.find(any(String.class))).thenReturn(staffPerson);
    when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(toCreate);
    when(laCountyTrigger.createCountyTrigger(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            isLaCountyTrigger = true;
            return true;
        }
    });
    referralClientService.create(request);
    assertThat(isLaCountyTrigger, is(true));
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Aggregations

ReferralClient (gov.ca.cwds.rest.api.domain.cms.ReferralClient)65 Test (org.junit.Test)61 Client (gov.ca.cwds.rest.api.domain.cms.Client)47 Response (gov.ca.cwds.rest.api.Response)46 Allegation (gov.ca.cwds.rest.api.domain.cms.Allegation)46 CmsReferral (gov.ca.cwds.rest.api.domain.cms.CmsReferral)46 CrossReport (gov.ca.cwds.rest.api.domain.cms.CrossReport)46 LinkedHashSet (java.util.LinkedHashSet)46 Referral (gov.ca.cwds.rest.api.domain.cms.Referral)45 Reporter (gov.ca.cwds.rest.api.domain.cms.Reporter)45 Set (java.util.Set)45 ChildClient (gov.ca.cwds.rest.api.domain.cms.ChildClient)43 PostedScreeningToReferral (gov.ca.cwds.rest.api.domain.PostedScreeningToReferral)42 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 LongText (gov.ca.cwds.rest.api.domain.cms.LongText)42 ErrorMessage (gov.ca.cwds.rest.api.domain.error.ErrorMessage)22 ExpectedException (org.junit.rules.ExpectedException)16 PostedClient (gov.ca.cwds.rest.api.domain.cms.PostedClient)5