Search in sources :

Example 1 with CountyOwnership

use of gov.ca.cwds.data.persistence.cms.CountyOwnership in project API by ca-cwds.

the class NonLACountyTriggersTest method testChecksReferralClientCreatedCountyOwnership.

/*
   * Test for checking the referral Client CountyOnwership created or updated through the PUT method
   */
@SuppressWarnings("javadoc")
@Test
public void testChecksReferralClientCreatedCountyOwnership() throws Exception {
    ReferralClient referralClientDomain = MAPPER.readValue(fixture("fixtures/legacy/business/rules/nonLaCountyTrigger/referralClientValid.json"), ReferralClient.class);
    gov.ca.cwds.data.persistence.cms.ReferralClient toCreate = new gov.ca.cwds.data.persistence.cms.ReferralClient(referralClientDomain, "ABC");
    ReferralClient request = new ReferralClient(toCreate);
    when(countyOwnershipDao.find(any(String.class))).thenReturn(null);
    when(countyOwnershipDao.create(any(CountyOwnership.class))).thenAnswer(new Answer<CountyOwnership>() {

        @Override
        public CountyOwnership answer(InvocationOnMock invocation) throws Throwable {
            CountyOwnership report = (CountyOwnership) invocation.getArguments()[0];
            countyOwnership = report;
            return report;
        }
    });
    nonLaCountyTriggers.createAndUpdateReferralClientCoutyOwnership(toCreate);
    Assert.assertNotNull(countyOwnership);
    assertThat(countyOwnership.getEntityCode(), is(equalTo("C")));
}
Also used : CountyOwnership(gov.ca.cwds.data.persistence.cms.CountyOwnership) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 2 with CountyOwnership

use of gov.ca.cwds.data.persistence.cms.CountyOwnership in project API by ca-cwds.

the class NonLACountyTriggers method createAndUpdateReferralClientCoutyOwnership.

/**
   * @param managed referralClient creates or updates the countyOwnership with the client foreign
   *        key
   */
public void createAndUpdateReferralClientCoutyOwnership(ReferralClient managed) {
    Boolean countyExists = true;
    CountyOwnership countyOwnership = countyOwnershipDao.find(managed.getClientId());
    if (countyOwnership == null) {
        countyExists = false;
        countyOwnership = new CountyOwnership();
        countyOwnership.setEntityId(managed.getClientId());
        countyOwnership.setEntityCode(CLIENT_ENTITY_CODE);
    }
    String methodName = SET_COUNTY + managed.getCountySpecificCode() + FLAG;
    Method method = null;
    try {
        method = countyOwnership.getClass().getMethod(methodName, String.class);
        method.invoke(countyOwnership, SET_FLAG);
    } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        LOGGER.info("CountyOwnership Unable to Trigger : {}", countyOwnership);
        LOGGER.error(e.getMessage(), e);
        throw new TriggerTableException();
    }
    if (countyExists) {
        countyOwnershipDao.update(countyOwnership);
    } else {
        countyOwnershipDao.create(countyOwnership);
    }
}
Also used : CountyOwnership(gov.ca.cwds.data.persistence.cms.CountyOwnership) Method(java.lang.reflect.Method) TriggerTableException(gov.ca.cwds.data.rules.TriggerTableException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with CountyOwnership

use of gov.ca.cwds.data.persistence.cms.CountyOwnership in project API by ca-cwds.

the class NonLACountyTriggers method createClientCountyTrigger.

/**
   * @param managed Client creates the countyOwnership with the client foreign key
   */
public void createClientCountyTrigger(Client managed) {
    CountyOwnership countyOwnership = new CountyOwnership();
    countyOwnership.setEntityId(managed.getPrimaryKey());
    countyOwnership.setEntityCode(CLIENT_ENTITY_CODE);
    countyOwnershipDao.create(countyOwnership);
}
Also used : CountyOwnership(gov.ca.cwds.data.persistence.cms.CountyOwnership)

Example 4 with CountyOwnership

use of gov.ca.cwds.data.persistence.cms.CountyOwnership in project API by ca-cwds.

the class CountyOwnershipDaoIT method testDelete.

@Override
@Test
public void testDelete() throws Exception {
    CountyOwnership deleted = countyOwnershipDao.delete(id);
    assertThat(deleted.getEntityId(), is(id));
}
Also used : CountyOwnership(gov.ca.cwds.data.persistence.cms.CountyOwnership) Test(org.junit.Test)

Example 5 with CountyOwnership

use of gov.ca.cwds.data.persistence.cms.CountyOwnership in project API by ca-cwds.

the class CountyOwnershipDaoIT method testUpdateEntityNotFoundException.

@Override
@Test
public void testUpdateEntityNotFoundException() throws Exception {
    thrown.expect(EntityNotFoundException.class);
    CountyOwnership countyOwnership = new CountyOwnership("AaQshqm0ML", "C", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", null);
    countyOwnershipDao.update(countyOwnership);
}
Also used : CountyOwnership(gov.ca.cwds.data.persistence.cms.CountyOwnership) Test(org.junit.Test)

Aggregations

CountyOwnership (gov.ca.cwds.data.persistence.cms.CountyOwnership)13 Test (org.junit.Test)10 ReferralClient (gov.ca.cwds.rest.api.domain.cms.ReferralClient)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Client (gov.ca.cwds.data.persistence.cms.Client)1 TriggerTableException (gov.ca.cwds.data.rules.TriggerTableException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1