Search in sources :

Example 1 with ChildClient

use of gov.ca.cwds.data.legacy.cms.entity.ChildClient in project api-core by ca-cwds.

the class R00743Test method testSecondaryLanguagesEmpty.

@Test
public void testSecondaryLanguagesEmpty() throws DroolsException {
    ChildClient client = new ChildClient();
    client.setPrimaryLanguageCode((short) 12);
    client.setSecondaryLanguageCode((short) 0);
    checkRuleSatisfied(client, RULE_NAME);
}
Also used : ChildClient(gov.ca.cwds.data.legacy.cms.entity.ChildClient) Test(org.junit.Test)

Example 2 with ChildClient

use of gov.ca.cwds.data.legacy.cms.entity.ChildClient in project api-core by ca-cwds.

the class R02761Test method createClient.

private static ChildClient createClient() {
    ChildClient client = new ChildClient();
    client.setBirthDate(DEFAULT_BIRTHDATE);
    client.setIdentifier(CLIENT_IDENTIFIER);
    return client;
}
Also used : ChildClient(gov.ca.cwds.data.legacy.cms.entity.ChildClient)

Example 3 with ChildClient

use of gov.ca.cwds.data.legacy.cms.entity.ChildClient in project api-core by ca-cwds.

the class R02761Test method initClient.

@Before
public void initClient() {
    ChildClient client = createClient();
    clientEntityAwareDTO.setEntity(client);
}
Also used : ChildClient(gov.ca.cwds.data.legacy.cms.entity.ChildClient) Before(org.junit.Before)

Example 4 with ChildClient

use of gov.ca.cwds.data.legacy.cms.entity.ChildClient in project api-core by ca-cwds.

the class OptimisticLockingTest method testClientLastUpdatedTimeUpdatesdAutomatically.

@Test
public void testClientLastUpdatedTimeUpdatesdAutomatically() throws Exception {
    cleanAllAndInsert("/dbunit/OptimisticLocking.xml");
    final ChildClientHolder childClientHolder = new ChildClientHolder();
    executeInTransaction(sessionFactory, (sessionFactory) -> {
        Client client = dao.find(ID);
        assertNotNull(client);
        assertTrue(client instanceof ChildClient);
        ChildClient childClient = (ChildClient) client;
        childClientHolder.setChildClient(childClient);
        Timestamp lastUpdateTime = childClient.getLastUpdateTime();
        assertNotNull(lastUpdateTime);
        assertEquals(new Short((short) 0), childClient.getAdoptedAge());
        // Change child client specific field and assure that Client timestamp changes
        childClient.setAdoptedAge((short) 10);
        dao.update(client);
        Session session = sessionFactory.getCurrentSession();
        session.flush();
        Timestamp newLastUpdateTime = childClient.getLastUpdateTime();
        assertNotNull(newLastUpdateTime);
        assertFalse(lastUpdateTime.equals(newLastUpdateTime));
        assertTrue((newLastUpdateTime.toLocalDateTime()).isAfter(lastUpdateTime.toLocalDateTime()));
        // Check if Client timestamp changes when otherEthnicities collection changes
        Set<ClientOtherEthnicity> otherEthnicities = childClient.getOtherEthnicities();
        assertEquals(1, otherEthnicities.size());
        ClientOtherEthnicity otherEthnicity = otherEthnicities.iterator().next();
        assertEquals(5922, otherEthnicity.getEthnicityCode());
        // Should increase Client timestamp but does not work
        session.lock(childClient, LockMode.OPTIMISTIC_FORCE_INCREMENT);
        ClientOtherEthnicity otherEthnicity2 = new ClientOtherEthnicity();
        otherEthnicity2.setEthnicityCode((short) 5923);
        otherEthnicity2.setId("BaoNM5i00J");
        otherEthnicity2.setLastUpdateTime(LocalDateTime.now());
        otherEthnicity2.setLastUpdateId("04Z");
        childClient.addOtherEthnicity(otherEthnicity2);
        dao.update(client);
    });
    executeInTransaction(sessionFactory, (sessionFactory) -> {
        ChildClient oldChildClient = childClientHolder.getChildClient();
        Timestamp oldLastUpdateTime = oldChildClient.getLastUpdateTime();
        Client client = dao.find(ID);
        assertNotNull(client);
        assertTrue(client instanceof ChildClient);
        ChildClient childClient = (ChildClient) client;
        Timestamp lastUpdateTime = childClient.getLastUpdateTime();
        assertNotNull(lastUpdateTime);
        // changes in otherEthnicities collection DOES NOT change Client timestamp
        assertTrue(oldLastUpdateTime.equals(lastUpdateTime));
    });
}
Also used : ClientOtherEthnicity(gov.ca.cwds.data.legacy.cms.entity.ClientOtherEthnicity) ChildClient(gov.ca.cwds.data.legacy.cms.entity.ChildClient) Client(gov.ca.cwds.data.legacy.cms.entity.Client) Timestamp(java.sql.Timestamp) ChildClient(gov.ca.cwds.data.legacy.cms.entity.ChildClient) Session(org.hibernate.Session) Test(org.junit.Test) BaseCwsCmsInMemoryPersistenceTest(gov.ca.cwds.data.legacy.cms.persistence.BaseCwsCmsInMemoryPersistenceTest)

