You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2015/06/17 23:09:20 UTC
[20/57] [partial] struts git commit: Merges xwork packages into struts
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java b/core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java
new file mode 100644
index 0000000..6aa6f7b
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java
@@ -0,0 +1,375 @@
+package com.opensymphony.xwork2.spring;
+
+/*
+ * Copyright 2002-2003,2009 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.
+ */
+/*
+ * Created on Mar 8, 2004
+ */
+
+import com.opensymphony.xwork2.*;
+import com.opensymphony.xwork2.config.ConfigurationException;
+import com.opensymphony.xwork2.config.entities.ActionConfig;
+import com.opensymphony.xwork2.config.entities.InterceptorConfig;
+import com.opensymphony.xwork2.config.entities.ResultConfig;
+import com.opensymphony.xwork2.inject.ContainerBuilder;
+import com.opensymphony.xwork2.interceptor.Interceptor;
+import com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor;
+import com.opensymphony.xwork2.interceptor.TimerInterceptor;
+import com.opensymphony.xwork2.test.StubConfigurationProvider;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
+import com.opensymphony.xwork2.validator.Validator;
+import com.opensymphony.xwork2.validator.validators.ExpressionValidator;
+import com.opensymphony.xwork2.validator.validators.RequiredStringValidator;
+import org.springframework.aop.framework.Advised;
+import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
+import org.springframework.aop.interceptor.DebugInterceptor;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.MutablePropertyValues;
+import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.support.StaticApplicationContext;
+
+import java.util.HashMap;
+import java.util.Map;
+
+// TODO: Document properly
+
+/**
+ * @author Simon Stewart
+ */
+public class SpringObjectFactoryTest extends XWorkTestCase {
+
+ StaticApplicationContext sac;
+ SpringObjectFactory objectFactory;
+
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ sac = new StaticApplicationContext();
+ loadConfigurationProviders(new StubConfigurationProvider() {
+
+ @Override
+ public void register(ContainerBuilder builder,
+ LocatableProperties props) throws ConfigurationException {
+ builder.factory(ObjectFactory.class, SpringObjectFactory.class);
+ }
+
+ });
+
+ objectFactory = (SpringObjectFactory) container.getInstance(ObjectFactory.class);
+ objectFactory.setApplicationContext(sac);
+ objectFactory.setAlwaysRespectAutowireStrategy(false);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ sac = null;
+ objectFactory = null;
+ }
+
+ public void testFallsBackToDefaultObjectFactoryActionSearching() throws Exception {
+ ActionConfig actionConfig = new ActionConfig.Builder("foo", "bar", ModelDrivenAction.class.getName()).build();
+
+ Object action = objectFactory.buildBean(actionConfig.getClassName(), null);
+
+ assertEquals(ModelDrivenAction.class, action.getClass());
+ }
+
+ public void testFallsBackToDefaultObjectFactoryInterceptorBuilding() throws Exception {
+ InterceptorConfig iConfig = new InterceptorConfig.Builder("timer", ModelDrivenInterceptor.class.getName()).build();
+
+ Interceptor interceptor = objectFactory.buildInterceptor(iConfig, new HashMap<String, String>());
+
+ assertEquals(ModelDrivenInterceptor.class, interceptor.getClass());
+ }
+
+ public void testFallsBackToDefaultObjectFactoryResultBuilding() throws Exception {
+ ResultConfig rConfig = new ResultConfig.Builder(Action.SUCCESS, ActionChainResult.class.getName()).build();
+ Result result = objectFactory.buildResult(rConfig, ActionContext.getContext().getContextMap());
+
+ assertEquals(ActionChainResult.class, result.getClass());
+ }
+
+ public void testFallsBackToDefaultObjectFactoryValidatorBuilding() throws Exception {
+ Map<String, Object> extraContext = new HashMap<>();
+ Validator validator = objectFactory.buildValidator(RequiredStringValidator.class.getName(), new HashMap<String, Object>(), extraContext);
+
+ assertEquals(RequiredStringValidator.class, validator.getClass());
+ }
+
+ public void testObtainActionBySpringName() throws Exception {
+ sac.registerPrototype("simple-action", SimpleAction.class, new MutablePropertyValues());
+
+ ActionConfig actionConfig = new ActionConfig.Builder("fs", "jim", "simple-action").build();
+ Object action = objectFactory.buildBean(actionConfig.getClassName(), null);
+
+ assertEquals(SimpleAction.class, action.getClass());
+ }
+
+ public void testObtainInterceptorBySpringName() throws Exception {
+ sac.registerSingleton("timer-interceptor", TimerInterceptor.class, new MutablePropertyValues());
+
+ InterceptorConfig iConfig = new InterceptorConfig.Builder("timer", "timer-interceptor").build();
+ Interceptor interceptor = objectFactory.buildInterceptor(iConfig, new HashMap<String, String>());
+
+ assertEquals(TimerInterceptor.class, interceptor.getClass());
+ }
+
+ public void testObtainResultBySpringName() throws Exception {
+ // TODO: Does this need to be a prototype?
+ sac.registerPrototype("chaining-result", ActionChainResult.class, new MutablePropertyValues());
+
+ ResultConfig rConfig = new ResultConfig.Builder(Action.SUCCESS, "chaining-result").build();
+ Result result = objectFactory.buildResult(rConfig, ActionContext.getContext().getContextMap());
+
+ assertEquals(ActionChainResult.class, result.getClass());
+ }
+
+ public void testObtainValidatorBySpringName() throws Exception {
+ sac.registerPrototype("expression-validator", ExpressionValidator.class, new MutablePropertyValues());
+
+ Map<String, Object> extraContext = new HashMap<>();
+ Validator validator = objectFactory.buildValidator("expression-validator", new HashMap<String, Object>(), extraContext);
+
+ assertEquals(ExpressionValidator.class, validator.getClass());
+ }
+
+ public void testShouldAutowireObjectsObtainedFromTheObjectFactoryByFullClassName() throws Exception {
+ sac.getBeanFactory().registerSingleton("bean", new TestBean());
+ TestBean bean = (TestBean) sac.getBean("bean");
+
+ SimpleAction action = (SimpleAction) objectFactory.buildBean(SimpleAction.class.getName(), null);
+
+ assertEquals(bean, action.getBean());
+ }
+
+ public void testShouldGiveReferenceToAppContextIfBeanIsApplicationContextAwareAndNotInstantiatedViaSpring() throws Exception {
+ Foo foo = (Foo) objectFactory.buildBean(Foo.class.getName(), null);
+
+ assertTrue("Expected app context to have been set", foo.isApplicationContextSet());
+ }
+
+ public static class Foo implements ApplicationContextAware {
+ boolean applicationContextSet = false;
+
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ applicationContextSet = true;
+ }
+
+ public boolean isApplicationContextSet() {
+ return applicationContextSet;
+ }
+ }
+
+ public void testShouldAutowireObjectsObtainedFromTheObjectFactoryByClass() throws Exception {
+ sac.getBeanFactory().registerSingleton("bean", new TestBean());
+ TestBean bean = (TestBean) sac.getBean("bean");
+
+ SimpleAction action = (SimpleAction) objectFactory.buildBean(SimpleAction.class, null);
+
+ assertEquals(bean, action.getBean());
+ }
+
+ public void testShouldGiveReferenceToAppContextIfBeanIsLoadedByClassApplicationContextAwareAndNotInstantiatedViaSpring() throws Exception {
+ Foo foo = (Foo) objectFactory.buildBean(Foo.class, null);
+
+ assertTrue("Expected app context to have been set", foo.isApplicationContextSet());
+ }
+
+ public void testLookingUpAClassInstanceDelegatesToSpring() throws Exception {
+ sac.registerPrototype("simple-action", SimpleAction.class, new MutablePropertyValues());
+
+ Class clazz = objectFactory.getClassInstance("simple-action");
+
+ assertNotNull("Nothing returned", clazz);
+ assertEquals("Expected to have instance of SimpleAction returned", SimpleAction.class, clazz);
+ }
+
+ public void testLookingUpAClassInstanceFallsBackToTheDefaultObjectFactoryIfSpringBeanNotFound() throws Exception {
+ Class clazz = objectFactory.getClassInstance(SimpleAction.class.getName());
+
+ assertNotNull("Nothing returned", clazz);
+ assertEquals("Expected to have instance of SimpleAction returned", SimpleAction.class, clazz);
+ }
+
+ public void testSetAutowireStrategy() throws Exception {
+ assertEquals(objectFactory.getAutowireStrategy(), AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
+
+ objectFactory.setAutowireStrategy(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE);
+
+ sac.getBeanFactory().registerSingleton("bean", new TestBean());
+ TestBean bean = (TestBean) sac.getBean("bean");
+
+ sac.registerPrototype("simple-action", SimpleAction.class, new MutablePropertyValues());
+
+ ActionConfig actionConfig = new ActionConfig.Builder("jim", "bob", "simple-action").build();
+ SimpleAction simpleAction = (SimpleAction) objectFactory.buildBean(actionConfig.getClassName(), null);
+ objectFactory.autoWireBean(simpleAction);
+ assertEquals(simpleAction.getBean(), bean);
+ }
+
+ public void testShouldUseConstructorBasedInjectionWhenCreatingABeanFromAClassName() throws Exception {
+ SpringObjectFactory factory = (SpringObjectFactory) objectFactory;
+ objectFactory.setAlwaysRespectAutowireStrategy(false);
+ sac.registerSingleton("actionBean", SimpleAction.class, new MutablePropertyValues());
+
+ ConstructorBean bean = (ConstructorBean) factory.buildBean(ConstructorBean.class, null);
+
+ assertNotNull("Bean should not be null", bean);
+ assertNotNull("Action should have been added via DI", bean.getAction());
+ }
+
+ public void testShouldUseAutowireStrategyWhenCreatingABeanFromAClassName_constructor() throws Exception {
+ objectFactory.setAlwaysRespectAutowireStrategy(true);
+ objectFactory.setAutowireStrategy(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR);
+ sac.registerSingleton("actionBean", SimpleAction.class, new MutablePropertyValues());
+
+ ConstructorBean bean = (ConstructorBean) objectFactory.buildBean(ConstructorBean.class, null);
+
+ assertNotNull("Bean should not be null", bean);
+ assertNotNull("Action should have been added via DI", bean.getAction());
+ }
+
+ public void testShouldUseAutowireStrategyWhenCreatingABeanFromAClassName_setterByType() throws Exception {
+ objectFactory.setAlwaysRespectAutowireStrategy(true);
+
+ objectFactory.setAutowireStrategy(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE);
+ sac.registerSingleton("actionBean", SimpleAction.class, new MutablePropertyValues());
+
+ SetterByTypeBean bean = (SetterByTypeBean) objectFactory.buildBean(SetterByTypeBean.class, null);
+
+ assertNotNull("Bean should not be null", bean);
+ assertNotNull("Action should have been added via DI", bean.getAction());
+ }
+
+ public void testShouldUseAutowireStrategyWhenCreatingABeanFromAClassName_setterByName() throws Exception {
+ objectFactory.setAlwaysRespectAutowireStrategy(true);
+
+ objectFactory.setAutowireStrategy(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
+ sac.registerSingleton("actionBean", SimpleAction.class, new MutablePropertyValues());
+
+ SetterByNameBean bean = (SetterByNameBean) objectFactory.buildBean(SetterByNameBean.class, null);
+
+ assertNotNull("Bean should not be null", bean);
+ assertNotNull("Action should have been added via DI", bean.getActionBean());
+ }
+
+ public void testFallBackToDefaultObjectFactoryWhenTheCConstructorDIIsAmbiguous() throws Exception {
+ objectFactory.setAlwaysRespectAutowireStrategy(true);
+ sac.registerSingleton("firstActionBean", SimpleAction.class, new MutablePropertyValues());
+ sac.registerSingleton("secondActionBean", SimpleAction.class, new MutablePropertyValues());
+
+ ConstructorBean bean = (ConstructorBean) objectFactory.buildBean(ConstructorBean.class, null);
+
+ assertNotNull("Bean should have been created using default constructor", bean);
+ assertNull("Not expecting this to have been set", bean.getAction());
+ }
+
+ public void testObjectFactoryUsesSpringObjectFactoryToCreateActions() throws Exception {
+ sac.registerSingleton("actionBean", SimpleAction.class, new MutablePropertyValues());
+ ActionConfig actionConfig = new ActionConfig.Builder("as", "as", ConstructorAction.class.getName()).build();
+
+ ConstructorAction action = (ConstructorAction) objectFactory.buildBean(actionConfig.getClassName(), null);
+
+ assertNotNull("Bean should not be null", action);
+ assertNotNull("Action should have been added via DI", action.getAction());
+ }
+
+ public void testShouldUseApplicationContextToApplyAspectsToGeneratedBeans() throws Exception {
+ sac.registerSingleton("debugInterceptor", DebugInterceptor.class, new MutablePropertyValues());
+
+ MutablePropertyValues values = new MutablePropertyValues();
+ values.addPropertyValue("beanNames", new String[]{"*Action"});
+ values.addPropertyValue("interceptorNames", new String[]{"debugInterceptor"});
+ sac.registerSingleton("proxyFactory", BeanNameAutoProxyCreator.class, values);
+
+ sac.refresh();
+
+ ActionConfig actionConfig = new ActionConfig.Builder("", "", SimpleAction.class.getName()).build();
+ Action action = (Action) objectFactory.buildBean(actionConfig.getClassName(), null);
+
+ assertNotNull("Bean should not be null", action);
+ System.out.println("Action class is: " + action.getClass().getName());
+ assertTrue("Action should have been advised", action instanceof Advised);
+ }
+
+ public static class ConstructorBean {
+ private SimpleAction action;
+
+ public ConstructorBean() {
+ // Empty constructor
+ }
+
+ public ConstructorBean(SimpleAction action) {
+ this.action = action;
+ }
+
+ public SimpleAction getAction() {
+ return action;
+ }
+ }
+
+ public static class SetterByNameBean {
+ private SimpleAction action;
+
+ public SetterByNameBean() {
+ // Empty constructor
+ }
+
+ public SimpleAction getActionBean() {
+ return action;
+ }
+
+ public void setActionBean(SimpleAction action) {
+ this.action = action;
+ }
+ }
+
+ public static class SetterByTypeBean {
+ private SimpleAction action;
+
+ public SetterByTypeBean() {
+ // Empty constructor
+ }
+
+ public SimpleAction getAction() {
+ return action;
+ }
+
+ public void setAction(SimpleAction action) {
+ this.action = action;
+ }
+ }
+
+ public static class ConstructorAction implements Action {
+ private SimpleAction action;
+
+ public ConstructorAction(SimpleAction action) {
+ this.action = action;
+ }
+
+ public String execute() throws Exception {
+ return SUCCESS;
+ }
+
+ public SimpleAction getAction() {
+ return action;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/spring/SpringResult.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/spring/SpringResult.java b/core/src/test/java/com/opensymphony/xwork2/spring/SpringResult.java
new file mode 100644
index 0000000..930152e
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/spring/SpringResult.java
@@ -0,0 +1,36 @@
+package com.opensymphony.xwork2.spring;
+
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.Result;
+
+public class SpringResult implements Result {
+
+ private static final long serialVersionUID = -2877126768401198951L;
+
+ private boolean initialize = false;
+
+ // this String should be populated by spring
+ private String stringParameter;
+
+ public void initialize() {
+ // this method should be called by spring
+ this.initialize = true;
+ }
+
+ public void execute(ActionInvocation invocation) throws Exception {
+ // intetionally empty
+ }
+
+ public void setStringParameter(String stringParameter) {
+ this.stringParameter = stringParameter;
+ }
+
+ public String getStringParameter() {
+ return this.stringParameter;
+ }
+
+ public boolean isInitialize() {
+ return this.initialize;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware.java b/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware.java
new file mode 100644
index 0000000..fd63584
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2002-2006,2009 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.test;
+
+import com.opensymphony.xwork2.conversion.annotations.Conversion;
+import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
+import com.opensymphony.xwork2.util.Bar;
+import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
+import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
+import com.opensymphony.xwork2.validator.annotations.Validation;
+
+
+/**
+ * Implemented by SimpleAction3 and AnnotationTestBean2 to test class hierarchy traversal.
+ *
+ * @author Mark Woon
+ * @author Rainer Hermanns
+ */
+@Validation()
+@Conversion()
+public interface AnnotationDataAware {
+
+ void setBarObj(Bar b);
+
+ @TypeConversion(
+ converter = "com.opensymphony.xwork2.conversion.impl.FooBarConverter"
+ )
+ Bar getBarObj();
+
+ @RequiredFieldValidator(message = "You must enter a value for data.")
+ @RequiredStringValidator(message = "You must enter a value for data.")
+ void setData(String data);
+
+ String getData();
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware2.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware2.java b/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware2.java
new file mode 100644
index 0000000..b075fcd
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware2.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2002-2006,2009 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.test;
+
+import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
+
+
+/**
+ * Used to test hierarchy traversal for interfaces.
+ *
+ * @author Mark Woon
+ * @author Rainer Hermanns
+ */
+public interface AnnotationDataAware2 extends AnnotationDataAware {
+
+ @RequiredStringValidator(message = "You must enter a value for data.")
+ public void setBling(String bling);
+
+ public String getBling();
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/AnnotationTestBean2.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/AnnotationTestBean2.java b/core/src/test/java/com/opensymphony/xwork2/test/AnnotationTestBean2.java
new file mode 100644
index 0000000..3a1396b
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/AnnotationTestBean2.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2002-2006,2009 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.test;
+
+import com.opensymphony.xwork2.AnnotatedTestBean;
+import com.opensymphony.xwork2.conversion.annotations.Conversion;
+import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
+import com.opensymphony.xwork2.util.Bar;
+import com.opensymphony.xwork2.util.Cat;
+
+
+/**
+ * Extend TestBean to test class hierarchy traversal.
+ *
+ * @author Mark Woon
+ * @author Rainer Hermanns
+ */
+@Conversion()
+public class AnnotationTestBean2 extends AnnotatedTestBean implements AnnotationDataAware {
+
+ private Bar bar;
+ private String data;
+ private Cat cat;
+
+
+ public void setBarObj(Bar b) {
+ bar = b;
+ }
+
+ public Bar getBarObj() {
+ return bar;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public Cat getCat() {
+ return cat;
+ }
+
+ @TypeConversion(
+ key = "cat", converter = "com.opensymphony.xwork2.conversion.impl.FooBarConverter"
+ )
+ public void setCat(Cat cat) {
+ this.cat = cat;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUser.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUser.java b/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUser.java
new file mode 100644
index 0000000..be2f863
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUser.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2002-2006,2009 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.test;
+
+import com.opensymphony.xwork2.conversion.annotations.ConversionRule;
+import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
+import com.opensymphony.xwork2.util.KeyProperty;
+import com.opensymphony.xwork2.validator.annotations.*;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * Test bean.
+ *
+ * @author Mark Woon
+ * @author Rainer Hermanns
+ */
+@Validation(
+ validations = @Validations(
+ expressions = {
+ @ExpressionValidator(expression = "email.startsWith('mark')", message = "Email does not start with mark"),
+ @ExpressionValidator(expression = "email2.startsWith('mark')", message = "Email2 does not start with mark")
+ }
+ )
+)
+public class AnnotationUser implements AnnotationUserMarker {
+
+ private Collection collection;
+ private List list;
+ private Map map;
+ private String email;
+ private String email2;
+ private String name;
+
+
+ public void setCollection(Collection collection) {
+ this.collection = collection;
+ }
+
+ public Collection getCollection() {
+ return collection;
+ }
+
+ @EmailValidator(shortCircuit = true, message = "Not a valid e-mail.")
+ @FieldExpressionValidator(expression = "email.endsWith('mycompany.com')", message = "Email not from the right company.")
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ @EmailValidator(message = "Not a valid e-mail2.")
+ @FieldExpressionValidator(expression = "email2.endsWith('mycompany.com')", message = "Email2 not from the right company.")
+ public void setEmail2(String email) {
+ email2 = email;
+ }
+
+ public String getEmail2() {
+ return email2;
+ }
+
+ public void setList(List l) {
+ list = l;
+ }
+
+ @KeyProperty( value = "name")
+ @TypeConversion( converter = "java.lang.String", rule = ConversionRule.COLLECTION)
+ public List getList() {
+ return list;
+ }
+
+ @TypeConversion( converter = "java.lang.String", rule = ConversionRule.MAP)
+ public void setMap(Map m) {
+ map = m;
+ }
+
+ public Map getMap() {
+ return map;
+ }
+
+ @RequiredFieldValidator(key = "name.key", message = "You must enter a value for name.")
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUserMarker.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUserMarker.java b/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUserMarker.java
new file mode 100644
index 0000000..e0d6b4d
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUserMarker.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2002-2006,2009 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.test;
+
+import com.opensymphony.xwork2.validator.annotations.ExpressionValidator;
+import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
+import com.opensymphony.xwork2.validator.annotations.Validation;
+import com.opensymphony.xwork2.validator.annotations.Validations;
+
+/**
+ * Marker interface to help test hierarchy traversal.
+ *
+ * @author Mark Woon
+ * @author Rainer Hermanns
+ */
+@Validation(
+ validations = @Validations(
+ requiredFields = {
+ @RequiredFieldValidator(fieldName = "email", shortCircuit = true, message = "You must enter a value for email."),
+ @RequiredFieldValidator(fieldName = "email2", shortCircuit = true, message = "You must enter a value for email2.")
+ },
+ expressions = {
+ @ExpressionValidator(shortCircuit = true, expression = "email.equals(email2)", message = "Email not the same as email2" )
+ }
+ )
+)
+public interface AnnotationUserMarker {
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/DataAware.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/DataAware.java b/core/src/test/java/com/opensymphony/xwork2/test/DataAware.java
new file mode 100644
index 0000000..5a5de5e
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/DataAware.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2002-2003,2009 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.test;
+
+import com.opensymphony.xwork2.util.Bar;
+
+
+/**
+ * Implemented by SimpleAction3 and TestBean2 to test class hierarchy traversal.
+ *
+ * @author Mark Woon
+ */
+public interface DataAware {
+
+ void setBarObj(Bar b);
+
+ Bar getBarObj();
+
+ void setData(String data);
+
+ String getData();
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/DataAware2.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/DataAware2.java b/core/src/test/java/com/opensymphony/xwork2/test/DataAware2.java
new file mode 100644
index 0000000..4a65fe0
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/DataAware2.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2002-2003,2009 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.test;
+
+
+/**
+ * Used to test hierarchy traversal for interfaces.
+ *
+ * @author Mark Woon
+ */
+public interface DataAware2 extends DataAware {
+
+ public void setBling(String bling);
+
+ public String getBling();
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/Equidae.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/Equidae.java b/core/src/test/java/com/opensymphony/xwork2/test/Equidae.java
new file mode 100644
index 0000000..e004875
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/Equidae.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2002-2003,2009 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.test;
+
+
+/**
+ * @author Mark Woon
+ */
+public class Equidae {
+
+ private String cow;
+ private String donkey;
+ private String horse;
+
+
+ public void setCow(String cow) {
+ this.cow = cow;
+ }
+
+ public String getCow() {
+ return cow;
+ }
+
+ public void setDonkey(String donkey) {
+ this.donkey = donkey;
+ }
+
+ public String getDonkey() {
+ return donkey;
+ }
+
+ public void setHorse(String horse) {
+ this.horse = horse;
+ }
+
+ public String getHorse() {
+ return horse;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java b/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java
new file mode 100644
index 0000000..5c21e08
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2002-2003,2009 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.test;
+
+import com.opensymphony.xwork2.ModelDrivenAction;
+
+
+/**
+ * Extend ModelDrivenAction to test class hierarchy traversal.
+ *
+ * @author Mark Woon
+ */
+public class ModelDrivenAction2 extends ModelDrivenAction {
+
+ private TestBean2 model = new TestBean2();
+
+
+ /**
+ * @return the model to be pushed onto the ValueStack after the Action itself
+ */
+ @Override
+ public Object getModel() {
+ return model;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java b/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java
new file mode 100644
index 0000000..038e2ee
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2002-2006,2009 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.test;
+
+import com.opensymphony.xwork2.ModelDrivenAnnotationAction;
+
+
+/**
+ * Extend ModelDrivenAction to test class hierarchy traversal.
+ *
+ * @author Mark Woon
+ * @author Rainer Hermanns
+ */
+public class ModelDrivenAnnotationAction2 extends ModelDrivenAnnotationAction {
+
+ private AnnotationTestBean2 model = new AnnotationTestBean2();
+
+
+ /**
+ * @return the model to be pushed onto the ValueStack after the Action itself
+ */
+ @Override
+ public Object getModel() {
+ return model;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java
new file mode 100644
index 0000000..dea7539
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2002-2003,2009 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.test;
+
+import com.opensymphony.xwork2.SimpleAction;
+
+
+/**
+ * SimpleAction2
+ *
+ * @author Jason Carreira
+ * Created Jun 14, 2003 9:51:12 PM
+ */
+public class SimpleAction2 extends SimpleAction {
+
+ private int count;
+
+
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ public int getCount() {
+ return count;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java
new file mode 100644
index 0000000..ba060ad
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2002-2003,2009 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.test;
+
+import com.opensymphony.xwork2.SimpleAction;
+import com.opensymphony.xwork2.util.Bar;
+
+
+/**
+ * Extend SimpleAction to test class hierarchy traversal.
+ *
+ * @author Mark Woon
+ */
+public class SimpleAction3 extends SimpleAction implements DataAware {
+
+ private Bar bar;
+ private String data;
+
+
+ public void setBarObj(Bar b) {
+ bar = b;
+ }
+
+ public Bar getBarObj() {
+ return bar;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public String getData() {
+ return data;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java
new file mode 100644
index 0000000..8eb3c2d
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2002-2006,2009 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.test;
+
+import com.opensymphony.xwork2.SimpleAnnotationAction;
+import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator;
+import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
+
+/**
+ * SimpleAction2
+ *
+ * @author Jason Carreira
+ * @author Rainer Hermanns
+ * Created Jun 14, 2003 9:51:12 PM
+ */
+public class SimpleAnnotationAction2 extends SimpleAnnotationAction {
+
+ private int count;
+
+ @RequiredFieldValidator(message = "You must enter a value for count.")
+ @IntRangeFieldValidator(min = "0", max = "5", message = "count must be between ${min} and ${max}, current value is ${count}.")
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ public int getCount() {
+ return count;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java
new file mode 100644
index 0000000..85e8438
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2002-2006,2009 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.test;
+
+import com.opensymphony.xwork2.SimpleAnnotationAction;
+import com.opensymphony.xwork2.util.Bar;
+
+
+/**
+ * Extend SimpleAction to test class hierarchy traversal.
+ *
+ * @author Mark Woon
+ * @author Rainer Hermanns
+ */
+public class SimpleAnnotationAction3 extends SimpleAnnotationAction implements AnnotationDataAware {
+
+ private Bar bar;
+ private String data;
+
+
+ public void setBarObj(Bar b) {
+ bar = b;
+ }
+
+ public Bar getBarObj() {
+ return bar;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public String getData() {
+ return data;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/TestBean2.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/TestBean2.java b/core/src/test/java/com/opensymphony/xwork2/test/TestBean2.java
new file mode 100644
index 0000000..89e2a04
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/TestBean2.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2002-2003,2009 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.test;
+
+import com.opensymphony.xwork2.TestBean;
+import com.opensymphony.xwork2.util.Bar;
+import com.opensymphony.xwork2.util.Cat;
+
+
+/**
+ * Extend TestBean to test class hierarchy traversal.
+ *
+ * @author Mark Woon
+ */
+public class TestBean2 extends TestBean implements DataAware {
+
+ private Bar bar;
+ private String data;
+ private Cat cat;
+
+
+ public void setBarObj(Bar b) {
+ bar = b;
+ }
+
+ public Bar getBarObj() {
+ return bar;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public Cat getCat() {
+ return cat;
+ }
+
+ public void setCat(Cat cat) {
+ this.cat = cat;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/User.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/User.java b/core/src/test/java/com/opensymphony/xwork2/test/User.java
new file mode 100644
index 0000000..ca72197
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/User.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2002-2003,2009 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.test;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * Test bean.
+ *
+ * @author Mark Woon
+ */
+public class User implements UserMarker {
+
+ private Collection collection;
+ private List<String> list;
+ private Map map;
+ private String email;
+ private String email2;
+ private String name;
+
+
+ public void setCollection(Collection collection) {
+ this.collection = collection;
+ }
+
+ public Collection getCollection() {
+ return collection;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail2(String email) {
+ email2 = email;
+ }
+
+ public String getEmail2() {
+ return email2;
+ }
+
+ public void setList(List<String> l) {
+ list = l;
+ }
+
+ public List<String> getList() {
+ return list;
+ }
+
+ public void setMap(Map m) {
+ map = m;
+ }
+
+ public Map getMap() {
+ return map;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/test/UserMarker.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/test/UserMarker.java b/core/src/test/java/com/opensymphony/xwork2/test/UserMarker.java
new file mode 100644
index 0000000..26818b2
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/test/UserMarker.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2002-2003,2009 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.test;
+
+
+/**
+ * Marker interface to help test hierarchy traversal.
+ *
+ * @author Mark Woon
+ */
+public interface UserMarker {
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/AnnotatedCat.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/AnnotatedCat.java b/core/src/test/java/com/opensymphony/xwork2/util/AnnotatedCat.java
new file mode 100644
index 0000000..5733159
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/AnnotatedCat.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2002-2006,2009 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.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;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java b/core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java
new file mode 100644
index 0000000..e59abe6
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java
@@ -0,0 +1,73 @@
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.util.annotation.Dummy2Class;
+import com.opensymphony.xwork2.util.annotation.DummyClass;
+import com.opensymphony.xwork2.util.annotation.DummyClassExt;
+import com.opensymphony.xwork2.util.annotation.MyAnnotation;
+import com.opensymphony.xwork2.util.annotation.MyAnnotation2;
+import junit.framework.TestCase;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.Collection;
+
+/**
+ * @author Dan Oxlade, dan d0t oxlade at gmail d0t c0m
+ */
+public class AnnotationUtilsTest extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ 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));
+ }
+
+ @SuppressWarnings("unchecked")
+ 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());
+ }
+
+ public void testFindAnnotationOnClass() {
+ MyAnnotation a1 = AnnotationUtils.findAnnotation(DummyClass.class, MyAnnotation.class);
+ assertNotNull(a1);
+ assertEquals("class-test", a1.value());
+ }
+
+ public void testFindAnnotationOnPackage() {
+ MyAnnotation ns = AnnotationUtils.findAnnotation(Dummy2Class.class, MyAnnotation.class);
+ assertNotNull(ns);
+ assertEquals("package-test", ns.value());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/Bar.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/Bar.java b/core/src/test/java/com/opensymphony/xwork2/util/Bar.java
new file mode 100644
index 0000000..fbddfab
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/Bar.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2002-2003,2009 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.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();
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/BarJunior.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/BarJunior.java b/core/src/test/java/com/opensymphony/xwork2/util/BarJunior.java
new file mode 100644
index 0000000..5e563c7
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/BarJunior.java
@@ -0,0 +1,4 @@
+package com.opensymphony.xwork2.util;
+
+public class BarJunior extends Bar {
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/Cat.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/Cat.java b/core/src/test/java/com/opensymphony/xwork2/util/Cat.java
new file mode 100644
index 0000000..cfb1b50
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/Cat.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2002-2003,2009 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 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;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/ClassLoaderUtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/ClassLoaderUtilTest.java b/core/src/test/java/com/opensymphony/xwork2/util/ClassLoaderUtilTest.java
new file mode 100644
index 0000000..2439bf3
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/ClassLoaderUtilTest.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2002-2003,2009 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 junit.framework.TestCase;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.Iterator;
+
+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<>();
+
+ Enumeration<String> en1 = new Enumeration<String>() {
+ private Iterator<String> itt = Arrays.asList("str1", "str1", "str3", "str1").iterator();
+ public boolean hasMoreElements() {
+ return itt.hasNext();
+ }
+
+ public String nextElement() {
+ return itt.next();
+ }
+ };
+
+ Enumeration<String> en2 = new Enumeration<String>() {
+ private Iterator<String> itt = Arrays.asList("str4", "str5").iterator();
+ public boolean hasMoreElements() {
+ return itt.hasNext();
+ }
+
+ public String 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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/ClassPathFinderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/ClassPathFinderTest.java b/core/src/test/java/com/opensymphony/xwork2/util/ClassPathFinderTest.java
new file mode 100644
index 0000000..616dcf3
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/ClassPathFinderTest.java
@@ -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);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/DefaultFileManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/DefaultFileManagerTest.java b/core/src/test/java/com/opensymphony/xwork2/util/DefaultFileManagerTest.java
new file mode 100644
index 0000000..25f29d6
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/DefaultFileManagerTest.java
@@ -0,0 +1,62 @@
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.FileManager;
+import com.opensymphony.xwork2.FileManagerFactory;
+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 DefaultFileManagerTest extends XWorkTestCase {
+
+ private FileManager fileManager;
+ private long lastModified;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ fileManager = container.getInstance(FileManagerFactory.class).getFileManager();
+ }
+
+ 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, DefaultFileManagerTest.class);
+ InputStream file = fileManager.loadFile(url);
+ assertNotNull(file);
+ assertTrue(fileManager.fileNeedsReloading(fileName));
+ }
+
+ public void testReloadingConfigs() throws Exception {
+ // given
+ container.getInstance(FileManagerFactory.class).setReloadingConfigs("false");
+ FileManager fm = container.getInstance(FileManagerFactory.class).getFileManager();
+ String resourceName = "xwork-sample.xml";
+ assertFalse(fm.fileNeedsReloading(resourceName));
+
+ // when
+ container.getInstance(FileManagerFactory.class).setReloadingConfigs("true");
+
+ // then
+ fm = container.getInstance(FileManagerFactory.class).getFileManager();
+ assertTrue(fm.fileNeedsReloading(resourceName));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/Dog.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/Dog.java b/core/src/test/java/com/opensymphony/xwork2/util/Dog.java
new file mode 100644
index 0000000..8bad047
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/Dog.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2002-2003,2009 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 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");
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/DomHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/DomHelperTest.java b/core/src/test/java/com/opensymphony/xwork2/util/DomHelperTest.java
new file mode 100644
index 0000000..fa1af79
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/DomHelperTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2002-2003,2009 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.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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/Foo.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/Foo.java b/core/src/test/java/com/opensymphony/xwork2/util/Foo.java
new file mode 100644
index 0000000..70c4fd3
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/Foo.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2002-2003,2009 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 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;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/FurColor.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/FurColor.java b/core/src/test/java/com/opensymphony/xwork2/util/FurColor.java
new file mode 100644
index 0000000..94c355b
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/FurColor.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2002-2003,2009 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;
+
+public enum FurColor {
+ BROWN, BLACK, GREEN
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/GetPropertiesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/GetPropertiesTest.java b/core/src/test/java/com/opensymphony/xwork2/util/GetPropertiesTest.java
new file mode 100644
index 0000000..6a24aca
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/GetPropertiesTest.java
@@ -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);
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/Indexed.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/Indexed.java b/core/src/test/java/com/opensymphony/xwork2/util/Indexed.java
new file mode 100644
index 0000000..15c6193
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/Indexed.java
@@ -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<>();
+
+ 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);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/core/src/test/java/com/opensymphony/xwork2/util/ListHolder.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/ListHolder.java b/core/src/test/java/com/opensymphony/xwork2/util/ListHolder.java
new file mode 100644
index 0000000..190fdef
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/util/ListHolder.java
@@ -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;
+ }
+}