Return-Path: X-Original-To: apmail-struts-commits-archive@minotaur.apache.org Delivered-To: apmail-struts-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8FF7B9B6C for ; Fri, 2 Dec 2011 16:38:19 +0000 (UTC) Received: (qmail 72493 invoked by uid 500); 2 Dec 2011 16:38:19 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 72456 invoked by uid 500); 2 Dec 2011 16:38:19 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 72449 invoked by uid 99); 2 Dec 2011 16:38:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Dec 2011 16:38:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Dec 2011 16:38:12 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0E82E2388CA2 for ; Fri, 2 Dec 2011 16:36:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1209569 [44/50] - in /struts/struts2/branches/STRUTS_3_X: apps/blank/src/main/java/example/ apps/blank/src/test/java/example/ apps/jboss-blank/src/main/java/example/ apps/jboss-blank/src/test/java/example/ apps/mailreader/src/main/java/mai... Date: Fri, 02 Dec 2011 16:33:45 -0000 To: commits@struts.apache.org From: lukaszlenart@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111202163614.0E82E2388CA2@eris.apache.org> Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ognl/SetPropertiesTest.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ognl/SetPropertiesTest.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ognl/SetPropertiesTest.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ognl/SetPropertiesTest.java Fri Dec 2 16:33:03 2011 @@ -0,0 +1,334 @@ +/* + * 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 6/10/2003 + * + */ +package org.apache.struts2.xwork2.ognl; + +import org.apache.struts2.xwork2.ActionContext; +import org.apache.struts2.xwork2.XWorkTestCase; +import org.apache.struts2.xwork2.config.ConfigurationException; +import org.apache.struts2.xwork2.conversion.ObjectTypeDeterminer; +import org.apache.struts2.xwork2.conversion.impl.FooBarConverter; +import org.apache.struts2.xwork2.conversion.impl.XWorkConverter; +import org.apache.struts2.xwork2.inject.ContainerBuilder; +import org.apache.struts2.xwork2.inject.Context; +import org.apache.struts2.xwork2.inject.Factory; +import org.apache.struts2.xwork2.inject.Scope; +import org.apache.struts2.xwork2.mock.MockObjectTypeDeterminer; +import org.apache.struts2.xwork2.test.StubConfigurationProvider; +import org.apache.struts2.xwork2.util.Bar; +import org.apache.struts2.xwork2.util.Cat; +import org.apache.struts2.xwork2.util.Foo; +import org.apache.struts2.xwork2.util.ValueStack; +import org.apache.struts2.xwork2.util.location.LocatableProperties; +import org.apache.struts2.xwork2.util.reflection.ReflectionContextState; +import ognl.Ognl; + +import java.util.*; + + +/** + * @author CameronBraid and Gabe + * @author tm_jee + */ +public class SetPropertiesTest extends XWorkTestCase { + + private OgnlUtil ognlUtil; + + @Override + public void setUp() throws Exception { + super.setUp(); + ognlUtil = container.getInstance(OgnlUtil.class); + ((OgnlValueStack)ActionContext.getContext().getValueStack()).setDevMode("true"); + } + public void testOgnlUtilEmptyStringAsLong() { + Bar bar = new Bar(); + Map context = Ognl.createDefaultContext(bar); + context.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE); + bar.setId(null); + + HashMap props = new HashMap(); + props.put("id", ""); + + ognlUtil.setProperties(props, bar, context); + assertNull(bar.getId()); + assertEquals(0, bar.getFieldErrors().size()); + + props.put("id", new String[]{""}); + + bar.setId(null); + ognlUtil.setProperties(props, bar, context); + assertNull(bar.getId()); + assertEquals(0, bar.getFieldErrors().size()); + } + + public void testSetCollectionByConverterFromArray() { + Foo foo = new Foo(); + ValueStack vs = ActionContext.getContext().getValueStack(); + vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE); + + XWorkConverter c = (XWorkConverter)((OgnlTypeConverterWrapper) Ognl.getTypeConverter(vs.getContext())).getTarget(); + c.registerConverter(Cat.class.getName(), new FooBarConverter()); + vs.push(foo); + + vs.setValue("cats", new String[]{"1", "2"}); + assertNotNull(foo.getCats()); + assertEquals(2, foo.getCats().size()); + assertEquals(Cat.class, foo.getCats().get(0).getClass()); + assertEquals(Cat.class, foo.getCats().get(1).getClass()); + } + + public void testSetCollectionByConverterFromCollection() { + Foo foo = new Foo(); + ValueStack vs = ActionContext.getContext().getValueStack(); + vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE); + + XWorkConverter c = (XWorkConverter)((OgnlTypeConverterWrapper) Ognl.getTypeConverter(vs.getContext())).getTarget(); + c.registerConverter(Cat.class.getName(), new FooBarConverter()); + vs.push(foo); + + HashSet s = new HashSet(); + s.add("1"); + s.add("2"); + vs.setValue("cats", s); + assertNotNull(foo.getCats()); + assertEquals(2, foo.getCats().size()); + assertEquals(Cat.class, foo.getCats().get(0).getClass()); + assertEquals(Cat.class, foo.getCats().get(1).getClass()); + } + + public void testValueStackSetValueEmptyStringAsLong() { + Bar bar = new Bar(); + ValueStack vs = ActionContext.getContext().getValueStack(); + vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE); + vs.push(bar); + + vs.setValue("id", ""); + assertNull(bar.getId()); + assertEquals(0, bar.getFieldErrors().size()); + + bar.setId(null); + + vs.setValue("id", new String[]{""}); + assertNull(bar.getId()); + assertEquals(0, bar.getFieldErrors().size()); + } + public void testAddingToListsWithObjectsTrue() { + doTestAddingToListsWithObjects(true); + } + public void testAddingToListsWithObjectsFalse() { + doTestAddingToListsWithObjects(false); + + } + public void doTestAddingToListsWithObjects(final boolean allowAdditions) { + + loadConfigurationProviders(new StubConfigurationProvider() { + @Override + public void register(ContainerBuilder builder, + LocatableProperties props) throws ConfigurationException { + builder.factory(ObjectTypeDeterminer.class, new Factory() { + public Object create(Context context) throws Exception { + return new MockObjectTypeDeterminer(null,Cat.class,null,allowAdditions); + } + + }); + } + }); + + Foo foo = new Foo(); + foo.setMoreCats(new ArrayList()); + String spielname = "Spielen"; + ValueStack vs = ActionContext.getContext().getValueStack(); + vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE); + vs.getContext().put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.TRUE); + vs.push(foo); + try { + vs.setValue("moreCats[2].name", spielname); + } catch (IndexOutOfBoundsException e) { + if (allowAdditions) { + throw e; + } + } + Object setCat = null; + if (allowAdditions) { + setCat = foo.getMoreCats().get(2); + + + assertNotNull(setCat); + assertTrue(setCat instanceof Cat); + assertTrue(((Cat) setCat).getName().equals(spielname)); + } else { + assertTrue(foo.getMoreCats()==null || foo.getMoreCats().size()==0); + } + + //now try to set a lower number + //to test setting after a higher one + //has been created + if (allowAdditions) { + spielname = "paws"; + vs.setValue("moreCats[0].name", spielname); + setCat = foo.getMoreCats().get(0); + assertNotNull(setCat); + assertTrue(setCat instanceof Cat); + assertTrue(((Cat) setCat).getName().equals(spielname)); + } + + } + + + public void testAddingToMapsWithObjectsTrue() throws Exception { + doTestAddingToMapsWithObjects(true); + } + + public void testAddingToMapsWithObjectsFalse() throws Exception { + doTestAddingToMapsWithObjects(false); + + } + + public void doTestAddingToMapsWithObjects(boolean allowAdditions) throws Exception { + + loadButAdd(ObjectTypeDeterminer.class, new MockObjectTypeDeterminer(Long.class,Cat.class,null,allowAdditions)); + + Foo foo = new Foo(); + foo.setAnotherCatMap(new HashMap()); + String spielname = "Spielen"; + ValueStack vs = ActionContext.getContext().getValueStack(); + vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE); + vs.getContext().put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.TRUE); + vs.push(foo); + vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE); + vs.setValue("anotherCatMap[\"3\"].name", spielname); + Object setCat = foo.getAnotherCatMap().get(new Long(3)); + if (allowAdditions) { + assertNotNull(setCat); + assertTrue(setCat instanceof Cat); + assertTrue(((Cat) setCat).getName().equals(spielname)); + } else { + assertNull(setCat); + } + + + } + + + public void testAddingAndModifyingCollectionWithObjectsSet() { + doTestAddingAndModifyingCollectionWithObjects(new HashSet()); + } + public void testAddingAndModifyingCollectionWithObjectsList() { + doTestAddingAndModifyingCollectionWithObjects(new ArrayList()); + + } + public void doTestAddingAndModifyingCollectionWithObjects(Collection barColl) { + + ValueStack vs = ActionContext.getContext().getValueStack(); + Foo foo = new Foo(); + + foo.setBarCollection(barColl); + Bar bar1 = new Bar(); + bar1.setId(new Long(11)); + barColl.add(bar1); + Bar bar2 = new Bar(); + bar2.setId(new Long(22)); + barColl.add(bar2); + //try modifying bar1 and bar2 + //check the logs here to make sure + //the Map is being created + ReflectionContextState.setCreatingNullObjects(vs.getContext(), true); + ReflectionContextState.setReportingConversionErrors(vs.getContext(), true); + vs.push(foo); + String bar1Title = "The Phantom Menace"; + String bar2Title = "The Clone Wars"; + vs.setValue("barCollection(22).title", bar2Title); + vs.setValue("barCollection(11).title", bar1Title); + for (Object aBarColl : barColl) { + Bar next = (Bar) aBarColl; + if (next.getId().intValue() == 22) { + assertEquals(bar2Title, next.getTitle()); + } else { + assertEquals(bar1Title, next.getTitle()); + } + } + //now test adding to a collection + String bar3Title = "Revenge of the Sith"; + String bar4Title = "A New Hope"; + vs.setValue("barCollection.makeNew[4].title", bar4Title, true); + vs.setValue("barCollection.makeNew[0].title", bar3Title, true); + + assertEquals(4, barColl.size()); + + for (Object aBarColl : barColl) { + Bar next = (Bar) aBarColl; + if (next.getId() == null) { + assertNotNull(next.getTitle()); + assertTrue(next.getTitle().equals(bar4Title) + || next.getTitle().equals(bar3Title)); + } + } + + } + public void testAddingToCollectionBasedOnPermission() { + final MockObjectTypeDeterminer determiner = new MockObjectTypeDeterminer(Long.class,Bar.class,"id",true); + loadConfigurationProviders(new StubConfigurationProvider() { + @Override + public void register(ContainerBuilder builder, + LocatableProperties props) throws ConfigurationException { + builder.factory(ObjectTypeDeterminer.class, new Factory() { + public Object create(Context context) throws Exception { + return determiner; + } + + }, Scope.SINGLETON); + } + }); + + Collection barColl=new HashSet(); + + ValueStack vs = ActionContext.getContext().getValueStack(); + ReflectionContextState.setCreatingNullObjects(vs.getContext(), true); + ReflectionContextState.setReportingConversionErrors(vs.getContext(), true); + Foo foo = new Foo(); + + foo.setBarCollection(barColl); + + vs.push(foo); + + String bar1Title="title"; + vs.setValue("barCollection(11).title", bar1Title); + + assertEquals(1, barColl.size()); + Object bar=barColl.iterator().next(); + assertTrue(bar instanceof Bar); + assertEquals(((Bar)bar).getTitle(), bar1Title); + assertEquals(((Bar)bar).getId(), new Long(11)); + + //now test where there is no permission + determiner.setShouldCreateIfNew(false); + + String bar2Title="another title"; + vs.setValue("barCollection(22).title", bar1Title); + + assertEquals(1, barColl.size()); + bar=barColl.iterator().next(); + assertTrue(bar instanceof Bar); + assertEquals(((Bar)bar).getTitle(), bar1Title); + assertEquals(((Bar)bar).getId(), new Long(11)); + + + } + +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java Fri Dec 2 16:33:03 2011 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2005 Opensymphony. All Rights Reserved. + */ +package org.apache.struts2.xwork2.ognl.accessor; + +import org.apache.struts2.xwork2.ActionContext; +import org.apache.struts2.xwork2.XWorkTestCase; +import org.apache.struts2.xwork2.util.ListHolder; +import org.apache.struts2.xwork2.util.ValueStack; + +import java.util.ArrayList; +import java.util.List; + +/** + * XWorkListPropertyAccessorTest + *

+ * Created : Nov 7, 2005 3:54:44 PM + * + * @author Jason Carreira + */ +public class XWorkListPropertyAccessorTest extends XWorkTestCase { + + public void testContains() { + ValueStack vs = ActionContext.getContext().getValueStack(); + ListHolder listHolder = new ListHolder(); + vs.push(listHolder); + + vs.setValue("longs", new String[] {"1", "2", "3"}); + + assertNotNull(listHolder.getLongs()); + assertEquals(3, listHolder.getLongs().size()); + assertEquals(new Long(1), (Long) listHolder.getLongs().get(0)); + assertEquals(new Long(2), (Long) listHolder.getLongs().get(1)); + assertEquals(new Long(3), (Long) listHolder.getLongs().get(2)); + + assertTrue(((Boolean) vs.findValue("longs.contains(1)")).booleanValue()); + } + + public void testCanAccessListSizeProperty() { + ValueStack vs = ActionContext.getContext().getValueStack(); + List myList = new ArrayList(); + myList.add("a"); + myList.add("b"); + + ListHolder listHolder = new ListHolder(); + listHolder.setStrings(myList); + + vs.push(listHolder); + + assertEquals(new Integer(myList.size()), vs.findValue("strings.size()")); + assertEquals(new Integer(myList.size()), vs.findValue("strings.size")); + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/ActionsFromSpringTest.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/ActionsFromSpringTest.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/ActionsFromSpringTest.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/ActionsFromSpringTest.java Fri Dec 2 16:33:03 2011 @@ -0,0 +1,82 @@ +/* + * Created on Jun 12, 2004 + */ +package org.apache.struts2.xwork2.spring; + +import org.apache.struts2.xwork2.config.providers.XmlConfigurationProvider; +import org.apache.struts2.xwork2.Action; +import org.apache.struts2.xwork2.ActionProxy; +import org.apache.struts2.xwork2.ObjectFactory; +import org.apache.struts2.xwork2.XWorkTestCase; +import org.apache.struts2.xwork2.SimpleAction; +import org.springframework.context.ApplicationContext; + +/** + * Test loading actions from the Spring Application Context. + * + * @author Simon Stewart + */ +public class ActionsFromSpringTest extends XWorkTestCase { + private ApplicationContext appContext; + + @Override public void setUp() throws Exception { + super.setUp(); + + // Set up XWork + loadConfigurationProviders(new XmlConfigurationProvider("org/apache/struts2/xwork2/spring/actionContext-xwork.xml")); + appContext = ((SpringObjectFactory)container.getInstance(ObjectFactory.class)).appContext; + } + + public void testLoadSimpleAction() throws Exception { + ActionProxy proxy = actionProxyFactory.createActionProxy(null, "simpleAction", null); + Object action = proxy.getAction(); + + Action expected = (Action) appContext.getBean("simple-action"); + + assertEquals(expected.getClass(), action.getClass()); + } + + public void testLoadActionWithDependencies() throws Exception { + ActionProxy proxy = actionProxyFactory.createActionProxy(null, "dependencyAction", null); + SimpleAction action = (SimpleAction) proxy.getAction(); + + assertEquals("injected", action.getBlah()); + } + + public void testProxiedActionIsNotStateful() throws Exception { + ActionProxy proxy = actionProxyFactory.createActionProxy(null, "proxiedAction", null); + SimpleAction action = (SimpleAction) proxy.getAction(); + + action.setBlah("Hello World"); + + proxy = actionProxyFactory.createActionProxy(null, "proxiedAction", null); + action = (SimpleAction) proxy.getAction(); + + // If the action is a singleton, this test will fail + SimpleAction sa = new SimpleAction(); + assertEquals(sa.getBlah(), action.getBlah()); + + // And if the advice is not being applied, this will be SUCCESS. + String result = action.execute(); + assertEquals(Action.INPUT, result); + } + + public void testAutoProxiedAction() throws Exception { + ActionProxy proxy = actionProxyFactory.createActionProxy(null, "autoProxiedAction", null); + + SimpleAction action = (SimpleAction) proxy.getAction(); + + String result = action.execute(); + assertEquals(Action.INPUT, result); + } + + public void testActionWithSpringResult() throws Exception { + ActionProxy proxy = actionProxyFactory.createActionProxy(null, "simpleActionSpringResult", null); + + proxy.execute(); + + SpringResult springResult = (SpringResult) proxy.getInvocation().getResult(); + assertTrue(springResult.isInitialize()); + assertNotNull(springResult.getStringParameter()); + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/Bar.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/Bar.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/Bar.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/Bar.java Fri Dec 2 16:33:03 2011 @@ -0,0 +1,56 @@ +/* + * Created on Nov 12, 2003 + */ +package org.apache.struts2.xwork2.spring; + +/** + * @author Mike + */ +public class Bar { + + private Foo foo; + private String thing; + private int value; + + /** + * @return Returns the foo. + */ + public Foo getFoo() { + return foo; + } + + /** + * @param foo The foo to set. + */ + public void setFoo(Foo foo) { + this.foo = foo; + } + + /** + * @return Returns the thing. + */ + public String getThing() { + return thing; + } + + /** + * @param thing The thing to set. + */ + public void setThing(String thing) { + this.thing = thing; + } + + /** + * @return Returns the value. + */ + public int getValue() { + return value; + } + + /** + * @param value The value to set. + */ + public void setValue(int value) { + this.value = value; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/ExecuteInterceptor.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/ExecuteInterceptor.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/ExecuteInterceptor.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/ExecuteInterceptor.java Fri Dec 2 16:33:03 2011 @@ -0,0 +1,21 @@ +/* + * Created on Jun 12, 2004 + */ +package org.apache.struts2.xwork2.spring; + +import org.apache.struts2.xwork2.Action; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; + + +/** + * @author Simon Stewart + */ +public class ExecuteInterceptor implements MethodInterceptor { + public Object invoke(MethodInvocation mi) throws Throwable { + if ("execute".equals(mi.getMethod().getName())) + return Action.INPUT; + return mi.proceed(); + } + +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/ExternalReferenceAction.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/ExternalReferenceAction.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/ExternalReferenceAction.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/ExternalReferenceAction.java Fri Dec 2 16:33:03 2011 @@ -0,0 +1,49 @@ +/* + * Created on Nov 11, 2003 + */ +package org.apache.struts2.xwork2.spring; + +import org.apache.struts2.xwork2.Action; + +/** + * @author Mike + */ +public class ExternalReferenceAction implements Action +{ + private Foo foo; + private Bar bar; + + public String execute() throws Exception { + return SUCCESS; + } + + /** + * @return Returns the foo. + */ + public Foo getFoo() { + return foo; + } + + /** + * @param foo + * The foo to set. + */ + public void setFoo(Foo foo) { + this.foo = foo; + } + + /** + * @return Returns the bar. + */ + public Bar getBar() { + return bar; + } + + /** + * @param bar + * The bar to set. + */ + public void setBar(Bar bar) { + this.bar = bar; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/Foo.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/Foo.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/Foo.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/Foo.java Fri Dec 2 16:33:03 2011 @@ -0,0 +1,30 @@ +/* + * Created on Nov 11, 2003 + */ +package org.apache.struts2.xwork2.spring; + +/** + * @author Mike + */ +public class Foo +{ + String name = null; + + public Foo() { + name = "not set"; + } + + public Foo(String name) { + this.name = name; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/SpringObjectFactoryTest.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/SpringObjectFactoryTest.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/SpringObjectFactoryTest.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/SpringObjectFactoryTest.java Fri Dec 2 16:33:03 2011 @@ -0,0 +1,380 @@ +package org.apache.struts2.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 org.apache.struts2.xwork2.config.ConfigurationException; +import org.apache.struts2.xwork2.Action; +import org.apache.struts2.xwork2.ActionContext; +import org.apache.struts2.xwork2.ObjectFactory; +import org.apache.struts2.xwork2.config.entities.ActionConfig; +import org.apache.struts2.xwork2.config.entities.InterceptorConfig; +import org.apache.struts2.xwork2.ActionChainResult; +import org.apache.struts2.xwork2.Result; +import org.apache.struts2.xwork2.config.entities.ResultConfig; +import org.apache.struts2.xwork2.XWorkTestCase; +import org.apache.struts2.xwork2.inject.ContainerBuilder; +import org.apache.struts2.xwork2.interceptor.Interceptor; +import org.apache.struts2.xwork2.interceptor.ModelDrivenInterceptor; +import org.apache.struts2.xwork2.interceptor.TimerInterceptor; +import org.apache.struts2.xwork2.test.StubConfigurationProvider; +import org.apache.struts2.xwork2.util.location.LocatableProperties; +import org.apache.struts2.xwork2.validator.Validator; +import org.apache.struts2.xwork2.validator.validators.ExpressionValidator; +import org.apache.struts2.xwork2.validator.validators.RequiredStringValidator; +import org.apache.struts2.xwork2.ModelDrivenAction; +import org.apache.struts2.xwork2.SimpleAction; +import org.apache.struts2.xwork2.TestBean; +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; + +// 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()); + + 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 { + Validator validator = objectFactory.buildValidator(RequiredStringValidator.class.getName(), new HashMap(), null); + + 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()); + + 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()); + + Validator validator = objectFactory.buildValidator("expression-validator", new HashMap(), null); + + 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; + } + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/SpringResult.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/SpringResult.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/SpringResult.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/SpringResult.java Fri Dec 2 16:33:03 2011 @@ -0,0 +1,36 @@ +package org.apache.struts2.xwork2.spring; + +import org.apache.struts2.xwork2.ActionInvocation; +import org.apache.struts2.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; + } +} + Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/interceptor/ActionAutowiringInterceptorTest.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/interceptor/ActionAutowiringInterceptorTest.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/interceptor/ActionAutowiringInterceptorTest.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/interceptor/ActionAutowiringInterceptorTest.java Fri Dec 2 16:33:03 2011 @@ -0,0 +1,114 @@ +/* + * Created on 6/11/2004 + */ +package org.apache.struts2.xwork2.spring.interceptor; + +import org.apache.struts2.xwork2.ActionContext; +import org.apache.struts2.xwork2.config.providers.XmlConfigurationProvider; +import org.apache.struts2.xwork2.ActionInvocation; +import org.apache.struts2.xwork2.XWorkTestCase; +import org.apache.struts2.xwork2.SimpleAction; +import org.apache.struts2.xwork2.TestBean; +import org.springframework.context.ApplicationContext; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.StaticWebApplicationContext; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Simon Stewart + */ +public class ActionAutowiringInterceptorTest extends XWorkTestCase { + + public void testShouldAutowireAction() throws Exception { + StaticWebApplicationContext context = new StaticWebApplicationContext(); + context.getBeanFactory().registerSingleton("bean", new TestBean()); + TestBean bean = (TestBean) context.getBean("bean"); + + loadSpringApplicationContextIntoApplication(context); + + SimpleAction action = new SimpleAction(); + ActionInvocation invocation = new TestActionInvocation(action); + + ActionAutowiringInterceptor interceptor = new ActionAutowiringInterceptor(); + interceptor.setApplicationContext(context); + interceptor.init(); + + interceptor.intercept(invocation); + + assertEquals(bean, action.getBean()); + } + + public void testSetAutowireType() throws Exception { + XmlConfigurationProvider prov = new XmlConfigurationProvider("xwork-default.xml"); + prov.setThrowExceptionOnDuplicateBeans(false); + XmlConfigurationProvider c = new XmlConfigurationProvider("org/apache/struts2/xwork2/spring/xwork-autowire.xml"); + loadConfigurationProviders(c, prov); + + StaticWebApplicationContext appContext = new StaticWebApplicationContext(); + + loadSpringApplicationContextIntoApplication(appContext); + + ActionAutowiringInterceptor interceptor = new ActionAutowiringInterceptor(); + interceptor.init(); + + SimpleAction action = new SimpleAction(); + ActionInvocation invocation = new TestActionInvocation(action); + + interceptor.intercept(invocation); + + ApplicationContext loadedContext = interceptor.getApplicationContext(); + + assertEquals(appContext, loadedContext); + } + + protected void loadSpringApplicationContextIntoApplication(ApplicationContext appContext) { + Map application = new HashMap(); + application.put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext); + + Map context = new HashMap(); + context.put(ActionContext.APPLICATION, application); + ActionContext actionContext = new ActionContext(context); + ActionContext.setContext(actionContext); + } + + public void testLoadsApplicationContextUsingWebApplicationContextUtils() throws Exception { + StaticWebApplicationContext appContext = new StaticWebApplicationContext(); + + loadSpringApplicationContextIntoApplication(appContext); + + ActionAutowiringInterceptor interceptor = new ActionAutowiringInterceptor(); + interceptor.init(); + + SimpleAction action = new SimpleAction(); + ActionInvocation invocation = new TestActionInvocation(action); + + interceptor.intercept(invocation); + + ApplicationContext loadedContext = interceptor.getApplicationContext(); + + assertEquals(appContext, loadedContext); + } + + public void testIfApplicationContextIsNullThenBeanWillNotBeWiredUp() throws Exception { + Map context = new HashMap(); + context.put(ActionContext.APPLICATION, new HashMap()); + ActionContext actionContext = new ActionContext(context); + ActionContext.setContext(actionContext); + + ActionAutowiringInterceptor interceptor = new ActionAutowiringInterceptor(); + interceptor.init(); + + SimpleAction action = new SimpleAction(); + ActionInvocation invocation = new TestActionInvocation(action); + TestBean bean = action.getBean(); + + // If an exception is thrown here, things are going to go wrong in + // production + interceptor.intercept(invocation); + + assertEquals(bean, action.getBean()); + } + +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/interceptor/TestActionInvocation.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/interceptor/TestActionInvocation.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/interceptor/TestActionInvocation.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/spring/interceptor/TestActionInvocation.java Fri Dec 2 16:33:03 2011 @@ -0,0 +1,77 @@ +/* + * Created on 6/11/2004 + */ +package org.apache.struts2.xwork2.spring.interceptor; + +import org.apache.struts2.xwork2.ActionContext; +import org.apache.struts2.xwork2.ActionEventListener; +import org.apache.struts2.xwork2.ActionInvocation; +import org.apache.struts2.xwork2.ActionProxy; +import org.apache.struts2.xwork2.interceptor.PreResultListener; +import org.apache.struts2.xwork2.util.ValueStack; +import org.apache.struts2.xwork2.Result; + +import java.lang.reflect.Method; + +/** + * @author Simon Stewart + */ +public class TestActionInvocation implements ActionInvocation { + private Object action; + private boolean executed; + + public TestActionInvocation(Object wrappedAction) { + this.action = wrappedAction; + } + + public Object getAction() { + return action; + } + + public boolean isExecuted() { + return executed; + } + + public ActionContext getInvocationContext() { + return null; + } + + public ActionProxy getProxy() { + return null; + } + + public Result getResult() throws Exception { + return null; + } + + public String getResultCode() { + return null; + } + + public void setResultCode(String resultCode) { + + } + + public ValueStack getStack() { + return null; + } + + public void addPreResultListener(PreResultListener listener) { + } + + public String invoke() throws Exception { + return invokeActionOnly(); + } + + public String invokeActionOnly() throws Exception { + executed = true; + Method method = action.getClass().getMethod("execute", new Class[0]); + return (String) method.invoke(action, new Object[0]); + } + + public void setActionEventListener(ActionEventListener listener) { + } + + public void init(ActionProxy proxy) { + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationDataAware.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationDataAware.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationDataAware.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationDataAware.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.xwork2.test; + +import org.apache.struts2.xwork2.conversion.annotations.Conversion; +import org.apache.struts2.xwork2.conversion.annotations.TypeConversion; +import org.apache.struts2.xwork2.util.Bar; +import org.apache.struts2.xwork2.validator.annotations.RequiredFieldValidator; +import org.apache.struts2.xwork2.validator.annotations.RequiredStringValidator; +import org.apache.struts2.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 = "org.apache.struts2.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(); +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationDataAware2.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationDataAware2.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationDataAware2.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationDataAware2.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.xwork2.test; + +import org.apache.struts2.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(); +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationTestBean2.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationTestBean2.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationTestBean2.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationTestBean2.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.xwork2.test; + +import org.apache.struts2.xwork2.AnnotatedTestBean; +import org.apache.struts2.xwork2.conversion.annotations.Conversion; +import org.apache.struts2.xwork2.conversion.annotations.TypeConversion; +import org.apache.struts2.xwork2.util.Bar; +import org.apache.struts2.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 = "org.apache.struts2.xwork2.conversion.impl.FooBarConverter" + ) + public void setCat(Cat cat) { + this.cat = cat; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationUser.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationUser.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationUser.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationUser.java Fri Dec 2 16:33:03 2011 @@ -0,0 +1,112 @@ +/* + * 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 org.apache.struts2.xwork2.test; + +import org.apache.struts2.xwork2.conversion.annotations.ConversionRule; +import org.apache.struts2.xwork2.conversion.annotations.TypeConversion; +import org.apache.struts2.xwork2.util.KeyProperty; +import org.apache.struts2.xwork2.validator.annotations.EmailValidator; +import org.apache.struts2.xwork2.validator.annotations.ExpressionValidator; +import org.apache.struts2.xwork2.validator.annotations.FieldExpressionValidator; +import org.apache.struts2.xwork2.validator.annotations.RequiredFieldValidator; +import org.apache.struts2.xwork2.validator.annotations.Validation; +import org.apache.struts2.xwork2.validator.annotations.Validations; + +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; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationUserMarker.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationUserMarker.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationUserMarker.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/AnnotationUserMarker.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.xwork2.test; + +import org.apache.struts2.xwork2.validator.annotations.ExpressionValidator; +import org.apache.struts2.xwork2.validator.annotations.RequiredFieldValidator; +import org.apache.struts2.xwork2.validator.annotations.Validation; +import org.apache.struts2.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 { +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/DataAware.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/DataAware.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/DataAware.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/DataAware.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.xwork2.test; + +import org.apache.struts2.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(); +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/DataAware2.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/DataAware2.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/DataAware2.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/DataAware2.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.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(); +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/Equidae.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/Equidae.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/Equidae.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/Equidae.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.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; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/ModelDrivenAction2.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/ModelDrivenAction2.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/ModelDrivenAction2.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/ModelDrivenAction2.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.xwork2.test; + +import org.apache.struts2.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; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/ModelDrivenAnnotationAction2.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/ModelDrivenAnnotationAction2.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/ModelDrivenAnnotationAction2.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/ModelDrivenAnnotationAction2.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.xwork2.test; + +import org.apache.struts2.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; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAction2.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAction2.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAction2.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAction2.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.xwork2.test; + +import org.apache.struts2.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; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAction3.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAction3.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAction3.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAction3.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.xwork2.test; + +import org.apache.struts2.xwork2.SimpleAction; +import org.apache.struts2.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; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAnnotationAction2.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAnnotationAction2.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAnnotationAction2.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAnnotationAction2.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.xwork2.test; + +import org.apache.struts2.xwork2.SimpleAnnotationAction; +import org.apache.struts2.xwork2.validator.annotations.IntRangeFieldValidator; +import org.apache.struts2.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; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAnnotationAction3.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAnnotationAction3.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAnnotationAction3.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/SimpleAnnotationAction3.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.xwork2.test; + +import org.apache.struts2.xwork2.SimpleAnnotationAction; +import org.apache.struts2.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; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/TestBean2.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/TestBean2.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/TestBean2.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/TestBean2.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.xwork2.test; + +import org.apache.struts2.xwork2.TestBean; +import org.apache.struts2.xwork2.util.Bar; +import org.apache.struts2.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; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/User.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/User.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/User.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/User.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.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 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 l) { + list = l; + } + + public List 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; + } +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/UserMarker.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/UserMarker.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/UserMarker.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/UserMarker.java Fri Dec 2 16:33:03 2011 @@ -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 org.apache.struts2.xwork2.test; + + +/** + * Marker interface to help test hierarchy traversal. + * + * @author Mark Woon + */ +public interface UserMarker { +} Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/annotations/Address.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/annotations/Address.java?rev=1209569&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/annotations/Address.java (added) +++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/test/java/org/apache/struts2/xwork2/test/annotations/Address.java Fri Dec 2 16:33:03 2011 @@ -0,0 +1,40 @@ +package org.apache.struts2.xwork2.test.annotations; + +public class Address { + private String line1; + private String line2; + private String city; + private String country; + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getLine1() { + return line1; + } + + public void setLine1(String line1) { + this.line1 = line1; + } + + public String getLine2() { + return line2; + } + + public void setLine2(String line2) { + this.line2 = line2; + } +} \ No newline at end of file