Search in sources :

Example 1 with BaseContextSensitiveTest

use of org.openmrs.test.BaseContextSensitiveTest in project openmrs-core by openmrs.

the class PersonServiceTest method getRelationships3_shouldFetchRelationshipsThatWereActiveDuringTheSpecifiedDateRange.

/**
 * @see PersonService#getRelationships(Person,Person,RelationshipType,Date,Date)
 */
@Test
public void getRelationships3_shouldFetchRelationshipsThatWereActiveDuringTheSpecifiedDateRange() throws Exception {
    executeDataSet(CREATE_PATIENT_XML);
    executeDataSet(CREATE_RELATIONSHIP_XML);
    // TODO use xml imported in BaseContextSensitiveTest#baseSetupWithStandardDataAndAuthentication()
    Patient patient = createTestPatient();
    List<Relationship> rels = createTestDatedRelationships(ps.getPatient(2), patient, personService.getRelationshipType(4));
    // Get relationships effective between 1987-01-01 and 1988-01-01
    List<Relationship> res = personService.getRelationships(ps.getPatient(2), patient, null, df.parse("1987-01-01"), df.parse("1988-01-01"));
    // Verify # of results and which results we have received
    assertEquals(5, res.size());
    for (Relationship rr : res) {
        if (!rr.equals(rels.get(0)) && !rr.equals(rels.get(2)) && !rr.equals(rels.get(3)) && !rr.equals(rels.get(7)) && !rr.equals(rels.get(8))) {
            if (rr.equals(rels.get(1))) {
                fail("unexpected relationship 1 in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
            } else if (rr.equals(rels.get(4))) {
                fail("unexpected relationship 4 in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
            } else if (rr.equals(rels.get(5))) {
                fail("unexpected relationship 5 in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
            } else if (rr.equals(rels.get(6))) {
                fail("unexpected relationship 6 in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
            } else {
                fail("unrecognized unexpected relationship in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
            }
        }
    }
}
Also used : Relationship(org.openmrs.Relationship) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 2 with BaseContextSensitiveTest

use of org.openmrs.test.BaseContextSensitiveTest in project openmrs-core by openmrs.

the class PersonServiceTest method getRelationshipsByPerson_shouldFetchRelationshipsThatWereActiveDuringEffectiveDate.

/**
 * Creates several relationships. Tests that a relationship is returned only when the effective
 * date is as follows: - for relationships with both a start date and an end date, the effective
 * date falls between the start and end dates; - for relationships with only a start date, the
 * effective date falls after the start date; - for relationships with only an end date, the
 * effective date falls before the end date; - relationship with neither a start nor end date
 * are always returned.
 *
 * @see PersonService#getRelationshipsByPerson(Person,Date)
 */
@Test
public void getRelationshipsByPerson_shouldFetchRelationshipsThatWereActiveDuringEffectiveDate() throws Exception {
    executeDataSet(CREATE_PATIENT_XML);
    executeDataSet(CREATE_RELATIONSHIP_XML);
    // TODO use xml imported in BaseContextSensitiveTest#baseSetupWithStandardDataAndAuthentication()
    Patient patient = createTestPatient();
    List<Relationship> rels = createTestDatedRelationships(ps.getPatient(2), patient, personService.getRelationshipType(4));
    // Get relationships effective 1988-01-01
    List<Relationship> res = personService.getRelationshipsByPerson(patient, df.parse("1988-01-01"));
    // Verify # of results and which results we have received
    assertEquals(5, res.size());
    for (Relationship rr : res) {
        if (!rr.equals(rels.get(0)) && !rr.equals(rels.get(2)) && !rr.equals(rels.get(3)) && !rr.equals(rels.get(7)) && !rr.equals(rels.get(8))) {
            if (rr.equals(rels.get(1))) {
                fail("unexpected relationship 1 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
            } else if (rr.equals(rels.get(4))) {
                fail("unexpected relationship 4 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
            } else if (rr.equals(rels.get(5))) {
                fail("unexpected relationship 5 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
            } else if (rr.equals(rels.get(6))) {
                fail("unexpected relationship 6 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
            } else {
                fail("unrecognized unexpected relationship in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
            }
        }
    }
}
Also used : Relationship(org.openmrs.Relationship) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with BaseContextSensitiveTest

use of org.openmrs.test.BaseContextSensitiveTest in project openmrs-core by openmrs.

the class PersonServiceTest method getRelationships2_shouldFetchRelationshipsThatWereActiveDuringEffectiveDate.

/**
 * @see PersonService#getRelationships(Person,Person,RelationshipType,Date)
 */
@Test
public void getRelationships2_shouldFetchRelationshipsThatWereActiveDuringEffectiveDate() throws Exception {
    executeDataSet(CREATE_PATIENT_XML);
    executeDataSet(CREATE_RELATIONSHIP_XML);
    // TODO use xml imported in BaseContextSensitiveTest#baseSetupWithStandardDataAndAuthentication()
    Patient patient = createTestPatient();
    List<Relationship> rels = createTestDatedRelationships(ps.getPatient(2), patient, personService.getRelationshipType(4));
    // Get relationships effective 1988-01-01
    List<Relationship> res = personService.getRelationships(ps.getPatient(2), patient, null, df.parse("1988-01-01"));
    // Verify # of results and which results we have received
    assertEquals(5, res.size());
    for (Relationship rr : res) {
        if (!rr.equals(rels.get(0)) && !rr.equals(rels.get(2)) && !rr.equals(rels.get(3)) && !rr.equals(rels.get(7)) && !rr.equals(rels.get(8))) {
            if (rr.equals(rels.get(1))) {
                fail("unexpected relationship 1 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
            } else if (rr.equals(rels.get(4))) {
                fail("unexpected relationship 4 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
            } else if (rr.equals(rels.get(5))) {
                fail("unexpected relationship 5 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
            } else if (rr.equals(rels.get(6))) {
                fail("unexpected relationship 6 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
            } else {
                fail("unrecognized unexpected relationship in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
            }
        }
    }
}
Also used : Relationship(org.openmrs.Relationship) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Test (org.junit.Test)3 Patient (org.openmrs.Patient)3 Relationship (org.openmrs.Relationship)3 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)3