Search in sources :

Example 21 with ServiceException

use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.

the class ReferralClientServiceTest method updateThrowsExceptionWhenReferralClientNotFound.

@SuppressWarnings("javadoc")
@Test
public void updateThrowsExceptionWhenReferralClientNotFound() throws Exception {
    try {
        ReferralClient referralClientRequest = 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(referralClientRequest, "ABC");
        when(referralClientDao.find(referralClient.getPrimaryKey().toString())).thenReturn(referralClient);
        when(referralClientDao.update(any())).thenReturn(referralClient);
        referralClientService.update("referralId=ZZZZZZZABC,clientId=ABCZZZZZZZ", referralClientRequest);
    } catch (ServiceException e) {
        assertEquals(e.getClass(), ServiceException.class);
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 22 with ServiceException

use of gov.ca.cwds.rest.services.ServiceException 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 23 with ServiceException

use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.

the class ReporterServiceTest method updateThrowsExceptionWhenReporterNotFound.

@SuppressWarnings("javadoc")
@Test
public void updateThrowsExceptionWhenReporterNotFound() throws Exception {
    try {
        Reporter reporterRequest = MAPPER.readValue(fixture("fixtures/domain/legacy/Reporter/valid/valid.json"), Reporter.class);
        when(reporterDao.update(any())).thenThrow(EntityNotFoundException.class);
        reporterService.update("ZZZZZZZZZZ", reporterRequest);
        Assert.fail("Expected ServiceException was not thrown");
    } catch (Exception ex) {
        assertEquals(ex.getClass(), ServiceException.class);
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) Reporter(gov.ca.cwds.rest.api.domain.cms.Reporter) EntityNotFoundException(javax.persistence.EntityNotFoundException) ServiceException(gov.ca.cwds.rest.services.ServiceException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 24 with ServiceException

use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.

the class ReporterServiceTest method failsWhenPostedReporterServiceEmpty.

@Test
public void failsWhenPostedReporterServiceEmpty() throws Exception {
    try {
        Reporter reporterDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Reporter/invalid/referralIdEmpty.json"), Reporter.class);
        gov.ca.cwds.data.persistence.cms.Reporter toCreate = new gov.ca.cwds.data.persistence.cms.Reporter(reporterDomain, "last_update");
        when(reporterDao.create(any(gov.ca.cwds.data.persistence.cms.Reporter.class))).thenReturn(toCreate);
        PostedReporter expected = new PostedReporter(toCreate);
        Assert.fail("Expected ServiceException was not thrown");
    } catch (ServiceException e) {
        assertEquals("Referral ID cannot be empty for Reporter", e.getMessage());
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) Reporter(gov.ca.cwds.rest.api.domain.cms.Reporter) PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) Test(org.junit.Test)

Example 25 with ServiceException

use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.

the class LongTextServiceTest method testCreateBlankIDError.

@Override
@Test
public void testCreateBlankIDError() throws Exception {
    try {
        LongText longTextDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/LongText/valid/valid.json"), LongText.class);
        gov.ca.cwds.data.persistence.cms.LongText toCreate = new gov.ca.cwds.data.persistence.cms.LongText(" ", longTextDomain, "q27");
        when(longTextDao.create(any(gov.ca.cwds.data.persistence.cms.LongText.class))).thenReturn(toCreate);
        PostedLongText expected = new PostedLongText(toCreate);
    } catch (ServiceException e) {
        assertEquals("LongText ID cannot be blank", e.getMessage());
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedLongText(gov.ca.cwds.rest.api.domain.cms.PostedLongText) LongText(gov.ca.cwds.rest.api.domain.cms.LongText) PostedLongText(gov.ca.cwds.rest.api.domain.cms.PostedLongText) Test(org.junit.Test)

Aggregations

ServiceException (gov.ca.cwds.rest.services.ServiceException)59 Test (org.junit.Test)22 EntityNotFoundException (javax.persistence.EntityNotFoundException)16 EntityExistsException (javax.persistence.EntityExistsException)15 StaffPerson (gov.ca.cwds.data.persistence.cms.StaffPerson)7 PostedReferral (gov.ca.cwds.rest.api.domain.cms.PostedReferral)5 PostedReporter (gov.ca.cwds.rest.api.domain.cms.PostedReporter)5 PostedStaffPerson (gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson)5 StaffPerson (gov.ca.cwds.rest.api.domain.cms.StaffPerson)5 PostedAllegation (gov.ca.cwds.rest.api.domain.cms.PostedAllegation)4 PostedAllegationPerpetratorHistory (gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory)4 PostedClient (gov.ca.cwds.rest.api.domain.cms.PostedClient)4 PostedLongText (gov.ca.cwds.rest.api.domain.cms.PostedLongText)4 Referral (gov.ca.cwds.rest.api.domain.cms.Referral)3 Reporter (gov.ca.cwds.rest.api.domain.cms.Reporter)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Address (gov.ca.cwds.data.persistence.cms.Address)2 Allegation (gov.ca.cwds.data.persistence.cms.Allegation)2 AllegationPerpetratorHistory (gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory)2 ChildClient (gov.ca.cwds.data.persistence.cms.ChildClient)2