Java Code Examples for org.apache.velocity.util.introspection.Uberspect#getPropertySet()

The following examples show how to use org.apache.velocity.util.introspection.Uberspect#getPropertySet() . 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: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void testNullPropertySetter()
    throws Exception
{
    Uberspect u = ri.getUberspect();
    GetPutObject gpo = new GetPutObject();
    Map map = new HashMap();

    // Don't screw up on null properties. That should map to put() on the GPO.
    VelPropertySet setter = u.getPropertySet(gpo, null, "", null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "put", setter.getMethodName());

    // And should be null on a Map which does not have a put()
    setter = u.getPropertySet(map, null, "", null);
    assertNull(setter);
}
 
Example 2
Source File: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void testNullParameterType()
        throws Exception
{
    VelPropertySet setter;

    Uberspect u = ri.getUberspect();
    UberspectorTestObject uto = new UberspectorTestObject();

    // setRegular()
    setter = u.getPropertySet(uto, "Regular", null, null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setRegular", setter.getMethodName());

    // setAmbigous() - String and StringBuffer available
    setter = u.getPropertySet(uto, "Ambigous", null, null);
    assertNull(setter);

    // setAmbigous() - same with Object?
    setter = u.getPropertySet(uto, "Ambigous", new Object(), null);
    assertNull(setter);
}
 
Example 3
Source File: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void testMultipleParameterTypes()
        throws Exception
{
    VelPropertySet setter;

    Uberspect u = ri.getUberspect();
    UberspectorTestObject uto = new UberspectorTestObject();

    // setAmbigous() - String
    setter = u.getPropertySet(uto, "Ambigous", "", null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setAmbigous", setter.getMethodName());

    // setAmbigous() - StringBuffer
    setter = u.getPropertySet(uto, "Ambigous", new StringBuffer(), null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setAmbigous", setter.getMethodName());
}
 
Example 4
Source File: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void testDisambiguation()
        throws Exception
{
    VelPropertySet setter;

    Uberspect u = ri.getUberspect();
    UberspectorTestObject uto = new UberspectorTestObject();

    // setUnambigous() - String
    setter = u.getPropertySet(uto, "unambiguous", "string", null);
    assertNotNull(setter);
    setter.invoke(uto, "string");

    // setUnambigous() - HashMap
    setter = u.getPropertySet(uto, "unambiguous", new HashMap(), null);
    assertNotNull(setter);
    setter.invoke(uto, new HashMap());
}
 
Example 5
Source File: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
public void testNullObjects()
        throws Exception
{
    // How about some null objects... Gee, I'm mean. ;-)
    Uberspect u = ri.getUberspect();

    VelPropertyGet getter = u.getPropertyGet(null, "foo", null);
    assertNull(getter);

    VelPropertySet setter = u.getPropertySet(null, "foo", Object.class, null);
    assertNull(setter);
}
 
Example 6
Source File: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
public void testEmptyPropertySetter()
        throws Exception
{
    Uberspect u = ri.getUberspect();
    Map map = new HashMap();

    VelPropertySet setter = u.getPropertySet(map, "", Object.class, null);

    // Don't screw up on empty properties. That should map to put("", Object)
    assertNotNull(setter);
    assertEquals("Found wrong method", "put", setter.getMethodName());
}
 
Example 7
Source File: UberspectorTestCase.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
public void testRegularSetters()
        throws Exception
{
    VelPropertySet setter;

    Uberspect u = ri.getUberspect();
    UberspectorTestObject uto = new UberspectorTestObject();

    // setRegular()
    setter = u.getPropertySet(uto, "Regular", "", null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setRegular", setter.getMethodName());

    // Lowercase regular
    setter = u.getPropertySet(uto, "regular", "", null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setRegular", setter.getMethodName());

    // lowercase: setpremium()
    setter = u.getPropertySet(uto, "premium", "", null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setpremium", setter.getMethodName());

    // test uppercase: getpremium()
    setter = u.getPropertySet(uto, "Premium", "", null);
    assertNotNull(setter);
    assertEquals("Found wrong method", "setpremium", setter.getMethodName());
}