Example usage for org.apache.commons.jxpath JXPathContext getValue

List of usage examples for org.apache.commons.jxpath JXPathContext getValue

Introduction

In this page you can find the example usage for org.apache.commons.jxpath JXPathContext getValue.

Prototype

public abstract Object getValue(String xpath);

Source Link

Document

Evaluates the xpath and returns the resulting object.

Usage

From source file:org.openvpms.archetype.function.party.PartyFunctionsTestCase.java

/**
 * Tests the {@link PartyFunctions#getHomeTelephone(Act)} method.
 *//*from  w  w w  . ja  va 2s. c o  m*/
@Test
public void testActGetHomeTelephone() {
    Act act = (Act) create("act.customerEstimation");
    Party party = TestHelper.createCustomer();

    JXPathContext ctx = createContext(act);
    assertEquals("", ctx.getValue("party:getHomeTelephone(.)"));

    party.addContact(createPhone("12345", true, "HOME"));
    save(party);

    ActBean bean = new ActBean(act);
    bean.addParticipation("participation.customer", party);

    assertEquals("(03) 12345", ctx.getValue("party:getHomeTelephone(.)"));
    assertEquals("", ctx.getValue("party:getWorkTelephone(.)"));
}

From source file:org.openvpms.archetype.function.party.PartyFunctionsTestCase.java

/**
 * Tests the {@link PartyFunctions#getWorkTelephone(Party)} method.
 *///from ww  w. ja v  a 2s .c o  m
@Test
public void testGetWorkTelephone() {
    Party party = TestHelper.createCustomer();
    party.getContacts().clear();

    JXPathContext ctx = createContext(party);
    assertEquals("", ctx.getValue("party:getWorkTelephone(.)"));

    party.addContact(createPhone("56789", true, "WORK"));
    assertEquals("(03) 56789", ctx.getValue("party:getWorkTelephone(.)"));
    assertEquals("(03) 56789", ctx.getValue("party:getHomeTelephone(.)")); // OVPMS-718
}

From source file:org.openvpms.archetype.function.party.PartyFunctionsTestCase.java

/**
 * Tests the {@link PartyFunctions#getWorkTelephone(Act)} method.
 *//*from w w  w. j av a 2  s  . c  o  m*/
@Test
public void testActGetWorkTelephone() {
    Act act = (Act) create("act.customerEstimation");
    Party party = TestHelper.createCustomer();
    party.getContacts().clear();

    JXPathContext ctx = createContext(act);
    assertEquals("", ctx.getValue("party:getWorkTelephone(.)"));

    party.addContact(createPhone("56789", true, "WORK"));
    save(party);

    ActBean bean = new ActBean(act);
    bean.addParticipation("participation.customer", party);

    assertEquals("(03) 56789", ctx.getValue("party:getWorkTelephone(.)"));
}

From source file:org.openvpms.archetype.function.party.PartyFunctionsTestCase.java

/**
 * Tests the {@link PartyFunctions#identities(ExpressionContext)} method.
 *///from  w w w.j a v  a2  s .  co  m
@Test
public void testIdentities() {
    Party party = TestHelper.createPatient(false);

    JXPathContext ctx = createContext(party);
    assertEquals("", ctx.getValue("party:identities()"));

    String tag = "1234567";
    party.addIdentity(createPetTag(tag));
    assertEquals("Pet Tag: " + tag, ctx.getValue("party:identities()"));
}

From source file:org.openvpms.archetype.function.party.PartyFunctionsTestCase.java

/**
 * Tests the {@link PartyFunctions#identities(Party)} method.
 *//* ww w  .  ja  va2s .  c  o  m*/
@Test
public void testIdentitiesForParty() {
    Act act = (Act) create("act.customerEstimationItem");
    Party party = TestHelper.createPatient();

    JXPathContext ctx = createContext(act);

    assertEquals("", ctx.getValue("party:identities(openvpms:get(., 'patient.entity'))"));
    String tag = "1234567";
    party.addIdentity(createPetTag(tag));
    save(party);

    ActBean bean = new ActBean(act);
    bean.addNodeParticipation("patient", party);

    assertEquals("Pet Tag: " + tag, ctx.getValue("party:identities(openvpms:get(., 'patient.entity'))"));
}