Example 5 with ChildClient

use of gov.ca.cwds.data.legacy.cms.entity.ChildClient in project api-core by ca-cwds.

the class OptimisticLockingTest method testUpdateSuccess.

@Test
public void testUpdateSuccess() throws Exception {
    cleanAllAndInsert("/dbunit/OptimisticLocking.xml");
    final ChildClientHolder childClientHolder = new ChildClientHolder();
    // read entity from DB
    executeInTransaction(sessionFactory, (sessionFactory) -> {
        Client client = dao.find(ID);
        assertNotNull(client);
        assertTrue(client instanceof ChildClient);
        ChildClient childClient = (ChildClient) client;
        assertEquals(AdoptionStatus.NOT_FREE, childClient.getAdoptionStatus());
        Timestamp lastUpdateTime = childClient.getLastUpdateTime();
        assertNotNull(lastUpdateTime);
        childClientHolder.setChildClient(childClient);
    });
    // UI edit
    childClientHolder.getChildClient().setAdoptionStatus(AdoptionStatus.NOT_APPLICABLE);
    // persist in new transaction
    executeInTransaction(sessionFactory, (sessionFactory) -> {
        dao.update(childClientHolder.getChildClient());
    });
}
Also used : ChildClient(gov.ca.cwds.data.legacy.cms.entity.ChildClient) Client(gov.ca.cwds.data.legacy.cms.entity.Client) Timestamp(java.sql.Timestamp) ChildClient(gov.ca.cwds.data.legacy.cms.entity.ChildClient) Test(org.junit.Test) BaseCwsCmsInMemoryPersistenceTest(gov.ca.cwds.data.legacy.cms.persistence.BaseCwsCmsInMemoryPersistenceTest)

Aggregations

ChildClient (gov.ca.cwds.data.legacy.cms.entity.ChildClient)42 Test (org.junit.Test)32 BaseCwsCmsInMemoryPersistenceTest (gov.ca.cwds.data.legacy.cms.persistence.BaseCwsCmsInMemoryPersistenceTest)7 Client (gov.ca.cwds.data.legacy.cms.entity.Client)5 FCEligibility (gov.ca.cwds.data.legacy.cms.entity.FCEligibility)3 Timestamp (java.sql.Timestamp)3 OptimisticLockException (javax.persistence.OptimisticLockException)2 Session (org.hibernate.Session)2 Before (org.junit.Before)2 ClientOtherEthnicity (gov.ca.cwds.data.legacy.cms.entity.ClientOtherEthnicity)1 MedicalEligibilityApplication (gov.ca.cwds.data.legacy.cms.entity.MedicalEligibilityApplication)1