Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 69508 invoked from network); 3 Nov 2005 15:37:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Nov 2005 15:37:11 -0000 Received: (qmail 41299 invoked by uid 500); 3 Nov 2005 14:40:05 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 37133 invoked by uid 500); 3 Nov 2005 14:39:29 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 30370 invoked by uid 99); 3 Nov 2005 14:38:39 -0000 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 03 Nov 2005 06:36:15 -0800 Received: (qmail 13397 invoked by uid 65534); 3 Nov 2005 14:35:55 -0000 Message-ID: <20051103143555.13396.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r330548 [117/132] - in /cocoon/whiteboard/maven2/cocoon-flat-layout: ./ cocoon-ajax-block/ cocoon-ajax-block/api/ cocoon-ajax-block/api/src/ cocoon-ajax-block/api/src/main/ cocoon-ajax-block/api/src/main/java/ cocoon-ajax-block/api/src/main... Date: Thu, 03 Nov 2005 14:00:48 -0000 To: cvs@cocoon.apache.org From: jheymans@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/resources/org/apache/cocoon/forms/system/i18n/messages_zh_CN.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/resources/org/apache/cocoon/forms/system/i18n/messages_zh_CN.xml?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/resources/org/apache/cocoon/forms/system/i18n/messages_zh_CN.xml (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/resources/org/apache/cocoon/forms/system/i18n/messages_zh_CN.xml Thu Nov 3 05:41:06 2005 @@ -0,0 +1,58 @@ + + + + + #CAPTCHA check failed.# + + 此域是必须的 + + 不是一个有效的{0}类型. + 小数 + 整数 + 整数 + 小数 + 小数 + 日期 + #time# + #date-time# + + 应为{0}个字符. + 应包含{0}到{1}个字符. + 应包含至少{0}个字符. + 不应超过{0}个字符. + 不能满足如下表达式: {0} + + 域不包含有效的邮件地址 + + 应有{0}个项目被选中. + 至少{0}个和最多{1}个项目应被选中. + 至少{0}个项目应被选中. + 至多{0}个项目应被选中. + + 选中的值当中有一个类型不正确. + + 数字范围应在{0}到{1}之间. + 数字应大于等于{0}. + 数字应小于等于{0}. + + Mod 10 检查失败. + + + 域的内容不能满足如下表达式: {0} + 内容类型不正确: {0}. + + Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/main/resources/org/apache/cocoon/forms/system/i18n/messages_zh_CN.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,124 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cocoon.forms.datatype; + +import java.io.Writer; +import java.util.Locale; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.apache.cocoon.core.container.ContainerTestCase; +import org.apache.cocoon.forms.FormsConstants; +import org.apache.cocoon.xml.dom.DOMBuilder; +import org.apache.excalibur.source.impl.ResourceSource; +import org.custommonkey.xmlunit.Diff; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Test case for CForms's DynamicSelectionList datatype. + * @version $Id: DynamicSelectionListTestCase.java 326838 2005-10-20 06:26:53Z sylvain $ + */ +public class DynamicSelectionListTestCase extends ContainerTestCase { + + protected DatatypeManager datatypeManager; + protected DocumentBuilder parser; + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + datatypeManager = (DatatypeManager) this.lookup(DatatypeManager.ROLE); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + parser = factory.newDocumentBuilder(); + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + if (datatypeManager != null) { + this.release(datatypeManager); + } + super.tearDown(); + } + + /** + * Test the generateSaxFragment method. + * @throws MalformedURLException + * @throws ParserConfigurationException + */ + public void testGenerateSaxFragment() throws Exception { + DOMBuilder dest = new DOMBuilder(); + ResourceSource source = + new ResourceSource("resource://org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.source.xml"); + Document sourceDoc = parser.parse(source.getInputStream()); + Element datatypeElement = (Element) sourceDoc.getElementsByTagNameNS(FormsConstants.DEFINITION_NS, "convertor").item(0); + Datatype datatype = datatypeManager.createDatatype(datatypeElement, false); + DynamicSelectionList list = + new DynamicSelectionList(datatype, null, this.getManager()); + list.generateSaxFragment(dest, Locale.ENGLISH, source); + ResourceSource expectedSource = + new ResourceSource("resource://org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.dest.xml"); + Document expected = parser.parse(expectedSource.getInputStream()); + assertEqual("Test if output is what is expected", + expected, dest.getDocument()); + } + + /** + * Check is the source document is equal to the one produced by the method under test. + * @param message A message to print in case of failure. + * @param expected The expected (source) document. + * @param actual The actual (output) document. + */ + private void assertEqual(String message, Document expected, Document actual) { + expected.getDocumentElement().normalize(); + actual.getDocumentElement().normalize(); + // DIRTY HACK WARNING: we add the "xmlns:wi" attribute reported + // by DOM, as expected, but not generated by the method under test, + // otherwise the comparison would fail. + actual.getDocumentElement().setAttribute(FormsConstants.INSTANCE_PREFIX, + FormsConstants.INSTANCE_NS); + Diff diff = new Diff(expected, actual); + assertTrue(message + ", " + diff.toString(), diff.similar()); + } + + /** + * Print a document to a writer for debugging purposes. + * @param document The document to print. + * @param out The writer to write to. + */ + public final void print(Document document, Writer out) { + TransformerFactory factory = TransformerFactory.newInstance(); + try { + javax.xml.transform.Transformer serializer = + factory.newTransformer(); + serializer.transform( + new DOMSource(document), + new StreamResult(out)); + out.write('\n'); + } catch (Exception e) { + e.printStackTrace(); + } + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,140 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cocoon.forms.datatype; + +import java.io.Writer; +import java.util.Locale; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.apache.cocoon.transformation.I18nTransformer; +import org.apache.cocoon.core.container.ContainerTestCase; +import org.apache.cocoon.forms.FormsConstants; +import org.apache.cocoon.forms.datatype.typeimpl.EnumType; +import org.apache.cocoon.xml.dom.DOMBuilder; +import org.apache.excalibur.source.impl.ResourceSource; +import org.custommonkey.xmlunit.Diff; +import org.w3c.dom.Document; + +/** + * Test case for CForms's DynamicSelectionList datatype. + * + * @version $Id: EnumSelectionListTestCase.java 326838 2005-10-20 06:26:53Z sylvain $ + */ +public class EnumSelectionListTestCase extends ContainerTestCase { + + protected DatatypeManager datatypeManager; + protected DocumentBuilder parser; + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + datatypeManager = (DatatypeManager) this.lookup(DatatypeManager.ROLE); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + parser = factory.newDocumentBuilder(); + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + if (datatypeManager != null) { + this.release(datatypeManager); + } + super.tearDown(); + } + + /** + * Test the generateSaxFragment method. + * @throws MalformedURLException + * @throws ParserConfigurationException + */ + public void testGenerateSaxFragment() throws Exception { + DOMBuilder dest = new DOMBuilder(); + EnumSelectionList list = + new EnumSelectionList(Sex.class.getName(), new EnumType(), false); + list.generateSaxFragment(dest, Locale.ENGLISH); + ResourceSource expectedSource = + new ResourceSource("resource://org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest-no-null.xml"); + Document expected = parser.parse(expectedSource.getInputStream()); + assertEqual("Test if output is what is expected", + expected, dest.getDocument()); + } + + /** + * Test the generateSaxFragment method with a nullable selection list + * @throws MalformedURLException + * @throws ParserConfigurationException + */ + public void testGenerateSaxFragmentNullable() throws Exception { + DOMBuilder dest = new DOMBuilder(); + EnumSelectionList list = + new EnumSelectionList(Sex.class.getName(), new EnumType(), true); + list.generateSaxFragment(dest, Locale.ENGLISH); + ResourceSource expectedSource = + new ResourceSource("resource://org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest.xml"); + Document expected = parser.parse(expectedSource.getInputStream()); + assertEqual("Test if output is what is expected", + expected, dest.getDocument()); + } + + /** + * Check is the source document is equal to the one produced by the method under test. + * @param message A message to print in case of failure. + * @param expected The expected (source) document. + * @param actual The actual (output) document. + */ + private void assertEqual(String message, Document expected, Document actual) { + expected.getDocumentElement().normalize(); + actual.getDocumentElement().normalize(); + // DIRTY HACK WARNING: we add the "xmlns:*" attributes reported + // by DOM, as expected, but not generated by the method under test, + // otherwise the comparison would fail. + actual.getDocumentElement().setAttribute(FormsConstants.INSTANCE_PREFIX, + FormsConstants.INSTANCE_NS); + actual.getDocumentElement().setAttribute("i18n", + I18nTransformer.I18N_NAMESPACE_URI); + Diff diff = new Diff(expected, actual); + assertTrue(message + ", " + diff.toString(), diff.similar()); + } + + /** + * Print a document to a writer for debugging purposes. + * @param document The document to print. + * @param out The writer to write to. + */ + public final void print(Document document, Writer out) { + TransformerFactory factory = TransformerFactory.newInstance(); + try { + javax.xml.transform.Transformer serializer = + factory.newTransformer(); + serializer.transform( + new DOMSource(document), + new StreamResult(out)); + out.write('\n'); + } catch (Exception e) { + e.printStackTrace(); + } + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,197 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cocoon.forms.datatype; + +import java.io.Writer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.apache.avalon.framework.context.Context; +import org.apache.avalon.framework.context.DefaultContext; +import org.apache.cocoon.components.ContextHelper; +import org.apache.cocoon.components.flow.FlowHelper; +import org.apache.cocoon.core.container.ContainerTestCase; +import org.apache.cocoon.environment.ObjectModelHelper; +import org.apache.cocoon.environment.Request; +import org.apache.cocoon.environment.mock.MockRequest; +import org.apache.cocoon.forms.FormsConstants; +import org.apache.cocoon.xml.dom.DOMBuilder; +import org.apache.excalibur.source.Source; +import org.apache.excalibur.source.impl.ResourceSource; +import org.custommonkey.xmlunit.Diff; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Test case for CForms's FlowModelSelectionList datatype. + * @version $Id: FlowJXPathSelectionListTestCase.java 326838 2005-10-20 06:26:53Z sylvain $ + */ +public class FlowJXPathSelectionListTestCase extends ContainerTestCase { + + protected DatatypeManager datatypeManager; + protected DocumentBuilder parser; + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + datatypeManager = (DatatypeManager) this.lookup(DatatypeManager.ROLE); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + parser = factory.newDocumentBuilder(); + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + if (datatypeManager != null) { + this.release(datatypeManager); + } + super.tearDown(); + } + + /** + * Test the generateSaxFragment method. + */ + public void testGenerateSaxFragment() throws Exception { + List beans = new ArrayList(2); + beans.add(new TestBean("1", "One")); + beans.add(new TestBean("2", "Two")); + Map flowContextObject = new HashMap(); + flowContextObject.put("beans", beans); + Request request = new MockRequest(); + Map objectModel = new HashMap(); + FlowHelper.setContextObject(objectModel, flowContextObject); + objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request); + Map contextObjectModel = new HashMap(); + contextObjectModel.put(ContextHelper.CONTEXT_OBJECT_MODEL, objectModel); + Context context = new DefaultContext(contextObjectModel); + Source sampleSource = new ResourceSource("resource://org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.source.xml"); + Document sample = parser.parse(sampleSource.getInputStream()); + Element datatypeElement = (Element) sample.getElementsByTagNameNS(FormsConstants.DEFINITION_NS, "datatype").item(0); + Datatype datatype = datatypeManager.createDatatype(datatypeElement, false); + FlowJXPathSelectionList list = new FlowJXPathSelectionList + (context, "beans", "key", "value", datatype,null,false,null,false); + DOMBuilder dest = new DOMBuilder(); + list.generateSaxFragment(dest, Locale.ENGLISH); + Source expectedSource = new ResourceSource("resource://org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.dest.xml"); + Document expected = parser.parse(expectedSource.getInputStream()); + assertEqual("Test if generated list matches expected", + expected, dest.getDocument()); + } + + /** + * Test the generateSaxFragment method with a list containing a null value. + */ + public void testGenerateSaxFragmentWithNull() throws Exception { + List beans = new ArrayList(2); + beans.add(null); + beans.add(new TestBean("1", "One")); + beans.add(new TestBean("2", "Two")); + Map flowContextObject = new HashMap(); + flowContextObject.put("beans", beans); + Request request = new MockRequest(); + Map objectModel = new HashMap(); + FlowHelper.setContextObject(objectModel, flowContextObject); + objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request); + Map contextObjectModel = new HashMap(); + contextObjectModel.put(ContextHelper.CONTEXT_OBJECT_MODEL, objectModel); + Context context = new DefaultContext(contextObjectModel); + Source sampleSource = new ResourceSource("resource://org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.source.xml"); + Document sample = parser.parse(sampleSource.getInputStream()); + Element datatypeElement = (Element) sample.getElementsByTagNameNS(FormsConstants.DEFINITION_NS, "datatype").item(0); + Datatype datatype = datatypeManager.createDatatype(datatypeElement, false); + FlowJXPathSelectionList list = new FlowJXPathSelectionList + (context, "beans", "key", "value", datatype,null,false,null,false); + DOMBuilder dest = new DOMBuilder(); + list.generateSaxFragment(dest, Locale.ENGLISH); + Source expectedSource = new ResourceSource("resource://org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCaseWithNull.dest.xml"); + Document expected = parser.parse(expectedSource.getInputStream()); + assertEqual("Test if generated list matches expected", + expected, dest.getDocument()); + } + + /** + * Check is the source document is equal to the one produced by the method under test. + * @param message A message to print in case of failure. + * @param expected The expected (source) document. + * @param actual The actual (output) document. + */ + private void assertEqual(String message, Document expected, Document actual) { + expected.getDocumentElement().normalize(); + actual.getDocumentElement().normalize(); + // DIRTY HACK WARNING: we add the "xmlns:wi" attribute reported + // by DOM, as expected, but not generated by the method under test, + // otherwise the comparison would fail. + actual.getDocumentElement().setAttribute(FormsConstants.INSTANCE_PREFIX, + FormsConstants.INSTANCE_NS); + Diff diff = new Diff(expected, actual); + assertTrue(message + ", " + diff.toString(), diff.similar()); + } + + /** + * Print a document to a writer for debugging purposes. + * @param document The document to print. + * @param out The writer to write to. + */ + public final void print(Document document, Writer out) { + TransformerFactory factory = TransformerFactory.newInstance(); + try { + javax.xml.transform.Transformer serializer = + factory.newTransformer(); + serializer.transform( + new DOMSource(document), + new StreamResult(out)); + out.write('\n'); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static class TestBean { + private String key; + private String value; + + public TestBean(String key, String value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public String getValue() { + return value; + } + + public String toString() { + return "{ " + key + " : " + value + " }"; + } + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/Sex.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/Sex.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/Sex.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/Sex.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,40 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.forms.datatype; + + +/** + * Description of Sex. + * + * @version $Id: Sex.java 151050 2005-02-02 20:47:40Z tim $ + */ +public class Sex { + + public static final Sex MALE = new Sex("M"); + public static final Sex FEMALE = new Sex("F"); + private String code; + + private Sex(String code) { this.code = code; } + + public String toString() { + // Will probably have some i18n support here + switch(code.charAt(0)) { + case 'M' : return this.getClass().getName() + ".MALE"; + case 'F' : return this.getClass().getName() + ".FEMALE"; + default : return "unknown"; // Should never happen + } + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/Sex.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorBuilderTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorBuilderTestCase.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorBuilderTestCase.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorBuilderTestCase.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,69 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.forms.datatype.convertor; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import junit.framework.TestCase; + +import org.apache.cocoon.forms.FormsConstants; +import org.apache.excalibur.source.Source; +import org.apache.excalibur.source.impl.ResourceSource; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Test case for the {@link EnumConvertorBuilder} class. + * + * @version $Id: EnumConvertorBuilderTestCase.java 326838 2005-10-20 06:26:53Z sylvain $ + */ +public class EnumConvertorBuilderTestCase extends TestCase { + + protected DocumentBuilder parser; + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + parser = factory.newDocumentBuilder(); + } + + public EnumConvertorBuilderTestCase(String name) { + super(name); + } + + /** + * Test the {@link EnumConvertorBuilder#build(org.w3c.dom.Element) + * build} method. + * @throws Exception + */ + public void testBuild() throws Exception { + Source confSource = new ResourceSource("resource://org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.conf.xml"); + Document sample = parser.parse(confSource.getInputStream()); + Element convertorElement = (Element) sample.getElementsByTagNameNS(FormsConstants.DEFINITION_NS, "convertor").item(0); + String enumClassName = convertorElement.getElementsByTagNameNS(FormsConstants.DEFINITION_NS, "enum").item(0).getFirstChild().getNodeValue(); + EnumConvertorBuilder builder = new EnumConvertorBuilder(); + Convertor convertor = builder.build(convertorElement); + assertTrue("The returned convertor is not an EnumConvertor", + convertor instanceof EnumConvertor); + assertEquals("The convertor does not convert the expected class", + Class.forName(enumClassName), convertor.getTypeClass()); + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorBuilderTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,57 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.forms.datatype.convertor; + +import java.util.Locale; + +import org.apache.cocoon.forms.datatype.Sex; + +import junit.framework.TestCase; + +/** + * Test case for the {@link EnumConvertor} class. + * + * @version $Id: EnumConvertorTestCase.java 151050 2005-02-02 20:47:40Z tim $ + */ +public class EnumConvertorTestCase extends TestCase { + + public EnumConvertorTestCase(String name) { + super(name); + } + + /** + * Test the {@link EnumConvertor#convertFromString(java.lang.String, java.util.Locale, org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache) + * method. + */ + public void testConvertFromString() { + EnumConvertor convertor = new EnumConvertor("org.apache.cocoon.forms.datatype.Sex"); + ConversionResult conversionResult = convertor.convertFromString + (Sex.class.getName() + ".FEMALE", Locale.getDefault(), null); + assertSame("Returned sex must be FEMALE", Sex.FEMALE, conversionResult.getResult()); + } + + /** + * Test the {@link EnumConvertor##convertToString(java.lang.Object, java.util.Locale, org.apache.cocoon.forms.datatype.convertor.Convertor.FormatCache) + * method. + */ + public void testConvertToString() { + EnumConvertor convertor = new EnumConvertor("org.apache.cocoon.forms.datatype.Sex"); + assertEquals("Converted value must match string", + Sex.class.getName() + ".MALE", + convertor.convertToString + (Sex.MALE, Locale.getDefault(), null)); + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRuleTest.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRuleTest.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRuleTest.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRuleTest.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,49 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.forms.datatype.validationruleimpl; + +import junit.framework.TestCase; + + +/** + * Description of EmailValidationRuleTest. + * + * @version $Id: EmailValidationRuleTest.java 151179 2005-02-03 16:55:16Z tim $ + */ +public class EmailValidationRuleTest extends TestCase { + + public EmailValidationRuleTest(String name) { + super(name); + } + + /** + * Test some patterns that should be accepted. + */ + public void testAccept() { + EmailValidationRule rule = new EmailValidationRule(); + assertTrue("dev@cocoon.apache.org", rule.isEmail("dev@cocoon.apache.org")); + assertTrue("\"Arc, Joan\"@ird.govt.nz", rule.isEmail("\"Arc, Joan\"@ird.govt.nz")); + } + + /** + * Test some patterns that should be rejected. + */ + public void testReject() { + EmailValidationRule rule = new EmailValidationRule(); + assertTrue("x@....", ! rule.isEmail("x@....")); + assertTrue("neville.@hotmail.com", ! rule.isEmail("neville.@hotmail.com")); + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/datatype/validationruleimpl/EmailValidationRuleTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/FieldTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/FieldTestCase.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/FieldTestCase.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/FieldTestCase.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,227 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cocoon.forms.formmodel; + +import org.apache.cocoon.core.container.ContainerTestCase; +import org.apache.cocoon.environment.mock.MockRequest; +import org.apache.cocoon.forms.FormContext; +import org.apache.cocoon.forms.event.ValueChangedEvent; +import org.apache.cocoon.forms.event.ValueChangedListener; +import org.w3c.dom.Document; + +/** + * Test case for CForm's Field widget + * + * @version $Id: FieldTestCase.java 106132 2004-11-21 22:29:26Z sylvain $ + */ + +public class FieldTestCase extends ContainerTestCase { + + public static final String VALUE_PATH = "fi:fragment/fi:field/fi:value"; + public static final String VALIDATION_PATH = "fi:fragment/fi:field/fi:validation-message"; + + + /** + * Nominal test where the request data is syntactically correct and validates + */ + public void testValueDoesParseAndValidate() throws Exception { + Form form = WidgetTestHelper.loadForm(getManager(), this, "FieldTestCase.model.xml"); + Field field = (Field)form.getChild("intfield"); + Action button = (Action)form.getChild("action"); + MockRequest request; + + request = new MockRequest(); + request.addParameter("intfield", "11"); + request.addParameter("action", "pressed"); + form.process(new FormContext(request)); + + // No parsing nor validation where performed + Document doc = WidgetTestHelper.getWidgetFragment(field, null); + WidgetTestHelper.assertXPathEquals("Displayed value", "11", VALUE_PATH, doc); + WidgetTestHelper.assertXPathNotExists("Validation error", VALIDATION_PATH, doc); + + // Now do some parsing. + assertEquals("Field value", new Integer(11), field.getValue()); + // And still no validation error (do not call getValidationError() as it does validate) + doc = WidgetTestHelper.getWidgetFragment(field, null); + WidgetTestHelper.assertXPathNotExists("Validation error", VALIDATION_PATH, doc); + + // Now validate + assertTrue("Field does validate", field.validate()); + assertNull("getValidationError() null after validation", field.getValidationError()); + doc = WidgetTestHelper.getWidgetFragment(field, null); + WidgetTestHelper.assertXPathNotExists("Validation error", VALIDATION_PATH, doc); + } + + /** + * Request data is not syntactically correct + */ + public void testValueDoesNotParse() throws Exception { + Form form = WidgetTestHelper.loadForm(getManager(), this, "FieldTestCase.model.xml"); + Field field = (Field)form.getChild("intfield"); + Action button = (Action)form.getChild("action"); + MockRequest request; + + request = new MockRequest(); + request.addParameter("intfield", "foo"); + request.addParameter("action", "pressed"); + form.process(new FormContext(request)); + + // No parsing nor validation where performed + Document doc = WidgetTestHelper.getWidgetFragment(field, null); + WidgetTestHelper.assertXPathEquals("Displayed velue", "foo", VALUE_PATH, doc); + WidgetTestHelper.assertXPathNotExists("Validation error before parse", VALIDATION_PATH, doc); + + // Now do some parsing. Will return null as it's not parseable + assertNull("Field value", field.getValue()); + // But still no validation error + doc = WidgetTestHelper.getWidgetFragment(field, null); + WidgetTestHelper.assertXPathEquals("Displayed value", "foo", VALUE_PATH, doc); + WidgetTestHelper.assertXPathNotExists("Validation error after parse", VALIDATION_PATH, doc); + + // Now validate + assertFalse("Field validation", field.validate()); + doc = WidgetTestHelper.getWidgetFragment(field, null); + WidgetTestHelper.assertXPathEquals("Displayed velue", "foo", VALUE_PATH, doc); + WidgetTestHelper.assertXPathExists("Validation not null after parse", VALIDATION_PATH, doc); + assertNotNull("getValidationError() not null after validation", field.getValidationError()); + } + + /** + * Request data is syntactically correct but doesn't validate + */ + public void testValueDoesNotValidate() throws Exception { + Form form = WidgetTestHelper.loadForm(getManager(), this, "FieldTestCase.model.xml"); + Field field = (Field)form.getChild("intfield"); + Action button = (Action)form.getChild("action"); + MockRequest request; + + request = new MockRequest(); + request.addParameter("intfield", "1"); + request.addParameter("action", "pressed"); + form.process(new FormContext(request)); + + // No parsing nor validation where performed + Document doc = WidgetTestHelper.getWidgetFragment(field, null); + WidgetTestHelper.assertXPathEquals("Displayed value", "1", VALUE_PATH, doc); + WidgetTestHelper.assertXPathNotExists("Validation error before parse", VALIDATION_PATH, doc); + + // Now do some parsing. Will return null although syntactically correct as it's invalid + assertNull("Field value", field.getValue()); + // But still no validation error + doc = WidgetTestHelper.getWidgetFragment(field, null); + WidgetTestHelper.assertXPathNotExists("Validation error after parse", VALIDATION_PATH, doc); + + // Now validate + assertFalse("Field validation", field.validate()); + doc = WidgetTestHelper.getWidgetFragment(field, null); + WidgetTestHelper.assertXPathExists("Validation error after validation", VALIDATION_PATH, doc); + assertNotNull("getValidationError() not null after validation", field.getValidationError()); + } + + /** + * Test that a field's value is properly set by a call to setValue("") with an + * empty string when the field is in unparsed state (there used to be a bug in + * that case) + */ + public void testSetEmptyValueWhenValueChangedOnRequest() throws Exception { + Form form = WidgetTestHelper.loadForm(getManager(), this, "FieldTestCase.model.xml"); + Field field = (Field)form.getChild("stringfield"); + Action button = (Action)form.getChild("action"); + MockRequest request; + + // Set a value in stringfield and submit with an action + // (no validation, thus no call to doParse()) + request = new MockRequest(); + request.addParameter("stringfield", "bar"); + request.addParameter("action", "pressed"); + form.process(new FormContext(request)); + + // Verify submit widget, just to be sure that validation did not occur + assertEquals("Form submit widget", button, form.getSubmitWidget()); + + // Set the value to an empty string. In that case, a faulty test made + // it actually ignore it when state was VALUE_UNPARSED + field.setValue(""); + + // Check value by various means + Document doc = WidgetTestHelper.getWidgetFragment(field, null); + WidgetTestHelper.assertXPathEquals("Displayed value", "", VALUE_PATH, doc); + assertEquals("Datatype string conversion", "", field.getDatatype().convertToString(field.value, null)); + assertEquals("Field value", "", (String)field.getValue()); + } + + /** + * Test that the previous field value is correctly passed to event listeners + * even if it was not already parsed. + */ + public void testOldValuePresentInEventEvenIfNotParsed() throws Exception { + Form form = WidgetTestHelper.loadForm(getManager(), this, "FieldTestCase.model.xml"); + Field field = (Field)form.getChild("stringfield"); + Action button = (Action)form.getChild("action"); + MockRequest request; + + // Set a value on "stringfield", and submit using an action so that + // it stays in unparsed state + request = new MockRequest(); + request.addParameter("stringfield", "foo"); + request.addParameter("action", "pressed"); + form.process(new FormContext(request)); + + // Now add an event listener that will check old an new value + field.addValueChangedListener(new ValueChangedListener (){ + public void valueChanged(ValueChangedEvent event) { + assertEquals("Old value", "foo", (String)event.getOldValue()); + assertEquals("New value", "bar", (String)event.getNewValue()); + } + }); + + // Change value to "bar", still without explicit validation + // That will call the event listener + request = new MockRequest(); + request.addParameter("stringfield", "bar"); + request.addParameter("button", "pressed"); + form.process(new FormContext(request)); + } + + /** + * Request parameters are not read when a field is not in active state + */ + public void testParameterNotReadWhenDisabled() throws Exception { + Form form = WidgetTestHelper.loadForm(getManager(), this, "FieldTestCase.model.xml"); + Field field = (Field)form.getChild("stringfield"); + MockRequest request; + + // Disable the form + form.setState(WidgetState.DISABLED); + field.setValue("foo"); + + request = new MockRequest(); + request.addParameter("stringfield", "bar"); + form.process(new FormContext(request)); + + // Check that "bar" was not read + assertEquals("foo", field.getValue()); + + // Switch back to active and resumbit the same request + form.setState(WidgetState.ACTIVE); + form.process(new FormContext(request)); + + // Should have changed now + assertEquals("bar", field.getValue()); + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/FieldTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/GroupTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/GroupTestCase.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/GroupTestCase.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/GroupTestCase.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,49 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cocoon.forms.formmodel; + +import junit.framework.Assert; + +import org.apache.cocoon.core.container.ContainerTestCase; +import org.apache.cocoon.forms.datatype.typeimpl.IntegerType; + +/** + * Test case for CForm's group widget and inheritance + * + * @version $Id: GroupTestCase.java 289538 2005-09-16 13:46:22Z sylvain $ + */ + +public class GroupTestCase extends ContainerTestCase { + + /** + * checks for correct inheritance + */ + public void testInheritance() throws Exception { + Form form = WidgetTestHelper.loadForm(getManager(), this, "GroupTestCase.model.xml"); + Field field1 = (Field)((Group)form.getChild("group2")).getChild("field1"); + Field field2 = (Field)((Group)form.getChild("group2")).getChild("field2"); + Field field3 = (Field)((Group)form.getChild("group2")).getChild("field3"); + Group group2 = (Group)form.getChild("group2"); + + Assert.assertNotNull("Inherited field present", field1 ); + Assert.assertNotNull("Added field present", field2 ); + Assert.assertNotNull("Internally inherited field present", field3 ); + + // check datatype + Assert.assertTrue("Datatype of internally inherited field", field3.getDatatype() instanceof IntegerType); + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/GroupTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/WidgetTestHelper.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/WidgetTestHelper.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/WidgetTestHelper.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/WidgetTestHelper.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,140 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cocoon.forms.formmodel; + +import java.util.Locale; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import junit.framework.Assert; + +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.cocoon.forms.FormsConstants; +import org.apache.cocoon.forms.FormManager; +import org.apache.cocoon.xml.AttributesImpl; +import org.apache.cocoon.xml.dom.DOMBuilder; +import org.apache.commons.jxpath.JXPathContext; +import org.apache.commons.jxpath.Pointer; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.NamespaceSupport; + +/** + * Helper class to build Widget test cases. + * + * @version $Id: WidgetTestHelper.java 326838 2005-10-20 06:26:53Z sylvain $ + */ +public class WidgetTestHelper { + + // Private constructor as we only have static methods + private WidgetTestHelper() {} + + /** + * Get the result of a widget's generateSaxFragment() method as a Document. + *

+ * The widget's fragment is encapsulated in a root <fi:fragment> element, + * since there's no guarantee that a widget outputs a single top-level element + * (there can be several elements, or even none if the widget is invisible) + * + * @param widget the widget of which we want the fragment + * @param locale the locale to be used to generate the fragment + * @return the document containing the fragment + */ + public static Document getWidgetFragment(Widget widget, Locale locale) throws SAXException { + + DOMBuilder domBuilder = new DOMBuilder(); + // Start document and "fi:fragment" root element + domBuilder.startDocument(); + domBuilder.startPrefixMapping(FormsConstants.INSTANCE_PREFIX, FormsConstants.INSTANCE_NS); + // FIXME: why simply declaring the prefix isn't enough? + AttributesImpl attr = new AttributesImpl(); + attr.addCDATAAttribute(NamespaceSupport.XMLNS, "fi:", "xmlns:fi", FormsConstants.INSTANCE_NS); + domBuilder.startElement(FormsConstants.INSTANCE_NS, "fragment", FormsConstants.INSTANCE_PREFIX_COLON + "fragment", attr); + + widget.generateSaxFragment(domBuilder, locale); + + // End "fi:fragment" element and document + domBuilder.endElement(FormsConstants.INSTANCE_NS, "fragment", FormsConstants.INSTANCE_PREFIX_COLON + "fragment"); + domBuilder.endPrefixMapping(FormsConstants.INSTANCE_PREFIX); + domBuilder.endDocument(); + + // Return the document + return domBuilder.getDocument(); + } + + public static void assertXPathEquals(String expected, String xpath, Document doc) { + // use xpath as the message + assertXPathEquals(xpath, expected, xpath, doc); + } + + public static void assertXPathEquals(String message, String expected, String xpath, Document doc) { + JXPathContext ctx = JXPathContext.newContext(doc); + ctx.setLenient(true); + Assert.assertEquals(message, expected, ctx.getValue(xpath)); + } + + public static void assertXPathExists(String xpath, Document doc) { + // use xpath as message + assertXPathExists(xpath, xpath, doc); + } + + public static void assertXPathExists(String message, String xpath, Document doc) { + JXPathContext ctx = JXPathContext.newContext(doc); + ctx.setLenient(true); + Pointer pointer = ctx.getPointer(xpath); + Assert.assertNotNull(message, pointer.getNode()); + } + + public static void assertXPathNotExists(String xpath, Document doc) { + // use xpath as message + assertXPathNotExists(xpath, xpath, doc); + } + + public static void assertXPathNotExists(String message, String xpath, Document doc) { + JXPathContext ctx = JXPathContext.newContext(doc); + ctx.setLenient(true); + Pointer pointer = ctx.getPointer(xpath); + Assert.assertNull(message, pointer.getNode()); + } + + /** + * Load a Form whose definition relative to a given object (typically, the TestCase class). + * + * @param manager the ServiceManager that will be used to create the form + * @param obj the object relative to which the resource will be read + * @param resource the relative resource name for the form definition + * @return the Form + * @throws Exception + */ + public static Form loadForm(ServiceManager manager, Object obj, String resource) throws Exception { + // Load the document + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + // Grmbl... why isn't this true by default? + factory.setNamespaceAware(true); + DocumentBuilder parser = factory.newDocumentBuilder(); + Document doc = parser.parse(obj.getClass().getResource(resource).toExternalForm()); + + // Create the form + FormManager formManager = (FormManager)manager.lookup(FormManager.ROLE); + try { + return formManager.createForm(doc.getDocumentElement()); + } finally { + manager.release(formManager); + } + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/java/org/apache/cocoon/forms/formmodel/WidgetTestHelper.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.dest.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.dest.xml?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.dest.xml (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.dest.xml Thu Nov 3 05:41:06 2005 @@ -0,0 +1,21 @@ + + + + + 10/11/03 + My birthdate + Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.dest.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.source.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.source.xml?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.source.xml (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.source.xml Thu Nov 3 05:41:06 2005 @@ -0,0 +1,31 @@ + + + + + + + + + yyyy-MM-dd + + + + My birthdate + Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/DynamicSelectionListTestCase.source.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest-no-null.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest-no-null.xml?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest-no-null.xml (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest-no-null.xml Thu Nov 3 05:41:06 2005 @@ -0,0 +1,19 @@ + + +org.apache.cocoon.forms.datatype.Sex.MALEorg.apache.cocoon.forms.datatype.Sex.FEMALE Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest-no-null.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest.xml?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest.xml (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest.xml Thu Nov 3 05:41:06 2005 @@ -0,0 +1,19 @@ + + +org.apache.cocoon.forms.datatype.Sex.MALEorg.apache.cocoon.forms.datatype.Sex.FEMALE Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/EnumSelectionListTestCase.dest.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.dest.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.dest.xml?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.dest.xml (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.dest.xml Thu Nov 3 05:41:06 2005 @@ -0,0 +1,17 @@ + + +OneTwo Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.dest.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.source.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.source.xml?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.source.xml (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.source.xml Thu Nov 3 05:41:06 2005 @@ -0,0 +1,27 @@ + + + + + + + + + Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCase.source.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCaseWithNull.dest.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCaseWithNull.dest.xml?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCaseWithNull.dest.xml (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCaseWithNull.dest.xml Thu Nov 3 05:41:06 2005 @@ -0,0 +1,17 @@ + + +OneTwo Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListTestCaseWithNull.dest.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.conf.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.conf.xml?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.conf.xml (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.conf.xml Thu Nov 3 05:41:06 2005 @@ -0,0 +1,26 @@ + + + + + Sex + + + org.apache.cocoon.forms.datatype.Sex + + + + Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.conf.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/formmodel/FieldTestCase.model.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/formmodel/FieldTestCase.model.xml?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/formmodel/FieldTestCase.model.xml (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/formmodel/FieldTestCase.model.xml Thu Nov 3 05:41:06 2005 @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/formmodel/FieldTestCase.model.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/formmodel/GroupTestCase.model.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/formmodel/GroupTestCase.model.xml?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/formmodel/GroupTestCase.model.xml (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/formmodel/GroupTestCase.model.xml Thu Nov 3 05:41:06 2005 @@ -0,0 +1,41 @@ + + + + + + + + + Field1 + + + + + + + + + Field2 + + + + + + + + Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/impl/src/test/resources/org/apache/cocoon/forms/formmodel/GroupTestCase.model.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/pom.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/pom.xml?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/pom.xml (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/pom.xml Thu Nov 3 05:41:06 2005 @@ -0,0 +1,83 @@ + + + + + + apache-cocoon + cocoon + 2.2-SNAPSHOT + + 4.0.0 + apache-cocoon + cocoon-forms-block + 2.2-SNAPSHOT + Forms Block + pom + + api + impl + samples + + + + apache-cocoon + cocoon-core + 2.2-SNAPSHOT + + + + apache-cocoon + cocoon-ajax-impl + 2.2-SNAPSHOT + + + jakarta-oro + jakarta-oro + 2.0.8 + + + jakarta-regexp + jakarta-regexp + 1.4 + + + xreporter + xreporter-expression + 20040701 + + + daisy + daisy-htmlcleaner + 1.1 + + + icu4j + icu4j + 3.0 + + + \ No newline at end of file Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/samples/pom.xml URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/samples/pom.xml?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/samples/pom.xml (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/samples/pom.xml Thu Nov 3 05:41:06 2005 @@ -0,0 +1,35 @@ + + + + + 4.0.0 + apache-cocoon + cocoon-forms-samples + 2.2-SNAPSHOT + jar + Forms Samples + + + apache-cocoon + cocoon-forms-impl + 2.2-SNAPSHOT + + + Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-forms-block/samples/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native