Search in sources :

Example 21 with ErrorMessage

use of gov.ca.cwds.rest.api.domain.error.ErrorMessage in project API by ca-cwds.

the class ScreeningToReferralServiceTest method testMoreThanOneSelfReportedFail.

@SuppressWarnings("javadoc")
@Test
public // R - 00836 Self rep Ind Limit
void testMoreThanOneSelfReportedFail() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferral.json"), Referral.class);
    gov.ca.cwds.data.persistence.cms.Referral referralToCreate = new gov.ca.cwds.data.persistence.cms.Referral("0123456ABC", referralDomain, "2016-10-31");
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(referralToCreate);
    ChildClient childClient = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/childClient.json"), ChildClient.class);
    gov.ca.cwds.data.persistence.cms.ChildClient childClientToCreate = new gov.ca.cwds.data.persistence.cms.ChildClient("1234567ABC", childClient, "0XA");
    when(childClientDao.create(any(gov.ca.cwds.data.persistence.cms.ChildClient.class))).thenReturn(childClientToCreate);
    Set<Client> clientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClient.json"), new TypeReference<Set<Client>>() {
    });
    gov.ca.cwds.data.persistence.cms.Client clientToCreate = new gov.ca.cwds.data.persistence.cms.Client("1234567ABC", (Client) clientDomain.toArray()[0], "2016-10-31");
    when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(clientToCreate);
    when(clientDao.find("1234567ABC")).thenReturn(clientToCreate);
    Set<ReferralClient> referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferralClient.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");
    when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(referralClientToCreate);
    Set<Allegation> allegationDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAllegation.json"), new TypeReference<Set<Allegation>>() {
    });
    gov.ca.cwds.data.persistence.cms.Allegation allegationToCreate = new gov.ca.cwds.data.persistence.cms.Allegation("2345678ABC", (Allegation) allegationDomain.toArray()[0], "2016-10-31");
    when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(allegationToCreate);
    Set<CrossReport> crossReportDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validCrossReport.json"), new TypeReference<Set<CrossReport>>() {
    });
    gov.ca.cwds.data.persistence.cms.CrossReport crossReportToCreate = new gov.ca.cwds.data.persistence.cms.CrossReport("3456789ABC", // ((CrossReport) crossReportDomain).getThirdId(),
    (CrossReport) crossReportDomain.toArray()[0], "OXA");
    when(crossReportDao.create(any(gov.ca.cwds.data.persistence.cms.CrossReport.class))).thenReturn(crossReportToCreate);
    Reporter reporterDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReporter.json"), Reporter.class);
    gov.ca.cwds.data.persistence.cms.Reporter reporterToCreate = new gov.ca.cwds.data.persistence.cms.Reporter(reporterDomain, "ABC");
    when(reporterDao.create(any(gov.ca.cwds.data.persistence.cms.Reporter.class))).thenReturn(reporterToCreate);
    Address addressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAddress.json"), Address.class);
    gov.ca.cwds.data.persistence.cms.Address addressToCreate = new gov.ca.cwds.data.persistence.cms.Address("3456789ABC", addressDomain, "ABC");
    when(addressDao.create(any(gov.ca.cwds.data.persistence.cms.Address.class))).thenReturn(addressToCreate);
    when(addressDao.find("3456789ABC")).thenReturn(addressToCreate);
    ClientAddress clientAddressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClientAddress.json"), ClientAddress.class);
    gov.ca.cwds.data.persistence.cms.ClientAddress clientAddressToCreate = new gov.ca.cwds.data.persistence.cms.ClientAddress("3456789ABC", clientAddressDomain, "ABC");
    when(clientAddressDao.create(any(gov.ca.cwds.data.persistence.cms.ClientAddress.class))).thenReturn(clientAddressToCreate);
    when(clientAddressDao.find("3456789ABC")).thenReturn(clientAddressToCreate);
    LongText longTextDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validLongText.json"), LongText.class);
    gov.ca.cwds.data.persistence.cms.LongText longTextToCreate = new gov.ca.cwds.data.persistence.cms.LongText("567890ABC", longTextDomain, "ABC");
    when(longTextDao.create(any(gov.ca.cwds.data.persistence.cms.LongText.class))).thenReturn(longTextToCreate);
    ScreeningToReferral screeningToReferral = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/invalid/moreThanOneSelfReported.json"), ScreeningToReferral.class);
    Boolean theErrorDetected = false;
    Response response = screeningToReferralService.create(screeningToReferral);
    if (response.hasMessages()) {
        Set<ErrorMessage> messages = response.getMessages();
        for (ErrorMessage message : messages) {
            if (message != null) {
                if (message.getMessage().contains("Incompatiable participants included in request")) {
                    theErrorDetected = true;
                }
            }
        }
        assertThat(theErrorDetected, is(equalTo(true)));
    } else {
        Assert.fail("Expected error messages were not thrown");
    }
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Address(gov.ca.cwds.rest.api.domain.cms.Address) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) Client(gov.ca.cwds.rest.api.domain.cms.Client) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) LongText(gov.ca.cwds.rest.api.domain.cms.LongText) Reporter(gov.ca.cwds.rest.api.domain.cms.Reporter) Response(gov.ca.cwds.rest.api.Response) CrossReport(gov.ca.cwds.rest.api.domain.cms.CrossReport) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) ErrorMessage(gov.ca.cwds.rest.api.domain.error.ErrorMessage) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 22 with ErrorMessage

