Search in sources :

Example 31 with ApplicantDTO

use of gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO in project cals-api by ca-cwds.

the class RFA1aApplicantResourceTest method testDuplicatePhoneNumbersButExtension.

@Test
public void testDuplicatePhoneNumbersButExtension() throws Exception {
    RFA1aFormDTO form = formAHelper.createRFA1aForm();
    ApplicantDTO applicant = getApplicantDTO();
    applicant.getPhones().clear();
    applicant.getPhones().add(createPhone());
    applicant.getPhones().add(createPhoneNoExtension());
    assertNoSuchError(() -> applicantHelper.postApplicant(form.getId(), applicant), APPLICANT_PHONE_NUMBERS_DUPLICATION);
}
Also used : RFA1aFormDTO(gov.ca.cwds.cals.service.dto.rfa.RFA1aFormDTO) ApplicantDTO(gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO) Test(org.junit.Test)

Example 32 with ApplicantDTO

use of gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO in project cals-api by ca-cwds.

the class RFA1aApplicantResourceTest method moreThenOnePreferredNumberInApplicantValidationTest.

@Test
public void moreThenOnePreferredNumberInApplicantValidationTest() throws Exception {
    RFA1aFormDTO form = formAHelper.createRFA1aForm();
    ApplicantDTO applicant = getApplicantDTO();
    applicant.getPhones().forEach(p -> p.setPreferred(true));
    try {
        applicant = applicantHelper.postApplicant(form.getId(), applicant);
        fail();
    } catch (ClientErrorException e) {
        assertEquals(422, e.getResponse().getStatus());
        String entity = e.getResponse().readEntity(String.class);
        Map<String, Object> parameters = new HashMap<>();
        BaseExceptionResponse exceptionResponse = e.getResponse().readEntity(BaseExceptionResponse.class);
        Set<IssueDetails> issueDetails = exceptionResponse.getIssueDetails();
        IssueDetails detail = issueDetails.iterator().next();
        parameters.put("incident_id", detail.getIncidentId());
        assertResponseByFixtureTemplate(entity, "fixtures/rfa/validation/applicant-more-then-one-preferred-number-response.json", parameters);
    }
    // Update test
    applicant.getPhones().forEach(p -> p.setPreferred(false));
    applicant = applicantHelper.postApplicant(form.getId(), applicant);
    try {
        applicant.getPhones().forEach(p -> p.setPreferred(true));
        putApplicant(form, applicant);
        fail();
    } catch (ClientErrorException e) {
        assertEquals(422, e.getResponse().getStatus());
        String entity = e.getResponse().readEntity(String.class);
        Map<String, Object> parameters = new HashMap<>();
        BaseExceptionResponse exceptionResponse = e.getResponse().readEntity(BaseExceptionResponse.class);
        Set<IssueDetails> issueDetails = exceptionResponse.getIssueDetails();
        IssueDetails detail = issueDetails.iterator().next();
        parameters.put("incident_id", detail.getIncidentId());
        assertResponseByFixtureTemplate(entity, "fixtures/rfa/validation/applicant-more-then-one-preferred-number-response.json", parameters);
    }
}
Also used : BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) Set(java.util.Set) RFA1aFormDTO(gov.ca.cwds.cals.service.dto.rfa.RFA1aFormDTO) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) ClientErrorException(javax.ws.rs.ClientErrorException) ApplicantDTO(gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 33 with ApplicantDTO

use of gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO in project cals-api by ca-cwds.

the class RFA1bResourceTest method getExternalEntityApiHelper.

@Override
protected BaseExternalEntityApiHelper<RFA1bFormDTO> getExternalEntityApiHelper() {
    TestExternalEntityConfiguration<RFA1bFormDTO> configuration = new TestExternalEntityConfiguration<RFA1bFormDTO>(clientTestRule, RFA1bFormDTO.class, API.RFA_1B_FORMS) {

        @Override
        protected String getFixture() {
            return RFA1B_FORM_FIXTURE;
        }

        @Override
        public GenericType<CollectionDTO<RFA1bFormDTO>> getCollectionDTOGenericType() {
            return new GenericType<CollectionDTO<RFA1bFormDTO>>() {
            };
        }

        @Override
        public void modifyEntity(RFA1bFormDTO rfa1bFormDTO) {
            rfa1bFormDTO.setApplicantFirstName("Petya");
        }
    };
    return new BaseExternalEntityApiHelper<RFA1bFormDTO>(clientTestRule, configuration, formAHelper) {

        @Override
        public RFA1bFormDTO createEntity(RFA1aFormDTO form) throws Exception {
            ApplicantDTO applicantDTO = applicantHelper.getFirstExistedOrPostNewApplicant(form.getId(), applicantHelper.getValidApplicant());
            WebTarget target = clientTestRule.target(API.RFA_1A_FORMS + "/" + form.getId() + "/" + configuration.getApiPath() + "/" + API.RFA_1A_APPLICANTS + "/" + applicantDTO.getId());
            RFA1bFormDTO entity = configuration.createEntity();
            return target.request(MediaType.APPLICATION_JSON).post(Entity.entity(entity, MediaType.APPLICATION_JSON_TYPE), configuration.getEntityClass());
        }

        public void getEntitiesByFormId() throws Exception {
        }
    };
}
Also used : GenericType(javax.ws.rs.core.GenericType) RFA1bFormDTO(gov.ca.cwds.cals.service.dto.rfa.RFA1bFormDTO) RFA1aFormDTO(gov.ca.cwds.cals.service.dto.rfa.RFA1aFormDTO) CollectionDTO(gov.ca.cwds.cals.service.dto.rfa.collection.CollectionDTO) ApplicantDTO(gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO) WebTarget(javax.ws.rs.client.WebTarget) TestExternalEntityConfiguration(gov.ca.cwds.cals.web.rest.rfa.configuration.TestExternalEntityConfiguration)

Example 34 with ApplicantDTO

use of gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO in project cals-api by ca-cwds.

the class RFA1bResourceTest method getRFA1bFormApplicantTest.

@Test
public void getRFA1bFormApplicantTest() throws Exception {
    RFA1aFormDTO form1a = formAHelper.createRFA1aForm();
    RFA1bFormDTO created = getExternalEntityApiHelper().createEntity(form1a);
    ApplicantDTO applicantDTO = applicantHelper.getFirstExistedOrPostNewApplicant(form1a.getId(), applicantHelper.getValidApplicant());
    WebTarget target = clientTestRule.target(API.RFA_1A_FORMS + "/" + form1a.getId() + "/" + getExternalEntityApiHelper().getConfiguration().getApiPath() + "/" + API.RFA_1A_APPLICANTS + "/" + applicantDTO.getId());
    RFA1bFormDTO found = target.request().get(RFA1bFormDTO.class);
    assertThat(found).isEqualTo(created);
}
Also used : RFA1bFormDTO(gov.ca.cwds.cals.service.dto.rfa.RFA1bFormDTO) RFA1aFormDTO(gov.ca.cwds.cals.service.dto.rfa.RFA1aFormDTO) ApplicantDTO(gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 35 with ApplicantDTO

use of gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO in project cals-api by ca-cwds.

the class ApplicantHelper method getFirstApplicant.

public ApplicantDTO getFirstApplicant(long formId) {
    Response response = clientTestRule.target(API.RFA_1A_FORMS + "/" + formId + "/" + API.RFA_1A_APPLICANTS).request(MediaType.APPLICATION_JSON).get();
    ApplicantDTO applicantDTO = null;
    if (response.getStatus() == 200) {
        GenericType<CollectionDTO<ApplicantDTO>> genericType = new GenericType<CollectionDTO<ApplicantDTO>>() {
        };
        CollectionDTO<ApplicantDTO> applicants = response.readEntity(genericType);
        if (applicants != null && !applicants.getCollection().isEmpty()) {
            applicantDTO = applicants.getCollection().iterator().next();
        }
    }
    return applicantDTO;
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) ApplicantDTO(gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO) CollectionDTO(gov.ca.cwds.cals.service.dto.rfa.collection.CollectionDTO)

Aggregations

ApplicantDTO (gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO)41 RFA1aFormDTO (gov.ca.cwds.cals.service.dto.rfa.RFA1aFormDTO)28 Test (org.junit.Test)27 IssueDetails (gov.ca.cwds.rest.exception.IssueDetails)12 HashMap (java.util.HashMap)11 BaseExceptionResponse (gov.ca.cwds.rest.exception.BaseExceptionResponse)10 Map (java.util.Map)10 Set (java.util.Set)10 ClientErrorException (javax.ws.rs.ClientErrorException)10 Response (javax.ws.rs.core.Response)8 MinorChildDTO (gov.ca.cwds.cals.service.dto.rfa.MinorChildDTO)6 RFA1bFormDTO (gov.ca.cwds.cals.service.dto.rfa.RFA1bFormDTO)6 BigDecimal (java.math.BigDecimal)6 WebTarget (javax.ws.rs.client.WebTarget)6 StateType (gov.ca.cwds.cals.persistence.model.calsns.dictionaries.StateType)5 ResidenceDTO (gov.ca.cwds.cals.service.dto.rfa.ResidenceDTO)5 EmploymentDTO (gov.ca.cwds.cals.service.dto.rfa.EmploymentDTO)4 AddressType (gov.ca.cwds.cals.persistence.model.calsns.dictionaries.AddressType)3 IncomeType (gov.ca.cwds.cals.persistence.model.calsns.dictionaries.IncomeType)3 PhoneNumberType (gov.ca.cwds.cals.persistence.model.calsns.dictionaries.PhoneNumberType)3