@Test public void testParseSingle() throws Exception { final AhcPropertyAccessor accessor = new AhcMapperExpressionParser(AhcMapperLogger.DEBUG_STDOUT) .parse(ClassA.class, "firstName", String.class, null, true); assertEquals(MethodBasedPropertyAccessor.class, accessor.getClass()); assertEquals(true, accessor.isPrimary()); assertEquals(true, accessor.isReadable()); assertEquals(true, accessor.isWritable()); assertEquals("firstName", accessor.getName()); final ClassA a = new ClassA(); accessor.setValue(a, "first"); assertEquals("first", a.getFirstName()); assertEquals("first", accessor.getValue(a)); }
@Test public void testParseOgnl() throws Exception { final AhcPropertyAccessor accessor = new AhcMapperExpressionParser(AhcMapperLogger.DEBUG_STDOUT) .parse(ClassA.class, "phone[0].phone", String.class, null, true); assertEquals(OgnlPropertyAccessor.class, accessor.getClass()); assertEquals(true, accessor.isPrimary()); assertEquals(true, accessor.isReadable()); assertEquals(true, accessor.isWritable()); assertEquals("phone[0].phone", accessor.getName()); final ClassA a = new ClassA(); a.getPhone().add(new InnerClassA()); accessor.setValue(a, "xyz"); assertEquals("xyz", a.getPhone().get(0).getPhone()); assertEquals("xyz", accessor.getValue(a)); }