From source file:org.openvpms.archetype.function.party.PartyFunctionsTestCase.java

/**
 * Tests the {@link PartyFunctions#getPatientMicrochip(Party)} method.
 *//*from   ww  w. j a  v a2  s  . c  o  m*/
@Test
public void testGetPatientMicrochip() {
    Party patient = TestHelper.createPatient(false);
    JXPathContext ctx = createContext(patient);

    assertEquals("", ctx.getValue("party:getPatientMicrochip(.)"));

    EntityIdentity microchip = (EntityIdentity) create("entityIdentity.microchip");
    IMObjectBean tagBean = new IMObjectBean(microchip);
    tagBean.setValue("microchip", "1234567");
    patient.addIdentity(microchip);

    assertEquals("1234567", ctx.getValue("party:getPatientMicrochip(.)"));
}

From source file:org.openvpms.archetype.function.party.PartyFunctionsTestCase.java

/**
 * Tests the {@link PartyFunctions#getPatientMicrochips(Party)} method.
 *//*from   w w w.  java2s  . c  o  m*/
@Test
public void testGetPatientMicrochips() {
    Party patient = TestHelper.createPatient(false);
    JXPathContext ctx = createContext(patient);

    assertEquals("", ctx.getValue("party:getPatientMicrochips(.)"));

    EntityIdentity microchip1 = (EntityIdentity) create("entityIdentity.microchip");
    IMObjectBean tagBean = new IMObjectBean(microchip1);
    tagBean.setValue("microchip", "123");
    patient.addIdentity(microchip1);
    save(patient);

    assertEquals("123", ctx.getValue("party:getPatientMicrochips(.)"));

    EntityIdentity microchip2 = (EntityIdentity) create("entityIdentity.microchip");
    tagBean = new IMObjectBean(microchip2);
    tagBean.setValue("microchip", "456");
    patient.addIdentity(microchip2);
    save(patient);

    assertEquals("456, 123", ctx.getValue("party:getPatientMicrochips(.)"));
}

From source file:org.openvpms.archetype.function.party.PartyFunctionsTestCase.java

/**
 * Tests the {@link PartyFunctions#getWeight(Party)} and {@link PartyFunctions#getWeight(Party, String)} methods.
 *///from w w  w  . j  av a 2 s  . c o  m
@Test
public void testGetWeight() {
    Party patient = TestHelper.createPatient();
    JXPathContext ctx = createContext(patient);
    assertEquals(ZERO, ctx.getValue("party:getWeight(.)"));

    Act weight1 = PatientTestHelper.createWeight(patient, ONE, WeightUnits.KILOGRAMS);
    checkEquals(ONE, (BigDecimal) ctx.getValue("party:getWeight(.)"));
    checkEquals(ONE, (BigDecimal) ctx.getValue("party:getWeight(., 'KILOGRAMS')"));
    checkEquals(ONE_THOUSAND, (BigDecimal) ctx.getValue("party:getWeight(., 'GRAMS')"));
    assertEquals(new BigDecimal("2.20462262"), ctx.getValue("party:getWeight(., 'POUNDS')"));

    remove(weight1);
    Act weight2 = PatientTestHelper.createWeight(patient, ONE_THOUSAND, WeightUnits.GRAMS);
    checkEquals(ONE, (BigDecimal) ctx.getValue("party:getWeight(.)"));
    checkEquals(ONE, (BigDecimal) ctx.getValue("party:getWeight(., 'KILOGRAMS')"));
    checkEquals(ONE_THOUSAND, (BigDecimal) ctx.getValue("party:getWeight(., 'GRAMS')"));
    assertEquals(new BigDecimal("2.20462262"), ctx.getValue("party:getWeight(., 'POUNDS')"));

    remove(weight2);

    PatientTestHelper.createWeight(patient, ONE, WeightUnits.POUNDS);
    checkEquals(ONE_POUND_IN_KILOS, (BigDecimal) ctx.getValue("party:getWeight(.)"));
    checkEquals(ONE_POUND_IN_KILOS, (BigDecimal) ctx.getValue("party:getWeight(., 'KILOGRAMS')"));
    checkEquals(ONE_POUND_IN_GRAMS, (BigDecimal) ctx.getValue("party:getWeight(., 'GRAMS')"));
    assertEquals(ONE, ctx.getValue("party:getWeight(., 'POUNDS')"));
}