use of gov.ca.cwds.rest.api.domain.error.ErrorMessage in project API by ca-cwds.

the class ScreeningToReferralServiceTest method testScreeningToReferralSuccess.

@SuppressWarnings("javadoc")
@Test
public void testScreeningToReferralSuccess() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferral.json"), Referral.class);
    gov.ca.cwds.data.persistence.cms.Referral referralToCreate = new gov.ca.cwds.data.persistence.cms.Referral("0123456ABC", referralDomain, "2016-10-31");
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(referralToCreate);
    ChildClient childClient = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/childClient.json"), ChildClient.class);
    gov.ca.cwds.data.persistence.cms.ChildClient childClientToCreate = new gov.ca.cwds.data.persistence.cms.ChildClient("1234567ABC", childClient, "0XA");
    when(childClientDao.create(any(gov.ca.cwds.data.persistence.cms.ChildClient.class))).thenReturn(childClientToCreate);
    Set<Client> clientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClient.json"), new TypeReference<Set<Client>>() {
    });
    gov.ca.cwds.data.persistence.cms.Client clientToCreate = new gov.ca.cwds.data.persistence.cms.Client("1234567ABC", (Client) clientDomain.toArray()[0], "2016-10-31");
    when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(clientToCreate);
    Set<ReferralClient> referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferralClient.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");
    when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(referralClientToCreate);
    Set<Allegation> allegationDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAllegation.json"), new TypeReference<Set<Allegation>>() {
    });
    gov.ca.cwds.data.persistence.cms.Allegation allegationToCreate = new gov.ca.cwds.data.persistence.cms.Allegation("2345678ABC", (Allegation) allegationDomain.toArray()[0], "2016-10-31");
    when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(allegationToCreate);
    Set<CrossReport> crossReportDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validCrossReport.json"), new TypeReference<Set<CrossReport>>() {
    });
    gov.ca.cwds.data.persistence.cms.CrossReport crossReportToCreate = new gov.ca.cwds.data.persistence.cms.CrossReport("3456789ABC", // ((CrossReport) crossReportDomain).getThirdId(),
    (CrossReport) crossReportDomain.toArray()[0], "OXA");
    when(crossReportDao.create(any(gov.ca.cwds.data.persistence.cms.CrossReport.class))).thenReturn(crossReportToCreate);
    Reporter reporterDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReporter.json"), Reporter.class);
    gov.ca.cwds.data.persistence.cms.Reporter reporterToCreate = new gov.ca.cwds.data.persistence.cms.Reporter(reporterDomain, "ABC");
    when(reporterDao.create(any(gov.ca.cwds.data.persistence.cms.Reporter.class))).thenReturn(reporterToCreate);
    Address addressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAddress.json"), Address.class);
    gov.ca.cwds.data.persistence.cms.Address addressToCreate = new gov.ca.cwds.data.persistence.cms.Address("345678ABC", addressDomain, "ABC");
    when(addressDao.create(any(gov.ca.cwds.data.persistence.cms.Address.class))).thenReturn(addressToCreate);
    ClientAddress clientAddressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClientAddress.json"), ClientAddress.class);
    gov.ca.cwds.data.persistence.cms.ClientAddress clientAddressToCreate = new gov.ca.cwds.data.persistence.cms.ClientAddress("456789ABC", clientAddressDomain, "ABC");
    when(clientAddressDao.create(any(gov.ca.cwds.data.persistence.cms.ClientAddress.class))).thenReturn(clientAddressToCreate);
    LongText longTextDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validLongText.json"), LongText.class);
    gov.ca.cwds.data.persistence.cms.LongText longTextToCreate = new gov.ca.cwds.data.persistence.cms.LongText("567890ABC", longTextDomain, "ABC");
    when(longTextDao.create(any(gov.ca.cwds.data.persistence.cms.LongText.class))).thenReturn(longTextToCreate);
    ScreeningToReferral screeningToReferral = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/valid.json"), ScreeningToReferral.class);
    Response response = screeningToReferralService.create(screeningToReferral);
    if (response.hasMessages()) {
        Set<ErrorMessage> messages = response.getMessages();
        for (ErrorMessage message : messages) {
            System.out.println(message.getMessage());
        }
    }
    assertThat(response.getClass(), is(PostedScreeningToReferral.class));
    assertThat(response.hasMessages(), is(equalTo(false)));
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Address(gov.ca.cwds.rest.api.domain.cms.Address) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) Client(gov.ca.cwds.rest.api.domain.cms.Client) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) LongText(gov.ca.cwds.rest.api.domain.cms.LongText) Reporter(gov.ca.cwds.rest.api.domain.cms.Reporter) Response(gov.ca.cwds.rest.api.Response) CrossReport(gov.ca.cwds.rest.api.domain.cms.CrossReport) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) ErrorMessage(gov.ca.cwds.rest.api.domain.error.ErrorMessage) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 23 with ErrorMessage

