struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mart...@apache.org
Subject svn commit: r894087 [34/46] - in /struts/xwork/trunk: ./ assembly/ assembly/src/ assembly/src/main/ assembly/src/main/assembly/ assembly/src/main/resources/ core/ core/src/ core/src/main/ core/src/main/java/ core/src/main/java/com/ core/src/main/java/c...
Date Sun, 27 Dec 2009 18:01:09 GMT
Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/Person.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/Person.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonAction.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonAction.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonAction.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonAction.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,47 @@
+package com.opensymphony.xwork2.test.annotations;
+
+import com.opensymphony.xwork2.conversion.annotations.Conversion;
+import com.opensymphony.xwork2.conversion.annotations.ConversionType;
+import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
+import com.opensymphony.xwork2.util.Element;
+
+import java.util.List;
+
+@Conversion(
+	conversions={
+		@TypeConversion(type=ConversionType.APPLICATION,
+						key="com.opensymphony.xwork2.test.annotations.Address",
+						converter="com.opensymphony.xwork2.test.annotations.AddressTypeConverter"),
+		@TypeConversion(type=ConversionType.APPLICATION,
+						key="com.opensymphony.xwork2.test.annotations.Person",
+						converter="com.opensymphony.xwork2.test.annotations.PersonTypeConverter")})
+public class PersonAction {
+	List<Person> users;
+	private List<Address> address;
+	@Element(com.opensymphony.xwork2.test.annotations.Address.class)
+	private List addressesNoGenericElementAnnotation;
+
+	public List<Person> getUsers() {
+		return users;
+	}
+
+	public void setUsers(List<Person> users) {
+		this.users = users;
+	}
+
+	public void setAddress(List<Address> address) {
+		this.address = address;
+	}
+
+	public List<Address> getAddress() {
+		return address;
+	}
+
+	public void setAddressesNoGenericElementAnnotation(List addressesNoGenericElementAnnotation) {
+		this.addressesNoGenericElementAnnotation = addressesNoGenericElementAnnotation;
+	}
+
+	public List getAddressesNoGenericElementAnnotation() {
+		return addressesNoGenericElementAnnotation;
+	}
+}
\ No newline at end of file

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonAction.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonActionTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonActionTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonActionTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonActionTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,87 @@
+package com.opensymphony.xwork2.test.annotations;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.XWorkTestCase;
+import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
+
+import java.util.Map;
+
+
+public class PersonActionTest extends XWorkTestCase {
+    
+	public void testAddPerson() {
+        ValueStack stack = ActionContext.getContext().getValueStack();
+
+        Map<String, Object> stackContext = stack.getContext();
+        stackContext.put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.TRUE);
+        stackContext.put(ReflectionContextState.DENY_METHOD_EXECUTION, Boolean.TRUE);
+        stackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
+
+        PersonAction action = new PersonAction();
+        stack.push(action);
+
+        stack.setValue("users", "jonathan:gerrish");
+        assertNotNull(action.getUsers());
+        assertEquals(1, action.getUsers().size());
+        
+        for(Object person : action.getUsers()) {
+        	System.out.println("Person: " + person);
+        }
+        
+        assertEquals(Person.class, action.getUsers().get(0).getClass());
+        assertEquals("jonathan", action.getUsers().get(0).getFirstName());
+        assertEquals("gerrish", action.getUsers().get(0).getLastName());
+	}
+	
+	public void testAddAddress() {
+        ValueStack stack = ActionContext.getContext().getValueStack();
+		Map<String, Object> stackContext = stack.getContext();
+		stackContext.put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.TRUE);
+		stackContext.put(ReflectionContextState.DENY_METHOD_EXECUTION, Boolean.TRUE);
+		stackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
+
+		PersonAction action = new PersonAction();
+		stack.push(action);
+
+		stack.setValue("address", "2 Chandos Court:61 Haverstock Hill:London:England");
+		assertNotNull(action.getAddress());
+		assertEquals(1, action.getAddress().size());
+
+		for(Object address : action.getAddress()) {
+			System.out.println("Address: " + address);
+		}
+
+		assertEquals(Address.class, action.getAddress().get(0).getClass());
+		assertEquals("2 Chandos Court", action.getAddress().get(0).getLine1());
+		assertEquals("61 Haverstock Hill", action.getAddress().get(0).getLine2());
+		assertEquals("London", action.getAddress().get(0).getCity());
+		assertEquals("England", action.getAddress().get(0).getCountry());
+	}
+	
+	public void testAddAddressesNoGenericElementAnnotation() {
+        ValueStack stack = ActionContext.getContext().getValueStack();
+		Map<String, Object> stackContext = stack.getContext();
+		stackContext.put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.TRUE);
+		stackContext.put(ReflectionContextState.DENY_METHOD_EXECUTION, Boolean.TRUE);
+		stackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
+
+		PersonAction action = new PersonAction();
+		stack.push(action);
+
+		stack.setValue("addressesNoGenericElementAnnotation", "2 Chandos Court:61 Haverstock Hill:London:England");
+		assertNotNull(action.getAddressesNoGenericElementAnnotation());
+		assertEquals(1, action.getAddressesNoGenericElementAnnotation().size());
+
+		for(Object address : action.getAddressesNoGenericElementAnnotation()) {
+			System.out.println("Address: " + address);
+		}
+
+		assertEquals(Address.class, action.getAddressesNoGenericElementAnnotation().get(0).getClass());
+		assertEquals("2 Chandos Court", ((Address)action.getAddressesNoGenericElementAnnotation().get(0)).getLine1());
+		assertEquals("61 Haverstock Hill", ((Address)action.getAddressesNoGenericElementAnnotation().get(0)).getLine2());
+		assertEquals("London", ((Address)action.getAddressesNoGenericElementAnnotation().get(0)).getCity());
+		assertEquals("England", ((Address)action.getAddressesNoGenericElementAnnotation().get(0)).getCountry());
+	}
+}
\ No newline at end of file

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonActionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonActionTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonTypeConverter.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonTypeConverter.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonTypeConverter.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonTypeConverter.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,27 @@
+package com.opensymphony.xwork2.test.annotations;
+
+import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter;
+
+import java.util.Map;
+
+public class PersonTypeConverter extends DefaultTypeConverter {
+	@Override
+    public Object convertValue(Map<String, Object> context, Object value, Class toType) {
+		if(value instanceof String) {
+			return decodePerson((String)value);
+		} else if(value instanceof String && value.getClass().isArray()) {
+			return decodePerson(((String[])value)[0]);
+		} else {
+			Person person = (Person)value;
+			return person.getFirstName() + ":" + person.getLastName();
+		}
+	}
+
+	private Person decodePerson(String encodedPerson) {
+		String[] parts = ((String)encodedPerson).split(":");
+		Person person = new Person();
+		person.setFirstName(parts[0]);
+		person.setLastName(parts[1]);
+		return person;
+	}
+}
\ No newline at end of file

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonTypeConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/PersonTypeConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/ValidateAnnotatedMethodOnlyAction.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/ValidateAnnotatedMethodOnlyAction.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/ValidateAnnotatedMethodOnlyAction.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/ValidateAnnotatedMethodOnlyAction.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,55 @@
+package com.opensymphony.xwork2.test.annotations;
+
+import com.opensymphony.xwork2.ActionSupport;
+import com.opensymphony.xwork2.validator.annotations.ExpressionValidator;
+import com.opensymphony.xwork2.validator.annotations.Validation;
+
+/**
+ * <code>ValidateAnnotatedMethodOnlyAction</code>
+ *
+ * @author <a href="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
+ * @version $Id$
+ */
+@Validation
+public class ValidateAnnotatedMethodOnlyAction extends ActionSupport {
+
+    String param1;
+    String param2;
+
+
+    public String getParam1() {
+        return param1;
+    }
+
+    public void setParam1(String param1) {
+        this.param1 = param1;
+    }
+
+    public String getParam2() {
+        return param2;
+    }
+
+    public void setParam2(String param2) {
+        this.param2 = param2;
+    }
+
+    @ExpressionValidator(expression = "(param1 != null) || (param2 != null)",
+            message = "Need param1 or param2.")
+    public String annotatedMethod() {
+        try {
+            // do search
+        } catch (Exception e) {
+            return INPUT;
+        }
+        return SUCCESS;
+    }
+
+    public String notAnnotatedMethod() {
+        try {
+            // do different search
+        } catch (Exception e) {
+            return INPUT;
+        }
+        return SUCCESS;
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/ValidateAnnotatedMethodOnlyAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/ValidateAnnotatedMethodOnlyAction.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/subtest/NullModelDrivenAction.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/subtest/NullModelDrivenAction.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/subtest/NullModelDrivenAction.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/subtest/NullModelDrivenAction.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,19 @@
+package com.opensymphony.xwork2.test.subtest;
+
+import com.opensymphony.xwork2.ModelDrivenAction;
+
+/**
+ * Extends ModelDrivenAction to return a null model.
+ *
+ * @author Mark Woon
+ */
+public class NullModelDrivenAction extends ModelDrivenAction {
+
+    /**
+     * @return the model to be pushed onto the ValueStack instead of the Action itself
+     */
+    @Override
+    public Object getModel() {
+        return null;
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/subtest/NullModelDrivenAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/subtest/NullModelDrivenAction.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/AnnotatedCat.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/AnnotatedCat.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/AnnotatedCat.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/AnnotatedCat.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.conversion.annotations.Conversion;
+import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
+
+import java.util.List;
+
+
+/**
+ * @author <a href="mailto:plightbo@cisco.com">Pat Lightbody</a>
+ * @author $Author$
+ * @author Rainer Hermanns
+ * @version $Revision$
+ */
+@Conversion()
+public class AnnotatedCat {
+
+    public static final String SCIENTIFIC_NAME = "Feline";
+
+
+    Foo foo;
+    List kittens;
+    String name;
+
+
+    public void setFoo(Foo foo) {
+        this.foo = foo;
+    }
+
+    public Foo getFoo() {
+        return foo;
+    }
+
+    public void setKittens(List kittens) {
+        this.kittens = kittens;
+    }
+
+    @TypeConversion(
+            key = "kittens", converter = "com.opensymphony.xwork2.util.Cat"
+    )
+    public List getKittens() {
+        return kittens;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/AnnotatedCat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/AnnotatedCat.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,101 @@
+package com.opensymphony.xwork2.util;
+
+import junit.framework.TestCase;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.AnnotatedElement;
+import java.util.Collection;
+
+/**
+ * @author Dan Oxlade, dan d0t oxlade at gmail d0t c0m
+ */
+public class AnnotationUtilsTest extends TestCase {
+
+
+    public void testIsAnnotatedByWithoutAnnotationArgsReturnsFalse() throws Exception {
+
+        assertFalse(AnnotationUtils.isAnnotatedBy(DummyClass.class));
+        assertFalse(AnnotationUtils.isAnnotatedBy(DummyClass.class.getMethod("methodWithAnnotation")));
+
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testIsAnnotatedByWithSingleAnnotationArgMatchingReturnsTrue() throws Exception {
+
+        assertTrue(AnnotationUtils.isAnnotatedBy(DummyClass.class.getMethod("methodWithAnnotation"), MyAnnotation.class));
+
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testIsAnnotatedByWithMultiAnnotationArgMatchingReturnsTrue() throws Exception {
+
+        assertFalse(AnnotationUtils.isAnnotatedBy(DummyClass.class.getMethod("methodWithAnnotation"), Deprecated.class));
+        assertTrue(AnnotationUtils.isAnnotatedBy(DummyClass.class.getMethod("methodWithAnnotation"), MyAnnotation.class, Deprecated.class));
+        assertTrue(AnnotationUtils.isAnnotatedBy(DummyClass.class.getMethod("methodWithAnnotation"), Deprecated.class, MyAnnotation.class));
+
+    }
+
+    public void testGetAnnotedMethodsWithoutAnnotationArgs() throws Exception {
+
+        Collection<? extends AnnotatedElement> ans = AnnotationUtils.getAnnotatedMethods(DummyClass.class);
+
+        assertTrue(ans.size() == 1);
+
+        assertEquals(ans.iterator().next(), DummyClass.class.getMethod("methodWithAnnotation"));
+
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testGetAnnotatedMethodsWithAnnotationArgs() throws Exception {
+
+        Collection<? extends AnnotatedElement> ans = AnnotationUtils.getAnnotatedMethods(DummyClass.class, Deprecated.class);
+        assertTrue(ans.isEmpty());
+
+        ans = AnnotationUtils.getAnnotatedMethods(DummyClass.class, Deprecated.class, MyAnnotation.class);
+        assertEquals(1, ans.size());
+
+        ans = AnnotationUtils.getAnnotatedMethods(DummyClass.class, MyAnnotation.class);
+        assertEquals(1, ans.size());
+
+        ans = AnnotationUtils.getAnnotatedMethods(DummyClass.class, MyAnnotation.class, MyAnnotation2.class);
+        assertEquals(1, ans.size());
+
+        ans = AnnotationUtils.getAnnotatedMethods(DummyClassExt.class, MyAnnotation.class, MyAnnotation2.class);
+        assertEquals(2, ans.size());
+
+    }
+
+    /**
+     * *****************************************************************
+     * <p/>
+     * TEST CLASSES
+     */
+    private static class DummyClass {
+
+        public DummyClass() {
+        }
+
+        @MyAnnotation
+        public void methodWithAnnotation() {
+        }
+
+    }
+
+    @Retention(RetentionPolicy.RUNTIME)
+    public @interface MyAnnotation {
+    }
+
+    private static final class DummyClassExt extends DummyClass {
+
+        @MyAnnotation2
+        public void anotherAnnotatedMethod() {
+        }
+
+    }
+
+    @Retention(RetentionPolicy.RUNTIME)
+    public @interface MyAnnotation2 {
+    }
+
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Bar.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Bar.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Bar.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Bar.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.ActionSupport;
+
+
+/**
+ * @author <a href="mailto:plightbo@cisco.com">Pat Lightbody</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+public class Bar extends ActionSupport {
+
+    Long id;
+    String title;
+    int somethingElse;
+
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getId() {
+        return this.id;
+    }
+
+    public void setSomethingElse(int somethingElse) {
+        this.somethingElse = somethingElse;
+    }
+
+    public int getSomethingElse() {
+        return somethingElse;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    @Override
+    public String toString() {
+        return getTitle() + ":" + getSomethingElse();
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Bar.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Bar.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/BarJunior.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/BarJunior.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/BarJunior.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/BarJunior.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,4 @@
+package com.opensymphony.xwork2.util;
+
+public class BarJunior extends Bar {
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/BarJunior.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/BarJunior.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Cat.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Cat.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Cat.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Cat.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import java.util.List;
+
+
+/**
+ * @author <a href="mailto:plightbo@cisco.com">Pat Lightbody</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+public class Cat {
+
+    public static final String SCIENTIFIC_NAME = "Feline";
+
+    Foo foo;
+    List kittens;
+    String name;
+
+
+    public void setFoo(Foo foo) {
+        this.foo = foo;
+    }
+
+    public Foo getFoo() {
+        return foo;
+    }
+
+    public void setKittens(List kittens) {
+        this.kittens = kittens;
+    }
+
+    public List getKittens() {
+        return kittens;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Cat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Cat.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ClassLoaderUtilTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ClassLoaderUtilTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ClassLoaderUtilTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ClassLoaderUtilTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import junit.framework.TestCase;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Arrays;
+import java.util.Enumeration;
+
+public class ClassLoaderUtilTest extends TestCase {
+
+    public void testGetResources() throws IOException {
+        Iterator<URL> i = ClassLoaderUtil.getResources("xwork-sample.xml", ClassLoaderUtilTest.class, false);
+        assertNotNull(i);
+        
+        assertTrue(i.hasNext());
+        URL url = i.next();
+        assertTrue(url.toString().endsWith("xwork-sample.xml"));
+        assertTrue(!i.hasNext());
+    }
+    
+    public void testGetResources_Multiple() throws IOException {
+        Iterator<URL> i = ClassLoaderUtil.getResources("xwork-1.0.dtd", ClassLoaderUtilTest.class, false);
+        assertNotNull(i);
+        
+        assertTrue(i.hasNext());
+        URL url = i.next();
+        assertTrue(url.toString().endsWith("xwork-1.0.dtd"));
+        url = i.next();
+        assertTrue(url.toString().endsWith("xwork-1.0.dtd"));
+        assertTrue(!i.hasNext());
+    }
+
+    public void testGetResources_Aggregate() throws IOException {
+        Iterator<URL> i = ClassLoaderUtil.getResources("xwork-1.0.dtd", ClassLoaderUtilTest.class, true);
+        assertNotNull(i);
+
+        assertTrue(i.hasNext());
+        URL url = i.next();
+        assertTrue(url.toString().endsWith("xwork-1.0.dtd"));
+        url = i.next();
+        assertTrue(url.toString().endsWith("xwork-1.0.dtd"));
+        assertTrue(!i.hasNext());
+    }
+
+    public void testGetResources_None() throws IOException {
+        Iterator<URL> i = ClassLoaderUtil.getResources("asdfasdf.html", ClassLoaderUtilTest.class, false);
+        assertNotNull(i);
+        
+        assertTrue(!i.hasNext());
+    }
+
+    public void testGetResource() {
+        URL url = ClassLoaderUtil.getResource("xwork-sample.xml", ClassLoaderUtilTest.class);
+        assertNotNull(url);
+        
+        assertTrue(url.toString().endsWith("xwork-sample.xml"));
+    }
+    
+    public void testGetResource_None() {
+        URL url = ClassLoaderUtil.getResource("asf.xml", ClassLoaderUtilTest.class);
+        assertNull(url);
+    }
+
+    public void testAggregateIterator() {
+       ClassLoaderUtil.AggregateIterator<String> aggr = new ClassLoaderUtil.AggregateIterator<String>();
+
+       Enumeration en1 = new Enumeration() {
+           private Iterator itt = Arrays.asList("str1", "str1", "str3", "str1").iterator();
+           public boolean hasMoreElements() {
+               return itt.hasNext();
+           }
+
+           public Object nextElement() {
+               return itt.next();
+           }
+       };
+
+       Enumeration en2 = new Enumeration() {
+           private Iterator itt = Arrays.asList("str4", "str5").iterator();
+           public boolean hasMoreElements() {
+               return itt.hasNext();
+           }
+
+           public Object nextElement() {
+               return itt.next();
+           }
+       };
+
+
+       aggr.addEnumeration(en1);
+       aggr.addEnumeration(en2);
+
+       assertTrue(aggr.hasNext());
+       assertEquals("str1", aggr.next());
+
+       assertTrue(aggr.hasNext());
+       assertEquals("str3", aggr.next());
+
+       assertTrue(aggr.hasNext());
+       assertEquals("str4", aggr.next());
+
+       assertTrue(aggr.hasNext());
+       assertEquals("str5", aggr.next());
+
+       assertFalse(aggr.hasNext());
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ClassLoaderUtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ClassLoaderUtilTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ClassPathFinderTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ClassPathFinderTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ClassPathFinderTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ClassPathFinderTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,54 @@
+/*
+ * $Id$
+ *
+ * Copyright 2003-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.XWorkTestCase;
+
+import java.util.Vector;
+
+public class ClassPathFinderTest extends XWorkTestCase {
+	
+	public void testFinder() {
+		ClassPathFinder finder = new ClassPathFinder();
+		finder.setPattern("**/xwork-test-wildcard-*.xml");
+		Vector<String> found = finder.findMatches();
+		assertEquals(found.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-1.xml"), true );
+		assertEquals(found.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-2.xml"), true );
+		assertEquals(found.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-include.xml"), true );
+		assertEquals(found.contains("com/opensymphony/xwork2/config/providers/xwork-test-results.xml"), false);
+		
+		ClassPathFinder finder2 = new ClassPathFinder();
+		finder2.setPattern("com/*/xwork2/config/providers/xwork-test-wildcard-1.xml");
+		Vector<String> found2 = finder2.findMatches();
+		assertEquals(found2.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-1.xml"), true);
+		assertEquals(found2.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-2.xml"), false);
+		
+		ClassPathFinder finder3 = new ClassPathFinder();
+		finder3.setPattern("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-1.xml");
+		Vector<String> found3 = finder3.findMatches();
+		assertEquals(found3.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-1.xml"), true);
+		assertEquals(found3.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-2.xml"), false);
+		
+		ClassPathFinder finder4 = new ClassPathFinder();
+		finder4.setPattern("no/matches/*");
+		Vector<String> found4 = finder4.findMatches();
+		assertEquals(found4.isEmpty(), true);
+		
+	}
+
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ClassPathFinderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ClassPathFinderTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Dog.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Dog.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Dog.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Dog.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import java.io.Serializable;
+
+
+/**
+ * @author <a href="mailto:plightbo@cisco.com">Pat Lightbody</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+public class Dog implements Serializable {
+
+    public static final String SCIENTIFIC_NAME = "Canine";
+
+
+    Cat hates;
+    String name;
+    int[] childAges;
+    boolean male;
+    int age;
+    static String deity;
+
+
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    public int getAge() {
+        return age;
+    }
+
+    public void setChildAges(int[] childAges) {
+        this.childAges = childAges;
+    }
+
+    public int[] getChildAges() {
+        return childAges;
+    }
+
+    public void setException(String blah) throws Exception {
+        throw new Exception("This is expected");
+    }
+
+    public String getException() throws Exception {
+        throw new Exception("This is expected");
+    }
+
+    public void setHates(Cat hates) {
+        this.hates = hates;
+    }
+
+    public Cat getHates() {
+        return hates;
+    }
+
+    public void setMale(boolean male) {
+        this.male = male;
+    }
+
+    public boolean isMale() {
+        return male;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+    
+    public static String getDeity() {
+        return deity;
+    }
+
+    public static void setDeity(String deity) {
+        Dog.deity = deity;
+    }
+
+    public int computeDogYears() {
+        return age * 7;
+    }
+
+    public int multiplyAge(int by) {
+        return age * by;
+    }
+
+    /**
+     * @return null
+     */
+    public Integer nullMethod() {
+        return null;
+    }
+
+    /**
+     * a method which is safe to call with a null argument
+     *
+     * @param arg the Boolean to return
+     * @return arg, if it is not null, or Boolean.TRUE if arg is null
+     */
+    public Boolean nullSafeMethod(Boolean arg) {
+        return (arg == null) ? Boolean.TRUE : arg;
+    }
+
+    public void getBite() {
+        throw new RuntimeException("wuf wuf");
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Dog.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Dog.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/DomHelperTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/DomHelperTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/DomHelperTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/DomHelperTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.util.location.Location;
+import junit.framework.TestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+import java.io.StringReader;
+
+/**
+ * Test cases for {@link DomHelper}.
+ */
+public class DomHelperTest extends TestCase {
+
+    private String xml = "<!DOCTYPE foo [\n" +
+                         "<!ELEMENT foo (bar)>\n" +
+                         "<!ELEMENT bar (#PCDATA)>\n" +
+                         "]>\n" +
+                         "<foo>\n" +
+                         " <bar/>\n" +
+                         "</foo>\n";
+    
+    public void testParse() throws Exception {
+        InputSource in = new InputSource(new StringReader(xml));
+        in.setSystemId("foo://bar");
+        
+        Document doc = DomHelper.parse(in);
+        assertNotNull(doc);
+        assertTrue("Wrong root node",
+            "foo".equals(doc.getDocumentElement().getNodeName()));
+        
+        NodeList nl = doc.getElementsByTagName("bar");
+        assertTrue(nl.getLength() == 1);
+        
+        
+        
+    }
+    
+    public void testGetLocationObject() throws Exception {
+        InputSource in = new InputSource(new StringReader(xml));
+        in.setSystemId("foo://bar");
+        
+        Document doc = DomHelper.parse(in);
+        
+        NodeList nl = doc.getElementsByTagName("bar");
+        
+        Location loc = DomHelper.getLocationObject((Element)nl.item(0));
+        
+        assertNotNull(loc);
+        assertTrue("Should be line 6, was "+loc.getLineNumber(), 
+            6==loc.getLineNumber());
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/DomHelperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/DomHelperTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/FileManagerTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/FileManagerTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/FileManagerTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/FileManagerTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,36 @@
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.XWorkTestCase;
+
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * FileManager Tester.
+ *
+ * @author <Lukasz>
+ * @since <pre>02/18/2009</pre>
+ * @version 1.0
+ */
+public class FileManagerTest extends XWorkTestCase {
+
+    public void testGetFileInJar() throws Exception {
+        testLoadFile("xwork-jar.xml");
+        testLoadFile("xwork - jar.xml");
+        testLoadFile("xwork-zip.xml");
+        testLoadFile("xwork - zip.xml");
+        testLoadFile("xwork-jar2.xml");
+        testLoadFile("xwork - jar2.xml");
+        testLoadFile("xwork-zip2.xml");
+        testLoadFile("xwork - zip2.xml");
+    }
+
+    private void testLoadFile(String fileName) {
+        FileManager.setReloadingConfigs(true);
+        URL url = ClassLoaderUtil.getResource(fileName, FileManagerTest.class);
+        InputStream file = FileManager.loadFile(url, true);
+        assertNotNull(file);
+        assertFalse(!FileManager.fileNeedsReloading(fileName));
+    }
+
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/FileManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/FileManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Foo.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Foo.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Foo.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Foo.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import java.util.*;
+
+
+/**
+ * @author <a href="mailto:plightbo@cisco.com">Pat Lightbody</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+public class Foo {
+
+    Bar bar;
+    Date birthday;
+    Date event;
+    Date meeting;
+    Foo child;
+    List cats;
+    List moreCats;
+    List strings;
+    Collection barCollection;
+    Map catMap;
+    Map anotherCatMap;
+    String title;
+    long[] points;
+    Foo[] relatives;
+    boolean useful;
+    int number;
+    long aLong;
+    Calendar calendar;
+    BarJunior barJunior;
+
+    public BarJunior getBarJunior() {
+        return barJunior;
+    }
+
+    public void setBarJunior(BarJunior barJunior) {
+        this.barJunior = barJunior;
+    }
+
+    public void setALong(long aLong) {
+        this.aLong = aLong;
+    }
+
+    public long getALong() {
+        return aLong;
+    }
+
+    public void setBar(Bar bar) {
+        this.bar = bar;
+    }
+
+    public Bar getBar() {
+        return bar;
+    }
+
+    public void setBirthday(Date birthday) {
+        this.birthday = birthday;
+    }
+
+    public Date getBirthday() {
+        return birthday;
+    }
+
+    public void setCatMap(Map catMap) {
+        this.catMap = catMap;
+    }
+
+    public Map getCatMap() {
+        return catMap;
+    }
+
+    public void setCats(List cats) {
+        this.cats = cats;
+    }
+
+    public List getCats() {
+        return cats;
+    }
+
+    public void setChild(Foo child) {
+        this.child = child;
+    }
+
+    public Foo getChild() {
+        return child;
+    }
+
+    public void setNumber(int number) {
+        this.number = number;
+    }
+
+    public int getNumber() {
+        return number;
+    }
+
+    /**
+     * @return Returns the anotherCatMap.
+     */
+    public Map getAnotherCatMap() {
+        return anotherCatMap;
+    }
+
+    /**
+     * @param anotherCatMap The anotherCatMap to set.
+     */
+    public void setAnotherCatMap(Map anotherCatMap) {
+        this.anotherCatMap = anotherCatMap;
+    }
+
+    /**
+     * @return Returns the moreCats.
+     */
+    public List getMoreCats() {
+        return moreCats;
+    }
+
+    /**
+     * @param moreCats The moreCats to set.
+     */
+    public void setMoreCats(List moreCats) {
+        this.moreCats = moreCats;
+    }
+
+    /**
+     * @return Returns the catSet.
+     */
+    public Collection getBarCollection() {
+        return barCollection;
+    }
+
+    /**
+     * @param barCollection The barCollection to set.
+     */
+    public void setBarCollection(Collection barCollection) {
+        this.barCollection = barCollection;
+    }
+
+    public void setPoints(long[] points) {
+        this.points = points;
+    }
+
+    public long[] getPoints() {
+        return points;
+    }
+
+    public void setRelatives(Foo[] relatives) {
+        this.relatives = relatives;
+    }
+
+    public Foo[] getRelatives() {
+        return relatives;
+    }
+
+    public void setStrings(List strings) {
+        this.strings = strings;
+    }
+
+    public List getStrings() {
+        return strings;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setUseful(boolean useful) {
+        this.useful = useful;
+    }
+
+    public boolean isUseful() {
+        return useful;
+    }
+    
+    
+    public Date getEvent() {
+    	return event;
+    }
+    
+    public void setEvent(Date event) {
+    	this.event = event;
+    }
+    
+    public Date getMeeting() {
+    	return meeting;
+    }
+    
+    public void setMeeting(Date meeting) {
+    	this.meeting = meeting;
+    }
+
+    public Calendar getCalendar() {
+        return calendar;
+    }
+
+    public void setCalendar(Calendar calendar) {
+        this.calendar = calendar;
+    }     
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Foo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Foo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/FurColor.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/FurColor.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/FurColor.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/FurColor.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,9 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+public enum FurColor {
+    BROWN, BLACK, GREEN
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/FurColor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/FurColor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/GetPropertiesTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/GetPropertiesTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/GetPropertiesTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/GetPropertiesTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,40 @@
+/*
+ * Created on Jan 23, 2006
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.XWorkTestCase;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+
+/**
+ * @author Gabe
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class GetPropertiesTest extends XWorkTestCase {
+
+    public void testGetCollectionProperties()  {
+        doGetCollectionPropertiesTest(new ArrayList());
+        doGetCollectionPropertiesTest(new HashSet());
+        
+    }
+    
+    public void doGetCollectionPropertiesTest(Collection c) {
+        ValueStack vs = ActionContext.getContext().getValueStack();
+        Foo foo = new Foo();
+        foo.setBarCollection(c);
+        vs.push(foo);
+        assertEquals(Boolean.TRUE, vs.findValue("barCollection.isEmpty"));
+        assertEquals(Boolean.TRUE, vs.findValue("barCollection.empty"));
+        assertEquals(new Integer(0), vs.findValue("barCollection.size"));
+        assertTrue(vs.findValue("barCollection.iterator") instanceof java.util.Iterator);
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/GetPropertiesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/GetPropertiesTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Indexed.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Indexed.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Indexed.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Indexed.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,41 @@
+package com.opensymphony.xwork2.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author mimo
+ *
+ */
+public class Indexed {
+
+    public Object[] values = new Object[3];
+    public Map<String, Object> map = new HashMap<String, Object>();
+
+    public void setSimple(int i, Object v) {
+        values[i] = v;
+    }
+
+    public Object getSimple(int i) {
+        return values[i];
+    }
+
+
+
+    public void setIntegerMap(String key, Integer value) {
+        map.put(key, value);
+    }
+
+    public Integer getIntegerMap(String key) {
+        return (Integer) map.get(key);
+    }
+
+    public void setStringMap(String key, String value) {
+        map.put(key, value);
+    }
+
+    public String getStringMap(String key) {
+        return (String) map.get(key);
+    }
+
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Indexed.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Indexed.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ListHolder.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ListHolder.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ListHolder.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ListHolder.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,37 @@
+package com.opensymphony.xwork2.util;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * User: patrick Date: Dec 20, 2005 Time: 11:15:29 AM
+ */
+public class ListHolder {
+    List<Long> longs;
+    List<String> strings;
+    List<Date> dates;
+
+    public List<Long> getLongs() {
+        return longs;
+    }
+
+    public void setLongs(List<Long> longs) {
+        this.longs = longs;
+    }
+
+    public List<String> getStrings() {
+        return strings;
+    }
+
+    public void setStrings(List<String> strings) {
+        this.strings = strings;
+    }
+
+    public List<Date> getDates() {
+        return dates;
+    }
+
+    public void setDates(List<Date> dates) {
+        this.dates = dates;
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ListHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ListHolder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/LocalizedTextUtilTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/LocalizedTextUtilTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/LocalizedTextUtilTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/LocalizedTextUtilTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,249 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import com.mockobjects.dynamic.Mock;
+import com.opensymphony.xwork2.*;
+import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
+import com.opensymphony.xwork2.test.ModelDrivenAction2;
+import com.opensymphony.xwork2.test.TestBean2;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+
+/**
+ * Unit test for {@link LocalizedTextUtil}.
+ *
+ * @author jcarreira
+ * @author tm_jee
+ * 
+ * @version $Date$ $Id$
+ */
+public class LocalizedTextUtilTest extends XWorkTestCase {
+
+	public void testNpeWhenClassIsPrimitive() throws Exception {
+		ValueStack stack = ActionContext.getContext().getValueStack();
+		stack.push(new MyObject());
+		String result = LocalizedTextUtil.findText(MyObject.class, "someObj.someI18nKey", Locale.ENGLISH, "default message", null, stack);
+		System.out.println(result);
+	}
+	
+	public static class MyObject extends ActionSupport {
+		public boolean getSomeObj() {
+			return true;
+		}
+	}
+	
+	public void testActionGetTextWithNullObject() throws Exception {
+		MyAction action = new MyAction();
+		
+		Mock mockActionInvocation = new Mock(ActionInvocation.class);
+        mockActionInvocation.expectAndReturn("getAction", action);
+        ActionContext.getContext().setActionInvocation((ActionInvocation) mockActionInvocation.proxy());
+		ActionContext.getContext().getValueStack().push(action);
+		
+		String message = action.getText("barObj.title");
+		assertEquals("Title:", message);
+	}
+	
+	
+	public static class MyAction extends ActionSupport {
+		private Bar testBean2;
+		
+		public Bar getBarObj() {
+			return testBean2;
+		}
+		public void setBarObj(Bar testBean2) {
+			this.testBean2 = testBean2;
+		}
+	}
+	
+    public void testActionGetText() throws Exception {
+        ModelDrivenAction2 action = new ModelDrivenAction2();
+        TestBean2 bean = (TestBean2) action.getModel();
+        Bar bar = new Bar();
+        bean.setBarObj(bar);
+
+        Mock mockActionInvocation = new Mock(ActionInvocation.class);
+        mockActionInvocation.expectAndReturn("getAction", action);
+        ActionContext.getContext().setActionInvocation((ActionInvocation) mockActionInvocation.proxy());
+        ActionContext.getContext().getValueStack().push(action);
+        ActionContext.getContext().getValueStack().push(action.getModel());
+
+        String message = action.getText("barObj.title");
+        assertEquals("Title:", message);
+    }
+
+    public void testNullKeys() {
+        LocalizedTextUtil.findText(this.getClass(), null, Locale.getDefault());
+    }
+
+    public void testActionGetTextXXX() throws Exception {
+        LocalizedTextUtil.addDefaultResourceBundle("com/opensymphony/xwork2/util/FindMe");
+
+        SimpleAction action = new SimpleAction();
+
+        Mock mockActionInvocation = new Mock(ActionInvocation.class);
+        mockActionInvocation.expectAndReturn("getAction", action);
+        ActionContext.getContext().setActionInvocation((ActionInvocation) mockActionInvocation.proxy());
+        ActionContext.getContext().getValueStack().push(action);
+
+        String message = action.getText("bean.name");
+        String foundBean2 = action.getText("bean2.name");
+
+        assertEquals("Okay! You found Me!", foundBean2);
+        assertEquals("Haha you cant FindMe!", message);
+    }
+
+    public void testAddDefaultResourceBundle() {
+        String text = LocalizedTextUtil.findDefaultText("foo.range", Locale.getDefault());
+        assertNull("Found message when it should not be available.", null);
+
+        LocalizedTextUtil.addDefaultResourceBundle("com/opensymphony/xwork2/SimpleAction");
+
+        String message = LocalizedTextUtil.findDefaultText("foo.range", Locale.US);
+        assertEquals("Foo Range Message", message);
+    }
+
+    public void testAddDefaultResourceBundle2() throws Exception {
+        LocalizedTextUtil.addDefaultResourceBundle("com/opensymphony/xwork2/SimpleAction");
+
+        ActionProxy proxy = actionProxyFactory.createActionProxy("/", "packagelessAction", new HashMap<String, Object>(), false, true);
+        proxy.execute();
+    }
+
+    public void testDefaultMessage() throws Exception {
+        String message = LocalizedTextUtil.findDefaultText(XWorkMessages.ACTION_EXECUTION_ERROR, Locale.getDefault());
+        assertEquals("Error during Action invocation", message);
+    }
+
+    public void testDefaultMessageOverride() throws Exception {
+        String message = LocalizedTextUtil.findDefaultText(XWorkMessages.ACTION_EXECUTION_ERROR, Locale.getDefault());
+        assertEquals("Error during Action invocation", message);
+
+        LocalizedTextUtil.addDefaultResourceBundle("com/opensymphony/xwork2/test");
+
+        message = LocalizedTextUtil.findDefaultText(XWorkMessages.ACTION_EXECUTION_ERROR, Locale.getDefault());
+        assertEquals("Testing resource bundle override", message);
+    }
+
+    public void testFindTextInChildProperty() throws Exception {
+        ModelDriven action = new ModelDrivenAction2();
+        TestBean2 bean = (TestBean2) action.getModel();
+        Bar bar = new Bar();
+        bean.setBarObj(bar);
+
+        Mock mockActionInvocation = new Mock(ActionInvocation.class);
+        mockActionInvocation.expectAndReturn("hashCode", 0);
+        mockActionInvocation.expectAndReturn("getAction", action);
+        ActionContext.getContext().setActionInvocation((ActionInvocation) mockActionInvocation.proxy());
+        ActionContext.getContext().getValueStack().push(action);
+        ActionContext.getContext().getValueStack().push(action.getModel());
+
+        String message = LocalizedTextUtil.findText(ModelDrivenAction2.class, "invalid.fieldvalue.barObj.title", Locale.getDefault());
+        assertEquals("Title is invalid!", message);
+    }
+
+    public void testFindTextInInterface() throws Exception {
+        Action action = new ModelDrivenAction2();
+        Mock mockActionInvocation = new Mock(ActionInvocation.class);
+        mockActionInvocation.expectAndReturn("getAction", action);
+        ActionContext.getContext().setActionInvocation((ActionInvocation) mockActionInvocation.proxy());
+
+        String message = LocalizedTextUtil.findText(ModelDrivenAction2.class, "test.foo", Locale.getDefault());
+        assertEquals("Foo!", message);
+    }
+
+    public void testFindTextInPackage() throws Exception {
+        ModelDriven action = new ModelDrivenAction2();
+
+        Mock mockActionInvocation = new Mock(ActionInvocation.class);
+        mockActionInvocation.expectAndReturn("getAction", action);
+        ActionContext.getContext().setActionInvocation((ActionInvocation) mockActionInvocation.proxy());
+
+        String message = LocalizedTextUtil.findText(ModelDrivenAction2.class, "package.properties", Locale.getDefault());
+        assertEquals("It works!", message);
+    }
+
+    public void testParameterizedDefaultMessage() throws Exception {
+        String message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_ACTION_EXCEPTION, Locale.getDefault(), new String[]{"AddUser"});
+        assertEquals("There is no Action mapped for action name AddUser.", message);
+    }
+
+    public void testParameterizedDefaultMessageWithPackage() throws Exception {
+        String message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_PACKAGE_ACTION_EXCEPTION, Locale.getDefault(), new String[]{"blah", "AddUser"});
+        assertEquals("There is no Action mapped for namespace blah and action name AddUser.", message);
+    }
+
+    public void testLocalizedDateFormatIsUsed() {
+        LocalizedTextUtil.addDefaultResourceBundle("com/opensymphony/xwork2/util/LocalizedTextUtilTest");
+        Object[] params = new Object[]{new Date()};
+        String usDate = LocalizedTextUtil.findDefaultText("test.format.date", Locale.US, params);
+        String germanDate = LocalizedTextUtil.findDefaultText("test.format.date", Locale.GERMANY, params);
+        assertFalse(usDate.equals(germanDate));
+    }
+
+    public void testXW377() {
+        LocalizedTextUtil.addDefaultResourceBundle("com/opensymphony/xwork2/util/LocalizedTextUtilTest");
+
+        String text = LocalizedTextUtil.findText(Bar.class, "xw377", ActionContext.getContext().getLocale(), "xw377", null, ActionContext.getContext().getValueStack());
+        assertEquals("xw377", text); // should not log
+
+        String text2 = LocalizedTextUtil.findText(LocalizedTextUtilTest.class, "notinbundle", ActionContext.getContext().getLocale(), "hello", null, ActionContext.getContext().getValueStack());
+        assertEquals("hello", text2); // should log WARN
+
+        String text3 = LocalizedTextUtil.findText(LocalizedTextUtilTest.class, "notinbundle.key", ActionContext.getContext().getLocale(), "notinbundle.key", null, ActionContext.getContext().getValueStack());
+        assertEquals("notinbundle.key", text3); // should log WARN
+
+        String text4 = LocalizedTextUtil.findText(LocalizedTextUtilTest.class, "xw377", ActionContext.getContext().getLocale(), "hello", null, ActionContext.getContext().getValueStack());
+        assertEquals("xw377", text4); // should not log
+
+        String text5 = LocalizedTextUtil.findText(LocalizedTextUtilTest.class, "username", ActionContext.getContext().getLocale(), null, null, ActionContext.getContext().getValueStack());
+        assertEquals("Santa", text5); // should not log
+    }
+
+    public void testXW404() {
+        // This tests will try to load bundles from the 3 locales but we only have files for France and Germany.
+        // Before this fix loading the bundle for Germany failed since Italy have previously failed and thus the misses cache
+        // contained a false entry
+
+        // Set default Locale to Locale.US
+        Locale defaultLocale = Locale.getDefault();
+        Locale.setDefault(Locale.US);
+
+        ResourceBundle rbFrance = LocalizedTextUtil.findResourceBundle("com/opensymphony/xwork2/util/XW404", Locale.FRANCE);
+        ResourceBundle rbItaly = LocalizedTextUtil.findResourceBundle("com/opensymphony/xwork2/util/XW404", Locale.ITALY);
+        ResourceBundle rbGermany = LocalizedTextUtil.findResourceBundle("com/opensymphony/xwork2/util/XW404", Locale.GERMANY);
+
+        // Reset to previous default Locale 
+        Locale.setDefault(defaultLocale);
+
+        assertNotNull(rbFrance);
+        assertEquals("Bonjour", rbFrance.getString("hello"));
+
+        assertNull(rbItaly);
+
+        assertNotNull(rbGermany);
+        assertEquals("Hallo", rbGermany.getString("hello"));
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        loadConfigurationProviders(new XmlConfigurationProvider("xwork-sample.xml"));
+
+        ActionContext.getContext().setLocale(Locale.US);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        LocalizedTextUtil.clearDefaultResourceBundles();
+    }
+
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/LocalizedTextUtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/LocalizedTextUtilTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBean.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBean.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBean.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBean.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import java.io.Serializable;
+
+/**
+ * <code>MyBean</code>
+ *
+ * @author Rainer Hermanns
+ */
+public class MyBean implements Serializable {
+
+    private Long id;
+    private String name;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+
+    @Override
+    public String toString() {
+        return "MyBean{" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                '}';
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBeanAction.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBeanAction.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBeanAction.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBeanAction.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.Action;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <code>MyBeanAction</code>
+ *
+ * @author Rainer Hermanns
+ */
+public class MyBeanAction implements Action {
+
+    private List beanList = new ArrayList();
+    private Map beanMap = new HashMap();
+
+    public List getBeanList() {
+        return beanList;
+    }
+
+    public void setBeanList(List beanList) {
+        this.beanList = beanList;
+    }
+
+    public Map getBeanMap() {
+        return beanMap;
+    }
+
+    public void setBeanMap(Map beanMap) {
+        this.beanMap = beanMap;
+    }
+
+    public String execute() throws Exception {
+        return SUCCESS;
+    }
+
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBeanAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBeanAction.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBeanActionTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBeanActionTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBeanActionTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBeanActionTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionProxy;
+import com.opensymphony.xwork2.XWorkTestCase;
+import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * <code>MyBeanActionTest</code>
+ *
+ * @author Rainer Hermanns
+ */
+public class MyBeanActionTest extends XWorkTestCase {
+
+    public void testIndexedList() {
+        HashMap<String, Object> params = new HashMap<String, Object>();
+        params.put("beanList(1234567890).name", "This is the bla bean");
+        params.put("beanList(1234567891).name", "This is the 2nd bla bean");
+
+        HashMap<String, Object> extraContext = new HashMap<String, Object>();
+        extraContext.put(ActionContext.PARAMETERS, params);
+
+        try {
+            ActionProxy proxy = actionProxyFactory.createActionProxy("", "MyBean", extraContext);
+            proxy.execute();
+            assertEquals(2, Integer.parseInt(proxy.getInvocation().getStack().findValue("beanList.size").toString()));
+            assertEquals(MyBean.class.getName(), proxy.getInvocation().getStack().findValue("beanList.get(0)").getClass().getName());
+            assertEquals(MyBean.class.getName(), proxy.getInvocation().getStack().findValue("beanList.get(1)").getClass().getName());
+
+            assertEquals("This is the bla bean", proxy.getInvocation().getStack().findValue("beanList.get(0).name"));
+            assertEquals(new Long(1234567890), Long.valueOf(proxy.getInvocation().getStack().findValue("beanList.get(0).id").toString()));
+            assertEquals("This is the 2nd bla bean", proxy.getInvocation().getStack().findValue("beanList.get(1).name"));
+            assertEquals(new Long(1234567891), Long.valueOf(proxy.getInvocation().getStack().findValue("beanList.get(1).id").toString()));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+
+    public void testIndexedMap() {
+        HashMap<String, Object> params = new HashMap<String, Object>();
+        params.put("beanMap[1234567890].id", "1234567890");
+        params.put("beanMap[1234567891].id", "1234567891");
+
+        params.put("beanMap[1234567890].name", "This is the bla bean");
+        params.put("beanMap[1234567891].name", "This is the 2nd bla bean");
+
+        HashMap<String, Object> extraContext = new HashMap<String, Object>();
+        extraContext.put(ActionContext.PARAMETERS, params);
+
+        try {
+            ActionProxy proxy = actionProxyFactory.createActionProxy("", "MyBean", extraContext);
+            proxy.execute();
+            MyBeanAction action = (MyBeanAction) proxy.getInvocation().getAction();
+
+            assertEquals(2, Integer.parseInt(proxy.getInvocation().getStack().findValue("beanMap.size").toString()));
+
+            Map map = (Map) proxy.getInvocation().getStack().findValue("beanMap");
+            assertEquals(true, action.getBeanMap().containsKey(new Long(1234567890)));
+            assertEquals(true, action.getBeanMap().containsKey(new Long(1234567891)));
+
+
+            assertEquals(MyBean.class.getName(), proxy.getInvocation().getStack().findValue("beanMap.get(1234567890L)").getClass().getName());
+            assertEquals(MyBean.class.getName(), proxy.getInvocation().getStack().findValue("beanMap.get(1234567891L)").getClass().getName());
+
+            assertEquals("This is the bla bean", proxy.getInvocation().getStack().findValue("beanMap.get(1234567890L).name"));
+            assertEquals("This is the 2nd bla bean", proxy.getInvocation().getStack().findValue("beanMap.get(1234567891L).name"));
+
+            assertEquals("1234567890", proxy.getInvocation().getStack().findValue("beanMap.get(1234567890L).id").toString());
+            assertEquals("1234567891", proxy.getInvocation().getStack().findValue("beanMap.get(1234567891L).id").toString());
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // ensure we're using the default configuration, not simple config
+        loadConfigurationProviders(new XmlConfigurationProvider("xwork-sample.xml"));
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBeanActionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/MyBeanActionTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcherTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcherTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcherTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcherTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.util.NamedVariablePatternMatcher.CompiledPattern;
+import junit.framework.TestCase;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+public class NamedVariablePatternMatcherTest extends TestCase {
+
+    public void testCompile() {
+        NamedVariablePatternMatcher matcher = new NamedVariablePatternMatcher();
+
+        assertNull(matcher.compilePattern(null));
+        assertNull(matcher.compilePattern(""));
+
+        CompiledPattern pattern = matcher.compilePattern("foo");
+        assertEquals("foo", pattern.getPattern().pattern());
+
+        pattern = matcher.compilePattern("foo{jim}");
+        assertEquals("foo([^/]+)", pattern.getPattern().pattern());
+        assertEquals("jim", pattern.getVariableNames().get(0));
+
+        pattern = matcher.compilePattern("foo{jim}/{bob}");
+        assertEquals("foo([^/]+)/([^/]+)", pattern.getPattern().pattern());
+        assertEquals("jim", pattern.getVariableNames().get(0));
+        assertEquals("bob", pattern.getVariableNames().get(1));
+        assertTrue(pattern.getPattern().matcher("foostar/jie").matches());
+        assertFalse(pattern.getPattern().matcher("foo/star/jie").matches());
+    }
+
+    public void testMatch() {
+        NamedVariablePatternMatcher matcher = new NamedVariablePatternMatcher();
+
+        Map<String,String> vars = new HashMap<String,String>();
+        CompiledPattern pattern = new CompiledPattern(Pattern.compile("foo([^/]+)"), Arrays.asList("bar"));
+
+        assertTrue(matcher.match(vars, "foobaz", pattern));
+        assertEquals("baz", vars.get("bar"));
+    }
+
+    public void testIsLiteral() {
+        NamedVariablePatternMatcher matcher = new NamedVariablePatternMatcher();
+
+        assertTrue(matcher.isLiteral("bob"));
+        assertFalse(matcher.isLiteral("bob{jim}"));
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcherTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcherTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Owner.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Owner.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Owner.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Owner.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class Owner {
+
+    private Dog dog;
+
+
+    public void setDog(Dog dog) {
+        this.dog = dog;
+    }
+
+    public Dog getDog() {
+        return dog;
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Owner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Owner.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ResolverUtilTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ResolverUtilTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ResolverUtilTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ResolverUtilTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.ObjectFactory;
+import com.opensymphony.xwork2.spring.SpringObjectFactory;
+import junit.framework.TestCase;
+
+import java.net.URL;
+import java.util.Set;
+
+public class ResolverUtilTest extends TestCase {
+
+    public void testSimpleFind() throws Exception {
+        ResolverUtil<ObjectFactory> resolver = new ResolverUtil<ObjectFactory>();
+        resolver.findImplementations(ObjectFactory.class, "com");
+        Set<Class<? extends ObjectFactory>> impls = resolver.getClasses();
+        
+        assertTrue(impls.contains(ObjectFactory.class));
+        assertTrue(impls.contains(SpringObjectFactory.class));
+    }
+    
+    public void testMissingSomeFind() throws Exception {
+        ResolverUtil<ObjectFactory> resolver = new ResolverUtil<ObjectFactory>();
+        resolver.findImplementations(ObjectFactory.class, "com.opensymphony.xwork2.spring");
+        Set<Class<? extends ObjectFactory>> impls = resolver.getClasses();
+        
+        assertFalse(impls.contains(ObjectFactory.class));
+        assertTrue(impls.contains(SpringObjectFactory.class));
+    }
+    
+    public void testFindNamedResource() throws Exception {
+        ResolverUtil resolver = new ResolverUtil();
+        resolver.findNamedResource("xwork-default.xml", "");
+        Set<URL> impls = resolver.getResources();
+        
+        assertTrue(impls.size() > 0);
+    }
+    
+    public void testFindNamedResourceInDir() throws Exception {
+        ResolverUtil resolver = new ResolverUtil();
+        resolver.findNamedResource("SimpleAction.properties", "com/opensymphony");
+        Set<URL> impls = resolver.getResources();
+        
+        assertTrue(impls.size() > 0);
+    }
+
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ResolverUtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/ResolverUtilTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/TextParseUtilTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/TextParseUtilTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/TextParseUtilTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/TextParseUtilTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.XWorkTestCase;
+
+import java.util.*;
+
+/**
+ * Unit test of {@link TextParseUtil}.
+ *
+ * @author plightbo
+ * @author tm_jee
+ *
+ * @version $Date$ $Id$
+ */
+public class TextParseUtilTest extends XWorkTestCase {
+
+
+	public void testTranslateVariablesWithEvaluator() throws Exception {
+		ValueStack stack = ActionContext.getContext().getValueStack();
+		stack.push(new Object() {
+			public String getMyVariable() {
+				return "My Variable ";
+			}
+		});
+
+		TextParseUtil.ParsedValueEvaluator evaluator = new TextParseUtil.ParsedValueEvaluator() {
+			public Object evaluate(Object parsedValue) {
+				return parsedValue.toString()+"Something";
+			}
+		};
+
+		String result = TextParseUtil.translateVariables("Hello ${myVariable}", stack, evaluator);
+
+		assertEquals(result, "Hello My Variable Something");
+	}
+
+    public void testTranslateVariables() {
+        ValueStack stack = ActionContext.getContext().getValueStack();
+
+        Object s = TextParseUtil.translateVariables("foo: ${{1, 2, 3}}, bar: ${1}", stack);
+        assertEquals("foo: [1, 2, 3], bar: 1", s);
+
+        s = TextParseUtil.translateVariables("foo: %{{1, 2, 3}}, bar: %{1}", stack);
+        assertEquals("foo: [1, 2, 3], bar: 1", s);
+
+        s = TextParseUtil.translateVariables("foo: %{{1, 2, 3}}, bar: %{1}", stack);
+        assertEquals("foo: [1, 2, 3], bar: 1", s);
+
+        s = TextParseUtil.translateVariables("foo: ${#{1 : 2, 3 : 4}}, bar: ${1}", stack);
+        assertEquals("foo: {1=2, 3=4}, bar: 1", s);
+
+        s = TextParseUtil.translateVariables("foo: %{#{1 : 2, 3 : 4}}, bar: %{1}", stack);
+        assertEquals("foo: {1=2, 3=4}, bar: 1", s);
+
+        s = TextParseUtil.translateVariables("foo: 1}", stack);
+        assertEquals("foo: 1}", s);
+
+        s = TextParseUtil.translateVariables("foo: {1}", stack);
+        assertEquals("foo: {1}", s);
+
+        s = TextParseUtil.translateVariables("foo: ${1", stack);
+        assertEquals("foo: ${1", s);
+
+        s = TextParseUtil.translateVariables("foo: %{1", stack);
+        assertEquals("foo: %{1", s);
+
+        s =  TextParseUtil.translateVariables('$', "${{1, 2, 3}}", stack, Object.class);
+        assertNotNull(s);
+        assertTrue("List not returned when parsing a 'pure' list", s instanceof List);
+        assertEquals(((List)s).size(), 3);
+
+        s = TextParseUtil.translateVariables('$', "${#{'key1':'value1','key2':'value2','key3':'value3'}}", stack, Object.class);
+        assertNotNull(s);
+        assertTrue("Map not returned when parsing a 'pure' map", s instanceof Map);
+        assertEquals(((Map)s).size(), 3);
+
+        s =  TextParseUtil.translateVariables('$', "${1} two ${3}", stack, Object.class);
+        assertEquals("1 two 3", s);
+
+        s = TextParseUtil.translateVariables('$', "count must be between ${123} and ${456}, current value is ${98765}.", stack, Object.class);
+        assertEquals("count must be between 123 and 456, current value is 98765.", s);
+    }
+
+    public void testCommaDelimitedStringToSet() {
+        assertEquals(0, TextParseUtil.commaDelimitedStringToSet("").size());
+        assertEquals(new HashSet<String>(Arrays.asList("foo", "bar", "tee")),
+                TextParseUtil.commaDelimitedStringToSet(" foo, bar,tee"));
+    }
+
+    public void testTranslateVariablesOpenChar() {
+        // just a quick test to see if the open char works
+        // most test are done the methods above
+        ValueStack stack = ActionContext.getContext().getValueStack();
+
+        Object s = TextParseUtil.translateVariables('$', "foo: ${{1, 2, 3}}, bar: ${1}", stack);
+        assertEquals("foo: [1, 2, 3], bar: 1", s);
+
+        Object s2 = TextParseUtil.translateVariables('#', "foo: #{{1, 2, 3}}, bar: #{1}", stack);
+        assertEquals("foo: [1, 2, 3], bar: 1", s2);
+    }
+
+    public void testTranslateNoVariables() {
+        ValueStack stack = ActionContext.getContext().getValueStack();
+
+        Object s = TextParseUtil.translateVariables('$', "foo: ${}", stack);
+        assertEquals("foo: ", s);
+    }
+
+    public void testTranslateVariablesNoRecursive() {
+        ValueStack stack = ActionContext.getContext().getValueStack();
+        stack.push(new HashMap<String, Object>() {{ put("foo", "${1+1}"); }});
+
+        Object s = TextParseUtil.translateVariables('$', "foo: ${foo}", stack, String.class, null, 1);
+        assertEquals("foo: ${1+1}", s);
+    }
+
+    public void testTranslateVariablesRecursive() {
+        ValueStack stack = ActionContext.getContext().getValueStack();
+        stack.push(new HashMap<String, Object>() {{ put("foo", "${1+1}"); }});
+
+        Object s = TextParseUtil.translateVariables('$', "foo: ${foo}", stack, String.class, null, 2);
+        assertEquals("foo: 2", s);
+    }
+
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/TextParseUtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/TextParseUtilTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Tiger.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Tiger.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Tiger.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Tiger.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import java.util.List;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class Tiger extends Cat {
+
+    List dogs;
+
+
+    public void setDogs(List dogs) {
+        this.dogs = dogs;
+    }
+
+    public List getDogs() {
+        return dogs;
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Tiger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/util/Tiger.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message