svn commit: r833573 [2/2] - in /struts/sandbox/trunk/struts2-uel-plugin/src: main/java/org/apache/struts2/uelplugin/ main/java/org/apache/struts2/uelplugin/elresolvers/ main/java/org/apache/struts2/uelplugin/reflection/ main/resources/ test/java/org/ap...

View: New views
1 Messages — Rating Filter:   Alert me  

svn commit: r833573 [2/2] - in /struts/sandbox/trunk/struts2-uel-plugin/src: main/java/org/apache/struts2/uelplugin/ main/java/org/apache/struts2/uelplugin/elresolvers/ main/java/org/apache/struts2/uelplugin/reflection/ main/resources/ test/java/org/ap...

by musachy-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Modified: struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/BuiltinFunctionsTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/BuiltinFunctionsTest.java?rev=833573&r1=833572&r2=833573&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/BuiltinFunctionsTest.java (original)
+++ struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/BuiltinFunctionsTest.java Fri Nov  6 22:10:43 2009
@@ -15,11 +15,7 @@
 import javax.servlet.ServletContextEvent;
 
 
-public class BuiltinFunctionsTest extends XWorkTestCase {
-    private XWorkConverter converter;
-    private CompoundRoot root;
-    private UelValueStack stack;
-
+public class BuiltinFunctionsTest extends AbstractUelBaseTest {
     public void testGetText() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
         TestAction action = new TestAction();
         stack.push(action);
@@ -27,25 +23,4 @@
 
         assertEquals("This is the key!", stack.findValue("${getText('key')}"));
     }
-
-
-
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        converter = container.getInstance(XWorkConverter.class);
-        this.root = new CompoundRoot();
-        this.stack = new UelValueStack(converter);
-        stack.setRoot(root);
-        stack.getContext().put(ActionContext.CONTAINER, container);
-
-        MockServletContext servletContext = new MockServletContext();
-        ActionContext context = new ActionContext(stack.getContext());
-        ActionContext.setContext(context);
-        ServletActionContext.setServletContext(servletContext);
-
-        //simulate start up
-        UelServletContextListener listener = new UelServletContextListener();
-        listener.contextInitialized(new ServletContextEvent(servletContext));
-    }
 }

Added: struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/DummyTypeConverter.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/DummyTypeConverter.java?rev=833573&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/DummyTypeConverter.java (added)
+++ struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/DummyTypeConverter.java Fri Nov  6 22:10:43 2009
@@ -0,0 +1,18 @@
+package org.apache.struts2.uelplugin;
+
+import com.opensymphony.xwork2.conversion.TypeConverter;
+
+import java.util.Map;
+import java.lang.reflect.Member;
+
+import org.apache.struts2.util.StrutsTypeConverter;
+
+public class DummyTypeConverter extends StrutsTypeConverter {
+    public Object convertFromString(Map context, String[] values, Class toClass) {
+        return "converted";
+    }
+
+    public String convertToString(Map context, Object o) {
+        return "converted-tostring";
+    }
+}

Modified: struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/JuelMethodInvocationTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/JuelMethodInvocationTest.java?rev=833573&r1=833572&r2=833573&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/JuelMethodInvocationTest.java (original)
+++ struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/JuelMethodInvocationTest.java Fri Nov  6 22:10:43 2009
@@ -13,11 +13,7 @@
 import java.util.HashMap;
 
 
-public class JuelMethodInvocationTest extends XWorkTestCase {
-    private XWorkConverter converter;
-    private CompoundRoot root;
-    private UelValueStack stack;
-
+public class JuelMethodInvocationTest extends AbstractUelBaseTest {
     public void testBasicMethods() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
         assertEquals("text", stack.findValue("${' text '.trim()}"));
         assertEquals(3, stack.findValue("${'123'.length()}"));
@@ -28,28 +24,9 @@
         assertEquals("123456", stack.findValue("${'123'.concat('456')}"));
     }
 
-      public void testMethodsWithParamsAndContextReference() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
-          stack.getContext().put("s0", "Lex");
-          stack.getContext().put("s1", "Luthor");
-          assertEquals("Lex Luthor", stack.findValue("${#s0.concat(' ').concat(#s1)}"));
-      }
-
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        converter = container.getInstance(XWorkConverter.class);
-        this.root = new CompoundRoot();
-        this.stack = new UelValueStack(converter);
-        stack.setRoot(root);
-        stack.getContext().put(ActionContext.CONTAINER, container);
-
-        MockServletContext servletContext = new MockServletContext();
-        ActionContext context = new ActionContext(stack.getContext());
-        ActionContext.setContext(context);
-        ServletActionContext.setServletContext(servletContext);
-
-        //simulate start up
-        UelServletContextListener listener = new UelServletContextListener();
-        listener.contextInitialized(new ServletContextEvent(servletContext));
+    public void testMethodsWithParamsAndContextReference() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
+        stack.getContext().put("s0", "Lex");
+        stack.getContext().put("s1", "Luthor");
+        assertEquals("Lex Luthor", stack.findValue("${#s0.concat(' ').concat(#s1)}"));
     }
 }