use of gov.ca.cwds.rest.api.domain.error.ErrorMessage in project API by ca-cwds.

the class ScreeningToReferralServiceTest method testWithInvalidDateTimeFormatFail.

@SuppressWarnings("javadoc")
@Test
public void testWithInvalidDateTimeFormatFail() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferral.json"), Referral.class);
    gov.ca.cwds.data.persistence.cms.Referral referralToCreate = new gov.ca.cwds.data.persistence.cms.Referral("0123456ABC", referralDomain, "2016-10-31");
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(referralToCreate);
    ChildClient childClient = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/childClient.json"), ChildClient.class);
    gov.ca.cwds.data.persistence.cms.ChildClient childClientToCreate = new gov.ca.cwds.data.persistence.cms.ChildClient("1234567ABC", childClient, "0XA");
    when(childClientDao.create(any(gov.ca.cwds.data.persistence.cms.ChildClient.class))).thenReturn(childClientToCreate);
    Set<Client> clientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClient.json"), new TypeReference<Set<Client>>() {
    });
    gov.ca.cwds.data.persistence.cms.Client clientToCreate = new gov.ca.cwds.data.persistence.cms.Client("1234567ABC", (Client) clientDomain.toArray()[0], "2016-10-31");
    when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(clientToCreate);
    when(clientDao.find("1234567ABC")).thenReturn(clientToCreate);
    Set<ReferralClient> referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferralClient.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");
    when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(referralClientToCreate);
    Set<Allegation> allegationDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAllegation.json"), new TypeReference<Set<Allegation>>() {
    });
    gov.ca.cwds.data.persistence.cms.Allegation allegationToCreate = new gov.ca.cwds.data.persistence.cms.Allegation("2345678ABC", (Allegation) allegationDomain.toArray()[0], "2016-10-31");
    when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(allegationToCreate);
    Set<CrossReport> crossReportDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validCrossReport.json"), new TypeReference<Set<CrossReport>>() {
    });
    gov.ca.cwds.data.persistence.cms.CrossReport crossReportToCreate = new gov.ca.cwds.data.persistence.cms.CrossReport("3456789ABC", // ((CrossReport) crossReportDomain).getThirdId(),
    (CrossReport) crossReportDomain.toArray()[0], "OXA");
    when(crossReportDao.create(any(gov.ca.cwds.data.persistence.cms.CrossReport.class))).thenReturn(crossReportToCreate);
    Reporter reporterDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReporter.json"), Reporter.class);
    gov.ca.cwds.data.persistence.cms.Reporter reporterToCreate = new gov.ca.cwds.data.persistence.cms.Reporter(reporterDomain, "ABC");
    when(reporterDao.create(any(gov.ca.cwds.data.persistence.cms.Reporter.class))).thenReturn(reporterToCreate);
    Address addressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAddress.json"), Address.class);
    gov.ca.cwds.data.persistence.cms.Address addressToCreate = new gov.ca.cwds.data.persistence.cms.Address("3456789ABC", addressDomain, "ABC");
    when(addressDao.create(any(gov.ca.cwds.data.persistence.cms.Address.class))).thenReturn(addressToCreate);
    when(addressDao.find("3456789ABC")).thenReturn(addressToCreate);
    ClientAddress clientAddressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClientAddress.json"), ClientAddress.class);
    gov.ca.cwds.data.persistence.cms.ClientAddress clientAddressToCreate = new gov.ca.cwds.data.persistence.cms.ClientAddress("3456789ABC", clientAddressDomain, "ABC");
    when(clientAddressDao.create(any(gov.ca.cwds.data.persistence.cms.ClientAddress.class))).thenReturn(clientAddressToCreate);
    when(clientAddressDao.find("3456789ABC")).thenReturn(clientAddressToCreate);
    LongText longTextDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validLongText.json"), LongText.class);
    gov.ca.cwds.data.persistence.cms.LongText longTextToCreate = new gov.ca.cwds.data.persistence.cms.LongText("567890ABC", longTextDomain, "ABC");
    when(longTextDao.create(any(gov.ca.cwds.data.persistence.cms.LongText.class))).thenReturn(longTextToCreate);
    ScreeningToReferral screeningToReferral = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/invalid/invalidDateTimeStamp.json"), ScreeningToReferral.class);
    Boolean theErrorDetected = false;
    Response response = screeningToReferralService.create(screeningToReferral);
    if (response.hasMessages()) {
        Set<ErrorMessage> messages = response.getMessages();
        for (ErrorMessage message : messages) {
            if (message.getMessage() != null) {
                if (message.getMessage().contains("parsing Start Date/Time")) {
                    theErrorDetected = true;
                }
            }
        }
        assertThat(theErrorDetected, is(equalTo(true)));
    } else {
        Assert.fail("Expected error messages were not thrown");
    }
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Address(gov.ca.cwds.rest.api.domain.cms.Address) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) Client(gov.ca.cwds.rest.api.domain.cms.Client) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) LongText(gov.ca.cwds.rest.api.domain.cms.LongText) Reporter(gov.ca.cwds.rest.api.domain.cms.Reporter) Response(gov.ca.cwds.rest.api.Response) CrossReport(gov.ca.cwds.rest.api.domain.cms.CrossReport) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) ErrorMessage(gov.ca.cwds.rest.api.domain.error.ErrorMessage) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 24 with ErrorMessage