From source file:org.openvpms.archetype.function.party.PartyFunctionsTestCase.java

/**
 * Tests the {@link PartyFunctions#getWeight(Act)} and {@link PartyFunctions#getWeight(Act, String)} methods.
 *//*w ww  .  j a v  a  2  s  . c  o  m*/
@Test
public void testActGetWeight() {
    Party patient = TestHelper.createPatient();
    Act visit = (Act) create(PatientArchetypes.CLINICAL_EVENT);
    ActBean bean = new ActBean(visit);
    bean.addNodeParticipation("patient", patient);

    JXPathContext ctx = createContext(visit);
    assertEquals(ZERO, ctx.getValue("party:getWeight(.)"));

    Act weight1 = PatientTestHelper.createWeight(patient, ONE, WeightUnits.KILOGRAMS);
    checkEquals(ONE, (BigDecimal) ctx.getValue("party:getWeight(.)"));
    checkEquals(ONE, (BigDecimal) ctx.getValue("party:getWeight(., 'KILOGRAMS')"));
    checkEquals(ONE_THOUSAND, (BigDecimal) ctx.getValue("party:getWeight(., 'GRAMS')"));
    assertEquals(new BigDecimal("2.20462262"), ctx.getValue("party:getWeight(., 'POUNDS')"));

    remove(weight1);
    Act weight2 = PatientTestHelper.createWeight(patient, ONE_THOUSAND, WeightUnits.GRAMS);
    checkEquals(ONE, (BigDecimal) ctx.getValue("party:getWeight(.)"));
    checkEquals(ONE, (BigDecimal) ctx.getValue("party:getWeight(., 'KILOGRAMS')"));
    checkEquals(ONE_THOUSAND, (BigDecimal) ctx.getValue("party:getWeight(., 'GRAMS')"));
    assertEquals(new BigDecimal("2.20462262"), ctx.getValue("party:getWeight(., 'POUNDS')"));

    remove(weight2);

    PatientTestHelper.createWeight(patient, ONE, WeightUnits.POUNDS);
    checkEquals(ONE_POUND_IN_KILOS, (BigDecimal) ctx.getValue("party:getWeight(.)"));
    checkEquals(ONE_POUND_IN_KILOS, (BigDecimal) ctx.getValue("party:getWeight(., 'KILOGRAMS')"));
    checkEquals(ONE_POUND_IN_GRAMS, (BigDecimal) ctx.getValue("party:getWeight(., 'GRAMS')"));
    assertEquals(ONE, ctx.getValue("party:getWeight(., 'POUNDS')"));
}

From source file:org.openvpms.archetype.function.party.PartyFunctionsTestCase.java

/**
 * Tests the {@link PartyFunctions#getPatientMicrochip(Act)} and {@link PartyFunctions#getMicrochip(Act)}
 * methods./*from  w  ww .  ja  va 2  s  .  c  om*/
 */
@Test
public void testActGetPatientMicrochip() {
    Act act = (Act) create("act.customerEstimation");
    Party patient = TestHelper.createPatient(false);

    JXPathContext ctx = createContext(act);
    assertEquals("", ctx.getValue("party:getPatientMicrochip(.)"));
    assertNull(ctx.getValue("party:getMicrochip(.)"));

    EntityIdentity microchip = (EntityIdentity) create("entityIdentity.microchip");
    IMObjectBean tagBean = new IMObjectBean(microchip);
    tagBean.setValue("microchip", "1234567");
    patient.addIdentity(microchip);
    save(patient);

    ActBean bean = new ActBean(act);
    bean.addParticipation("participation.patient", patient);

    assertEquals("1234567", ctx.getValue("party:getPatientMicrochip(.)"));
    assertEquals(microchip, ctx.getValue("party:getMicrochip(.)"));
    assertEquals("1234567", ctx.getValue("openvpms:get(party:getMicrochip(.), 'microchip')"));
}