struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [15/50] git commit: Updates test to use new excluded classes
Date Wed, 18 Jun 2014 06:49:32 GMT
Updates test to use new excluded classes


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/cdfb94d7
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/cdfb94d7
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/cdfb94d7

Branch: refs/heads/develop
Commit: cdfb94d712e2b71bcf42f87f6c1b7d02d784dd87
Parents: afb5af1
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Sat May 3 20:17:19 2014 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Sat May 3 20:17:19 2014 +0200

----------------------------------------------------------------------
 .../impl/AnnotationXWorkConverterTest.java      |  10 +-
 .../opensymphony/xwork2/ognl/OgnlUtilTest.java  | 115 ++++++++-----------
 .../xwork2/ognl/OgnlValueStackTest.java         |   1 +
 3 files changed, 54 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/cdfb94d7/xwork-core/src/test/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverterTest.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/test/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverterTest.java
b/xwork-core/src/test/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverterTest.java
index 4a7f517..14d9be1 100644
--- a/xwork-core/src/test/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverterTest.java
+++ b/xwork-core/src/test/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverterTest.java
@@ -374,8 +374,8 @@ public class AnnotationXWorkConverterTest extends XWorkTestCase {
         stack.setValue("genericMap[456.12]", "42");
 
         assertEquals(2, gb.getGenericMap().size());
-        assertEquals(Integer.class, stack.findValue("genericMap.get(123.12).class"));
-        assertEquals(Integer.class, stack.findValue("genericMap.get(456.12).class"));
+        assertEquals("66", stack.findValue("genericMap.get(123.12).toString()"));
+        assertEquals("42", stack.findValue("genericMap.get(456.12).toString()"));
         assertEquals(66, stack.findValue("genericMap.get(123.12)"));
         assertEquals(42, stack.findValue("genericMap.get(456.12)"));
         assertEquals(true, stack.findValue("genericMap.containsValue(66)"));
@@ -393,8 +393,8 @@ public class AnnotationXWorkConverterTest extends XWorkTestCase {
         stack.setValue("genericMap[456.12]", "42");
 
         assertEquals(2, gb.getGenericMap().size());
-        assertEquals(Integer.class, stack.findValue("genericMap.get(123.12).class"));
-        assertEquals(Integer.class, stack.findValue("genericMap.get(456.12).class"));
+        assertEquals("66", stack.findValue("genericMap.get(123.12).toString()"));
+        assertEquals("42", stack.findValue("genericMap.get(456.12).toString()"));
         assertEquals(66, stack.findValue("genericMap.get(123.12)"));
         assertEquals(42, stack.findValue("genericMap.get(456.12)"));
         assertEquals(true, stack.findValue("genericMap.containsValue(66)"));
@@ -409,7 +409,7 @@ public class AnnotationXWorkConverterTest extends XWorkTestCase {
         stack.push(gb);
 
         assertEquals(1, gb.getGetterList().size());
-        assertEquals(Double.class, stack.findValue("getterList.get(0).class"));
+        assertEquals("42.42", stack.findValue("getterList.get(0).toString()"));
         assertEquals(new Double(42.42), stack.findValue("getterList.get(0)"));
         assertEquals(new Double(42.42), gb.getGetterList().get(0));
 

http://git-wip-us.apache.org/repos/asf/struts/blob/cdfb94d7/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java b/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java
index 98ff671..e8733d6 100644
--- a/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java
+++ b/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java
@@ -82,7 +82,7 @@ public class OgnlUtilTest extends XWorkTestCase {
         });
 
         Owner owner = new Owner();
-        Map context = Ognl.createDefaultContext(owner);
+        Map context = ognlUtil.createDefaultContext(owner);
         Map props = new HashMap();
         props.put("dog.name", dogName);
 
@@ -107,7 +107,7 @@ public class OgnlUtilTest extends XWorkTestCase {
 
     public void testCanSetDependentObjectArray() {
         EmailAction action = new EmailAction();
-        Map<String, Object> context = Ognl.createDefaultContext(action);
+        Map<String, Object> context = ognlUtil.createDefaultContext(action);
 
         Map<String, Object> props = new HashMap<String, Object>();
         props.put("email[0].address", "addr1");
@@ -125,7 +125,7 @@ public class OgnlUtilTest extends XWorkTestCase {
         Foo foo1 = new Foo();
         Foo foo2 = new Foo();
 
-        Map context = Ognl.createDefaultContext(foo1);
+        Map context = ognlUtil.createDefaultContext(foo1);
 
         Calendar cal = Calendar.getInstance();
         cal.clear();
@@ -171,7 +171,7 @@ public class OgnlUtilTest extends XWorkTestCase {
         foo2.setTitle("foo2 title");
         foo2.setNumber(2);
 
-        Map<String, Object> context = Ognl.createDefaultContext(foo1);
+        Map<String, Object> context = ognlUtil.createDefaultContext(foo1);
 
         List<String> excludes = new ArrayList<String>();
         excludes.add("title");
@@ -200,7 +200,7 @@ public class OgnlUtilTest extends XWorkTestCase {
         b2.setTitle("");
         b2.setId(new Long(2));
 
-        context = Ognl.createDefaultContext(b1);
+        context = ognlUtil.createDefaultContext(b1);
         List<String> includes = new ArrayList<String>();
         includes.add("title");
         includes.add("somethingElse");
@@ -220,7 +220,7 @@ public class OgnlUtilTest extends XWorkTestCase {
         Foo foo = new Foo();
         Bar bar = new Bar();
 
-        Map<String, Object> context = Ognl.createDefaultContext(foo);
+        Map<String, Object> context = ognlUtil.createDefaultContext(foo);
 
         Calendar cal = Calendar.getInstance();
         cal.clear();
@@ -244,7 +244,7 @@ public class OgnlUtilTest extends XWorkTestCase {
         Foo foo = new Foo();
         foo.setBar(new Bar());
 
-        Map<String, Object> context = Ognl.createDefaultContext(foo);
+        Map<String, Object> context = ognlUtil.createDefaultContext(foo);
 
         Map<String, Object> props = new HashMap();
         props.put("bar.title", "i am barbaz");
@@ -280,7 +280,7 @@ public class OgnlUtilTest extends XWorkTestCase {
 
     public void testOgnlHandlesCrapAtTheEndOfANumber() {
         Foo foo = new Foo();
-        Map<String, Object> context = Ognl.createDefaultContext(foo);
+        Map<String, Object> context = ognlUtil.createDefaultContext(foo);
 
         Map<String, Object> props = new HashMap<String, Object>();
         props.put("aLong", "123a");
@@ -317,7 +317,7 @@ public class OgnlUtilTest extends XWorkTestCase {
     public void testSetPropertiesBoolean() {
         Foo foo = new Foo();
 
-        Map context = Ognl.createDefaultContext(foo);
+        Map context = ognlUtil.createDefaultContext(foo);
 
         Map props = new HashMap();
         props.put("useful", "true");
@@ -338,7 +338,7 @@ public class OgnlUtilTest extends XWorkTestCase {
 
         Foo foo = new Foo();
 
-        Map context = Ognl.createDefaultContext(foo);
+        Map context = ognlUtil.createDefaultContext(foo);
 
         Map props = new HashMap();
         props.put("birthday", "02/12/1982");
@@ -408,7 +408,7 @@ public class OgnlUtilTest extends XWorkTestCase {
     public void testSetPropertiesInt() {
         Foo foo = new Foo();
 
-        Map context = Ognl.createDefaultContext(foo);
+        Map context = ognlUtil.createDefaultContext(foo);
 
         Map props = new HashMap();
         props.put("number", "2");
@@ -420,7 +420,7 @@ public class OgnlUtilTest extends XWorkTestCase {
     public void testSetPropertiesLongArray() {
         Foo foo = new Foo();
 
-        Map context = Ognl.createDefaultContext(foo);
+        Map context = ognlUtil.createDefaultContext(foo);
 
         Map props = new HashMap();
         props.put("points", new String[]{"1", "2"});
@@ -435,7 +435,7 @@ public class OgnlUtilTest extends XWorkTestCase {
     public void testSetPropertiesString() {
         Foo foo = new Foo();
 
-        Map context = Ognl.createDefaultContext(foo);
+        Map context = ognlUtil.createDefaultContext(foo);
 
         Map props = new HashMap();
         props.put("title", "this is a title");
@@ -446,7 +446,7 @@ public class OgnlUtilTest extends XWorkTestCase {
 
     public void testSetProperty() {
         Foo foo = new Foo();
-        Map context = Ognl.createDefaultContext(foo);
+        Map context = ognlUtil.createDefaultContext(foo);
         assertFalse(123456 == foo.getNumber());
         ognlUtil.setProperty("number", "123456", foo, context);
         assertEquals(123456, foo.getNumber());
@@ -457,7 +457,7 @@ public class OgnlUtilTest extends XWorkTestCase {
         ChainingInterceptor foo = new ChainingInterceptor();
         ChainingInterceptor foo2 = new ChainingInterceptor();
 
-        OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);
+        OgnlContext context = (OgnlContext) ognlUtil.createDefaultContext(null);
         SimpleNode expression = (SimpleNode) Ognl.parseExpression("{'a','ruby','b','tom'}");
 
 
@@ -499,7 +499,7 @@ public class OgnlUtilTest extends XWorkTestCase {
     public void testStringToLong() {
         Foo foo = new Foo();
 
-        Map context = Ognl.createDefaultContext(foo);
+        Map context = ognlUtil.createDefaultContext(foo);
 
         Map props = new HashMap();
         props.put("aLong", "123");
@@ -518,7 +518,7 @@ public class OgnlUtilTest extends XWorkTestCase {
         Foo foo = new Foo();
         foo.setALong(88);
 
-        Map context = Ognl.createDefaultContext(foo);
+        Map context = ognlUtil.createDefaultContext(foo);
 
         ognlUtil.setProperties(null, foo, context);
         assertEquals(88, foo.getALong());
@@ -531,7 +531,7 @@ public class OgnlUtilTest extends XWorkTestCase {
     
     public void testCopyNull() {
         Foo foo = new Foo();
-        Map context = Ognl.createDefaultContext(foo);
+        Map context = ognlUtil.createDefaultContext(foo);
    		ognlUtil.copy(null, null, context);
 
    		ognlUtil.copy(foo, null, context);
@@ -540,7 +540,7 @@ public class OgnlUtilTest extends XWorkTestCase {
     
     public void testGetTopTarget() throws Exception {
         Foo foo = new Foo();
-        Map context = Ognl.createDefaultContext(foo);
+        Map context = ognlUtil.createDefaultContext(foo);
 
         CompoundRoot root = new CompoundRoot();
         Object top = ognlUtil.getRealTarget("top", context, root);
@@ -633,146 +633,127 @@ public class OgnlUtilTest extends XWorkTestCase {
 
     public void testAvoidCallingMethodsOnObjectClass() throws Exception {
         Foo foo = new Foo();
-        OgnlUtil util = new OgnlUtil();
-        util.setEnableExpressionCache("false");
-        util.setExcludedProperties("class");
 
         Exception expected = null;
         try {
-            util.setValue("class.classLoader.defaultAssertionStatus", ActionContext.getContext().getContextMap(),
foo, true);
+            ognlUtil.setExcludedClasses(Object.class.getName());
+            ognlUtil.setValue("class.classLoader.defaultAssertionStatus", ognlUtil.createDefaultContext(foo),
foo, true);
             fail();
         } catch (OgnlException e) {
             expected = e;
         }
         assertNotNull(expected);
-        assertSame(expected.getClass(), OgnlException.class);
-        assertEquals(expected.getMessage(), "Tree [class.classLoader.defaultAssertionStatus]
trying access excluded pattern [class]");
+        assertSame(NoSuchPropertyException.class, expected.getClass());
+        assertEquals("com.opensymphony.xwork2.util.Foo.class", expected.getMessage());
     }
 
     public void testAvoidCallingMethodsOnObjectClassUpperCased() throws Exception {
         Foo foo = new Foo();
-        OgnlUtil util = new OgnlUtil();
-        util.setEnableExpressionCache("false");
-        util.setExcludedProperties("class");
 
         Exception expected = null;
         try {
-            util.setValue("Class.ClassLoader.DefaultAssertionStatus", ActionContext.getContext().getContextMap(),
foo, true);
+            ognlUtil.setExcludedClasses(Object.class.getName());
+            ognlUtil.setValue("Class.ClassLoader.DefaultAssertionStatus", ognlUtil.createDefaultContext(foo),
foo, true);
             fail();
         } catch (OgnlException e) {
             expected = e;
         }
         assertNotNull(expected);
-        assertSame(expected.getClass(), OgnlException.class);
-        assertEquals(expected.getMessage(), "Tree [Class.ClassLoader.DefaultAssertionStatus]
trying access excluded pattern [class]");
+        assertSame(NoSuchPropertyException.class, expected.getClass());
+        assertEquals("com.opensymphony.xwork2.util.Foo.Class", expected.getMessage());
     }
 
     public void testAvoidCallingMethodsOnObjectClassAsMap() throws Exception {
         Foo foo = new Foo();
-        OgnlUtil util = new OgnlUtil();
-        util.setEnableExpressionCache("false");
-        util.setExcludedProperties("class");
 
         Exception expected = null;
         try {
-            util.setValue("class['classLoader']['defaultAssertionStatus']", ActionContext.getContext().getContextMap(),
foo, true);
+            ognlUtil.setExcludedClasses(Object.class.getName());
+            ognlUtil.setValue("class['classLoader']['defaultAssertionStatus']", ognlUtil.createDefaultContext(foo),
foo, true);
             fail();
         } catch (OgnlException e) {
             expected = e;
         }
         assertNotNull(expected);
-        assertSame(expected.getClass(), OgnlException.class);
-        assertEquals(expected.getMessage(), "Tree [class[\"classLoader\"][\"defaultAssertionStatus\"]]
trying access excluded pattern [class]");
+        assertSame(NoSuchPropertyException.class, expected.getClass());
+        assertEquals("com.opensymphony.xwork2.util.Foo.class", expected.getMessage());
     }
 
     public void testAvoidCallingMethodsOnObjectClassAsMap2() throws Exception {
         Foo foo = new Foo();
-        OgnlUtil util = new OgnlUtil();
-        util.setEnableExpressionCache("false");
-        util.setExcludedProperties("class");
 
         Exception expected = null;
         try {
-            util.setValue("model['class']['classLoader']['defaultAssertionStatus']", ActionContext.getContext().getContextMap(),
foo, true);
+            ognlUtil.setValue("foo['class']['classLoader']['defaultAssertionStatus']", ognlUtil.createDefaultContext(foo),
foo, true);
             fail();
         } catch (OgnlException e) {
             expected = e;
         }
         assertNotNull(expected);
-        assertSame(expected.getClass(), OgnlException.class);
-        assertEquals(expected.getMessage(), "Tree [class[\"classLoader\"][\"defaultAssertionStatus\"]]
trying access excluded pattern [class]");
+        assertSame(NoSuchPropertyException.class, expected.getClass());
+        assertEquals("com.opensymphony.xwork2.util.Foo.foo", expected.getMessage());
     }
 
     public void testAvoidCallingMethodsOnObjectClassAsMapWithQuotes() throws Exception {
         Foo foo = new Foo();
-        OgnlUtil util = new OgnlUtil();
-        util.setEnableExpressionCache("false");
-        util.setExcludedProperties("class");
 
         Exception expected = null;
         try {
-            util.setValue("class[\"classLoader\"]['defaultAssertionStatus']", ActionContext.getContext().getContextMap(),
foo, true);
+            ognlUtil.setExcludedClasses(Object.class.getName());
+            ognlUtil.setValue("class[\"classLoader\"]['defaultAssertionStatus']", ognlUtil.createDefaultContext(foo),
foo, true);
             fail();
         } catch (OgnlException e) {
             expected = e;
         }
         assertNotNull(expected);
-        assertSame(expected.getClass(), OgnlException.class);
-        assertEquals(expected.getMessage(), "Tree [class[\"classLoader\"][\"defaultAssertionStatus\"]]
trying access excluded pattern [class]");
+        assertSame(NoSuchPropertyException.class, expected.getClass());
+        assertEquals("com.opensymphony.xwork2.util.Foo.class", expected.getMessage());
     }
 
     public void testAvoidCallingToString() throws Exception {
         Foo foo = new Foo();
-        OgnlUtil util = new OgnlUtil();
-        util.setEnableExpressionCache("false");
-        util.setExcludedProperties("toString");
 
         Exception expected = null;
         try {
-            util.setValue("toString", ActionContext.getContext().getContextMap(), foo, true);
+            ognlUtil.setValue("toString", ognlUtil.createDefaultContext(foo), foo, null);
             fail();
         } catch (OgnlException e) {
             expected = e;
         }
         assertNotNull(expected);
-        assertSame(expected.getClass(), OgnlException.class);
-        assertEquals(expected.getMessage(), "Tree [toString] trying access excluded pattern
[toString]");
+        assertSame(OgnlException.class, expected.getClass());
+        assertEquals("toString", expected.getMessage());
     }
 
     public void testAvoidCallingMethodsWithBraces() throws Exception {
         Foo foo = new Foo();
-        OgnlUtil util = new OgnlUtil();
-        util.setEnableExpressionCache("false");
-        util.setExcludedProperties("toString");
 
         Exception expected = null;
         try {
-            util.setValue("toString()", ActionContext.getContext().getContextMap(), foo,
true);
+            ognlUtil.setValue("toString()", ognlUtil.createDefaultContext(foo), foo, true);
             fail();
         } catch (OgnlException e) {
             expected = e;
         }
         assertNotNull(expected);
-        assertSame(expected.getClass(), OgnlException.class);
-        assertEquals(expected.getMessage(), "Tree [toString()] trying access excluded pattern
[toString()]");
+        assertSame(InappropriateExpressionException.class, expected.getClass());
+        assertEquals(expected.getMessage(), "Inappropriate OGNL expression: toString()");
     }
 
     public void testAvoidCallingSomeClasses() throws Exception {
         Foo foo = new Foo();
-        OgnlUtil util = new OgnlUtil();
-        util.setEnableExpressionCache("false");
-        util.setExcludedProperties("Runtime");
 
         Exception expected = null;
         try {
-            util.setValue("@java.lang.Runtime@getRuntime().exec('mate')", ActionContext.getContext().getContextMap(),
foo, true);
+            ognlUtil.setExcludedClasses(Runtime.class.getName());
+            ognlUtil.setValue("@java.lang.Runtime@getRuntime().exec('mate')", ognlUtil.createDefaultContext(foo),
foo, true);
             fail();
         } catch (OgnlException e) {
             expected = e;
         }
         assertNotNull(expected);
-        assertSame(expected.getClass(), OgnlException.class);
-        assertEquals(expected.getMessage(), "Tree [toString()] trying access excluded pattern
[toString()]");
+        assertSame(MethodFailedException.class, expected.getClass());
+        assertEquals(expected.getMessage(), "Method \"getRuntime\" failed for object class
java.lang.Runtime");
     }
 
     public static class Email {

http://git-wip-us.apache.org/repos/asf/struts/blob/cdfb94d7/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java
b/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java
index a4a153a..cb71081 100644
--- a/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java
+++ b/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java
@@ -58,6 +58,7 @@ public class OgnlValueStackTest extends XWorkTestCase {
                 (CompoundRootAccessor) container.getInstance(PropertyAccessor.class, CompoundRoot.class.getName()),
                 container.getInstance(TextProvider.class, "system"), allowStaticMethodAccess);
         container.inject(stack);
+        ognlUtil.setAllowStaticMethodAccess(Boolean.toString(allowStaticMethodAccess));
         return stack;
     }
 


Mime
View raw message