use of gov.ca.cwds.rest.api.domain.error.ErrorMessage in project API by ca-cwds.

the class ScreeningToReferralServiceTest method testCrossReportDoesNotExsitFail.

@SuppressWarnings("javadoc")
@Test
public void testCrossReportDoesNotExsitFail() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferral.json"), Referral.class);
    gov.ca.cwds.data.persistence.cms.Referral referralToCreate = new gov.ca.cwds.data.persistence.cms.Referral("0123456ABC", referralDomain, "2016-10-31");
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(referralToCreate);
    ChildClient childClient = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/childClient.json"), ChildClient.class);
    gov.ca.cwds.data.persistence.cms.ChildClient childClientToCreate = new gov.ca.cwds.data.persistence.cms.ChildClient("1234567ABC", childClient, "0XA");
    when(childClientDao.create(any(gov.ca.cwds.data.persistence.cms.ChildClient.class))).thenReturn(childClientToCreate);
    Set<Client> clientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClient.json"), new TypeReference<Set<Client>>() {
    });
    gov.ca.cwds.data.persistence.cms.Client clientToCreate = new gov.ca.cwds.data.persistence.cms.Client("1234567ABC", (Client) clientDomain.toArray()[0], "2016-10-31");
    when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(clientToCreate);
    when(clientDao.find("1234567ABC")).thenReturn(clientToCreate);
    Set<ReferralClient> referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferralClient.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");
    when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(referralClientToCreate);
    Set<Allegation> allegationDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAllegation.json"), new TypeReference<Set<Allegation>>() {
    });
    gov.ca.cwds.data.persistence.cms.Allegation allegationToCreate = new gov.ca.cwds.data.persistence.cms.Allegation("2345678ABC", (Allegation) allegationDomain.toArray()[0], "2016-10-31");
    when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(allegationToCreate);
    when(allegationDao.find("2345678ABC")).thenReturn(allegationToCreate);
    Set<CrossReport> crossReportDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validCrossReport.json"), new TypeReference<Set<CrossReport>>() {
    });
    gov.ca.cwds.data.persistence.cms.CrossReport crossReportToCreate = new gov.ca.cwds.data.persistence.cms.CrossReport("3456789ABC", // ((CrossReport) crossReportDomain).getThirdId(),
    (CrossReport) crossReportDomain.toArray()[0], "OXA");
    when(crossReportDao.create(any(gov.ca.cwds.data.persistence.cms.CrossReport.class))).thenReturn(crossReportToCreate);
    Reporter reporterDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReporter.json"), Reporter.class);
    gov.ca.cwds.data.persistence.cms.Reporter reporterToCreate = new gov.ca.cwds.data.persistence.cms.Reporter(reporterDomain, "ABC");
    when(reporterDao.create(any(gov.ca.cwds.data.persistence.cms.Reporter.class))).thenReturn(reporterToCreate);
    Address addressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAddress.json"), Address.class);
    gov.ca.cwds.data.persistence.cms.Address addressToCreate = new gov.ca.cwds.data.persistence.cms.Address("4567890ABC", addressDomain, "ABC");
    when(addressDao.create(any(gov.ca.cwds.data.persistence.cms.Address.class))).thenReturn(addressToCreate);
    when(addressDao.find("4567890ABC")).thenReturn(addressToCreate);
    ClientAddress clientAddressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClientAddress.json"), ClientAddress.class);
    gov.ca.cwds.data.persistence.cms.ClientAddress clientAddressToCreate = new gov.ca.cwds.data.persistence.cms.ClientAddress("4567890ABC", clientAddressDomain, "ABC");
    when(clientAddressDao.create(any(gov.ca.cwds.data.persistence.cms.ClientAddress.class))).thenReturn(clientAddressToCreate);
    when(clientAddressDao.find("4567890ABC")).thenReturn(clientAddressToCreate);
    LongText longTextDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validLongText.json"), LongText.class);
    gov.ca.cwds.data.persistence.cms.LongText longTextToCreate = new gov.ca.cwds.data.persistence.cms.LongText("3456789ABC", longTextDomain, "ABC");
    when(longTextDao.create(any(gov.ca.cwds.data.persistence.cms.LongText.class))).thenReturn(longTextToCreate);
    ScreeningToReferral screeningToReferral = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/invalid/crossReportIdDoesNotExist.json"), ScreeningToReferral.class);
    Boolean theErrorDetected = false;
    Response response = screeningToReferralService.create(screeningToReferral);
    if (response.hasMessages()) {
        Set<ErrorMessage> messages = response.getMessages();
        for (ErrorMessage message : messages) {
            if (message.getMessage() != null) {
                if (message.getMessage().contains("Legacy Id on Cross Report does not correspond to an existing CMS/CWS Cross Report")) {
                    theErrorDetected = true;
                }
            }
        }
        assertThat(theErrorDetected, is(equalTo(true)));
    } else {
        Assert.fail("Expected error was not returned in messages");
    }
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Address(gov.ca.cwds.rest.api.domain.cms.Address) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) Client(gov.ca.cwds.rest.api.domain.cms.Client) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) LongText(gov.ca.cwds.rest.api.domain.cms.LongText) Reporter(gov.ca.cwds.rest.api.domain.cms.Reporter) Response(gov.ca.cwds.rest.api.Response) CrossReport(gov.ca.cwds.rest.api.domain.cms.CrossReport) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) ErrorMessage(gov.ca.cwds.rest.api.domain.error.ErrorMessage) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 25 with ErrorMessage

