Search in sources :

Example 1 with ClientOtherEthnicity

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

the class R00742Test method createListOfDifferentClientOtherEthnicities.

private static List<ClientOtherEthnicity> createListOfDifferentClientOtherEthnicities(Client client) {
    List<ClientOtherEthnicity> clientScpEthnicityList = new ArrayList<>();
    ClientOtherEthnicity clientScpEthnicity1 = createClientOtherEthnicity(client, (short) 3162);
    ClientOtherEthnicity clientScpEthnicity2 = createClientOtherEthnicity(client, (short) 3163);
    ClientOtherEthnicity clientScpEthnicity3 = createClientOtherEthnicity(client, (short) 0);
    clientScpEthnicityList.addAll(Arrays.asList(clientScpEthnicity1, clientScpEthnicity2, clientScpEthnicity3));
    return clientScpEthnicityList;
}
Also used : ClientOtherEthnicity(gov.ca.cwds.data.legacy.cms.entity.ClientOtherEthnicity) ArrayList(java.util.ArrayList)

Example 2 with ClientOtherEthnicity

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

the class R00742Test method testValidListofEthnicities.

@Test
public void testValidListofEthnicities() throws Exception {
    Client client = new Client();
    client.setIdentifier(CLIENT_IDENTIFIER);
    client.setPrimaryEthnicityCode((short) 1);
    clientEntityAwareDTO.setEntity(client);
    List<ClientOtherEthnicity> clientScpEthnicityList = createListOfDifferentClientOtherEthnicities(client);
    clientEntityAwareDTO.getOtherEthnicities().addAll(clientScpEthnicityList);
    checkRuleSatisfied(RULE_NAME);
}
Also used : ClientOtherEthnicity(gov.ca.cwds.data.legacy.cms.entity.ClientOtherEthnicity) Client(gov.ca.cwds.data.legacy.cms.entity.Client) Test(org.junit.Test)

Example 3 with ClientOtherEthnicity

use of gov.ca.cwds.data.legacy.cms.entity.ClientOtherEthnicity 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 4 with ClientOtherEthnicity

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

the class ClientOtherEthnicitiesTest method testFindEthnicitiesByClient.

@Test
public void testFindEthnicitiesByClient() throws Exception {
    cleanAllAndInsert("/dbunit/ClientOtherEthnicities.xml");
    executeInTransaction(sessionFactory, (sessionFactory) -> {
        Session session = sessionFactory.getCurrentSession();
        Client client1 = session.load(Client.class, "05gLqgG10R");
        Set<ClientOtherEthnicity> result1 = client1.getOtherEthnicities();
        assertNotNull(result1);
        assertTrue(result1.size() == 2);
        Client client2 = session.load(Client.class, "fG5y8Sdg3F");
        Set<ClientOtherEthnicity> result2 = client2.getOtherEthnicities();
        assertNotNull(result2);
        assertTrue(result2.size() == 0);
    });
}
Also used : ClientOtherEthnicity(gov.ca.cwds.data.legacy.cms.entity.ClientOtherEthnicity) Client(gov.ca.cwds.data.legacy.cms.entity.Client) Session(org.hibernate.Session) BaseCwsCmsInMemoryPersistenceTest(gov.ca.cwds.data.legacy.cms.persistence.BaseCwsCmsInMemoryPersistenceTest) Test(org.junit.Test)

Example 5 with ClientOtherEthnicity

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

the class R00742Test method testOtherEthnicityPresentWhenNoPrimary.

@Test
public void testOtherEthnicityPresentWhenNoPrimary() throws Exception {
    Client client = new Client();
    client.setIdentifier(CLIENT_IDENTIFIER);
    client.setPrimaryEthnicityCode((short) 0);
    clientEntityAwareDTO.setEntity(client);
    List<ClientOtherEthnicity> clientScpEthnicityList = createListOfDifferentClientOtherEthnicities(client);
    clientEntityAwareDTO.getOtherEthnicities().addAll(clientScpEthnicityList);
    checkRuleViolatedOnce(RULE_NAME);
}
Also used : ClientOtherEthnicity(gov.ca.cwds.data.legacy.cms.entity.ClientOtherEthnicity) Client(gov.ca.cwds.data.legacy.cms.entity.Client) Test(org.junit.Test)

Aggregations

ClientOtherEthnicity (gov.ca.cwds.data.legacy.cms.entity.ClientOtherEthnicity)6 Client (gov.ca.cwds.data.legacy.cms.entity.Client)4 Test (org.junit.Test)4 BaseCwsCmsInMemoryPersistenceTest (gov.ca.cwds.data.legacy.cms.persistence.BaseCwsCmsInMemoryPersistenceTest)2 Session (org.hibernate.Session)2 ChildClient (gov.ca.cwds.data.legacy.cms.entity.ChildClient)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1