Added: struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/ParametersTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/ParametersTest.java?rev=833573&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/ParametersTest.java (added)
+++ struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/ParametersTest.java Fri Nov  6 22:10:43 2009
@@ -0,0 +1,85 @@
+package org.apache.struts2.uelplugin;
+
+import com.opensymphony.xwork2.interceptor.ParametersInterceptor;
+import com.opensymphony.xwork2.ActionProxy;
+import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
+
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+import java.lang.reflect.InvocationTargetException;
+
+
+public class ParametersTest extends AbstractUelBaseTest {
+    public void testWriteList() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
+        //not null
+        List list = new ArrayList();
+        TestObject obj = new TestObject();
+        obj.setList(list);
+        assertNotNull(obj.getList());
+        root.push(obj);
+
+        stack.setValue("list[0]", "val");
+        assertEquals(1, list.size());
+        assertEquals("val", list.get(0));
+
+        //null list
+        obj.setList(null);
+        assertNull(obj.getList());
+        stack.setValue("list[0]", "val");
+        assertNotNull(obj.getList());
+        assertEquals("val", stack.findValue("list[0]"));
+
+        //test out of index
+        obj.setList(null);
+        stack.setValue("list[3]", "val");
+        assertEquals(4, obj.getList().size());
+        assertEquals("val", obj.getList().get(3));
+
+        //test type determiner
+        obj.setTypedList(null);
+        stack.setValue("typedList[1].value", "val");
+        assertEquals(2, obj.getTypedList().size());
+        assertEquals("val", obj.getTypedList().get(1).getValue());
+    }
+
+    public void testAnnotatedTypeConverter() {
+        TestAction action = new TestAction();
+        assertNull(action.getConverted());
+        root.push(action);
+
+        stack.setValue("converted", "someval");
+        assertEquals("converted", action.getConverted());
+    }
+
+
+    public void testSetPropertiesOnNestedNullObject() {
+        TestObject obj = new TestObject();
+        assertNull(obj.getInner());
+        root.push(obj);
+
+        //inner is null, it will be catched bye the CompoundRoolELResolver
+        stack.setValue("inner.value", "val");
+        assertNotNull(obj.getInner());
+        assertEquals("val", obj.getInner().getValue());
+
+
+        //second nested property null
+        stack.setValue("inner.inner.value", "val");
+        assertNotNull(obj.getInner().getInner());
+        assertEquals("val", obj.getInner().getInner().getValue());
+    }
+
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        Map context = stack.getContext();
+
+        ReflectionContextState.setCreatingNullObjects(context, true);
+        ReflectionContextState.setDenyMethodExecution(context, true);
+        ReflectionContextState.setReportingConversionErrors(context, true);
+    }
+}

Modified: struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/TestAction.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/TestAction.java?rev=833573&r1=833572&r2=833573&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/TestAction.java (original)
+++ struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/TestAction.java Fri Nov  6 22:10:43 2009
@@ -1,6 +1,30 @@
 package org.apache.struts2.uelplugin;
 
 import com.opensymphony.xwork2.ActionSupport;
+import com.opensymphony.xwork2.conversion.annotations.Conversion;
+import com.opensymphony.xwork2.conversion.annotations.ConversionType;
+import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
 