use of gov.ca.cwds.rest.api.domain.error.ErrorMessage in project API by ca-cwds.

the class ScreeningToReferralServiceTest method testWithReferralExistSuccess.

@SuppressWarnings("javadoc")
@Test
public void testWithReferralExistSuccess() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferral.json"), Referral.class);
    gov.ca.cwds.data.persistence.cms.Referral referralToCreate = new gov.ca.cwds.data.persistence.cms.Referral("0123456ABC", referralDomain, "2016-10-31");
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(referralToCreate);
    when(referralDao.find("0123456ABC")).thenReturn(referralToCreate);
    ChildClient childClient = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/childClient.json"), ChildClient.class);
    gov.ca.cwds.data.persistence.cms.ChildClient childClientToCreate = new gov.ca.cwds.data.persistence.cms.ChildClient("1234567ABC", childClient, "0XA");
    when(childClientDao.create(any(gov.ca.cwds.data.persistence.cms.ChildClient.class))).thenReturn(childClientToCreate);
    Set<Client> clientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClient.json"), new TypeReference<Set<Client>>() {
    });
    gov.ca.cwds.data.persistence.cms.Client clientToCreate = new gov.ca.cwds.data.persistence.cms.Client("1234567ABC", (Client) clientDomain.toArray()[0], "2016-10-31");
    when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(clientToCreate);
    Set<ReferralClient> referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReferralClient.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");
    when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(referralClientToCreate);
    Set<Allegation> allegationDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAllegation.json"), new TypeReference<Set<Allegation>>() {
    });
    gov.ca.cwds.data.persistence.cms.Allegation allegationToCreate = new gov.ca.cwds.data.persistence.cms.Allegation("2345678ABC", (Allegation) allegationDomain.toArray()[0], "2016-10-31");
    when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(allegationToCreate);
    Set<CrossReport> crossReportDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validCrossReport.json"), new TypeReference<Set<CrossReport>>() {
    });
    gov.ca.cwds.data.persistence.cms.CrossReport crossReportToCreate = new gov.ca.cwds.data.persistence.cms.CrossReport("3456789ABC", // ((CrossReport) crossReportDomain).getThirdId(),
    (CrossReport) crossReportDomain.toArray()[0], "OXA");
    when(crossReportDao.create(any(gov.ca.cwds.data.persistence.cms.CrossReport.class))).thenReturn(crossReportToCreate);
    Reporter reporterDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validReporter.json"), Reporter.class);
    gov.ca.cwds.data.persistence.cms.Reporter reporterToCreate = new gov.ca.cwds.data.persistence.cms.Reporter(reporterDomain, "ABC");
    when(reporterDao.create(any(gov.ca.cwds.data.persistence.cms.Reporter.class))).thenReturn(reporterToCreate);
    Address addressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validAddress.json"), Address.class);
    gov.ca.cwds.data.persistence.cms.Address addressToCreate = new gov.ca.cwds.data.persistence.cms.Address("345678ABC", addressDomain, "ABC");
    when(addressDao.create(any(gov.ca.cwds.data.persistence.cms.Address.class))).thenReturn(addressToCreate);
    ClientAddress clientAddressDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validClientAddress.json"), ClientAddress.class);
    gov.ca.cwds.data.persistence.cms.ClientAddress clientAddressToCreate = new gov.ca.cwds.data.persistence.cms.ClientAddress("456789ABC", clientAddressDomain, "ABC");
    when(clientAddressDao.create(any(gov.ca.cwds.data.persistence.cms.ClientAddress.class))).thenReturn(clientAddressToCreate);
    LongText longTextDomain = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/validLongText.json"), LongText.class);
    gov.ca.cwds.data.persistence.cms.LongText longTextToCreate = new gov.ca.cwds.data.persistence.cms.LongText("567890ABC", longTextDomain, "ABC");
    when(longTextDao.create(any(gov.ca.cwds.data.persistence.cms.LongText.class))).thenReturn(longTextToCreate);
    ScreeningToReferral screeningToReferral = MAPPER.readValue(fixture("fixtures/domain/ScreeningToReferral/valid/withReferralId.json"), ScreeningToReferral.class);
    Response response = screeningToReferralService.create(screeningToReferral);
    if (response.hasMessages()) {
        Set<ErrorMessage> messages = response.getMessages();
        for (ErrorMessage message : messages) {
            System.out.println(message.getMessage());
        }
    }
    assertThat(response.getClass(), is(PostedScreeningToReferral.class));
    assertThat(response.hasMessages(), is(equalTo(false)));
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Address(gov.ca.cwds.rest.api.domain.cms.Address) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) Client(gov.ca.cwds.rest.api.domain.cms.Client) ChildClient(gov.ca.cwds.rest.api.domain.cms.ChildClient) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) LongText(gov.ca.cwds.rest.api.domain.cms.LongText) Reporter(gov.ca.cwds.rest.api.domain.cms.Reporter) Response(gov.ca.cwds.rest.api.Response) CrossReport(gov.ca.cwds.rest.api.domain.cms.CrossReport) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) CmsReferral(gov.ca.cwds.rest.api.domain.cms.CmsReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ScreeningToReferral(gov.ca.cwds.rest.api.domain.ScreeningToReferral) ErrorMessage(gov.ca.cwds.rest.api.domain.error.ErrorMessage) PostedScreeningToReferral(gov.ca.cwds.rest.api.domain.PostedScreeningToReferral) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Aggregations

ErrorMessage (gov.ca.cwds.rest.api.domain.error.ErrorMessage)25 PostedScreeningToReferral (gov.ca.cwds.rest.api.domain.PostedScreeningToReferral)23 ScreeningToReferral (gov.ca.cwds.rest.api.domain.ScreeningToReferral)23 Response (gov.ca.cwds.rest.api.Response)22 Address (gov.ca.cwds.rest.api.domain.cms.Address)22 Allegation (gov.ca.cwds.rest.api.domain.cms.Allegation)22 ChildClient (gov.ca.cwds.rest.api.domain.cms.ChildClient)22 Client (gov.ca.cwds.rest.api.domain.cms.Client)22 ClientAddress (gov.ca.cwds.rest.api.domain.cms.ClientAddress)22 CmsReferral (gov.ca.cwds.rest.api.domain.cms.CmsReferral)22 CrossReport (gov.ca.cwds.rest.api.domain.cms.CrossReport)22 LongText (gov.ca.cwds.rest.api.domain.cms.LongText)22 Referral (gov.ca.cwds.rest.api.domain.cms.Referral)22 ReferralClient (gov.ca.cwds.rest.api.domain.cms.ReferralClient)22 LinkedHashSet (java.util.LinkedHashSet)22 Set (java.util.Set)22 Test (org.junit.Test)22 Reporter (gov.ca.cwds.rest.api.domain.cms.Reporter)21 Allegation (gov.ca.cwds.rest.api.domain.Allegation)1 CrossReport (gov.ca.cwds.rest.api.domain.CrossReport)1