Search in sources :

Example 11 with ClientRelationship

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

the class ClientRelationshipDaoTest method testFindRelationshipsByClientId.

@Test
public void testFindRelationshipsByClientId() throws Exception {
    cleanAllAndInsert("/dbunit/ClientsRelationships.xml");
    executeInTransaction(sessionFactory, (sessionFactory) -> {
        final LocalDate CURRENT_DATE = LocalDate.of(2018, 1, 18);
        List<ClientRelationship> rghtRels = dao.findRelationshipsBySecondaryClientId("AaiU7IW0Rt", CURRENT_DATE);
        assertEquals(3, rghtRels.size());
        Map<String, ClientRelationship> relMap = rghtRels.stream().collect(Collectors.toMap(clientRelationship -> clientRelationship.getPrimaryClient().getIdentifier(), clientRelationship -> clientRelationship));
        assertTrue(relMap.containsKey("AasRx3r0Ha"));
        assertTrue(relMap.containsKey("AazXkWY06s"));
        assertTrue(relMap.containsKey("AfGN4uS0CR"));
        // both dates are NULL
        ClientRelationship rel0 = relMap.get("AasRx3r0Ha");
        assertEquals("AaiU7IW0Rt", rel0.getSecondaryClient().getIdentifier());
        assertEquals("AasRx3r0Ha", rel0.getPrimaryClient().getIdentifier());
        assertFalse(rel0.getAbsentParentIndicator());
        assertEquals(YesNoUnknown.YES, rel0.getSameHomeStatus());
        ClientRelationshipType relType0 = rel0.getType();
        assertEquals((short) 276, relType0.getPrimaryKey());
        assertEquals("Sister/Brother", relType0.getShortDescription());
        // both dates are not null
        ClientRelationship rel1 = relMap.get("AazXkWY06s");
        assertEquals("AaiU7IW0Rt", rel1.getSecondaryClient().getIdentifier());
        assertEquals("AazXkWY06s", rel1.getPrimaryClient().getIdentifier());
        assertTrue(rel1.getAbsentParentIndicator());
        assertEquals(YesNoUnknown.NO, rel1.getSameHomeStatus());
        ClientRelationshipType relType1 = rel1.getType();
        assertEquals((short) 190, relType1.getPrimaryKey());
        assertEquals("Daughter/Father (Birth)", relType1.getShortDescription());
        // start date is null, end date greater than current date
        ClientRelationship rel2 = relMap.get("AfGN4uS0CR");
        assertEquals("AaiU7IW0Rt", rel2.getSecondaryClient().getIdentifier());
        assertEquals("AfGN4uS0CR", rel2.getPrimaryClient().getIdentifier());
        assertFalse(rel2.getAbsentParentIndicator());
        assertEquals(YesNoUnknown.NO, rel2.getSameHomeStatus());
        ClientRelationshipType relType2 = rel2.getType();
        assertEquals((short) 301, relType2.getPrimaryKey());
        assertEquals("Ward/Guardian", relType2.getShortDescription());
        // the same relation is taken from the right side
        List<ClientRelationship> leftRels = dao.findRelationshipsByPrimaryClientId("AasRx3r0Ha", CURRENT_DATE);
        assertEquals(1, leftRels.size());
        ClientRelationship relR0 = leftRels.get(0);
        assertEquals(rel0, relR0);
        // no relations when take them from left side by right side id
        List<ClientRelationship> rightRels2 = dao.findRelationshipsBySecondaryClientId("AasRx3r0Ha", CURRENT_DATE);
        assertEquals(0, rightRels2.size());
        // relation is not taken into account if its type is inactive
        List<ClientRelationship> rightRels3 = dao.findRelationshipsBySecondaryClientId("AapJGAU04Z", CURRENT_DATE);
        assertEquals(0, rightRels3.size());
    });
}
Also used : YesNoUnknown(gov.ca.cwds.data.legacy.cms.entity.enums.YesNoUnknown) ClientRelationshipType(gov.ca.cwds.data.legacy.cms.entity.syscodes.ClientRelationshipType) Test(org.junit.Test) Collectors(java.util.stream.Collectors) BaseCwsCmsInMemoryPersistenceTest(gov.ca.cwds.data.legacy.cms.persistence.BaseCwsCmsInMemoryPersistenceTest) ClientRelationship(gov.ca.cwds.data.legacy.cms.entity.ClientRelationship) List(java.util.List) TestCase.assertTrue(junit.framework.TestCase.assertTrue) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) Map(java.util.Map) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) ClientRelationship(gov.ca.cwds.data.legacy.cms.entity.ClientRelationship) LocalDate(java.time.LocalDate) ClientRelationshipType(gov.ca.cwds.data.legacy.cms.entity.syscodes.ClientRelationshipType) Test(org.junit.Test) BaseCwsCmsInMemoryPersistenceTest(gov.ca.cwds.data.legacy.cms.persistence.BaseCwsCmsInMemoryPersistenceTest)

