List of usage examples for org.apache.commons.jxpath JXPathContext getValue
public abstract Object getValue(String xpath);
From source file:org.opennms.protocols.json.collector.JsonCollectorSolarisZonesIT.java
/** * Test to verify XPath content./* w w w . j a v a 2 s . c o m*/ * * @throws Exception the exception */ @Test @SuppressWarnings("unchecked") public void testXpath() throws Exception { JSONObject json = MockDocumentBuilder.getJSONDocument(); JXPathContext context = JXPathContext.newContext(json); Iterator<Pointer> itr = context.iteratePointers("/zones/zone"); while (itr.hasNext()) { Pointer resPtr = itr.next(); JXPathContext relativeContext = context.getRelativeContext(resPtr); String resourceName = (String) relativeContext.getValue("@name"); Assert.assertNotNull(resourceName); String value = (String) relativeContext.getValue("parameter[@key='nproc']/@value"); Assert.assertNotNull(Integer.valueOf(value)); } }
From source file:org.openvpms.archetype.function.history.HistoryFunctionsTestCase.java
/** * Tests the {@link HistoryFunctions#medication(Party)} method. *///from w w w . j a va 2 s . c o m @Test @SuppressWarnings("unchecked") public void testMedication() { Act medication1 = PatientTestHelper.createMedication(patient); Act medication2 = PatientTestHelper.createMedication(patient); medication1.setActivityStartTime(TestHelper.getDate("2013-09-19")); medication2.setActivityStartTime(TestHelper.getDate("2013-09-20")); save(medication1, medication2); JXPathContext ctx = createContext(patient); Iterable<Act> acts = (Iterable<Act>) ctx.getValue("history:medication(.)"); checkActs(acts, medication2, medication1); }
From source file:org.openvpms.archetype.function.history.HistoryFunctionsTestCase.java
/** * Tests the {@link HistoryFunctions#medication(Party, Date, Date)} method. *///w w w . jav a 2s . com @SuppressWarnings("unchecked") @Test public void testMedicationByDate() { Act medication1 = PatientTestHelper.createMedication(patient); Act medication2 = PatientTestHelper.createMedication(patient); medication1.setActivityStartTime(TestHelper.getDate("2013-09-19")); medication2.setActivityStartTime(TestHelper.getDate("2013-09-20")); save(medication1, medication2); JXPathContext ctx = createContext(patient); Iterable<Act> acts1 = (Iterable<Act>) ctx.getValue("history:medication(., null, null)"); checkActs(acts1, medication2, medication1); Iterable<Act> acts2 = (Iterable<Act>) ctx.getValue( "history:medication(., java.sql.Date.valueOf('2013-09-19'), java.sql.Date.valueOf('2013-09-20'))"); checkActs(acts2, medication2, medication1); Iterable<Act> acts3 = (Iterable<Act>) ctx.getValue( "history:medication(., java.sql.Date.valueOf('2013-09-19'), java.sql.Date.valueOf('2013-09-19'))"); checkActs(acts3, medication1); Iterable<Act> acts4 = (Iterable<Act>) ctx .getValue("history:medication(., null, java.sql.Date.valueOf('2013-09-19'))"); checkActs(acts4, medication1); Iterable<Act> acts5 = (Iterable<Act>) ctx .getValue("history:medication(., null, java.sql.Date.valueOf('2013-09-20'))"); checkActs(acts5, medication2, medication1); Iterable<Act> acts6 = (Iterable<Act>) ctx .getValue("history:medication(., java.sql.Date.valueOf('2013-09-19'), null)"); checkActs(acts6, medication2, medication1); }
From source file:org.openvpms.archetype.function.history.HistoryFunctionsTestCase.java
/** * Tests the {@link HistoryFunctions#medication(Party, String)} method. *//*from www . ja v a 2 s . co m*/ @Test @SuppressWarnings("unchecked") public void testMedicationByProductType() { Entity productType1 = createProductType("Vaccination"); Entity productType2 = createProductType("Euthanasia"); Product product1 = createProduct(productType1); Product product2 = createProduct(productType2); Act medication1 = PatientTestHelper.createMedication(patient, product1); Act medication2 = PatientTestHelper.createMedication(patient, product2); JXPathContext ctx = createContext(patient); Iterable<Act> acts1 = (Iterable<Act>) ctx.getValue("history:medication(., 'Vaccination')"); checkActs(acts1, medication1); Iterable<Act> acts2 = (Iterable<Act>) ctx.getValue("history:medication(., 'Euthanasia')"); checkActs(acts2, medication2); Iterable<Act> acts3 = (Iterable<Act>) ctx.getValue("history:medication(., 'Procedure')"); checkActs(acts3); }
From source file:org.openvpms.archetype.function.history.HistoryFunctionsTestCase.java
/** * Tests the {@link HistoryFunctions#medication(Party, String, Date, Date)} method. *//* w ww. j a v a 2 s .c om*/ @Test @SuppressWarnings("unchecked") public void testMedicationByProductTypeAndDate() { Entity productType1 = createProductType("Vaccination"); Entity productType2 = createProductType("Euthanasia"); Product product1 = createProduct(productType1); Product product2 = createProduct(productType2); Act medication1 = PatientTestHelper.createMedication(patient, product1); Act medication2 = PatientTestHelper.createMedication(patient, product2); medication1.setActivityStartTime(TestHelper.getDate("2013-09-19")); medication2.setActivityStartTime(TestHelper.getDate("2013-09-20")); save(medication1, medication2); JXPathContext ctx = createContext(patient); Iterable<Act> acts1 = (Iterable<Act>) ctx.getValue("history:medication(., 'Vaccination', null, null)"); checkActs(acts1, medication1); Iterable<Act> acts2 = (Iterable<Act>) ctx .getValue("history:medication(., 'Vaccination', java.sql.Date.valueOf('2013-09-19'), " + "java.sql.Date.valueOf('2013-09-20'))"); checkActs(acts2, medication1); Iterable<Act> acts3 = (Iterable<Act>) ctx .getValue("history:medication(., 'Vaccination', java.sql.Date.valueOf('2013-09-01'), " + "java.sql.Date.valueOf('2013-09-18'))"); checkActs(acts3); }
From source file:org.openvpms.archetype.function.history.HistoryFunctionsTestCase.java
/** * Tests the medication methods when a null patient is supplied. *//*from www .jav a 2s .c om*/ @Test @SuppressWarnings("unchecked") public void testMedicationWithNullPatient() { Act event = (Act) create(PatientArchetypes.CLINICAL_EVENT); JXPathContext ctx = createContext(event); Iterable<Act> acts1 = (Iterable<Act>) ctx.getValue("history:medication(openvpms:get(., 'patient.entity'))"); checkActs(acts1); Iterable<Act> acts2 = (Iterable<Act>) ctx .getValue("history:medication(openvpms:get(., 'patient.entity'), null, null)"); checkActs(acts2); Iterable<Act> acts3 = (Iterable<Act>) ctx .getValue("history:medication(openvpms:get(., 'patient.entity'), 'Vaccination')"); checkActs(acts3); Iterable<Act> acts4 = (Iterable<Act>) ctx .getValue("history:medication(openvpms:get(., 'patient.entity'), 'Vaccination', null, null)"); checkActs(acts4); }
From source file:org.openvpms.archetype.function.list.ListFunctionsTestCase.java
/** * Tests the {@link ListFunctions#sortNamesOf(ExpressionContext, String)} method *//*from w w w . j a v a 2 s . c o m*/ @Test public void testSortNamesOf() { Party vet = (Party) create(SupplierArchetypes.SUPPLIER_VET); vet.addClassification(createVetSpecialty("Surgery")); vet.addClassification(createVetSpecialty("Large Animals")); vet.addClassification(createVetSpecialty("Snakes")); JXPathContext ctx = createContext(vet); assertEquals("Large Animals, Snakes, Surgery", ctx.getValue("list:sortNamesOf('classifications')")); assertEquals("(Large Animals, Snakes, Surgery)", ctx.getValue("expr:concatIf('(', list:sortNamesOf('classifications'), ')')")); }
From source file:org.openvpms.archetype.function.party.PartyFunctionsTestCase.java
/** * Tests the {@link PartyFunctions#getTelephone(Party)} method. *//*w w w . j a va 2 s .c o m*/ @Test public void testGetTelephone() { Party party = TestHelper.createCustomer(false); party.getContacts().clear(); // remove all contacts JXPathContext ctx = createContext(party); assertEquals("", ctx.getValue("party:getTelephone(.)")); party.addContact(createPhone("12345", false, "HOME")); party.addContact(createPhone("45678", true, null)); // preferred assertEquals("(03) 45678", ctx.getValue("party:getTelephone(.)")); }
From source file:org.openvpms.archetype.function.party.PartyFunctionsTestCase.java
/** * Tests the {@link PartyFunctions#getTelephone(Act)} method. */// w w w. j a v a2s . co m @Test public void testActGetTelephone() { Act act = (Act) create("act.customerEstimation"); Party party = TestHelper.createCustomer(); party.getContacts().clear(); // remove all contacts save(party); JXPathContext ctx = createContext(act); assertEquals("", ctx.getValue("party:getTelephone(.)")); party.addContact(createPhone("12345", false, "HOME")); party.addContact(createPhone("45678", true, null)); // preferred save(party); ActBean bean = new ActBean(act); bean.addParticipation("participation.customer", party); assertEquals("(03) 45678", ctx.getValue("party:getTelephone(.)")); }
From source file:org.openvpms.archetype.function.party.PartyFunctionsTestCase.java
/** * Tests the {@link PartyFunctions#getHomeTelephone(Party)} method. *//* w w w. ja v a2 s. c om*/ @Test public void testGetHomeTelephone() { Party party = TestHelper.createCustomer(false); JXPathContext ctx = createContext(party); assertEquals("", ctx.getValue("party:getHomeTelephone(.)")); party.addContact(createPhone("12345", true, "HOME")); assertEquals("(03) 12345", ctx.getValue("party:getHomeTelephone(.)")); }