From commitsjoshua86@example.net Sat Jul 01 16:30:43 2006 Return-Path: <commitsjoshua86@example.net> Delivered-To: joshua86@example.net Received: (qmail 29015 invoked from network); 1 Jul 2006 16:30:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 1 Jul 2006 16:30:43 -0000 Received: (qmail 97603 invoked by uid 500); 1 Jul 2006 16:30:41 -0000 Delivered-To: joshua86@example.net Received: (qmail 97581 invoked by uid 500); 1 Jul 2006 16:30:41 -0000 Mailing-List: contact joshua86@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:joshua86@example.net> List-Unsubscribe: <mailto:joshua86@example.net> List-Post: <mailto:joshua86@example.net> List-Id: <commits.tapestry.apache.org> Reply-To: joshua86@example.net Delivered-To: mailing list joshua86@example.net Received: (qmail 97572 invoked by uid 99); 1 Jul 2006 16:30:41 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Jul 2006 09:30:41 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Jul 2006 09:30:39 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 7D19F1A983A; Sat, 1 Jul 2006 09:30:19 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r418490 - in /tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry: ./ callback/ components/ describe/ engine/state/ error/ form/ form/translator/ junit/script/ pageload/ services/impl/ util/ valid/ Date: Sat, 01 Jul 2006 16:30:16 -0000 To: joshua86@example.net From: joshua86@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <joshua86@example.net> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jkuhnert Date: Sat Jul 1 09:30:13 2006 New Revision: 418490 URL: http://svn.apache.org/viewvc?rev=418490&view=rev Log: all framework tests pass again (finally) Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/BaseComponentTestCase.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/callback/TestDirectCallback.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/components/TestAny.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/describe/TestLocationRenderStrategy.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/engine/state/TestSessionScopeManager.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/error/BaseErrorTestCase.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/error/TestExceptionPresenter.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/FormComponentContributorTestCase.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/LinkSubmitTest.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/TestTextArea.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/translator/TestNumberTranslator.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/junit/script/MockScriptProcessor.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/junit/script/TestScript.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/pageload/PageLoaderTest.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineServiceInnerProxyTest.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/util/TestPageRenderSupport.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/valid/TestEmailValidator.java Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/BaseComponentTestCase.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/BaseComponentTestCase.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/BaseComponentTestCase.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/BaseComponentTestCase.java Sat Jul 1 09:30:13 2006 @@ -162,7 +162,8 @@ protected IRequestCycle newCycle(boolean rewinding, IMarkupWriter writer) { IRequestCycle cycle = newRequestCycle(); - + checkOrder(cycle, false); + trainIsRewinding(cycle, rewinding); if (writer != null) @@ -236,7 +237,8 @@ protected IComponent newComponent(String extendedId, Location location) { IComponent component = newMock(IComponent.class); - + checkOrder(component, false); + expect(component.getExtendedId()).andReturn(extendedId); expect(component.getLocation()).andReturn(location); return component; Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/callback/TestDirectCallback.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/callback/TestDirectCallback.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/callback/TestDirectCallback.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/callback/TestDirectCallback.java Sat Jul 1 09:30:13 2006 @@ -112,7 +112,7 @@ expect(component.getPage()).andReturn(page); expect(page.getPageName()).andReturn("Fred"); - + expect(component.getIdPath()).andReturn("foo.bar"); replay(); @@ -124,10 +124,10 @@ verify(); IRequestCycle cycle = newCycleGetPage("Fred", page); - + Location l = newLocation(); IComponent component2 = newComponent("Fred/foo.bar", l); - + expect(page.getNestedComponent("foo.bar")).andReturn(component2); replay(); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/components/TestAny.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/components/TestAny.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/components/TestAny.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/components/TestAny.java Sat Jul 1 09:30:13 2006 @@ -66,10 +66,10 @@ { IMarkupWriter writer = newWriter(); IRequestCycle cycle = newCycle(false, writer); - IRender body = newRender(); - + writer.begin("span"); - + + IRender body = newRender(); body.render(writer, cycle); writer.end("span"); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/describe/TestLocationRenderStrategy.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/describe/TestLocationRenderStrategy.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/describe/TestLocationRenderStrategy.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/describe/TestLocationRenderStrategy.java Sat Jul 1 09:30:13 2006 @@ -14,7 +14,7 @@ package org.apache.tapestry.describe; -import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.*; import java.net.URL; @@ -38,7 +38,8 @@ private Resource newResource(URL url) { Resource resource = newMock(Resource.class); - + checkOrder(resource, false); + expect(resource.getResourceURL()).andReturn(url); return resource; @@ -88,10 +89,10 @@ IRequestCycle cycle = newCycle(); Location l = newLocation(); - expect(l.getLineNumber()).andReturn(0); - writer.print(l.toString()); - + + expect(l.getLineNumber()).andReturn(0); + replay(); new LocationRenderStrategy().renderObject(l, writer, cycle); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/engine/state/TestSessionScopeManager.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/engine/state/TestSessionScopeManager.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/engine/state/TestSessionScopeManager.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/engine/state/TestSessionScopeManager.java Sat Jul 1 09:30:13 2006 @@ -14,6 +14,7 @@ package org.apache.tapestry.engine.state; +import static org.easymock.EasyMock.checkOrder; import static org.easymock.EasyMock.expect; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertSame; @@ -54,7 +55,8 @@ private WebSession newSession(String key, Object value) { WebSession session = newSession(); - + checkOrder(session, false); + trainGetAttribute(session, key, value); return session; @@ -87,7 +89,7 @@ { WebSession session = newSession("state:myapp:fred", null); WebRequest request = newRequest(false, session); - + replay(); SessionScopeManager m = new SessionScopeManager(); @@ -135,16 +137,17 @@ public void testGetAndCreate() { Object stateObject = new Object(); - StateObjectFactory factory = newFactory(stateObject); - + WebSession session = newSession(); - + + WebRequest request = newRequest(session); + trainGetAttribute(session, "state:myapp:fred", null); + StateObjectFactory factory = newFactory(stateObject); + session.setAttribute("state:myapp:fred", stateObject); - WebRequest request = newRequest(session); - replay(); SessionScopeManager m = new SessionScopeManager(); @@ -166,10 +169,9 @@ Object stateObject = new Object(); WebSession session = newSession(); - - session.setAttribute("state:myapp:fred", stateObject); - WebRequest request = newRequest(session); + + session.setAttribute("state:myapp:fred", stateObject); replay(); @@ -214,10 +216,9 @@ Object stateObject = newOptimized(true); WebSession session = newSession(); - - session.setAttribute("state:myapp:fred", stateObject); - WebRequest request = newRequest(session); + + session.setAttribute("state:myapp:fred", stateObject); replay(); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/error/BaseErrorTestCase.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/error/BaseErrorTestCase.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/error/BaseErrorTestCase.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/error/BaseErrorTestCase.java Sat Jul 1 09:30:13 2006 @@ -14,8 +14,7 @@ package org.apache.tapestry.error; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.*; import org.apache.tapestry.BaseComponentTestCase; import org.apache.tapestry.IPage; @@ -43,6 +42,7 @@ protected IRequestCycle newCycle(String pageName, IPage page) { IRequestCycle cycle = newCycle(); + checkOrder(cycle, false); expect(cycle.getPage(pageName)).andReturn(page); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/error/TestExceptionPresenter.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/error/TestExceptionPresenter.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/error/TestExceptionPresenter.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/error/TestExceptionPresenter.java Sat Jul 1 09:30:13 2006 @@ -68,16 +68,16 @@ IPage page = newPage(); IRequestCycle cycle = newCycle("Exception", page); - ResponseRenderer renderer = newRenderer(cycle, renderCause); + RequestExceptionReporter reporter = newReporter(); - + cycle.activate(page); - + reporter.reportRequestException(ErrorMessages.unableToProcessClientRequest(cause), cause); - reporter.reportRequestException( - ErrorMessages.unableToPresentExceptionPage(renderCause), - renderCause); - + reporter.reportRequestException(ErrorMessages.unableToPresentExceptionPage(renderCause), renderCause); + + ResponseRenderer renderer = newRenderer(cycle, renderCause); + replay(); ExceptionPresenterImpl ep = new ExceptionPresenterImpl(); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/FormComponentContributorTestCase.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/FormComponentContributorTestCase.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/FormComponentContributorTestCase.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/FormComponentContributorTestCase.java Sat Jul 1 09:30:13 2006 @@ -82,7 +82,8 @@ protected IFormComponent newField(String displayName, String clientId, int count) { IFormComponent field = newMock(IFormComponent.class); - + checkOrder(field, false); + expect(field.getDisplayName()).andReturn(displayName); expect(field.getClientId()).andReturn(clientId).times(count); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/LinkSubmitTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/LinkSubmitTest.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/LinkSubmitTest.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/LinkSubmitTest.java Sat Jul 1 09:30:13 2006 @@ -157,9 +157,9 @@ } catch (ApplicationRuntimeException ex) { - assertEquals( - "LinkSubmit MyPage/fred may not be enclosed by another LinkSubmit (MyPage/barney, at classpath:/org/apache/tapestry/form/LinkSubmitTest, line 1).", - ex.getMessage()); + assert ex.getMessage() + .indexOf("LinkSubmit MyPage/fred may not be enclosed by another LinkSubmit ") > -1; + assertSame(linkSubmit, ex.getComponent()); assertSame(floc, ex.getLocation()); } @@ -230,12 +230,12 @@ trainGetDelegate(form, delegate); - trainGetElementId(form, linkSubmit, "fred"); - delegate.setFormComponent(linkSubmit); - + + trainGetElementId(form, linkSubmit, "fred"); + trainIsRewinding(form, true); - + // Finally, code inside LinkSubmit ... trainGetParameter(cycle, FormConstants.SUBMIT_NAME_PARAMETER, null); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/TestTextArea.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/TestTextArea.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/TestTextArea.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/TestTextArea.java Sat Jul 1 09:30:13 2006 @@ -285,14 +285,19 @@ delegate.setFormComponent(component); trainGetDelegate(form, delegate); - trainGetDelegate(form, delegate); - trainGetDelegate(form, delegate); expect(tfs.format(component, " text area value ")).andReturn("text area value"); + trainGetDelegate(form, delegate); + tfs.renderContributions(component, writer, cycle); + + trainGetDelegate(form, delegate); + vfs.renderContributions(component, writer, cycle); + trainGetDelegate(form, delegate); + replay(); component.render(writer, cycle); @@ -328,16 +333,19 @@ trainIsRewinding(cycle, false); delegate.setFormComponent(component); - - trainGetDelegate(form, delegate); - trainGetDelegate(form, delegate); - trainGetDelegate(form, delegate); - + expect(tfs.format(component, " text area value ")).andReturn("text area value"); + trainGetDelegate(form, delegate); + tfs.renderContributions(component, writer, cycle); + + trainGetDelegate(form, delegate); + vfs.renderContributions(component, writer, cycle); + trainGetDelegate(form, delegate); + replay(); component.render(writer, cycle); @@ -378,10 +386,6 @@ delegate.setFormComponent(component); - trainGetDelegate(form, delegate); - trainGetDelegate(form, delegate); - trainGetDelegate(form, delegate); - expect(tfs.format(component, " text area value ")).andReturn("text area value"); tfs.renderContributions(component, writer, cycle); @@ -423,15 +427,18 @@ delegate.setFormComponent(component); - trainGetDelegate(form, delegate); - trainGetDelegate(form, delegate); - trainGetDelegate(form, delegate); - expect(tfs.format(component, null)).andReturn(""); + trainGetDelegate(form, delegate); + tfs.renderContributions(component, writer, cycle); + + trainGetDelegate(form, delegate); + vfs.renderContributions(component, writer, cycle); + trainGetDelegate(form, delegate); + replay(); component.render(writer, cycle); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/translator/TestNumberTranslator.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/translator/TestNumberTranslator.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/translator/TestNumberTranslator.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/translator/TestNumberTranslator.java Sat Jul 1 09:30:13 2006 @@ -75,7 +75,7 @@ testFormat(translator, new Double(0.10), "10%"); } - public void testFormat(Translator translator, Number number, String expected) + private void testFormat(Translator translator, Number number, String expected) { IFormComponent field = newField(); @@ -143,7 +143,7 @@ public void testFailedParseDefaultMessage() { NumberTranslator translator = new NumberTranslator(); - + testFailedParse(translator, null); } @@ -165,7 +165,6 @@ ValidationMessages messages = newMock(ValidationMessages.class); trainGetLocale(messages, Locale.ENGLISH); - trainGetLocale(messages, Locale.ENGLISH); trainBuildMessage( messages, @@ -195,24 +194,22 @@ public void testRenderContribution() { NumberTranslator translator = new NumberTranslator(); - + IFormComponent field = newField("Number Field", "numberField", 1); + IMarkupWriter writer = newWriter(); IRequestCycle cycle = newCycle(); FormComponentContributorContext context = newMock(FormComponentContributorContext.class); - + context.includeClasspathScript(translator.defaultScript()); - + trainGetLocale(context, Locale.ENGLISH); - + trainBuildMessage(context, null, ValidationStrings.INVALID_NUMBER, new Object[] { "Number Field", "#" }, "invalid number message"); - context - .addSubmitHandler("function(event) { Tapestry.validate_number(event, 'numberField', 'invalid number message'); }"); - - IFormComponent field = newField("Number Field", "numberField", 1); - + context.addSubmitHandler("function(event) { Tapestry.validate_number(event, 'numberField', 'invalid number message'); }"); + replay(); translator.renderContribution(writer, cycle, context, field); @@ -223,7 +220,8 @@ public void testMessageRenderContribution() { NumberTranslator translator = new NumberTranslator(); - + IFormComponent field = newField("Number Field", "myfield", 1); + String messageOverride = "You entered a bunk value for {0}. I should look like {1}. Watch out for ''this''!"; IMarkupWriter writer = newWriter(); @@ -243,10 +241,7 @@ { "Number Field", "#" }, "Blah Blah 'Field Name' Blah."); - context - .addSubmitHandler("function(event) { Tapestry.validate_number(event, 'myfield', 'Blah Blah \\'Field Name\\' Blah.'); }"); - - IFormComponent field = newField("Number Field", "myfield", 1); + context.addSubmitHandler("function(event) { Tapestry.validate_number(event, 'myfield', 'Blah Blah \\'Field Name\\' Blah.'); }"); replay(); @@ -259,7 +254,6 @@ public void testTrimRenderContribution() { - IFormComponent field = newField("Number Field", "myfield", 2); NumberTranslator translator = new NumberTranslator(); @@ -270,7 +264,7 @@ FormComponentContributorContext context = newMock(FormComponentContributorContext.class); context.includeClasspathScript(translator.defaultScript()); - + trainTrim(context, "myfield"); trainGetLocale(context, Locale.ENGLISH); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/junit/script/MockScriptProcessor.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/junit/script/MockScriptProcessor.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/junit/script/MockScriptProcessor.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/junit/script/MockScriptProcessor.java Sat Jul 1 09:30:13 2006 @@ -38,6 +38,17 @@ private IdAllocator _idAllocator = new IdAllocator(); + public void reset() + { + if (_body != null) + _body.delete(0, _body.length()); + if (_initialization != null) + _initialization.delete(0, _initialization.length()); + if (_externalScripts != null) + _externalScripts.clear(); + _idAllocator.clear(); + } + public void addBodyScript(String script) { addBodyScript(null, script); @@ -89,7 +100,7 @@ { if (_externalScripts == null) _externalScripts = new ArrayList(); - + _externalScripts.add(scriptResource); } @@ -108,4 +119,4 @@ return _idAllocator.allocateId(baseValue); } -} \ No newline at end of file +} Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/junit/script/TestScript.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/junit/script/TestScript.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/junit/script/TestScript.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/junit/script/TestScript.java Sat Jul 1 09:30:13 2006 @@ -15,7 +15,6 @@ package org.apache.tapestry.junit.script; import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertNull; import java.util.Arrays; import java.util.HashMap; @@ -37,6 +36,7 @@ import org.apache.tapestry.services.impl.ExpressionCacheImpl; import org.apache.tapestry.services.impl.ExpressionEvaluatorImpl; import org.apache.tapestry.util.xml.DocumentParseException; +import org.testng.annotations.Configuration; import org.testng.annotations.Test; /** @@ -50,6 +50,12 @@ { private MockScriptProcessor _processor = new MockScriptProcessor(); + @Configuration(afterTestMethod = true) + public void reset() + { + _processor.reset(); + } + protected static ExpressionEvaluator createExpressionEvaluator() { ExpressionCache cache = new ExpressionCacheImpl(); @@ -101,10 +107,12 @@ public void testSimple() throws Exception { execute("simple.script", null); - + assertEquals("body", "\nBODY\n", _processor.getBody()); assertEquals("initialization", "\nINITIALIZATION\n", _processor.getInitialization()); - assertNull(_processor.getExternalScripts()); + + assert _processor.getExternalScripts() == null + || _processor.getExternalScripts().length == 0; } /** @@ -132,9 +140,9 @@ public void testEmpty() throws Exception { execute("empty.script", null); - - assertNull("body", _processor.getBody()); - assertNull("initialization", _processor.getInitialization()); + + assert _processor.getBody() == null || _processor.getBody().length() == 0; + assert _processor.getInitialization() == null || _processor.getInitialization().length() == 0; } /** Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/pageload/PageLoaderTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/pageload/PageLoaderTest.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/pageload/PageLoaderTest.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/pageload/PageLoaderTest.java Sat Jul 1 09:30:13 2006 @@ -14,8 +14,9 @@ package org.apache.tapestry.pageload; +import static org.easymock.EasyMock.endsWith; import static org.easymock.EasyMock.expect; -import static org.testng.AssertJUnit.assertEquals; +import static org.easymock.EasyMock.startsWith; import static org.testng.AssertJUnit.assertSame; import org.apache.commons.logging.Log; @@ -64,9 +65,8 @@ } catch (ApplicationRuntimeException ex) { - assertEquals( - "A binding for parameter dupe conflicts with a previous binding (at classpath:/org/apache/tapestry/pageload/PageLoaderTest, line 1).", - ex.getMessage()); + assert ex.getMessage() + .indexOf("A binding for parameter dupe conflicts with a previous binding") > -1; assertSame(component, ex.getComponent()); assertSame(l2, ex.getLocation()); } @@ -100,8 +100,7 @@ trainGetSpecification(component, spec); - log - .warn("Parameter barney (for component FredComponent, at classpath:/org/apache/tapestry/pageload/PageLoaderTest, line 1) was bound; this parameter has been deprecated, bind parameter fred instead."); + log.warn(startsWith("Parameter barney (for component FredComponent, at ")); trainCreateBinding( source, @@ -167,10 +166,9 @@ trainGetSpecification(component, spec); - log - .warn("Parameter fred (at classpath:/org/apache/tapestry/pageload/PageLoaderTest, line 1) has been deprecated, " + log.warn(endsWith("has been deprecated, " + "and may be removed in a future release. Consult the documentation for component FredComponent to " - + "determine an appropriate replacement."); + + "determine an appropriate replacement.")); trainCreateBinding(source, container, "parameter fred", "an-expression", "ognl", l, binding); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineServiceInnerProxyTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineServiceInnerProxyTest.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineServiceInnerProxyTest.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/EngineServiceInnerProxyTest.java Sat Jul 1 09:30:13 2006 @@ -68,11 +68,11 @@ IEngineService service = newEngineService(); Object parameter = new Object(); - - trainGetLink(service, false, parameter, link); - + EngineServiceSource source = newSource("fred", service); + trainGetLink(service, false, parameter, link); + replay(); EngineServiceOuterProxy outer = new EngineServiceOuterProxy("fred"); @@ -95,10 +95,10 @@ Object parameter = new Object(); - trainGetLink(service, true, parameter, link); - EngineServiceSource source = newSource("fred", service); - + + trainGetLink(service, true, parameter, link); + replay(); EngineServiceOuterProxy outer = new EngineServiceOuterProxy("fred"); @@ -116,11 +116,11 @@ { IRequestCycle cycle = newCycle(); IEngineService service = newEngineService(); - - service.service(cycle); - + EngineServiceSource source = newSource("fred", service); - + + service.service(cycle); + replay(); EngineServiceOuterProxy outer = new EngineServiceOuterProxy("fred"); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/util/TestPageRenderSupport.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/util/TestPageRenderSupport.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/util/TestPageRenderSupport.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/util/TestPageRenderSupport.java Sat Jul 1 09:30:13 2006 @@ -14,7 +14,7 @@ package org.apache.tapestry.util; -import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.*; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertSame; @@ -51,7 +51,8 @@ private IAsset newAsset(IRequestCycle cycle, String url) { IAsset asset = newMock(IAsset.class); - + checkOrder(asset, false); + expect(asset.buildURL()).andReturn(url); return asset; @@ -252,13 +253,14 @@ String newline = System.getProperty("line.separator"); IRequestCycle cycle = newCycle(); - + IMarkupWriter writer = createWriter(); AssetFactory assetFactory = newMock(AssetFactory.class); - + Resource script1 = newResource(); IAsset asset1 = newAsset(cycle, "/script1.js"); + Resource script2 = newResource(); IAsset asset2 = newAsset(cycle, "/script2.js"); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/valid/TestEmailValidator.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/valid/TestEmailValidator.java?rev=418490&r1=418489&r2=418490&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/valid/TestEmailValidator.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/valid/TestEmailValidator.java Sat Jul 1 09:30:13 2006 @@ -17,6 +17,7 @@ import static org.testng.AssertJUnit.assertEquals; import org.apache.tapestry.form.IFormComponent; +import org.testng.annotations.Configuration; import org.testng.annotations.Test; /** @@ -30,6 +31,17 @@ { private EmailValidator v = new EmailValidator(); + @Configuration(afterTestMethod = true) + public void reset() + { + v.setClientScriptingEnabled(false); + v.setInvalidEmailFormatMessage(null); + v.setMinimumLength(-1); + v.setMinimumLengthMessage(null); + v.setRequired(false); + v.setRequiredMessage(null); + } + public void testValidEmail() throws ValidatorException { IFormComponent field = newField(); From commitsjoshua86@example.net Sat Jul 01 17:28:48 2006 Return-Path: <commitsjoshua86@example.net> Delivered-To: joshua86@example.net Received: (qmail 33442 invoked from network); 1 Jul 2006 17:28:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 1 Jul 2006 17:28:48 -0000 Received: (qmail 15505 invoked by uid 500); 1 Jul 2006 17:28:47 -0000 Delivered-To: joshua86@example.net Received: (qmail 15490 invoked by uid 500); 1 Jul 2006 17:28:47 -0000 Mailing-List: contact joshua86@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:joshua86@example.net> List-Unsubscribe: <mailto:joshua86@example.net> List-Post: <mailto:joshua86@example.net> List-Id: <commits.tapestry.apache.org> Reply-To: joshua86@example.net Delivered-To: mailing list joshua86@example.net Received: (qmail 15481 invoked by uid 99); 1 Jul 2006 17:28:47 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Jul 2006 10:28:47 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Jul 2006 10:28:46 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 5819B1A983A; Sat, 1 Jul 2006 10:28:26 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r418492 - in /tapestry/tapestry4/trunk: .settings/org.eclipse.jdt.ui.prefs forrest.properties framework/pom.xml framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java pom.xml project.properties Date: Sat, 01 Jul 2006 17:28:25 -0000 To: joshua86@example.net From: joshua86@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <joshua86@example.net> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jkuhnert Date: Sat Jul 1 10:28:24 2006 New Revision: 418492 URL: http://svn.apache.org/viewvc?rev=418492&view=rev Log: Cleaned up some files, fixed another unit test, added source jar distributions Removed: tapestry/tapestry4/trunk/forrest.properties tapestry/tapestry4/trunk/project.properties Modified: tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.ui.prefs tapestry/tapestry4/trunk/framework/pom.xml tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java tapestry/tapestry4/trunk/pom.xml Modified: tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.ui.prefs URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.ui.prefs?rev=418492&r1=418491&r2=418492&view=diff ============================================================================== --- tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.ui.prefs (original) +++ tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.ui.prefs Sat Jul 1 10:28:24 2006 @@ -1,4 +1,4 @@ -#Sat Mar 11 20:18:44 EST 2006 +#Sat Jul 01 12:53:42 EDT 2006 eclipse.preferences.version=1 formatter_profile=_tapestry formatter_settings_version=10 @@ -12,4 +12,4 @@ org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 -org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" deleted \="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">// Copyright ${date} The Apache Software Foundation\n//\n// Licensed under the Apache License, Version 2.0 (the "License");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http\://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an "AS IS" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment ">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/** \n * {@inheritDoc}\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name \="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="an notationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Co de in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates> +org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment _context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">// Copyright ${date} The Apache Software Foundation\n//\n// Licensed under the Apache License, Version 2.0 (the "License");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http\://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an "AS IS" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" n ame\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/** \n * {@inheritDoc}\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetempla tes.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotati onbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template></templates> Modified: tapestry/tapestry4/trunk/framework/pom.xml URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/pom.xml?rev=418492&r1=418491&r2=418492&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/pom.xml (original) +++ tapestry/tapestry4/trunk/framework/pom.xml Sat Jul 1 10:28:24 2006 @@ -173,18 +173,22 @@ <configuration> <source>1.5</source> <target>1.5</target> - <fork>true</fork> - <verbose>true</verbose> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.1-SNAPSHOT</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-clover-plugin</artifactId> <version>2.1</version> <configuration> <licenseLocation> ${user.home}/.m2/repository/com/cenqua/clover/clover.license </licenseLocation> + <jdk>1.5</jdk> </configuration> <executions> <execution> @@ -256,6 +260,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> + <version>2.2-SNAPSHOT</version> <configuration> <configLocation>${basedir}/../tapestry-checkstyle.xml</configLocation> </configuration> Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java?rev=418492&r1=418491&r2=418492&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java Sat Jul 1 10:28:24 2006 @@ -14,19 +14,24 @@ package org.apache.tapestry.asset; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertNull; +import static org.testng.AssertJUnit.assertTrue; + import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.TreeMap; import org.apache.hivemind.impl.DefaultClassResolver; -import org.apache.hivemind.test.HiveMindTestCase; import org.apache.oro.text.regex.MalformedPatternException; import org.apache.oro.text.regex.Pattern; import org.apache.oro.text.regex.PatternCompiler; import org.apache.oro.text.regex.PatternMatcher; import org.apache.oro.text.regex.Perl5Compiler; import org.apache.oro.text.regex.Perl5Matcher; +import org.apache.tapestry.BaseComponentTestCase; import org.apache.tapestry.services.ServiceConstants; import org.testng.annotations.Test; @@ -36,7 +41,7 @@ * @author jkuhnert */ @Test -public class TestUnprotectedAsset extends HiveMindTestCase +public class TestUnprotectedAsset extends BaseComponentTestCase { PatternCompiler compiler = new Perl5Compiler(); Modified: tapestry/tapestry4/trunk/pom.xml URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/pom.xml?rev=418492&r1=418491&r2=418492&view=diff ============================================================================== --- tapestry/tapestry4/trunk/pom.xml (original) +++ tapestry/tapestry4/trunk/pom.xml Sat Jul 1 10:28:24 2006 @@ -197,6 +197,10 @@ <target>1.5</target> </configuration> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + </plugin> </plugins> </pluginManagement> </build> From commitsjoshua86@example.net Sat Jul 01 17:41:28 2006 Return-Path: <commitsjoshua86@example.net> Delivered-To: joshua86@example.net Received: (qmail 34210 invoked from network); 1 Jul 2006 17:41:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 1 Jul 2006 17:41:28 -0000 Received: (qmail 24295 invoked by uid 500); 1 Jul 2006 17:41:27 -0000 Delivered-To: joshua86@example.net Received: (qmail 24276 invoked by uid 500); 1 Jul 2006 17:41:27 -0000 Mailing-List: contact joshua86@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:joshua86@example.net> List-Unsubscribe: <mailto:joshua86@example.net> List-Post: <mailto:joshua86@example.net> List-Id: <commits.tapestry.apache.org> Reply-To: joshua86@example.net Delivered-To: mailing list joshua86@example.net Received: (qmail 24267 invoked by uid 99); 1 Jul 2006 17:41:27 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Jul 2006 10:41:27 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Jul 2006 10:41:26 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 617A51A983A; Sat, 1 Jul 2006 10:41:06 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r418493 - in /tapestry/tapestry4/trunk/framework/src: descriptor/META-INF/tapestry.services.xml java/org/apache/tapestry/asset/AssetService.java Date: Sat, 01 Jul 2006 17:41:05 -0000 To: joshua86@example.net From: joshua86@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <joshua86@example.net> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jkuhnert Date: Sat Jul 1 10:41:05 2006 New Revision: 418493 URL: http://svn.apache.org/viewvc?rev=418493&view=rev Log: Added asset service to the list of reset event listeners so that resources are also not cached in disabled caching mode (now that caching works it's kind of annoying during dev ) Modified: tapestry/tapestry4/trunk/framework/src/descriptor/META-INF/tapestry.services.xml tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/asset/AssetService.java Modified: tapestry/tapestry4/trunk/framework/src/descriptor/META-INF/tapestry.services.xml URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/descriptor/META-INF/tapestry.services.xml?rev=418493&r1=418492&r2=418493&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/descriptor/META-INF/tapestry.services.xml (original) +++ tapestry/tapestry4/trunk/framework/src/descriptor/META-INF/tapestry.services.xml Sat Jul 1 10:41:05 2006 @@ -80,6 +80,7 @@ <set-service property="digestSource" service-id="tapestry.asset.ResourceDigestSource" /> <set-service property="unprotectedMatcher" service-id="tapestry.asset.UnprotectedResourceMatcher" /> + <event-listener service-id="tapestry.ResetEventHub"/> </construct> </invoke-factory> </service-point> Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/asset/AssetService.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/asset/AssetService.java?rev=418493&r1=418492&r2=418493&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/asset/AssetService.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/asset/AssetService.java Sat Jul 1 10:41:05 2006 @@ -39,6 +39,7 @@ import org.apache.tapestry.engine.IEngineService; import org.apache.tapestry.engine.ILink; import org.apache.tapestry.error.RequestExceptionReporter; +import org.apache.tapestry.event.ResetEventListener; import org.apache.tapestry.services.LinkFactory; import org.apache.tapestry.services.ServiceConstants; import org.apache.tapestry.util.ContentType; @@ -60,7 +61,7 @@ * @author Howard Lewis Ship */ -public class AssetService implements IEngineService +public class AssetService implements IEngineService, ResetEventListener { /** * Query parameter that stores the path to the resource (with a leading slash). @@ -142,6 +143,18 @@ private RequestExceptionReporter _exceptionReporter; + /** Used to prevent caching of resources when in disabled caching mode. */ + + private long _lastResetTime = -1; + + /** + * {@inheritDoc} + */ + public void resetEventDidOccur() + { + _lastResetTime = System.currentTimeMillis(); + } + /** * Builds a {@link ILink}for a {@link PrivateAsset}. * <p> @@ -296,7 +309,8 @@ modify = CACHED_FORMAT.parse(header).getTime(); } catch (ParseException e) { e.printStackTrace(); } - if (resource.lastModified() > modify) + if (resource.lastModified() > modify + || _lastResetTime > modify) return false; _response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); From commitsjoshua86@example.net Sat Jul 01 22:20:56 2006 Return-Path: <commitsjoshua86@example.net> Delivered-To: joshua86@example.net Received: (qmail 83650 invoked from network); 1 Jul 2006 22:20:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 1 Jul 2006 22:20:56 -0000 Received: (qmail 78156 invoked by uid 500); 1 Jul 2006 22:20:55 -0000 Delivered-To: joshua86@example.net Received: (qmail 78133 invoked by uid 500); 1 Jul 2006 22:20:54 -0000 Mailing-List: contact joshua86@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:joshua86@example.net> List-Unsubscribe: <mailto:joshua86@example.net> List-Post: <mailto:joshua86@example.net> List-Id: <commits.tapestry.apache.org> Reply-To: joshua86@example.net Delivered-To: mailing list joshua86@example.net Received: (qmail 78123 invoked by uid 99); 1 Jul 2006 22:20:54 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Jul 2006 15:20:54 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Jul 2006 15:20:53 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id C16041A983A; Sat, 1 Jul 2006 15:20:32 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r418513 - in /tapestry/tapestry4/trunk: examples/TimeTracker/src/context/ examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/ framework/src/java/org/apache/tapestry/form/ framework/src/java/org/apache/tapestry/form/validator... Date: Sat, 01 Jul 2006 22:20:29 -0000 To: joshua86@example.net From: joshua86@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <joshua86@example.net> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jkuhnert Date: Sat Jul 1 15:20:28 2006 New Revision: 418513 URL: http://svn.apache.org/viewvc?rev=418513&view=rev Log: Added much improved client side date validation Added: tapestry/tapestry4/trunk/framework/src/js/tapestry/form/datetime.js (with props) tapestry/tapestry4/trunk/framework/src/js/tests/form/ tapestry/tapestry4/trunk/framework/src/js/tests/form/test_datetime.js (with props) tapestry/tapestry4/trunk/framework/src/js/tests/widget/test_TimePickerDate.js - copied unchanged from r418490, tapestry/tapestry4/trunk/framework/src/js/tests/widget/test_datetime.js Removed: tapestry/tapestry4/trunk/framework/src/js/tests/widget/test_datetime.js Modified: tapestry/tapestry4/trunk/examples/TimeTracker/src/context/Home.html tapestry/tapestry4/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContext.java tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContextImpl.java tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Email.java tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Max.java tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxDate.java tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/json/JSONObject.java tapestry/tapestry4/trunk/framework/src/js/tapestry/__package__.js tapestry/tapestry4/trunk/framework/src/js/tapestry/form.js tapestry/tapestry4/trunk/framework/src/js/tapestry/form/__package__.js tapestry/tapestry4/trunk/framework/src/js/tapestry/form/validation.js tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestEmail.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMax.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMaxDate.java Modified: tapestry/tapestry4/trunk/examples/TimeTracker/src/context/Home.html URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/examples/TimeTracker/src/context/Home.html?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/examples/TimeTracker/src/context/Home.html (original) +++ tapestry/tapestry4/trunk/examples/TimeTracker/src/context/Home.html Sat Jul 1 15:20:28 2006 @@ -46,6 +46,18 @@ <input jwcid="@Submit" value="message:button.add" class="submitButton" action="listener:addTask" /> </td> </tr> + + <!-- + <tr> + <td> + <div class="field required"> + <input jwcid="emailInput@TextField" value="ognl:email" + validators="validators:email,required" /> + </div> + </td> + </tr> + --> + </table> </fieldset> </form> Modified: tapestry/tapestry4/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java (original) +++ tapestry/tapestry4/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java Sat Jul 1 15:20:28 2006 @@ -59,7 +59,9 @@ public abstract Project getCurrentProject(); @Component(type = "DropdownDatePicker", id = "datePicker", - bindings = {"value=date", "displayName=message:task.start.date"}) + bindings = {"value=date", + "displayName=message:task.start.date", + "validators=validators:required,maxDate=05/29/2006"}) public abstract DropdownDatePicker getDatePicker(); public abstract Date getDate(); @@ -84,6 +86,8 @@ @InjectObject("service:timetracker.dao.TaskDao") public abstract TaskDao getTaskDao(); + + public abstract String getEmail(); /** * Selection model for projects. Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContext.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContext.java?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContext.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContext.java Sat Jul 1 15:20:28 2006 @@ -14,6 +14,7 @@ package org.apache.tapestry.form; +import org.apache.tapestry.IComponent; import org.apache.tapestry.json.JSONObject; /** @@ -45,7 +46,16 @@ */ void addSubmitHandler(String handler); - + + /** + * Adds initialization javascript code that will be executed on page/content/etc load. + * @param target + * The component the script is being added for. + * @param script + * The javascript code to execute. + */ + void addInitializationScript(IComponent target, String script); + /** * Registers a field for automatic focus. The goal is for the first field that is in error to * get focus; failing that, the first required field; failing that, any field. Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContextImpl.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContextImpl.java?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContextImpl.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContextImpl.java Sat Jul 1 15:20:28 2006 @@ -19,6 +19,7 @@ import org.apache.hivemind.ClassResolver; import org.apache.hivemind.Resource; import org.apache.hivemind.util.ClasspathResource; +import org.apache.tapestry.IComponent; import org.apache.tapestry.IForm; import org.apache.tapestry.IRequestCycle; import org.apache.tapestry.PageRenderSupport; @@ -85,7 +86,12 @@ _pageRenderSupport.addInitializationScript("Tapestry.onsubmit('" + _formId + "', " + submitListener + ");"); } - + + public void addInitializationScript(IComponent target, String script) + { + _pageRenderSupport.addInitializationScript(target, script); + } + public void registerForFocus(int priority) { _form.registerForFocus(_field, priority); Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Email.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Email.java?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Email.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Email.java Sat Jul 1 15:20:28 2006 @@ -37,16 +37,16 @@ public class Email extends BaseValidator { static final String PATTERN = "^\\w[-._\\w]*\\w@\\w[-._\\w]*\\w\\.\\w{2,6}$"; - + // TODO: Possible thread safety issue if the validator // is shared across threads, because the matcher // will be too. private RegexpMatcher _matcher = new RegexpMatcher(); - + public Email() { } - + public Email(String initializer) { super(initializer); @@ -74,6 +74,7 @@ public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) { + context.addInitializationScript(field, "dojo.require(\"dojo.validate.web\");"); JSONObject profile = context.getProfile(); Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Max.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Max.java?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Max.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Max.java Sat Jul 1 15:20:28 2006 @@ -14,12 +14,16 @@ package org.apache.tapestry.form.validator; +import java.text.DecimalFormatSymbols; + import org.apache.tapestry.IMarkupWriter; import org.apache.tapestry.IRequestCycle; -import org.apache.tapestry.TapestryUtils; import org.apache.tapestry.form.FormComponentContributorContext; import org.apache.tapestry.form.IFormComponent; import org.apache.tapestry.form.ValidationMessages; +import org.apache.tapestry.json.JSONLiteral; +import org.apache.tapestry.json.JSONObject; +import org.apache.tapestry.valid.ValidationConstants; import org.apache.tapestry.valid.ValidationConstraint; import org.apache.tapestry.valid.ValidationStrings; import org.apache.tapestry.valid.ValidatorException; @@ -69,19 +73,24 @@ public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) { - context.includeClasspathScript("/org/apache/tapestry/form/validator/NumberValidator.js"); - - String message = TapestryUtils.enquote(buildMessage(context, field)); - - StringBuffer buffer = new StringBuffer("function(event) { Tapestry.validate_max_number(event, '"); - buffer.append(field.getClientId()); - buffer.append("', "); - buffer.append(_max); - buffer.append(", "); - buffer.append(message); - buffer.append("); }"); - - context.addSubmitHandler(buffer.toString()); + JSONObject profile = context.getProfile(); + + if (!profile.has(ValidationConstants.CONSTRAINTS)) { + profile.put(ValidationConstants.CONSTRAINTS, new JSONObject()); + } + JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS); + + // TODO: Should find some way to provide this globally and cache. + DecimalFormatSymbols symbols = new DecimalFormatSymbols(context.getLocale()); + + cons.put(field.getClientId(), + new JSONLiteral("[dojo.validate.isInRange,{" + + "max:" + _max + "," + + "decimal:" + JSONObject.quote(symbols.getDecimalSeparator()) + + "]")); + + setProfileProperty(field, profile, + ValidationConstants.CONSTRAINTS, buildMessage(context, field)); } public void setMax(double max) Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxDate.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxDate.java?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxDate.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxDate.java Sat Jul 1 15:20:28 2006 @@ -16,8 +16,18 @@ import java.util.Date; +import org.apache.tapestry.IMarkupWriter; +import org.apache.tapestry.IRequestCycle; +import org.apache.tapestry.form.FormComponentContributorContext; import org.apache.tapestry.form.IFormComponent; +import org.apache.tapestry.form.TranslatedField; import org.apache.tapestry.form.ValidationMessages; +import org.apache.tapestry.form.translator.DateTranslator; +import org.apache.tapestry.form.translator.Translator; +import org.apache.tapestry.json.JSONLiteral; +import org.apache.tapestry.json.JSONObject; +import org.apache.tapestry.util.Strftime; +import org.apache.tapestry.valid.ValidationConstants; import org.apache.tapestry.valid.ValidationConstraint; import org.apache.tapestry.valid.ValidationStrings; import org.apache.tapestry.valid.ValidatorException; @@ -45,22 +55,77 @@ throws ValidatorException { Date date = (Date) object; - + DateTranslator translator = getFieldTranslator(field); + if (date.after(_maxDate)) - throw new ValidatorException(buildMessage(messages, field), + throw new ValidatorException(buildMessage(messages, field, translator), ValidationConstraint.TOO_LARGE); - + } - - private String buildMessage(ValidationMessages messages, IFormComponent field) + + private String buildMessage(ValidationMessages messages, IFormComponent field, + DateTranslator translator) { return messages.formatValidationMessage( getMessage(), ValidationStrings.DATE_TOO_LATE, new Object[] - { field.getDisplayName(), _maxDate }); + { field.getDisplayName(), + (translator != null) ? + translator.format(field, messages.getLocale(), _maxDate) + : _maxDate}); } - + + public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, + FormComponentContributorContext context, IFormComponent field) + { + // TODO: This is a little hacky, but validators need to be able to cooperate + // with translators during client side validation as well + DateTranslator translator = getFieldTranslator(field); + if (translator == null) + return; + + JSONObject profile = context.getProfile(); + + context.addInitializationScript(field, "dojo.require(\"tapestry.form.datetime\");"); + + if (!profile.has(ValidationConstants.CONSTRAINTS)) { + profile.put(ValidationConstants.CONSTRAINTS, new JSONObject()); + } + JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS); + + cons.put(field.getClientId(), + new JSONLiteral("[tapestry.form.datetime.isValidDate,{" + + "max:" + + JSONObject.quote(translator.format(field, context.getLocale(), _maxDate)) + + "," + + "format:" + + JSONObject.quote(Strftime.convertToPosixFormat(translator.getPattern())) + + "}]")); + + setProfileProperty(field, profile, + ValidationConstants.CONSTRAINTS, buildMessage(context, field, translator)); + } + + /** + * Used to grab the corresponding {@link DateTranslator} for + * the field, if one exists. + * @param field + * @return The translator, or null if the required translator type + * doesn't exist. + */ + private DateTranslator getFieldTranslator(IFormComponent field) + { + if (TranslatedField.class.isAssignableFrom(field.getClass())) { + Translator trans = ((TranslatedField)field).getTranslator(); + if (DateTranslator.class.isInstance(trans)) { + return (DateTranslator)trans; + } + } + + return null; + } + public void setMaxDate(Date minDate) { _maxDate = minDate; Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/json/JSONObject.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/json/JSONObject.java?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/json/JSONObject.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/json/JSONObject.java Sat Jul 1 15:20:28 2006 @@ -639,6 +639,16 @@ } /** + * @see {{@link #quote(String)}. + * @param value + * @return + */ + public static String quote(char value) + { + return quote(new String(new char[]{value})); + } + + /** * Produce a string in double quotes with backslash sequences in all the * right places. * Modified: tapestry/tapestry4/trunk/framework/src/js/tapestry/__package__.js URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/tapestry/__package__.js?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/js/tapestry/__package__.js (original) +++ tapestry/tapestry4/trunk/framework/src/js/tapestry/__package__.js Sat Jul 1 15:20:28 2006 @@ -1,6 +1,6 @@ dojo.kwCompoundRequire({ common: [ - "tapestry.core","tapestry.event" + "tapestry.core","tapestry.event","tapestry.form" ], browser: ["tapestry.html"] }); Modified: tapestry/tapestry4/trunk/framework/src/js/tapestry/form.js URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/tapestry/form.js?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/js/tapestry/form.js (original) +++ tapestry/tapestry4/trunk/framework/src/js/tapestry/form.js Sat Jul 1 15:20:28 2006 @@ -2,7 +2,6 @@ dojo.require("dojo.event"); dojo.require("dojo.event.browser"); -dojo.require("dojo.validate.web"); dojo.require("tapestry.core"); Modified: tapestry/tapestry4/trunk/framework/src/js/tapestry/form/__package__.js URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/tapestry/form/__package__.js?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/js/tapestry/form/__package__.js (original) +++ tapestry/tapestry4/trunk/framework/src/js/tapestry/form/__package__.js Sat Jul 1 15:20:28 2006 @@ -1,6 +1,6 @@ dojo.kwCompoundRequire({ browser: [ - "tapestry.form.validation" + "tapestry.form.validation", "tapestry.form.datetime" ] }); dojo.provide("tapestry.form.*"); Added: tapestry/tapestry4/trunk/framework/src/js/tapestry/form/datetime.js URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/tapestry/form/datetime.js?rev=418513&view=auto ============================================================================== --- tapestry/tapestry4/trunk/framework/src/js/tapestry/form/datetime.js (added) +++ tapestry/tapestry4/trunk/framework/src/js/tapestry/form/datetime.js Sat Jul 1 15:20:28 2006 @@ -0,0 +1,55 @@ +dojo.provide("tapestry.form.datetime"); + +dojo.require("dojo.validate.datetime"); +dojo.require("dojo.date"); + +tapestry.form.datetime={ + + /** + * Checks if the specified value is a valid date, according to + * the flags passed in. + * + * @param value The string value of the date being validated. + * @param flags An object. + * flags.format A string format pattern that will be used to validate + * the incoming value via @link dojo.validate.isValidDate(value, format). + * flags.max A string date value representing the maximum date that can be selected. + * flags.min A string date value representing the minimum date that can be selected. + * @return Boolean. True if valid, false otherwise. + */ + isValidDate:function(value, flags){ + // default generic validation if no flags specified + if (!flags || typeof flags.format != "string") + return dojo.validate.isValidDate(value); + + // basic format validation + if (!dojo.validate.isValidDate(value, flags.format)) + return false; + + // parse date value + var dateValue=null; + try { + dateValue = new Date(value); + } catch (e) { + dojo.log.exception("Error parsing input date.", e, true); + return false; + } + + // max date + if (typeof flags.max == "string") { + var max = new Date(flags.max); + if (dojo.date.compare(dateValue, max, dojo.date.compareTypes.DATE) >= 0) + return false; + } + + // min date + if (typeof flags.min == "string") { + var min = new Date(flags.min); + if (dojo.date.compare(dateValue, min, dojo.date.compareTypes.DATE) < 0) + return false; + } + + return true; + } + +} Propchange: tapestry/tapestry4/trunk/framework/src/js/tapestry/form/datetime.js ------------------------------------------------------------------------------ svn:eol-style = native Modified: tapestry/tapestry4/trunk/framework/src/js/tapestry/form/validation.js URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/tapestry/form/validation.js?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/js/tapestry/form/validation.js (original) +++ tapestry/tapestry4/trunk/framework/src/js/tapestry/form/validation.js Sat Jul 1 15:20:28 2006 @@ -199,4 +199,4 @@ }, node); dialog.show(); } -} \ No newline at end of file +} Added: tapestry/tapestry4/trunk/framework/src/js/tests/form/test_datetime.js URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/tests/form/test_datetime.js?rev=418513&view=auto ============================================================================== --- tapestry/tapestry4/trunk/framework/src/js/tests/form/test_datetime.js (added) +++ tapestry/tapestry4/trunk/framework/src/js/tests/form/test_datetime.js Sat Jul 1 15:20:28 2006 @@ -0,0 +1,44 @@ +dojo.setModulePrefix("tapestry", "../tapestry"); + +dojo.require("dojo.date"); + +dojo.require("tapestry.*"); +dojo.require("tapestry.test"); +dojo.require("tapestry.form.datetime"); + +function test_datetime_validDate(){ + var value = "08/15/1999"; + jum.assertTrue(value, tapestry.form.datetime.isValidDate(value)); + + value = "12112/12/23434"; + jum.assertFalse(value, tapestry.form.datetime.isValidDate(value)); + jum.assertFalse("null value", tapestry.form.datetime.isValidDate()); +} + +function test_datetime_maxDate(){ + var maxValue = "09/28/2020"; + + var value = "08/15/2021"; + jum.assertTrue(value, tapestry.form.datetime.isValidDate(value, {max:maxValue})); + + jum.assertFalse(value, tapestry.form.datetime.isValidDate(value, + {max:maxValue, format:"MM/DD/YYYY"})); + + value = "08/15/2020"; + jum.assertTrue(value, tapestry.form.datetime.isValidDate(value, + {max:maxValue, format:"MM/DD/YYYY"})); +} + +function test_datetime_minDate(){ + var minValue = "09/28/2000"; + + var value = "09/27/2000"; + jum.assertTrue(value, tapestry.form.datetime.isValidDate(value, {min:minValue})); + + jum.assertFalse(value, tapestry.form.datetime.isValidDate(value, + {min:minValue, format:"MM/DD/YYYY"})); + + value = "09/28/2000"; + jum.assertTrue(value, tapestry.form.datetime.isValidDate(value, + {min:minValue, format:"MM/DD/YYYY"})); +} Propchange: tapestry/tapestry4/trunk/framework/src/js/tests/form/test_datetime.js ------------------------------------------------------------------------------ svn:eol-style = native Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestEmail.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestEmail.java?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestEmail.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestEmail.java Sat Jul 1 15:20:28 2006 @@ -111,6 +111,8 @@ IFormComponent field = newField("Fred", "myfield"); + context.addInitializationScript(field, "dojo.require(\"dojo.validate.web\");"); + expect(context.getProfile()).andReturn(json); trainFormatMessage(context, null, ValidationStrings.INVALID_EMAIL, @@ -122,15 +124,9 @@ verify(); - /* - assertNotNull(json.get(ValidationConstants.REQUIRED)); - JSONArray arr = json.getJSONArray(ValidationConstants.REQUIRED); - assertEquals("fred", arr.getString(0)); - - assertNotNull(json.get("fred")); - JSONObject obj = json.getJSONObject("fred"); - assertEquals("Default\\Message for Fred.", obj.getString(ValidationConstants.REQUIRED)); - */ + assertEquals("{\"myfield\":{\"constraints\":\"default\\\\message\"}," + + "\"constraints\":{\"myfield\":[dojo.validate.isEmailAddress,false,true]}}", + json.toString()); } public void testRenderContributionCustomMessage() @@ -143,6 +139,8 @@ IFormComponent field = newField("Fred", "barney"); + context.addInitializationScript(field, "dojo.require(\"dojo.validate.web\");"); + expect(context.getProfile()).andReturn(json); trainFormatMessage( @@ -156,17 +154,11 @@ replay(); new Email("message=custom").renderContribution(writer, cycle, context, field); - + verify(); - /* - assertNotNull(json.get(ValidationConstants.REQUIRED)); - JSONArray arr = json.getJSONArray(ValidationConstants.REQUIRED); - assertEquals("fred", arr.getString(0)); - - assertNotNull(json.get("fred")); - JSONObject obj = json.getJSONObject("fred"); - assertEquals("Default\\Message for Fred.", obj.getString(ValidationConstants.REQUIRED)); - */ + assertEquals("{\"constraints\":{\"barney\":[dojo.validate.isEmailAddress,false,true]}," + + "\"barney\":{\"constraints\":\"custom message\"}}", + json.toString()); } } Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMax.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMax.java?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMax.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMax.java Sat Jul 1 15:20:28 2006 @@ -14,13 +14,18 @@ package org.apache.tapestry.form.validator; +import static org.easymock.EasyMock.*; import static org.testng.AssertJUnit.assertEquals; +import java.text.DecimalFormatSymbols; +import java.util.Locale; + import org.apache.tapestry.IMarkupWriter; import org.apache.tapestry.IRequestCycle; import org.apache.tapestry.form.FormComponentContributorContext; import org.apache.tapestry.form.IFormComponent; import org.apache.tapestry.form.ValidationMessages; +import org.apache.tapestry.json.JSONObject; import org.apache.tapestry.valid.ValidationConstraint; import org.apache.tapestry.valid.ValidationStrings; import org.apache.tapestry.valid.ValidatorException; @@ -100,34 +105,52 @@ { IMarkupWriter writer = newWriter(); IRequestCycle cycle = newCycle(); + JSONObject json = new JSONObject(); + IFormComponent field = newField("My Field", "myfield"); FormComponentContributorContext context = newMock(FormComponentContributorContext.class); - - context.includeClasspathScript("/org/apache/tapestry/form/validator/NumberValidator.js"); + + Locale locale = Locale.FRANCE; + DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale); + + expect(context.getLocale()).andReturn(locale); + + expect(context.getProfile()).andReturn(json); trainFormatMessage(context, null, ValidationStrings.VALUE_TOO_LARGE, new Object[] { "My Field", new Double(20) }, "default message"); - - context.addSubmitHandler("function(event) { Tapestry.validate_max_number(event, 'myfield', 20.0, 'default message'); }"); - + replay(); new Max("max=20").renderContribution(writer, cycle, context, field); verify(); + + assertEquals("{\"myfield\":{\"constraints\":\"default message\"}," + + "\"constraints\":{\"myfield\":[dojo.validate.isInRange,{max:20.0,decimal:\"" + + symbols.getDecimalSeparator() + "\"]}}", + json.toString()); } - + public void testRenderContributionCustomMessage() { IMarkupWriter writer = newWriter(); IRequestCycle cycle = newCycle(); + + JSONObject json = new JSONObject(); + IFormComponent field = newField("My Field", "myfield"); FormComponentContributorContext context = newMock(FormComponentContributorContext.class); - - context.includeClasspathScript("/org/apache/tapestry/form/validator/NumberValidator.js"); - + + Locale locale = Locale.FRANCE; + DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale); + + expect(context.getLocale()).andReturn(locale); + + expect(context.getProfile()).andReturn(json); + trainFormatMessage( context, "custom", @@ -136,13 +159,16 @@ { "My Field", new Double(20) }, "custom\\message"); - context.addSubmitHandler("function(event) { Tapestry.validate_max_number(event, 'myfield', 20.0, 'custom\\\\message'); }"); - replay(); - + new Max("max=20,message=custom").renderContribution(writer, cycle, context, field); verify(); + + assertEquals("{\"myfield\":{\"constraints\":\"custom\\\\message\"}," + + "\"constraints\":{\"myfield\":[dojo.validate.isInRange,{max:20.0,decimal:\"" + + symbols.getDecimalSeparator() + "\"]}}", + json.toString()); } } Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMaxDate.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMaxDate.java?rev=418513&r1=418512&r2=418513&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMaxDate.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMaxDate.java Sat Jul 1 15:20:28 2006 @@ -14,15 +14,22 @@ package org.apache.tapestry.form.validator; +import static org.easymock.EasyMock.checkOrder; +import static org.easymock.EasyMock.expect; import static org.testng.AssertJUnit.assertEquals; import java.util.Date; +import java.util.Locale; import org.apache.tapestry.IMarkupWriter; import org.apache.tapestry.IRequestCycle; import org.apache.tapestry.form.FormComponentContributorContext; import org.apache.tapestry.form.IFormComponent; +import org.apache.tapestry.form.TranslatedField; import org.apache.tapestry.form.ValidationMessages; +import org.apache.tapestry.form.translator.DateTranslator; +import org.apache.tapestry.json.JSONObject; +import org.apache.tapestry.util.Strftime; import org.apache.tapestry.valid.ValidationConstraint; import org.apache.tapestry.valid.ValidationStrings; import org.apache.tapestry.valid.ValidatorException; @@ -38,7 +45,7 @@ public class TestMaxDate extends BaseValidatorTestCase { private static final long ONE_DAY = 24 * 60 * 60 * 1000l; - + public void testOK() throws Exception { long now = System.currentTimeMillis(); @@ -126,18 +133,99 @@ verify(); } - - public void testRenderComponentNoOp() + + public void testRenderContribution() { IMarkupWriter writer = newWriter(); IRequestCycle cycle = newCycle(); - FormComponentContributorContext context = newContext(); - IFormComponent field = newField(); - + JSONObject json = new JSONObject(); + + TranslatedField field = newMock(TranslatedField.class); + checkOrder(field, false); + + Date maxDate = new Date(System.currentTimeMillis() + ONE_DAY); + DateTranslator translator = new DateTranslator(); + + expect(field.getTranslator()).andReturn(translator); + + expect(field.getClientId()).andReturn("myfield").anyTimes(); + + expect(field.getDisplayName()).andReturn("My Field"); + + FormComponentContributorContext context = newMock(FormComponentContributorContext.class); + + Locale locale = Locale.ENGLISH; + expect(context.getLocale()).andReturn(locale).anyTimes(); + + expect(context.getProfile()).andReturn(json); + + context.addInitializationScript(field, "dojo.require(\"tapestry.form.datetime\");"); + + String strMax = translator.format(field, locale, maxDate); + + trainFormatMessage(context, null, ValidationStrings.DATE_TOO_LATE, + new Object[] { "My Field", strMax }, "default message"); + replay(); - - new MaxDate().renderContribution(writer, cycle, context, field); - + + new MaxDate("maxDate="+strMax).renderContribution(writer, cycle, context, field); + + verify(); + + assertEquals("{\"myfield\":{\"constraints\":\"default message\"}," + + "\"constraints\":{\"myfield\":[" + + "tapestry.form.datetime.isValidDate,{max:\"" + + strMax + "\",format:" + + JSONObject.quote(Strftime.convertToPosixFormat(translator.getPattern())) + + "}]}}", + json.toString()); + } + + public void testRenderContributionCustomMessage() + { + IMarkupWriter writer = newWriter(); + IRequestCycle cycle = newCycle(); + JSONObject json = new JSONObject(); + + TranslatedField field = newMock(TranslatedField.class); + checkOrder(field, false); + + Date maxDate = new Date(System.currentTimeMillis() + ONE_DAY); + DateTranslator translator = new DateTranslator(); + + expect(field.getTranslator()).andReturn(translator); + + expect(field.getClientId()).andReturn("myfield").anyTimes(); + + expect(field.getDisplayName()).andReturn("My Field"); + + FormComponentContributorContext context = newMock(FormComponentContributorContext.class); + + Locale locale = Locale.ENGLISH; + expect(context.getLocale()).andReturn(locale).anyTimes(); + + expect(context.getProfile()).andReturn(json); + + context.addInitializationScript(field, "dojo.require(\"tapestry.form.datetime\");"); + + String strMax = translator.format(field, locale, maxDate); + + trainFormatMessage(context, "custom", ValidationStrings.DATE_TOO_LATE, + new Object[] { "My Field", strMax }, + "custom\\message"); + + replay(); + + new MaxDate("maxDate=" + strMax + ",message=custom").renderContribution(writer, cycle, context, field); + verify(); + + assertEquals("{\"myfield\":{\"constraints\":\"custom\\\\message\"}," + + "\"constraints\":{\"myfield\":[" + + "tapestry.form.datetime.isValidDate,{max:\"" + + strMax + "\",format:" + + JSONObject.quote(Strftime.convertToPosixFormat(translator.getPattern())) + + "}]}}", + json.toString()); } } From commitsjoshua86@example.net Sat Jul 01 23:19:54 2006 Return-Path: <commitsjoshua86@example.net> Delivered-To: joshua86@example.net Received: (qmail 91746 invoked from network); 1 Jul 2006 23:19:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (83.161.120.155) by minotaur.apache.org with SMTP; 1 Jul 2006 23:19:54 -0000 Received: (qmail 13200 invoked by uid 500); 1 Jul 2006 23:19:53 -0000 Delivered-To: joshua86@example.net Received: (qmail 13181 invoked by uid 500); 1 Jul 2006 23:19:53 -0000 Mailing-List: contact joshua86@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:joshua86@example.net> List-Unsubscribe: <mailto:joshua86@example.net> List-Post: <mailto:joshua86@example.net> List-Id: <commits.tapestry.apache.org> Reply-To: joshua86@example.net Delivered-To: mailing list joshua86@example.net Received: (qmail 13172 invoked by uid 99); 1 Jul 2006 23:19:53 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Jul 2006 16:19:53 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Jul 2006 16:19:51 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 1FF431A983A; Sat, 1 Jul 2006 16:19:31 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r418519 - in /tapestry/tapestry4/trunk/framework/src: java/org/apache/tapestry/form/validator/ js/tapestry/form/ test/org/apache/tapestry/form/validator/ Date: Sat, 01 Jul 2006 23:19:28 -0000 To: joshua86@example.net From: joshua86@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <joshua86@example.net> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jkuhnert Date: Sat Jul 1 16:19:27 2006 New Revision: 418519 URL: http://svn.apache.org/viewvc?rev=418519&view=rev Log: Finished off remaining client side validation upgrades. Will save new logic for another time. Removed: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/NumberValidator.js tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/RegExValidator.js tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/StringValidator.js Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/BaseValidator.java tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxDate.java tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxLength.java tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Min.java tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MinDate.java tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MinLength.java tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Pattern.java tapestry/tapestry4/trunk/framework/src/js/tapestry/form/validation.js tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMax.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMaxLength.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMin.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMinDate.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMinLength.java tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestPattern.java Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/BaseValidator.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/BaseValidator.java?rev=418519&r1=418518&r2=418519&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/BaseValidator.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/BaseValidator.java Sat Jul 1 16:19:27 2006 @@ -19,6 +19,8 @@ import org.apache.tapestry.IRequestCycle; import org.apache.tapestry.form.FormComponentContributorContext; import org.apache.tapestry.form.IFormComponent; +import org.apache.tapestry.form.TranslatedField; +import org.apache.tapestry.form.translator.Translator; import org.apache.tapestry.json.JSONArray; import org.apache.tapestry.json.JSONObject; @@ -115,5 +117,24 @@ profile.put(key, new JSONArray()); profile.accumulate(key, value); + } + + /** + * Used to grab the corresponding {@link Translator} for + * the field, if one exists. + * @param field + * @return The translator, or null if the required translator type + * doesn't exist. + */ + public Translator getFieldTranslator(IFormComponent field, Class clazz) + { + if (TranslatedField.class.isAssignableFrom(field.getClass())) { + Translator trans = ((TranslatedField)field).getTranslator(); + if (clazz.isInstance(trans)) { + return trans; + } + } + + return null; } } Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxDate.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxDate.java?rev=418519&r1=418518&r2=418519&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxDate.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxDate.java Sat Jul 1 16:19:27 2006 @@ -20,10 +20,8 @@ import org.apache.tapestry.IRequestCycle; import org.apache.tapestry.form.FormComponentContributorContext; import org.apache.tapestry.form.IFormComponent; -import org.apache.tapestry.form.TranslatedField; import org.apache.tapestry.form.ValidationMessages; import org.apache.tapestry.form.translator.DateTranslator; -import org.apache.tapestry.form.translator.Translator; import org.apache.tapestry.json.JSONLiteral; import org.apache.tapestry.json.JSONObject; import org.apache.tapestry.util.Strftime; @@ -55,7 +53,7 @@ throws ValidatorException { Date date = (Date) object; - DateTranslator translator = getFieldTranslator(field); + DateTranslator translator = (DateTranslator) getFieldTranslator(field, DateTranslator.class); if (date.after(_maxDate)) throw new ValidatorException(buildMessage(messages, field, translator), @@ -81,7 +79,7 @@ { // TODO: This is a little hacky, but validators need to be able to cooperate // with translators during client side validation as well - DateTranslator translator = getFieldTranslator(field); + DateTranslator translator = (DateTranslator) getFieldTranslator(field, DateTranslator.class); if (translator == null) return; @@ -105,25 +103,6 @@ setProfileProperty(field, profile, ValidationConstants.CONSTRAINTS, buildMessage(context, field, translator)); - } - - /** - * Used to grab the corresponding {@link DateTranslator} for - * the field, if one exists. - * @param field - * @return The translator, or null if the required translator type - * doesn't exist. - */ - private DateTranslator getFieldTranslator(IFormComponent field) - { - if (TranslatedField.class.isAssignableFrom(field.getClass())) { - Translator trans = ((TranslatedField)field).getTranslator(); - if (DateTranslator.class.isInstance(trans)) { - return (DateTranslator)trans; - } - } - - return null; } public void setMaxDate(Date minDate) Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxLength.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxLength.java?rev=418519&r1=418518&r2=418519&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxLength.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MaxLength.java Sat Jul 1 16:19:27 2006 @@ -16,10 +16,12 @@ import org.apache.tapestry.IMarkupWriter; import org.apache.tapestry.IRequestCycle; -import org.apache.tapestry.TapestryUtils; import org.apache.tapestry.form.FormComponentContributorContext; import org.apache.tapestry.form.IFormComponent; import org.apache.tapestry.form.ValidationMessages; +import org.apache.tapestry.json.JSONLiteral; +import org.apache.tapestry.json.JSONObject; +import org.apache.tapestry.valid.ValidationConstants; import org.apache.tapestry.valid.ValidationConstraint; import org.apache.tapestry.valid.ValidationStrings; import org.apache.tapestry.valid.ValidatorException; @@ -71,17 +73,19 @@ public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) { - context.includeClasspathScript("/org/apache/tapestry/form/validator/StringValidator.js"); - - StringBuffer buffer = new StringBuffer("function(event) { Tapestry.validate_max_length(event, '"); - buffer.append(field.getClientId()); - buffer.append("', "); - buffer.append(_maxLength); - buffer.append(", "); - buffer.append(TapestryUtils.enquote(buildMessage(context, field))); - buffer.append("); }"); - - context.addSubmitHandler(buffer.toString()); + JSONObject profile = context.getProfile(); + + if (!profile.has(ValidationConstants.CONSTRAINTS)) { + profile.put(ValidationConstants.CONSTRAINTS, new JSONObject()); + } + JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS); + + cons.put(field.getClientId(), + new JSONLiteral("[dojo.validate.isText,{" + + "maxlength:" + _maxLength + "}]")); + + setProfileProperty(field, profile, + ValidationConstants.CONSTRAINTS, buildMessage(context, field)); } } Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Min.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Min.java?rev=418519&r1=418518&r2=418519&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Min.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Min.java Sat Jul 1 16:19:27 2006 @@ -14,12 +14,16 @@ package org.apache.tapestry.form.validator; +import java.text.DecimalFormatSymbols; + import org.apache.tapestry.IMarkupWriter; import org.apache.tapestry.IRequestCycle; -import org.apache.tapestry.TapestryUtils; import org.apache.tapestry.form.FormComponentContributorContext; import org.apache.tapestry.form.IFormComponent; import org.apache.tapestry.form.ValidationMessages; +import org.apache.tapestry.json.JSONLiteral; +import org.apache.tapestry.json.JSONObject; +import org.apache.tapestry.valid.ValidationConstants; import org.apache.tapestry.valid.ValidationConstraint; import org.apache.tapestry.valid.ValidationStrings; import org.apache.tapestry.valid.ValidatorException; @@ -65,23 +69,28 @@ new Object[] { field.getDisplayName(), new Double(_min) }); } - + public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) { - context.includeClasspathScript("/org/apache/tapestry/form/validator/NumberValidator.js"); - - String message = buildMessage(context, field); - - StringBuffer buffer = new StringBuffer("function(event) { Tapestry.validate_min_number(event, '"); - buffer.append(field.getClientId()); - buffer.append("', "); - buffer.append(_min); - buffer.append(", "); - buffer.append(TapestryUtils.enquote(message)); - buffer.append("); }"); - - context.addSubmitHandler(buffer.toString()); + JSONObject profile = context.getProfile(); + + if (!profile.has(ValidationConstants.CONSTRAINTS)) { + profile.put(ValidationConstants.CONSTRAINTS, new JSONObject()); + } + JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS); + + // TODO: Should find some way to provide this globally and cache. + DecimalFormatSymbols symbols = new DecimalFormatSymbols(context.getLocale()); + + cons.put(field.getClientId(), + new JSONLiteral("[dojo.validate.isInRange,{" + + "min:" + _min + "," + + "decimal:" + JSONObject.quote(symbols.getDecimalSeparator()) + + "]")); + + setProfileProperty(field, profile, + ValidationConstants.CONSTRAINTS, buildMessage(context, field)); } public void setMin(double min) Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MinDate.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MinDate.java?rev=418519&r1=418518&r2=418519&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MinDate.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MinDate.java Sat Jul 1 16:19:27 2006 @@ -16,8 +16,16 @@ import java.util.Date; +import org.apache.tapestry.IMarkupWriter; +import org.apache.tapestry.IRequestCycle; +import org.apache.tapestry.form.FormComponentContributorContext; import org.apache.tapestry.form.IFormComponent; import org.apache.tapestry.form.ValidationMessages; +import org.apache.tapestry.form.translator.DateTranslator; +import org.apache.tapestry.json.JSONLiteral; +import org.apache.tapestry.json.JSONObject; +import org.apache.tapestry.util.Strftime; +import org.apache.tapestry.valid.ValidationConstants; import org.apache.tapestry.valid.ValidationConstraint; import org.apache.tapestry.valid.ValidationStrings; import org.apache.tapestry.valid.ValidatorException; @@ -41,29 +49,65 @@ { super(initializer); } - + public void setMinDate(Date minDate) { _minDate = minDate; } - + public void validate(IFormComponent field, ValidationMessages messages, Object object) - throws ValidatorException + throws ValidatorException { Date date = (Date) object; - + DateTranslator translator = (DateTranslator) getFieldTranslator(field, DateTranslator.class); + if (date.before(_minDate)) - throw new ValidatorException(buildMessage(messages, field), + throw new ValidatorException(buildMessage(messages, field, translator), ValidationConstraint.TOO_SMALL); - } - private String buildMessage(ValidationMessages messages, IFormComponent field) + } + + private String buildMessage(ValidationMessages messages, IFormComponent field, + DateTranslator translator) { return messages.formatValidationMessage( getMessage(), ValidationStrings.DATE_TOO_EARLY, new Object[] - { field.getDisplayName(), _minDate }); + { field.getDisplayName(), + (translator != null) ? + translator.format(field, messages.getLocale(), _minDate) + : _minDate}); + } + + public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, + FormComponentContributorContext context, IFormComponent field) + { + // TODO: This is a little hacky, but validators need to be able to cooperate + // with translators during client side validation as well + DateTranslator translator = (DateTranslator) getFieldTranslator(field, DateTranslator.class); + if (translator == null) + return; + + JSONObject profile = context.getProfile(); + + context.addInitializationScript(field, "dojo.require(\"tapestry.form.datetime\");"); + + if (!profile.has(ValidationConstants.CONSTRAINTS)) { + profile.put(ValidationConstants.CONSTRAINTS, new JSONObject()); + } + JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS); + + cons.put(field.getClientId(), + new JSONLiteral("[tapestry.form.datetime.isValidDate,{" + + "min:" + + JSONObject.quote(translator.format(field, context.getLocale(), _minDate)) + + "," + + "format:" + + JSONObject.quote(Strftime.convertToPosixFormat(translator.getPattern())) + + "}]")); + + setProfileProperty(field, profile, + ValidationConstants.CONSTRAINTS, buildMessage(context, field, translator)); } - } Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MinLength.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MinLength.java?rev=418519&r1=418518&r2=418519&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MinLength.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/MinLength.java Sat Jul 1 16:19:27 2006 @@ -16,10 +16,12 @@ import org.apache.tapestry.IMarkupWriter; import org.apache.tapestry.IRequestCycle; -import org.apache.tapestry.TapestryUtils; import org.apache.tapestry.form.FormComponentContributorContext; import org.apache.tapestry.form.IFormComponent; import org.apache.tapestry.form.ValidationMessages; +import org.apache.tapestry.json.JSONLiteral; +import org.apache.tapestry.json.JSONObject; +import org.apache.tapestry.valid.ValidationConstants; import org.apache.tapestry.valid.ValidationConstraint; import org.apache.tapestry.valid.ValidationStrings; import org.apache.tapestry.valid.ValidatorException; @@ -75,16 +77,18 @@ public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) { - context.includeClasspathScript("/org/apache/tapestry/form/validator/StringValidator.js"); - - StringBuffer buffer = new StringBuffer("function(event) { Tapestry.validate_min_length(event, '"); - buffer.append(field.getClientId()); - buffer.append("', "); - buffer.append(_minLength); - buffer.append(", "); - buffer.append(TapestryUtils.enquote(buildMessage(context, field))); - buffer.append("); }"); - - context.addSubmitHandler(buffer.toString()); + JSONObject profile = context.getProfile(); + + if (!profile.has(ValidationConstants.CONSTRAINTS)) { + profile.put(ValidationConstants.CONSTRAINTS, new JSONObject()); + } + JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS); + + cons.put(field.getClientId(), + new JSONLiteral("[dojo.validate.isText,{" + + "minlength:" + _minLength + "}]")); + + setProfileProperty(field, profile, + ValidationConstants.CONSTRAINTS, buildMessage(context, field)); } } Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Pattern.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Pattern.java?rev=418519&r1=418518&r2=418519&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Pattern.java (original) +++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/validator/Pattern.java Sat Jul 1 16:19:27 2006 @@ -16,11 +16,13 @@ import org.apache.tapestry.IMarkupWriter; import org.apache.tapestry.IRequestCycle; -import org.apache.tapestry.TapestryUtils; import org.apache.tapestry.form.FormComponentContributorContext; import org.apache.tapestry.form.IFormComponent; import org.apache.tapestry.form.ValidationMessages; +import org.apache.tapestry.json.JSONLiteral; +import org.apache.tapestry.json.JSONObject; import org.apache.tapestry.util.RegexpMatcher; +import org.apache.tapestry.valid.ValidationConstants; import org.apache.tapestry.valid.ValidationConstraint; import org.apache.tapestry.valid.ValidationStrings; import org.apache.tapestry.valid.ValidatorException; @@ -66,26 +68,27 @@ getMessage(), ValidationStrings.REGEX_MISMATCH, new Object[] - { field.getDisplayName() }); + { _pattern, field.getDisplayName() }); } - + public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) { - context.includeClasspathScript("/org/apache/tapestry/form/validator/RegExValidator.js"); - String pattern = _matcher.getEscapedPatternString(_pattern); - String message = buildMessage(context, field); - - StringBuffer buffer = new StringBuffer("function(event) { Tapestry.validate_regex(event, '"); - buffer.append(field.getClientId()); - buffer.append("', '"); - buffer.append(pattern); - buffer.append("', "); - buffer.append(TapestryUtils.enquote(message)); - buffer.append("); }"); - - context.addSubmitHandler(buffer.toString()); + + JSONObject profile = context.getProfile(); + + if (!profile.has(ValidationConstants.CONSTRAINTS)) { + profile.put(ValidationConstants.CONSTRAINTS, new JSONObject()); + } + JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS); + + cons.put(field.getClientId(), + new JSONLiteral("[tapestry.form.validation.isValidPattern,\"" + + pattern + "\"]")); + + setProfileProperty(field, profile, + ValidationConstants.CONSTRAINTS, buildMessage(context, field)); } public void setPattern(String pattern) Modified: tapestry/tapestry4/trunk/framework/src/js/tapestry/form/validation.js URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/tapestry/form/validation.js?rev=418519&r1=418518&r2=418519&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/js/tapestry/form/validation.js (original) +++ tapestry/tapestry4/trunk/framework/src/js/tapestry/form/validation.js Sat Jul 1 16:19:27 2006 @@ -198,5 +198,19 @@ message:msg }, node); dialog.show(); + }, + + /** + * Validates that the input value matches the given + * regexp pattern. + * + * @param value The string value to be evaluated. + * @param pattern The regexp pattern used to match against value. + */ + isValidPattern:function(value, pattern){ + if (typeof value != "string" || typeof pattern != "string") { return false; } + + var re = new RegExp(pattern); + return re.test(value); } } Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMax.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMax.java?rev=418519&r1=418518&r2=418519&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMax.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMax.java Sat Jul 1 16:19:27 2006 @@ -122,7 +122,7 @@ { "My Field", new Double(20) }, "default message"); replay(); - + new Max("max=20").renderContribution(writer, cycle, context, field); verify(); Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMaxLength.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMaxLength.java?rev=418519&r1=418518&r2=418519&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMaxLength.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMaxLength.java Sat Jul 1 16:19:27 2006 @@ -14,6 +14,7 @@ package org.apache.tapestry.form.validator; +import static org.easymock.EasyMock.expect; import static org.testng.AssertJUnit.assertEquals; import org.apache.tapestry.IMarkupWriter; @@ -21,6 +22,7 @@ import org.apache.tapestry.form.FormComponentContributorContext; import org.apache.tapestry.form.IFormComponent; import org.apache.tapestry.form.ValidationMessages; +import org.apache.tapestry.json.JSONObject; import org.apache.tapestry.valid.ValidationConstraint; import org.apache.tapestry.valid.ValidationStrings; import org.apache.tapestry.valid.ValidatorException; @@ -98,22 +100,25 @@ { IMarkupWriter writer = newWriter(); IRequestCycle cycle = newCycle(); + JSONObject json = new JSONObject(); + IFormComponent field = newField("My Field", "myfield"); FormComponentContributorContext context = newMock(FormComponentContributorContext.class); - - context.includeClasspathScript("/org/apache/tapestry/form/validator/StringValidator.js"); - - trainFormatMessage(context, null, ValidationStrings.VALUE_TOO_LONG, new Object[] - { new Integer(20), "My Field" }, "default\\message"); - - context - .addSubmitHandler("function(event) { Tapestry.validate_max_length(event, 'myfield', 20, 'default\\\\message'); }"); - + + expect(context.getProfile()).andReturn(json); + + trainFormatMessage(context, null, ValidationStrings.VALUE_TOO_LONG, + new Object[] { new Integer(20), "My Field" }, "default\\message"); + replay(); - + new MaxLength("maxLength=20").renderContribution(writer, cycle, context, field); - + verify(); + + assertEquals("{\"myfield\":{\"constraints\":\"default\\\\message\"}," + + "\"constraints\":{\"myfield\":[dojo.validate.isText,{maxlength:20}]}}", + json.toString()); } } Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMin.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMin.java?rev=418519&r1=418518&r2=418519&view=diff ============================================================================== --- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMin.java (original) +++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/form/validator/TestMin.java Sat Jul 1 16:19:27 2006 @@ -14,13 +14,18 @@ package org.apache.tapestry.form.validator; +import static org.easymock.EasyMock.expect; import static org.testng.AssertJUnit.assertEquals; +import java.text.DecimalFormatSymbols; +import java.util.Locale; + import org.apache.tapestry.IMarkupWriter; import org.apache.tapestry.IRequestCycle; import org.apache.tapestry.form.FormComponentContributorContext; import org.apache.tapestry.form.IFormComponent; import org.apache.tapestry.form.ValidationMessages; +import org.apache.tapestry.json.JSONObject; import org.apache.tapestry.valid.ValidationConstraint; import org.apache.tapestry.valid.ValidationStrings; import org.apache.tapestry.valid.ValidatorException; @@ -99,35 +104,52 @@ { IMarkupWriter writer = newWriter(); IRequestCycle cycle = newCycle(); + JSONObject json = new JSONObject(); + IFormComponent field = newField("My Field", "myfield"); FormComponentContributorContext context = newMock(FormComponentContributorContext.class); - context.includeClasspathScript("/org/apache/tapestry/form/validator/NumberValidator.js"); + Locale locale = Locale.FRANCE; + DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale); + + expect(context.getLocale()).andReturn(locale); + + expect(context.getProfile()).andReturn(json); trainFormatMessage(context, null, ValidationStrings.VALUE_TOO_SMALL, new Object[] { "My Field", new Double(20) }, "default message"); - context - .addSubmitHandler("function(event) { Tapestry.validate_min_number(event, 'myfield', 20.0, 'default message'); }"); - replay(); new Min("min=20").renderContribution(writer, cycle, context, field); - + verify(); + + assertEquals("{\"myfield\":{\"constraints\":\"default message\"}," + + "\"constraints\":{\"myfield\":[dojo.validate.isInRange,{min:20.0,decimal:\"" + + symbols.getDecimalSeparator() + "\"]}}", + json.toString()); } - + public void testRenderContributionCustomMessage()
{'source': 'Apache Software Foundation Public Mail Archives'}