Example 12 with ClientRelationship

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

the class R00755Test method testStartDateNull.

@Test
public void testStartDateNull() throws Exception {
    LocalDate date = LocalDate.of(2003, 03, 01);
    ClientRelationship entity = getClientRelationship(null, date);
    awareDTO.setEntity(entity);
    checkRuleSatisfied(RULE_NAME);
}
Also used : ClientRelationship(gov.ca.cwds.data.legacy.cms.entity.ClientRelationship) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 13 with ClientRelationship

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

the class R00755Test method startDateAndDateNull.

@Test
public void startDateAndDateNull() throws Exception {
    LocalDate date = LocalDate.of(2003, 03, 01);
    ClientRelationship entity = getClientRelationship(null, null);
    awareDTO.setEntity(entity);
    checkRuleSatisfied(RULE_NAME);
}
Also used : ClientRelationship(gov.ca.cwds.data.legacy.cms.entity.ClientRelationship) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 14 with ClientRelationship

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

the class R00755Test method testStartDateEndDate.

@Test
public void testStartDateEndDate() throws Exception {
    LocalDate date = LocalDate.of(2003, 03, 01);
    ClientRelationship entity = getClientRelationship(date, date);
    awareDTO.setEntity(entity);
    checkRuleSatisfied(RULE_NAME);
}
Also used : ClientRelationship(gov.ca.cwds.data.legacy.cms.entity.ClientRelationship) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 15 with ClientRelationship

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

the class R00753Test method overlap2.

/**
 * @throws DroolsException
 *
 *      x-------------x
 *    x------------x
 */
@Test
public void overlap2() throws DroolsException {
    LocalDate localDateStartA = LocalDate.of(2001, 11, 11);
    LocalDate localDateEndA = LocalDate.of(2020, 11, 11);
    ClientRelationship entity = getRelationship(localDateStartA, localDateEndA);
    awareDTO.setEntity(entity);
    List<ClientRelationship> relationships = new ArrayList<>();
    ClientRelationship overlapRelationship1 = getRelationship(localDateStartA.minusYears(1), localDateEndA.minusYears(1));
    relationships.add(overlapRelationship1);
    relationships.add(getRelationship(localDateStartA.minusYears(3), localDateStartA.minusYears(2)));
    relationships.add(getRelationship(localDateEndA.plusYears(3), localDateEndA.plusYears(4)));
    awareDTO.getClientRelationshipList().addAll(relationships);
    checkRuleViolatedOnce(RULE_NAME);
}
Also used : ArrayList(java.util.ArrayList) ClientRelationship(gov.ca.cwds.data.legacy.cms.entity.ClientRelationship) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Aggregations

ClientRelationship (gov.ca.cwds.data.legacy.cms.entity.ClientRelationship)19 Test (org.junit.Test)15 LocalDate (java.time.LocalDate)13 ArrayList (java.util.ArrayList)8 Client (gov.ca.cwds.data.legacy.cms.entity.Client)1 YesNoUnknown (gov.ca.cwds.data.legacy.cms.entity.enums.YesNoUnknown)1 ClientRelationshipType (gov.ca.cwds.data.legacy.cms.entity.syscodes.ClientRelationshipType)1 BaseCwsCmsInMemoryPersistenceTest (gov.ca.cwds.data.legacy.cms.persistence.BaseCwsCmsInMemoryPersistenceTest)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 TestCase.assertTrue (junit.framework.TestCase.assertTrue)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Before (org.junit.Before)1