Search in sources :

Example 1 with PostedReferral

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

the class ReferralServiceTest method testCreateEmptyIDError.

@Override
@Test
public void testCreateEmptyIDError() throws Exception {
    try {
        Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Referral/valid/valid.json"), Referral.class);
        gov.ca.cwds.data.persistence.cms.Referral toCreate = new gov.ca.cwds.data.persistence.cms.Referral("", referralDomain, "0XA");
        Referral request = new Referral(toCreate);
        when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(toCreate);
        @SuppressWarnings("unused") PostedReferral returned = referralService.create(request);
    } catch (ServiceException e) {
        assertEquals("Referral ID cannot be empty", e.getMessage());
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) Test(org.junit.Test)

Example 2 with PostedReferral

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

the class ReferralServiceTest method createReturnsGeneratedId.

/*
   * Test for checking the new Referral Id generated and lenght is 10
   */
@SuppressWarnings("javadoc")
@Test
public void createReturnsGeneratedId() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Referral/valid/valid.json"), Referral.class);
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenAnswer(new Answer<gov.ca.cwds.data.persistence.cms.Referral>() {

        @Override
        public gov.ca.cwds.data.persistence.cms.Referral answer(InvocationOnMock invocation) throws Throwable {
            gov.ca.cwds.data.persistence.cms.Referral report = (gov.ca.cwds.data.persistence.cms.Referral) invocation.getArguments()[0];
            return report;
        }
    });
    PostedReferral returned = referralService.create(referralDomain);
    assertEquals(returned.getId().length(), 10);
    PostedReferral newReturned = referralService.create(referralDomain);
    Assert.assertNotEquals(returned.getId(), newReturned.getId());
}
Also used : Referral(gov.ca.cwds.rest.api.domain.cms.Referral) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) Test(org.junit.Test)

Example 3 with PostedReferral

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

the class ReferralServiceTest method testCreateReturnsCorrectReferralId.

@SuppressWarnings("javadoc")
@Test
public void testCreateReturnsCorrectReferralId() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Referral/valid/valid.json"), Referral.class);
    gov.ca.cwds.data.persistence.cms.Referral toCreate = new gov.ca.cwds.data.persistence.cms.Referral("1234567ABC", referralDomain, "0XA");
    Referral request = new Referral(toCreate);
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(toCreate);
    PostedReferral returned = referralService.create(request);
    assertThat(returned.getId(), is("1234567ABC"));
}
Also used : Referral(gov.ca.cwds.rest.api.domain.cms.Referral) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) Test(org.junit.Test)

Example 4 with PostedReferral

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

the class CmsReferralServiceTest method createReturnsCorrectPostedCmsReferral.

@Test
public void createReturnsCorrectPostedCmsReferral() 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<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("1234567ABC", (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");
    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");
    Referral referralRequest = new Referral(referralToCreate);
    ReferralClient referralClientRequest = new ReferralClient(referralClientToCreate);
    Set<ReferralClient> referralClientRequestSet = new LinkedHashSet<>();
    referralClientRequestSet.add(referralClientRequest);
    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);
    Client clientRequest = new Client(clientToCreate, false);
    Set<Client> clientRequestSet = new LinkedHashSet<>();
    clientRequestSet.add(clientRequest);
    PostedReferral postedReferral = new PostedReferral(referralToCreate);
    ReferralClient postedReferralClient = new ReferralClient(referralClientToCreate);
    Set<ReferralClient> postedReferralClientSet = new LinkedHashSet<>();
    postedReferralClientSet.add(postedReferralClient);
    PostedAllegation postedAllegation = new PostedAllegation(allegationToCreate);
    Set<PostedAllegation> postedAllegationSet = new LinkedHashSet<>();
    postedAllegationSet.add(postedAllegation);
    CrossReport postedCrossReport = new CrossReport(crossReportToCreate);
    Set<CrossReport> postedCrossReportSet = new LinkedHashSet<>();
    postedCrossReportSet.add(postedCrossReport);
    PostedReporter postedReporter = new PostedReporter(reporterToCreate);
    PostedClient postedClient = new PostedClient(clientToCreate, false);
    Set<PostedClient> postedClientSet = new LinkedHashSet<>();
    postedClientSet.add(postedClient);
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(referralToCreate);
    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);
    when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(clientToCreate);
    CmsReferral cmsReferralToCreate = new CmsReferral(referralRequest, clientRequestSet, allegationRequestSet, crossReportRequestSet, referralClientRequestSet, reporterRequest);
    CmsReferralService cmsReferralRequest = new CmsReferralService(referralService, clientService, allegationService, crossReportService, referralClientService, reporterService, clientUcService);
    PostedCmsReferral expected = new PostedCmsReferral(postedReferral, postedClientSet, postedAllegationSet, postedCrossReportSet, postedReferralClientSet, postedReporter);
    PostedCmsReferral returned = (PostedCmsReferral) cmsReferralRequest.create(cmsReferralToCreate);
    assertThat(returned, is(expected));
}
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) PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) 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) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation) 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 5 with PostedReferral

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

the class ReferralServiceTest method testCreateBlankIDError.

@Override
@Test
public void testCreateBlankIDError() throws Exception {
    try {
        Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Referral/valid/valid.json"), Referral.class);
        gov.ca.cwds.data.persistence.cms.Referral toCreate = new gov.ca.cwds.data.persistence.cms.Referral("   ", referralDomain, "0XA");
        when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(toCreate);
        @SuppressWarnings("unused") PostedReferral expected = new PostedReferral(toCreate);
    } catch (ServiceException e) {
        assertEquals("Referral ID cannot be empty", e.getMessage());
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) Test(org.junit.Test)

Aggregations

PostedReferral (gov.ca.cwds.rest.api.domain.cms.PostedReferral)10 Referral (gov.ca.cwds.rest.api.domain.cms.Referral)8 Test (org.junit.Test)7 ServiceException (gov.ca.cwds.rest.services.ServiceException)4 Allegation (gov.ca.cwds.rest.api.domain.cms.Allegation)2 Client (gov.ca.cwds.rest.api.domain.cms.Client)2 CmsReferral (gov.ca.cwds.rest.api.domain.cms.CmsReferral)2 CrossReport (gov.ca.cwds.rest.api.domain.cms.CrossReport)2 PostedAllegation (gov.ca.cwds.rest.api.domain.cms.PostedAllegation)2 PostedClient (gov.ca.cwds.rest.api.domain.cms.PostedClient)2 PostedCmsReferral (gov.ca.cwds.rest.api.domain.cms.PostedCmsReferral)2 PostedReporter (gov.ca.cwds.rest.api.domain.cms.PostedReporter)2 ReferralClient (gov.ca.cwds.rest.api.domain.cms.ReferralClient)2 Reporter (gov.ca.cwds.rest.api.domain.cms.Reporter)2 LinkedHashSet (java.util.LinkedHashSet)2 Referral (gov.ca.cwds.data.persistence.cms.Referral)1 StaffPerson (gov.ca.cwds.data.persistence.cms.StaffPerson)1 PostedScreeningToReferral (gov.ca.cwds.rest.api.domain.PostedScreeningToReferral)1 ScreeningToReferral (gov.ca.cwds.rest.api.domain.ScreeningToReferral)1 ClientUc (gov.ca.cwds.rest.api.domain.cms.ClientUc)1