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.chiba.xml.xforms.ui.test.OutputTest.java

/**
 * Tests output with a model binding.//from w w w .ja  v a2s . c o  m
 *
 * @throws Exception if any error occurred during the test.
 */
public void testModelBinding() throws Exception {
    Output output = (Output) this.chibaBean.getContainer().lookup("output-2");
    JXPathContext context = this.chibaBean.getContainer().getRootContext();
    assertEquals("2", context.getValue("//xf:output[@id='output-2']/chiba:data"));
    assertEquals("/data[1]/item[2]", context.getValue("//xf:output[@id='output-2']/chiba:data/@chiba:xpath"));
    assertEquals("2", output.getValue());

    Model model = this.chibaBean.getContainer().getModel("model-1");
    model.getDefaultInstance().setNodeValue("/data/item[2]", "3");
    model.refresh();
    assertEquals("3", context.getValue("//xf:output[@id='output-2']/chiba:data"));
    assertEquals("3", output.getValue());
}

From source file:org.chiba.xml.xforms.ui.test.OutputTest.java

/**
 * Tests output with a value expression.
 *
 * @throws Exception if any error occurred during the test.
 *//*from  w  w w . j  av a2 s .  c o m*/
public void testValueExpression() throws Exception {
    Output output = (Output) this.chibaBean.getContainer().lookup("output-3");
    JXPathContext context = this.chibaBean.getContainer().getRootContext();
    assertEquals("3.0", context.getValue("//xf:output[@id='output-3']/chiba:data"));
    assertEquals("sum(item)", context.getValue("//xf:output[@id='output-3']/chiba:data/@chiba:xpath"));
    assertEquals("3.0", output.getValue());

    Model model = this.chibaBean.getContainer().getModel("model-1");
    model.getDefaultInstance().setNodeValue("/data/item[1]", "3");
    model.refresh();
    assertEquals("5.0", context.getValue("//xf:output[@id='output-3']/chiba:data"));
    assertEquals("5.0", output.getValue());
}

From source file:org.chiba.xml.xforms.ui.test.OutputTest.java

/**
 * Tests output with a value expression.
 *
 * @throws Exception if any error occurred during the test.
 *//* www .ja v a2  s . com*/
public void testValueExpressionContext() throws Exception {
    Output output = (Output) this.chibaBean.getContainer().lookup("output-4");
    JXPathContext context = this.chibaBean.getContainer().getRootContext();
    assertEquals("3.0", context.getValue("//xf:output[@id='output-4']/chiba:data"));
    assertEquals("sum(../item)", context.getValue("//xf:output[@id='output-4']/chiba:data/@chiba:xpath"));
    assertEquals("3.0", output.getValue());

    Model model = this.chibaBean.getContainer().getModel("model-1");
    model.getDefaultInstance().setNodeValue("/data/item[1]", "3");
    model.refresh();
    assertEquals("5.0", context.getValue("//xf:output[@id='output-4']/chiba:data"));
    assertEquals("5.0", output.getValue());
}

From source file:org.chiba.xml.xforms.ui.test.OutputTest.java

/**
 * Tests output with an ui binding and a value expression.
 *
 * @throws Exception if any error occurred during the test.
 *//*from   w w  w.j a v  a 2  s.c o m*/
public void testUIBindingPrecedence() throws Exception {
    Output output = (Output) this.chibaBean.getContainer().lookup("output-5");
    JXPathContext context = this.chibaBean.getContainer().getRootContext();
    assertEquals("1", context.getValue("//xf:output[@id='output-5']/chiba:data"));
    assertEquals("/data[1]/item[1]", context.getValue("//xf:output[@id='output-5']/chiba:data/@chiba:xpath"));
    assertEquals("1", output.getValue());
}

From source file:org.chiba.xml.xforms.ui.test.OutputTest.java

/**
 * Tests output with a model binding and a value expression.
 *
 * @throws Exception if any error occurred during the test.
 *//*from  ww w.  ja va2 s  .  co m*/
public void testModelBindingPrecedence() throws Exception {
    Output output = (Output) this.chibaBean.getContainer().lookup("output-6");
    JXPathContext context = this.chibaBean.getContainer().getRootContext();
    assertEquals("2", context.getValue("//xf:output[@id='output-6']/chiba:data"));
    assertEquals("/data[1]/item[2]", context.getValue("//xf:output[@id='output-6']/chiba:data/@chiba:xpath"));
    assertEquals("2", output.getValue());
}

From source file:org.chiba.xml.xforms.ui.test.OutputTest.java

/**
 * Tests output with neither a binding nor a value expression.
 *
 * @throws Exception if any error occurred during the test.
 *///from  w w w .j  a va  2s  .c  o m
public void testUnspecified() throws Exception {
    Output output = (Output) this.chibaBean.getContainer().lookup("output-7");
    JXPathContext context = this.chibaBean.getContainer().getRootContext();
    assertEquals(new Double(0), context.getValue("count(//xf:output[@id='output-7']/chiba:data)"));
    assertNull(output.getValue());
}

From source file:org.chiba.xml.xforms.ui.test.RangeTest.java

/**
 * Tests range bound to integer./*from  w  ww .j av  a2 s. c o  m*/
 *
 * @throws Exception if any error occurred during the test.
 */
public void testInteger() throws Exception {
    JXPathContext context = this.chibaBean.getContainer().getRootContext();

    assertEquals("-2", context.getValue("//xf:range[@id='range-1']/@xf:start"));
    assertEquals("2", context.getValue("//xf:range[@id='range-1']/@xf:end"));
    assertEquals("1", context.getValue("//xf:range[@id='range-1']/@xf:step"));
}

From source file:org.chiba.xml.xforms.ui.test.RangeTest.java

/**
 * Tests range bound to integer.//from ww  w  .  java 2 s  .  c  om
 *
 * @throws Exception if any error occurred during the test.
 */
public void testIntegerDefaults() throws Exception {
    JXPathContext context = this.chibaBean.getContainer().getRootContext();

    assertEquals("-2", context.getValue("//xf:range[@id='range-2']/@xf:start"));
    assertEquals("2", context.getValue("//xf:range[@id='range-2']/@xf:end"));
    assertEquals("1", context.getValue("//xf:range[@id='range-2']/@xf:step"));
}

From source file:org.chiba.xml.xforms.ui.test.RangeTest.java

/**
 * Tests range bound to float./*from w  ww.  j a  v a  2 s  .  co  m*/
 *
 * @throws Exception if any error occurred during the test.
 */
public void testFloat() throws Exception {
    JXPathContext context = this.chibaBean.getContainer().getRootContext();

    assertEquals("-2", context.getValue("//xf:range[@id='range-3']/@xf:start"));
    assertEquals("2", context.getValue("//xf:range[@id='range-3']/@xf:end"));
    assertEquals("1", context.getValue("//xf:range[@id='range-3']/@xf:step"));
}

From source file:org.chiba.xml.xforms.ui.test.RangeTest.java

/**
 * Tests range bound to float.//w  w  w.j a v  a2  s  .c om
 *
 * @throws Exception if any error occurred during the test.
 */
public void testFloatDefaults() throws Exception {
    JXPathContext context = this.chibaBean.getContainer().getRootContext();

    assertEquals("-2", context.getValue("//xf:range[@id='range-4']/@xf:start"));
    assertEquals("2", context.getValue("//xf:range[@id='range-4']/@xf:end"));
    assertEquals("1", context.getValue("//xf:range[@id='range-4']/@xf:step"));
}