+@Conversion
 public class TestAction extends ActionSupport {
+    private TestObject object;
+
+    private String converted;
+
+    @TypeConversion(type = ConversionType.APPLICATION, converter = "org.apache.struts2.uelplugin.DummyTypeConverter")
+    public String getConverted() {
+        return converted;
+    }
+
+    public void setConverted(String converted) {
+        this.converted = converted;
+    }
+
+    public TestObject getObject() {
+        return object;
+    }
+
+    public void setObject(TestObject object) {
+        this.object = object;
+    }
 }

Modified: struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/TestObject.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/TestObject.java?rev=833573&r1=833572&r2=833573&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/TestObject.java (original)
+++ struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/TestObject.java Fri Nov  6 22:10:43 2009
@@ -2,6 +2,7 @@
 
 import java.util.Date;
 import java.util.Map;
+import java.util.List;
 
 
 public class TestObject {
@@ -11,6 +12,24 @@
     private TestObject inner;
     private Map parameters;
     private Object object;
+    private List list;
+    private List<TestObject> typedList;
+
+    public List<TestObject> getTypedList() {
+        return typedList;
+    }
+
+    public void setTypedList(List<TestObject> typedList) {
+        this.typedList = typedList;
+    }
+
+    public List getList() {
+        return list;
+    }
+
+    public void setList(List list) {
+        this.list = list;
+    }
 
     public TestObject() {
     }

Modified: struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/UelTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/UelTest.java?rev=833573&r1=833572&r2=833573&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/UelTest.java (original)
+++ struts/sandbox/trunk/struts2-uel-plugin/src/test/java/org/apache/struts2/uelplugin/UelTest.java Fri Nov  6 22:10:43 2009
@@ -2,7 +2,21 @@
 
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.XWorkTestCase;
+import com.opensymphony.xwork2.ActionProxyFactory;
+import com.opensymphony.xwork2.ognl.OgnlReflectionProvider;
+import com.opensymphony.xwork2.inject.Container;
+import com.opensymphony.xwork2.inject.ContainerBuilder;
+import com.opensymphony.xwork2.inject.Scope;
+import com.opensymphony.xwork2.config.ConfigurationManager;
+import com.opensymphony.xwork2.config.Configuration;
+import com.opensymphony.xwork2.config.ConfigurationProvider;
+import com.opensymphony.xwork2.config.ConfigurationException;
 import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
+import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.util.ValueStackFactory;
+import com.opensymphony.xwork2.util.LocalizedTextUtil;
 import com.opensymphony.xwork2.util.CompoundRoot;
 import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.uelplugin.UelServletContextListener;
@@ -16,49 +30,17 @@
 import java.text.ParseException;
 import java.util.*;
 
-public class UelTest extends XWorkTestCase {
-    private ExpressionFactory factory = ExpressionFactory.newInstance();
-    private XWorkConverter converter;
-    private DateFormat format = DateFormat.getDateInstance();
-    private CompoundRoot root;
-    private UelValueStack stack;
-
-    private class DateConverter extends StrutsTypeConverter {
-
-        @Override
-        public Object convertFromString(Map context, String[] values, Class toClass) {
-            try {
-                return format.parseObject(values[0]);
-            } catch (ParseException e) {
-                return null;
-            }
-        }
-
-        @Override
-        public String convertToString(Map context, Object o) {
-            return format.format(o);
-        }
+public class UelTest extends AbstractUelBaseTest {
 
-    }
+    public void testReadList() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
+        TestObject obj = new TestObject();
+        root.push(obj);
 
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        converter = container.getInstance(XWorkConverter.class);
-        converter.registerConverter("java.util.Date", new DateConverter());
-        this.root = new CompoundRoot();
-        this.stack = new UelValueStack(converter);
-        stack.setRoot(root);
-        stack.getContext().put(ActionContext.CONTAINER, container);
-
-        MockServletContext servletContext = new MockServletContext();
-        ActionContext context = new ActionContext(stack.getContext());
-        ActionContext.setContext(context);
-        ServletActionContext.setServletContext(servletContext);
-
-        //simulate start up
-        UelServletContextListener listener = new UelServletContextListener();
-        listener.contextInitialized(new ServletContextEvent(servletContext));
+        //list
+        List someList = new ArrayList(3);
+        obj.setObject(someList);
+        someList.add(10);
+        assertEquals(10, stack.findValue("object[0]"));
     }