Java Code Examples for org.apache.commons.jxpath.JXPathContext#selectSingleNode()

The following examples show how to use org.apache.commons.jxpath.JXPathContext#selectSingleNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JXPath172DynamicTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_propertyExistAndIsNotNull()
{
    final JXPathContext context = getContext("ciao", false);
    final Object bRet = context.selectSingleNode("value");
    assertNotNull("null!!", bRet);
    assertEquals("Is " + bRet.getClass(), "ciao", bRet);

    final Pointer pointer = context.getPointer("value");
    assertNotNull(pointer);
    assertEquals(DynamicPropertyPointer.class, pointer.getClass());
    assertEquals("ciao", pointer.getValue());
}
 
Example 2
Source File: JXPath172DynamicTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_propertyExistAndIsNull()
{
    final JXPathContext context = getContext(null, false);
    final Object bRet = context.selectSingleNode("value");
    assertNull("not null!!", bRet);

    final Pointer pointer = context.getPointer("value");
    assertNotNull(pointer);
    assertEquals(DynamicPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());
}
 
Example 3
Source File: JXPath172DynamicTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_propertyDoesNotExist()
{
    final JXPathContext context = getContext(null, false);
    final Object bRet = context.selectSingleNode("unexisting");
    assertNull(bRet);

    final Pointer pointer = context.getPointer("unexisting");
    assertEquals(DynamicPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());

}
 
Example 4
Source File: JXPath172DynamicTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_propertyDoesNotExist_Lenient()
{
    final JXPathContext context = getContext(null, true);
    final Object bRet = context.selectSingleNode("unexisting");
    assertNull(bRet);

    final Pointer pointer = context.getPointer("unexisting");
    assertEquals(DynamicPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());

}
 
Example 5
Source File: JXPath172DynamicTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_nestedpropertyDoesNotExist_Lenient()
{
    final JXPathContext context = getContext(null, true);
    final Object bRet = context.selectSingleNode("value.unexisting");
    assertNull(bRet);

    final Pointer pointer = context.getPointer("value.unexisting");
    assertEquals(DynamicPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());

}
 
Example 6
Source File: JXPath172DynamicTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_nestedpropertyDoesNotExist_NotLenient()
{
    final JXPathContext context = getContext(null, false);
    final Object bRet = context.selectSingleNode("value.unexisting");
    assertNull(bRet);

    final Pointer pointer = context.getPointer("value.unexisting");
    assertEquals(DynamicPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());

}
 
Example 7
Source File: JXPath172Test.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_propertyExistAndIsNotNull()
{
    final JXPathContext context = getContext("ciao", false);
    final Object bRet = context.selectSingleNode("value");
    assertNotNull("null!!", bRet);
    assertEquals("Is " + bRet.getClass(), "ciao", bRet);

    final Pointer pointer = context.getPointer("value");
    assertNotNull(pointer);
    assertEquals(BeanPropertyPointer.class, pointer.getClass());
    assertEquals("ciao", pointer.getValue());
}
 
Example 8
Source File: JXPath172Test.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_propertyExistAndIsNull()
{
    final JXPathContext context = getContext(null, false);
    final Object bRet = context.selectSingleNode("value");
    assertNull("not null!!", bRet);

    final Pointer pointer = context.getPointer("value");
    assertNotNull(pointer);
    assertEquals(BeanPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());
}
 
Example 9
Source File: JXPath172Test.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_PropertyUnexisting()
{
    final JXPathContext context = getContext(null, true);
    final Object bRet = context.selectSingleNode("unexisting");
    assertNull("not null!!", bRet);

    final Pointer pointer = context.getPointer("unexisting");
    assertNotNull(pointer);
    assertEquals(NullPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());
}
 
Example 10
Source File: JXPath172Test.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_NestedPropertyUnexisting()
{
    final JXPathContext context = getContext(null, true);
    final Object bRet = context.selectSingleNode("value.child");
    assertNull("not null!!", bRet);

    final Pointer pointer = context.getPointer("value.child");
    assertNotNull(pointer);
    assertEquals(NullPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());
}
 
Example 11
Source File: ClassLoaderUtilTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Performs a basic query that requires a class be loaded dynamically by
 * JXPath and asserts the dynamic class load fails.
 */
public static void callExampleMessageMethodAndAssertClassNotFoundJXPathException() {
  JXPathContext context = JXPathContext.newContext(new Object());
  try {
    context.selectSingleNode(EXAMPLE_CLASS_NAME+".getMessage()");
    fail("We should not be able to load "+EXAMPLE_CLASS_NAME+".");
  } catch( Exception e ) {
    assertTrue( e instanceof JXPathException );
  }
}
 
Example 12
Source File: ClassLoaderUtilTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Performs a basic query that requires a class be loaded dynamically by
 * JXPath and asserts the dynamic class load succeeds.
 */
public static void callExampleMessageMethodAndAssertSuccess() {
  JXPathContext context = JXPathContext.newContext(new Object());
  Object value;
  try {
    value = context.selectSingleNode(EXAMPLE_CLASS_NAME+".getMessage()");
    assertEquals("an example class", value);
  } catch( Exception e ) {
    fail(e.getMessage());
  }
}