Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/internal/FormSupportImplTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/internal/FormSupportImplTest.java?rev=632085&r1=632084&r2=632085&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/internal/FormSupportImplTest.java (original) +++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/corelib/internal/FormSupportImplTest.java Thu Feb 28 10:52:45 2008 @@ -1,4 +1,4 @@ -// Copyright 2007 The Apache Software Foundation +// Copyright 2007, 2008 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. @@ -15,9 +15,8 @@ package org.apache.tapestry.corelib.internal; import org.apache.tapestry.Field; +import org.apache.tapestry.internal.services.ClientBehaviorSupport; import org.apache.tapestry.internal.test.InternalBaseTestCase; -import org.apache.tapestry.ioc.internal.util.CollectionFactory; -import org.apache.tapestry.json.JSONObject; import org.testng.annotations.Test; public class FormSupportImplTest extends InternalBaseTestCase @@ -135,40 +134,33 @@ @Test public void add_validations() { - Field barney = newField("barney"); - Field fred = newField("fred"); + Field barney = mockField(); + ClientBehaviorSupport clientBehaviorSupport = mockClientBehaviorSupport(); + + clientBehaviorSupport.addValidation(barney, "required", "Who can live without Barney?", null); replay(); - FormSupportImpl support = new FormSupportImpl(); + FormSupportImpl support = new FormSupportImpl(null, null, clientBehaviorSupport, true); support.addValidation(barney, "required", "Who can live without Barney?", null); - support.addValidation(barney, "email", "You know, an e-mail address.", null); - support.addValidation(fred, "maxlength", "Up to 10 characters", 10); verify(); - - - JSONObject validations = support.getValidations(); - - // Tip-toe around the fact that the order of the keys is JDK specific. - - assertEquals(CollectionFactory.newSet(validations.keys()), CollectionFactory.newSet("fred", "barney")); - - assertEquals(validations.get("fred").toString(), "[[\"maxlength\",\"Up to 10 characters\",10]]"); - assertEquals(validations.get("barney").toString(), - "[[\"required\",\"Who can live without Barney?\"],[\"email\",\"You know, an e-mail address.\"]]"); - - } - private Field newField(String clientId) + @Test + public void add_validation_when_client_validation_is_disabled() { - Field field = newMock(Field.class); + Field barney = mockField(); + ClientBehaviorSupport clientBehaviorSupport = mockClientBehaviorSupport(); + + replay(); - expect(field.getClientId()).andReturn(clientId).atLeastOnce(); + FormSupportImpl support = new FormSupportImpl(null, null, clientBehaviorSupport, false); - return field; + support.addValidation(barney, "required", "Who can live without Barney?", null); + + verify(); }
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/components/Any.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/components/Any.java?rev=632085&r1=632084&r2=632085&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/components/Any.java (original) +++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/components/Any.java Thu Feb 28 10:52:45 2008 @@ -27,7 +27,7 @@ void beginRender(MarkupWriter writer) { - writer.element(_resources.getElementName()); + writer.element(_resources.getElementName(null)); _resources.renderInformalParameters(writer); } Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormInjectorDemo.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormInjectorDemo.java?rev=632085&view=auto ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormInjectorDemo.java (added) +++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormInjectorDemo.java Thu Feb 28 10:52:45 2008 @@ -0,0 +1,77 @@ +// Copyright 2008 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.tapestry.integration.app1.pages; + +import org.apache.tapestry.Block; +import org.apache.tapestry.PageRenderSupport; +import org.apache.tapestry.annotations.Component; +import org.apache.tapestry.annotations.Persist; +import org.apache.tapestry.corelib.components.FormInjector; +import org.apache.tapestry.ioc.annotations.Inject; + +public class FormInjectorDemo +{ + @Persist + private double _sum; + + private double _value; + + @Inject + private Block _newRow; + + @Inject + private PageRenderSupport _pageRenderSupport; + + @Component + private FormInjector _formInjector; + + public double getSum() + { + return _sum; + } + + public double getValue() + { + return _value; + } + + public void setValue(double value) + { + _value = value; + } + + void onPrepareForSubmit() + { + _sum = 0; + } + + void onAfterSubmit() + { + _sum += _value; + } + + + void afterRender() + { + _pageRenderSupport.addScript( + "$('addnewrow').observe('click', function() { $('%s').trigger(); return false; });", + _formInjector.getClientId()); + } + + Object onActionFromFormInjector() + { + return _newRow; + } +} Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java?rev=632085&r1=632084&r2=632085&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java (original) +++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java Thu Feb 28 10:52:45 2008 @@ -66,6 +66,8 @@ new Item("numberbeaneditordemo", "Number BeanEditor Demo", "use of nulls and wrapper types with BeanEditor"), + new Item("forminjectordemo", "FormInjector Demo", "extending a form dynamically via Ajax"), + new Item("music", "Music Page", "demo handling of edge cases of page naming"), new Item("PersistentDemo", "Persistent Demo", "storing and clearing persistent properties"), Copied: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ClientBehaviorSupportImplTest.java (from r630031, tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ZoneSetupImplTest.java) URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ClientBehaviorSupportImplTest.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ClientBehaviorSupportImplTest.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ZoneSetupImplTest.java&r1=630031&r2=632085&rev=632085&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ZoneSetupImplTest.java (original) +++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ClientBehaviorSupportImplTest.java Thu Feb 28 10:52:45 2008 @@ -15,12 +15,12 @@ package org.apache.tapestry.internal.services; import org.apache.tapestry.PageRenderSupport; -import static org.apache.tapestry.internal.services.ZoneSetupImpl.ZONE_INITIALIZER_STRING; +import static org.apache.tapestry.internal.services.ClientBehaviorSupportImpl.ZONE_INITIALIZER_STRING; import org.apache.tapestry.json.JSONObject; import org.apache.tapestry.test.TapestryTestCase; import org.testng.annotations.Test; -public class ZoneSetupImplTest extends TapestryTestCase +public class ClientBehaviorSupportImplTest extends TapestryTestCase { @Test public void no_changes() @@ -29,7 +29,7 @@ replay(); - ZoneSetupImpl setup = new ZoneSetupImpl(support); + ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(support); setup.writeInitializationScript(); @@ -47,7 +47,7 @@ replay(); - ZoneSetupImpl setup = new ZoneSetupImpl(support); + ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(support); setup.linkZone("client1", "zone1"); setup.linkZone("client2", "zone2"); @@ -68,7 +68,7 @@ replay(); - ZoneSetupImpl setup = new ZoneSetupImpl(support); + ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(support); setup.addZone("client1", null, null); setup.addZone("client2", null, null); @@ -91,7 +91,7 @@ replay(); - ZoneSetupImpl setup = new ZoneSetupImpl(support); + ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(support); setup.addZone("client1", "showme", null); setup.addZone("client2", null, "updateme"); @@ -113,7 +113,7 @@ replay(); - ZoneSetupImpl setup = new ZoneSetupImpl(support); + ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(support); setup.addZone("client1", "ShowMe", null); setup.addZone("client2", null, "UpdateMe"); Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java?rev=632085&r1=632084&r2=632085&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java (original) +++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java Thu Feb 28 10:52:45 2008 @@ -639,4 +639,9 @@ { expect(securityManager.getBaseURL(page)).andReturn(baseURL).atLeastOnce(); } + + protected final ClientBehaviorSupport mockClientBehaviorSupport() + { + return newMock(ClientBehaviorSupport.class); + } }
