Return-Path: Delivered-To: apmail-struts-commits-archive@minotaur.apache.org Received: (qmail 95660 invoked from network); 27 Dec 2009 18:03:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Dec 2009 18:03:15 -0000 Received: (qmail 33325 invoked by uid 500); 27 Dec 2009 18:03:13 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 33268 invoked by uid 500); 27 Dec 2009 18:03:13 -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 33220 invoked by uid 99); 27 Dec 2009 18:03:13 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Dec 2009 18:03:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Sun, 27 Dec 2009 18:02:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B7DCD2388C5A; Sun, 27 Dec 2009 18:01:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r894087 [33/46] - in /struts/xwork/trunk: ./ assembly/ assembly/src/ assembly/src/main/ assembly/src/main/assembly/ assembly/src/main/resources/ core/ core/src/ core/src/main/ core/src/main/java/ core/src/main/java/com/ core/src/main/java/c... Date: Sun, 27 Dec 2009 18:01:09 -0000 To: commits@struts.apache.org From: martinc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091227180133.B7DCD2388C5A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ognl/SetPropertiesTest.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ognl/SetPropertiesTest.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ognl/SetPropertiesTest.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ognl/SetPropertiesTest.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,323 @@ +/* + * Copyright (c) 2002-2003 by OpenSymphony + * All rights reserved. + */ +/* + * Created on 6/10/2003 + * + */ +package com.opensymphony.xwork2.ognl; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.XWorkTestCase; +import com.opensymphony.xwork2.config.ConfigurationException; +import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer; +import com.opensymphony.xwork2.conversion.impl.FooBarConverter; +import com.opensymphony.xwork2.conversion.impl.XWorkConverter; +import com.opensymphony.xwork2.inject.ContainerBuilder; +import com.opensymphony.xwork2.inject.Context; +import com.opensymphony.xwork2.inject.Factory; +import com.opensymphony.xwork2.inject.Scope; +import com.opensymphony.xwork2.mock.MockObjectTypeDeterminer; +import com.opensymphony.xwork2.test.StubConfigurationProvider; +import com.opensymphony.xwork2.util.Bar; +import com.opensymphony.xwork2.util.Cat; +import com.opensymphony.xwork2.util.Foo; +import com.opensymphony.xwork2.util.ValueStack; +import com.opensymphony.xwork2.util.location.LocatableProperties; +import com.opensymphony.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)); + + + } + +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ognl/SetPropertiesTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ognl/SetPropertiesTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2005 Opensymphony. All Rights Reserved. + */ +package com.opensymphony.xwork2.ognl.accessor; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.XWorkTestCase; +import com.opensymphony.xwork2.util.ListHolder; +import com.opensymphony.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")); + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ActionsFromSpringTest.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ActionsFromSpringTest.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ActionsFromSpringTest.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ActionsFromSpringTest.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,78 @@ +/* + * Created on Jun 12, 2004 + */ +package com.opensymphony.xwork2.spring; + +import com.opensymphony.xwork2.*; +import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider; +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("com/opensymphony/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()); + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ActionsFromSpringTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ActionsFromSpringTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/Bar.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/Bar.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/Bar.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/Bar.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,56 @@ +/* + * Created on Nov 12, 2003 + */ +package com.opensymphony.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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/Bar.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/Bar.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ExecuteInterceptor.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ExecuteInterceptor.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ExecuteInterceptor.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ExecuteInterceptor.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,21 @@ +/* + * Created on Jun 12, 2004 + */ +package com.opensymphony.xwork2.spring; + +import com.opensymphony.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(); + } + +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ExecuteInterceptor.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ExecuteInterceptor.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ExternalReferenceAction.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ExternalReferenceAction.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ExternalReferenceAction.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ExternalReferenceAction.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,49 @@ +/* + * Created on Nov 11, 2003 + */ +package com.opensymphony.xwork2.spring; + +import com.opensymphony.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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ExternalReferenceAction.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/ExternalReferenceAction.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/Foo.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/Foo.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/Foo.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/Foo.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,30 @@ +/* + * Created on Nov 11, 2003 + */ +package com.opensymphony.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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/Foo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/Foo.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,362 @@ +package com.opensymphony.xwork2.spring; + +/* + * Copyright (c) 2002-2003 by OpenSymphony + * All rights reserved. + */ +/* + * 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.beans.factory.BeanCreationException; +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; + } + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/SpringObjectFactoryTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/SpringResult.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/SpringResult.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/SpringResult.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/SpringResult.java Sun Dec 27 18:00:13 2009 @@ -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; + } +} + Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/SpringResult.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/SpringResult.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptorTest.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptorTest.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptorTest.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptorTest.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,110 @@ +/* + * Created on 6/11/2004 + */ +package com.opensymphony.xwork2.spring.interceptor; + +import com.opensymphony.xwork2.*; +import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider; +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("com/opensymphony/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()); + } + +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptorTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptorTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/interceptor/TestActionInvocation.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/interceptor/TestActionInvocation.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/interceptor/TestActionInvocation.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/interceptor/TestActionInvocation.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,73 @@ +/* + * Created on 6/11/2004 + */ +package com.opensymphony.xwork2.spring.interceptor; + +import com.opensymphony.xwork2.*; +import com.opensymphony.xwork2.interceptor.PreResultListener; +import com.opensymphony.xwork2.util.ValueStack; + +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) { + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/interceptor/TestActionInvocation.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/spring/interceptor/TestActionInvocation.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2002-2006 by OpenSymphony + * All rights reserved. + */ +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(); +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware2.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware2.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware2.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware2.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2002-2006 by OpenSymphony + * All rights reserved. + */ +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(); +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware2.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationDataAware2.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationTestBean2.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationTestBean2.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationTestBean2.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationTestBean2.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2002-2006 by OpenSymphony + * All rights reserved. + */ +package com.opensymphony.xwork2.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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationTestBean2.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationTestBean2.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUser.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUser.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUser.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUser.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2002-2006 by OpenSymphony + * All rights reserved. + */ +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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUser.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUser.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUserMarker.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUserMarker.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUserMarker.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUserMarker.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2002-2006 by OpenSymphony + * All rights reserved. + */ +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 { +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUserMarker.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/AnnotationUserMarker.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/DataAware.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/DataAware.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/DataAware.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/DataAware.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2002-2003 by OpenSymphony + * All rights reserved. + */ +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(); +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/DataAware.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/DataAware.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/DataAware2.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/DataAware2.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/DataAware2.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/DataAware2.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2002-2003 by OpenSymphony + * All rights reserved. + */ +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(); +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/DataAware2.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/DataAware2.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/Equidae.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/Equidae.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/Equidae.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/Equidae.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2002-2003 by OpenSymphony + * All rights reserved. + */ +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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/Equidae.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/Equidae.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2002-2003 by OpenSymphony + * All rights reserved. + */ +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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2002-2006 by OpenSymphony + * All rights reserved. + */ +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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2002-2003 by OpenSymphony + * All rights reserved. + */ +package com.opensymphony.xwork2.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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction2.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2002-2003 by OpenSymphony + * All rights reserved. + */ +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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAction3.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2002-2006 by OpenSymphony + * All rights reserved. + */ +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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction2.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2002-2006 by OpenSymphony + * All rights reserved. + */ +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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/SimpleAnnotationAction3.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/TestBean2.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/TestBean2.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/TestBean2.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/TestBean2.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2002-2003 by OpenSymphony + * All rights reserved. + */ +package com.opensymphony.xwork2.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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/TestBean2.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/TestBean2.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/User.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/User.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/User.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/User.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2002-2003 by OpenSymphony + * All rights reserved. + */ +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 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; + } +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/User.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/User.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/UserMarker.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/UserMarker.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/UserMarker.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/UserMarker.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2002-2003 by OpenSymphony + * All rights reserved. + */ +package com.opensymphony.xwork2.test; + + +/** + * Marker interface to help test hierarchy traversal. + * + * @author Mark Woon + */ +public interface UserMarker { +} Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/UserMarker.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/UserMarker.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/Address.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/Address.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/Address.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/Address.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,40 @@ +package com.opensymphony.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 Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/Address.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/Address.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/AddressTypeConverter.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/AddressTypeConverter.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/AddressTypeConverter.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/AddressTypeConverter.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,29 @@ +package com.opensymphony.xwork2.test.annotations; + +import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter; + +import java.util.Map; + +public class AddressTypeConverter extends DefaultTypeConverter { + @Override public Object convertValue(Map context, Object value, Class toType) { + if(value instanceof String) { + return decodeAddress((String)value); + } else if(value instanceof String && value.getClass().isArray()) { + return decodeAddress(((String[])value)[0]); + } else { + Address address = (Address)value; + return address.getLine1() + ":" + address.getLine2() + ":" + + address.getCity() + ":" + address.getCountry(); + } + } + + private Address decodeAddress(String encodedAddress) { + String[] parts = ((String)encodedAddress).split(":"); + Address address = new Address(); + address.setLine1(parts[0]); + address.setLine2(parts[1]); + address.setCity(parts[2]); + address.setCountry(parts[3]); + return address; + } +} \ No newline at end of file Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/AddressTypeConverter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/AddressTypeConverter.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/Person.java URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/Person.java?rev=894087&view=auto ============================================================================== --- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/Person.java (added) +++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/test/annotations/Person.java Sun Dec 27 18:00:13 2009 @@ -0,0 +1,22 @@ +package com.opensymphony.xwork2.test.annotations; + +public class Person { + private String firstName; + private String lastName; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } +}