All,
I would like to be able to write junit tests for all my custom java processors that extends the SimpleProcessor class. Has anyone done this before? Does anyone know how to approach this / have some code? Thanks! Sincerely, Henrik Pettersen Advanced Computation Laboratory , Cancer Research UK http://www.acl.icnet.uk/lab/index.html Here is one example class that I would like to test: package org.cruk.aspic.editor.api.orbeon; import org.cruk.aspic.editor.exception.EditorException; import org.cruk.aspic.editor.model.User; import org.cruk.aspic.editor.util.OrbeonUtil; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Node; import org.dom4j.XPath; import org.orbeon.oxf.pipeline.api.PipelineContext; import org.orbeon.oxf.processor.ProcessorInputOutputInfo; import org.orbeon.oxf.processor.SimpleProcessor; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; public class AddUser extends SimpleProcessor { private static final XPath mXPath = DocumentHelper.createXPath("/"); static { mXPath.setNamespaceURIs(OrbeonUtil.NAMESPACE_MAP); } public AddUser() { addInputInfo(new ProcessorInputOutputInfo(INPUT_DATA)); } public void generateData(PipelineContext context, ContentHandler contentHandler) throws SAXException, EditorException { Document inputDoc = readInputAsDOM4J(context, INPUT_DATA); Node node = mXPath.selectSingleNode(inputDoc); User pUser = (User) OrbeonUtil.fromXml((Document)node.clone()); org.cruk.aspic.editor.workflow.AddUser.execute(pUser); } } -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Hi Henrik
Could you use the same structure as the current processor unit tests, these are found in /orbeon/src/examples/web/ops/unit-tests tests.xml is the overall configuration file, you'll see examples for all the processors in there. Not exactly direct junit tests, but maybe this would do the job? Steve -----Original Message----- From: Henrik Pettersen [mailto:[hidden email]] Sent: 25 July 2006 14:04 To: [hidden email] Subject: [ops-users] JUnit test for SimpleProcessor extension class All, I would like to be able to write junit tests for all my custom java processors that extends the SimpleProcessor class. Has anyone done this before? Does anyone know how to approach this / have some code? Thanks! Sincerely, Henrik Pettersen Advanced Computation Laboratory , Cancer Research UK http://www.acl.icnet.uk/lab/index.html Here is one example class that I would like to test: package org.cruk.aspic.editor.api.orbeon; import org.cruk.aspic.editor.exception.EditorException; import org.cruk.aspic.editor.model.User; import org.cruk.aspic.editor.util.OrbeonUtil; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Node; import org.dom4j.XPath; import org.orbeon.oxf.pipeline.api.PipelineContext; import org.orbeon.oxf.processor.ProcessorInputOutputInfo; import org.orbeon.oxf.processor.SimpleProcessor; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; public class AddUser extends SimpleProcessor { private static final XPath mXPath = DocumentHelper.createXPath("/"); static { mXPath.setNamespaceURIs(OrbeonUtil.NAMESPACE_MAP); } public AddUser() { addInputInfo(new ProcessorInputOutputInfo(INPUT_DATA)); } public void generateData(PipelineContext context, ContentHandler contentHandler) throws SAXException, EditorException { Document inputDoc = readInputAsDOM4J(context, INPUT_DATA); Node node = mXPath.selectSingleNode(inputDoc); User pUser = (User) OrbeonUtil.fromXml((Document)node.clone()); org.cruk.aspic.editor.workflow.AddUser.execute(pUser); } } -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Thanks, Stephen! Looking at this now... I don't suppose there are any
documentation for this anywhere? Thanks! Henrik On 7/25/06, Stephen Bayliss <[hidden email]> wrote: > Hi Henrik > > Could you use the same structure as the current processor unit tests, > these are found in /orbeon/src/examples/web/ops/unit-tests > > tests.xml is the overall configuration file, you'll see examples for all > the processors in there. > > Not exactly direct junit tests, but maybe this would do the job? > > Steve > > > > -----Original Message----- > From: Henrik Pettersen [mailto:[hidden email]] > Sent: 25 July 2006 14:04 > To: [hidden email] > Subject: [ops-users] JUnit test for SimpleProcessor extension class > > All, > > I would like to be able to write junit tests for all my custom java > processors that extends the SimpleProcessor class. Has anyone done > this before? Does anyone know how to approach this / have some code? > > Thanks! > > Sincerely, > Henrik Pettersen > Advanced Computation Laboratory , Cancer Research UK > http://www.acl.icnet.uk/lab/index.html > > Here is one example class that I would like to test: > > package org.cruk.aspic.editor.api.orbeon; > > import org.cruk.aspic.editor.exception.EditorException; > import org.cruk.aspic.editor.model.User; > import org.cruk.aspic.editor.util.OrbeonUtil; > import org.dom4j.Document; > import org.dom4j.DocumentHelper; > import org.dom4j.Node; > import org.dom4j.XPath; > import org.orbeon.oxf.pipeline.api.PipelineContext; > import org.orbeon.oxf.processor.ProcessorInputOutputInfo; > import org.orbeon.oxf.processor.SimpleProcessor; > import org.xml.sax.ContentHandler; > import org.xml.sax.SAXException; > > > public class AddUser extends SimpleProcessor { > > private static final XPath mXPath = DocumentHelper.createXPath("/"); > static { > mXPath.setNamespaceURIs(OrbeonUtil.NAMESPACE_MAP); > } > > public AddUser() { > addInputInfo(new ProcessorInputOutputInfo(INPUT_DATA)); > } > > public void generateData(PipelineContext context, > ContentHandler contentHandler) throws SAXException, > EditorException > { > Document inputDoc = readInputAsDOM4J(context, INPUT_DATA); > Node node = mXPath.selectSingleNode(inputDoc); > User pUser = (User) OrbeonUtil.fromXml((Document)node.clone()); > org.cruk.aspic.editor.workflow.AddUser.execute(pUser); > } > } > > > > > > > -- > You receive this message as a subscriber of the [hidden email] mailing list. > To unsubscribe: mailto:[hidden email] > For general help: mailto:[hidden email]?subject=help > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws > > > -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
In reply to this post by Henrik Pettersen
Hi Henrik
No probs. Found this post by Erik with more details: http://www.orbeon.com/blog/2005/02/22/xml-unit-testing/ I have used it myself, but not exactly extensively! Steve -----Original Message----- From: Henrik Pettersen [mailto:[hidden email]] Sent: 08 August 2006 15:23 To: [hidden email] Subject: Re: [ops-users] JUnit test for SimpleProcessor extension class Thanks, Stephen! Looking at this now... I don't suppose there are any documentation for this anywhere? Thanks! Henrik On 7/25/06, Stephen Bayliss <[hidden email]> wrote: > Hi Henrik > > Could you use the same structure as the current processor unit tests, > these are found in /orbeon/src/examples/web/ops/unit-tests > > tests.xml is the overall configuration file, you'll see examples for all > the processors in there. > > Not exactly direct junit tests, but maybe this would do the job? > > Steve > > > > -----Original Message----- > From: Henrik Pettersen [mailto:[hidden email]] > Sent: 25 July 2006 14:04 > To: [hidden email] > Subject: [ops-users] JUnit test for SimpleProcessor extension class > > All, > > I would like to be able to write junit tests for all my custom java > processors that extends the SimpleProcessor class. Has anyone done > this before? Does anyone know how to approach this / have some code? > > Thanks! > > Sincerely, > Henrik Pettersen > Advanced Computation Laboratory , Cancer Research UK > http://www.acl.icnet.uk/lab/index.html > > Here is one example class that I would like to test: > > package org.cruk.aspic.editor.api.orbeon; > > import org.cruk.aspic.editor.exception.EditorException; > import org.cruk.aspic.editor.model.User; > import org.cruk.aspic.editor.util.OrbeonUtil; > import org.dom4j.Document; > import org.dom4j.DocumentHelper; > import org.dom4j.Node; > import org.dom4j.XPath; > import org.orbeon.oxf.pipeline.api.PipelineContext; > import org.orbeon.oxf.processor.ProcessorInputOutputInfo; > import org.orbeon.oxf.processor.SimpleProcessor; > import org.xml.sax.ContentHandler; > import org.xml.sax.SAXException; > > > public class AddUser extends SimpleProcessor { > > private static final XPath mXPath = > static { > mXPath.setNamespaceURIs(OrbeonUtil.NAMESPACE_MAP); > } > > public AddUser() { > addInputInfo(new ProcessorInputOutputInfo(INPUT_DATA)); > } > > public void generateData(PipelineContext context, > ContentHandler contentHandler) throws SAXException, > EditorException > { > Document inputDoc = readInputAsDOM4J(context, INPUT_DATA); > Node node = mXPath.selectSingleNode(inputDoc); > User pUser = (User) > org.cruk.aspic.editor.workflow.AddUser.execute(pUser); > } > } > > > > > > > -- > You receive this message as a subscriber of the > To unsubscribe: mailto:[hidden email] > For general help: mailto:[hidden email]?subject=help > ObjectWeb mailing lists service home page: > > > -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
He he, thanks for pointing that out, I had almost forgotten about that
post myself. -Erik Stephen Bayliss wrote: > Hi Henrik > > No probs. Found this post by Erik with more details: > http://www.orbeon.com/blog/2005/02/22/xml-unit-testing/ > > I have used it myself, but not exactly extensively! > > Steve > > -----Original Message----- > From: Henrik Pettersen [mailto:[hidden email]] > Sent: 08 August 2006 15:23 > To: [hidden email] > Subject: Re: [ops-users] JUnit test for SimpleProcessor extension class > > Thanks, Stephen! Looking at this now... I don't suppose there are any > documentation for this anywhere? > > Thanks! > > Henrik > > On 7/25/06, Stephen Bayliss <[hidden email]> wrote: >> Hi Henrik >> >> Could you use the same structure as the current processor unit tests, >> these are found in /orbeon/src/examples/web/ops/unit-tests >> >> tests.xml is the overall configuration file, you'll see examples for > all >> the processors in there. >> >> Not exactly direct junit tests, but maybe this would do the job? >> >> Steve >> >> >> >> -----Original Message----- >> From: Henrik Pettersen [mailto:[hidden email]] >> Sent: 25 July 2006 14:04 >> To: [hidden email] >> Subject: [ops-users] JUnit test for SimpleProcessor extension class >> >> All, >> >> I would like to be able to write junit tests for all my custom java >> processors that extends the SimpleProcessor class. Has anyone done >> this before? Does anyone know how to approach this / have some code? >> >> Thanks! >> >> Sincerely, >> Henrik Pettersen >> Advanced Computation Laboratory , Cancer Research UK >> http://www.acl.icnet.uk/lab/index.html >> >> Here is one example class that I would like to test: >> >> package org.cruk.aspic.editor.api.orbeon; >> >> import org.cruk.aspic.editor.exception.EditorException; >> import org.cruk.aspic.editor.model.User; >> import org.cruk.aspic.editor.util.OrbeonUtil; >> import org.dom4j.Document; >> import org.dom4j.DocumentHelper; >> import org.dom4j.Node; >> import org.dom4j.XPath; >> import org.orbeon.oxf.pipeline.api.PipelineContext; >> import org.orbeon.oxf.processor.ProcessorInputOutputInfo; >> import org.orbeon.oxf.processor.SimpleProcessor; >> import org.xml.sax.ContentHandler; >> import org.xml.sax.SAXException; >> >> >> public class AddUser extends SimpleProcessor { >> >> private static final XPath mXPath = > DocumentHelper.createXPath("/"); >> static { >> mXPath.setNamespaceURIs(OrbeonUtil.NAMESPACE_MAP); >> } >> >> public AddUser() { >> addInputInfo(new ProcessorInputOutputInfo(INPUT_DATA)); >> } >> >> public void generateData(PipelineContext context, >> ContentHandler contentHandler) throws SAXException, >> EditorException >> { >> Document inputDoc = readInputAsDOM4J(context, INPUT_DATA); >> Node node = mXPath.selectSingleNode(inputDoc); >> User pUser = (User) > OrbeonUtil.fromXml((Document)node.clone()); >> org.cruk.aspic.editor.workflow.AddUser.execute(pUser); >> } >> } >> >> >> >> >> >> >> -- >> You receive this message as a subscriber of the > [hidden email] mailing list. >> To unsubscribe: mailto:[hidden email] >> For general help: mailto:[hidden email]?subject=help >> ObjectWeb mailing lists service home page: > http://www.objectweb.org/wws >> >> > > > > > ------------------------------------------------------------------------ > > > -- > You receive this message as a subscriber of the [hidden email] mailing list. > To unsubscribe: mailto:[hidden email] > For general help: mailto:[hidden email]?subject=help > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws -- Orbeon - XForms Everywhere: http://www.orbeon.com/blog/ -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
All,
I am happy to report that I was successfull in implementing the Orbeon unit test framework, and I recomend anyone who has not done so yet, to look into using it. Incredibly helpfull! However, I had to make one small code change to org.orbeon.oxf.test.ProcessorTest: When I am testing my "GetAllBlah" function, I get repeated xml nodes for each user entry. The number, order and content of each user node changes quite often, and so the test for the actual and expected results is not 'clever' enough: outputPassed = Dom4jUtils.domToString(expectedData).equals(Dom4jUtils.domToString(actualDataClone)); My solution (hack?) was to add support for an attribute "verify=false()" on an xml element in the 'expected output' xml document, where the presence of this attribute causes the particular node to be ignored for the test. This is not a particularly clever solution, but might come in use for some of you. Another way to solve this problem would be to create a copy of your database for testing purposes only, where the data does not change. Here is my code, for those that are interested: ******************************************************************************************** Document expectedDataClone = (Document)expectedData.clone(); Document actualDataClone = (Document)actualData.clone(); List lRemovableNodes = expectedData.selectNodes("//*[@verify = \"false()\"]"); for (Iterator<Node> removableNodesIt = lRemovableNodes.iterator(); removableNodesIt.hasNext();){ Node removableNode = (Node) removableNodesIt.next(); List lNodesToRemoveFromExpected = expectedDataClone.selectNodes(removableNode.getPath()); for (Iterator nodesToRemoveIt = lNodesToRemoveFromExpected.iterator(); nodesToRemoveIt.hasNext();){ Node lNodeToRemove = (Node)nodesToRemoveIt.next(); //System.out.println("Ignoring: [" + lNodeToRemove.getPath() + "]"); lNodeToRemove.detach(); } List lNodesToRemoveFromActual = actualDataClone.selectNodes(removableNode.getPath()); for (Iterator nodesToRemoveIt = lNodesToRemoveFromActual.iterator(); nodesToRemoveIt.hasNext();){ Node lNodeToRemove = (Node)nodesToRemoveIt.next(); //System.out.println("Ignoring: [" + lNodeToRemove.getPath() + "]"); lNodeToRemove.detach(); } } outputPassed = Dom4jUtils.domToString(expectedDataClone) .equals(Dom4jUtils.domToString(actualDataClone)); ****************************************************** Note that the "verify=true()" construct is not supported, only "verify=false()" Henrik Also, here is a sample of my unit tests (located in WEB-INF/resources/unit-tests): tests.xml ======== <?xml version="1.0" encoding="ISO-8859-1"?> <tests xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:xalan="http://xml.apache.org/xalan" xmlns:delegation="http://orbeon.org/oxf/xml/delegation" xmlns:d="http://orbeon.org/oxf/xml/document" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xu="http://www.xmldb.org/xupdate" xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:xi="http://www.w3.org/2003/XInclude" xmlns:aspic="http://www.cruk.com/aspic/editor/v1"> <xi:include href="test/UserCrudTest.xml"/> </tests> test/UserCrudTest.xml ================= <group xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:aspic="http://www.cruk.com/aspic/editor/v1" xmlns:xi="http://www.w3.org/2003/XInclude"> <test description="User: [AddEntity] + [UpdateEntity] + [DeleteEntity] + [GetAllEntities]" name="oxf:pipeline"> <!-- SCHEMA DEFINITIONS --> <xi:include href="../schema/AddUserInput.xml"/> <xi:include href="../schema/GetAllUsersInput.xml"/> <xi:include href="../schema/GetAllUsersOutput.xml"/> <input name="config"> <p:config xmlns:oxf="http://www.orbeon.com/oxf/processors"> <!-- DECLARE--> <!-- For each schema definition, add an entry here (one-to-one) --> <p:param name="call" type="input"/> <p:param name="getall.input" type="input"/> <p:param name="getall.output" type="output"/> <!-- TESTS --> <xi:include href="../entity/AddEntityTest.xml"/> <xi:include href="UserPrepareUpdateTest.xml"/> <xi:include href="../entity/UpdateEntityTest.xml"/> <xi:include href="../entity/DeleteEntityTest.xml"/> <xi:include href="../entity/GetAllEntitiesTest.xml"/> </p:config> </input> </test> </group> schema/GetAllUsersInput.xml: ======================== <input name="getall.input" xmlns:aspic="http://www.cruk.com/aspic/editor/v1"> <aspic:entity> <aspic:classname>org.cruk.aspic.editor.model.User</aspic:classname> </aspic:entity> </input> schema/GetAllUsersOutput.xml ======================= <output name="getall.output" xmlns:aspic="http://www.cruk.com/aspic/editor/v1"> <aspic:users> <aspic:user verify="false()"/> <!-- note: by my extension of ProcessorTest.java --> </aspic:users> </output> entity/addEntity.xml: ================ <p:processor name="oxf:java"> <p:input name="config"> <config sourcepath="oxf:/java" class="org.cruk.aspic.editor.api.orbeon.AddEntity"/> </p:input> <p:input name="data" href="#call"/> <p:output name="data" id="add-out"/> </p:processor> UserPrepareUpdateTest.xml: ======================== <p:processor name="oxf:xupdate" xmlns:xu="http://www.xmldb.org/xupdate"> <p:input name="data" href="#add-out"/> <p:input name="config"> <xu:modifications version="1.0"> <xu:update select="/aspic:user/aspic:firstname">JUNIT_MODIFIED_FIRSTNAME</xu:update> <xu:update select="/aspic:user/aspic:lastname">JUNIT_MODIFIED_LASTNAME</xu:update> <xu:update select="/aspic:user/aspic:username">JUNIT_MODIFIED_USERNAME</xu:update> <xu:update select="/aspic:user/aspic:email">JUNIT_MODIFIED_EMAIL</xu:update> <xu:update select="/aspic:user/aspic:password">JUNIT_MODIFIED_PASSWORD</xu:update> </xu:modifications> </p:input> <p:output name="data" id="xupdate-out"/> </p:processor> entity/UpdateEntityTest.xml: ======================== <p:processor name="oxf:java"> <p:input name="config"> <config sourcepath="oxf:/java" class="org.cruk.aspic.editor.api.orbeon.UpdateQuery"/> </p:input> <p:input name="data" href="#xupdate-out"/> <p:output name="data" id="update-out"/> </p:processor> entity/DeleteEntityTest.xml: ======================== <p:processor name="oxf:java"> <p:input name="config"> <config sourcepath="oxf:/java" class="org.cruk.aspic.editor.api.orbeon.DeleteEntity"/> </p:input> <p:input name="data" href="#update-out"/> <p:output name="data" id="blank"/> </p:processor> entity/GetAllEntitiesTest.xml: ======================== <p:processor name="oxf:java"> <p:input name="config"> <config sourcepath="oxf:/java" class="org.cruk.aspic.editor.api.orbeon.GetAllEntities"/> </p:input> <p:input name="data" href="#getall.input"/> <p:output name="data" ref="getall.output"/> </p:processor> Here is my ant task for running the unit test: ================================= <target name="test.orbeon.api" description="Run the JUnit tests for the Orbeon connection points" depends="your dependencies here"> <delete dir="${temp.dir}"/> <mkdir dir="${temp.dir}"/> <junit fork="yes" haltonerror="yes" haltonfailure="yes"> <formatter type="plain" usefile="false"/> <classpath refid="junit.classpath" /> <batchtest> <fileset dir="${test-src.dir}"> <include name="org/orbeon/oxf/test/*Test*.java"/> </fileset> </batchtest> <sysproperty key="oxf.resources.factory" value="org.orbeon.oxf.resources.PriorityResourceManagerFactory"/> <sysproperty key="oxf.resources.filesystem.sandbox-directory" value="${build.resources.dir}"/> <sysproperty key="oxf.resources.priority.1" value="org.orbeon.oxf.resources.FilesystemResourceManagerFactory"/> <sysproperty key="oxf.resources.priority.2" value="org.orbeon.oxf.resources.ClassLoaderResourceManagerFactory"/> <sysproperty key="oxf.resources.common.min-reload-interval" value="50"/> <sysproperty key="oxf.test.config" value="oxf:/unit-tests/tests.xml"/> <sysproperty key="java.io.tmpdir" value="${temp.dir}" /> </junit> </target> What to do (implementation checklist): 1. create unit test descriptions 2. add org.orbeon.oxf.test.ProcessorTest to your project 3. add junit to your project 4. add the ant target Hope this is helpfull to someone! Thanks for all your help, Stephen and Erik! Henrik On 8/9/06, Erik Bruchez <[hidden email]> wrote: > He he, thanks for pointing that out, I had almost forgotten about that > post myself. > > -Erik > > Stephen Bayliss wrote: > > Hi Henrik > > > > No probs. Found this post by Erik with more details: > > http://www.orbeon.com/blog/2005/02/22/xml-unit-testing/ > > > > I have used it myself, but not exactly extensively! > > > > Steve > > > > -----Original Message----- > > From: Henrik Pettersen [mailto:[hidden email]] > > Sent: 08 August 2006 15:23 > > To: [hidden email] > > Subject: Re: [ops-users] JUnit test for SimpleProcessor extension class > > > > Thanks, Stephen! Looking at this now... I don't suppose there are any > > documentation for this anywhere? > > > > Thanks! > > > > Henrik > > > > On 7/25/06, Stephen Bayliss <[hidden email]> wrote: > >> Hi Henrik > >> > >> Could you use the same structure as the current processor unit tests, > >> these are found in /orbeon/src/examples/web/ops/unit-tests > >> > >> tests.xml is the overall configuration file, you'll see examples for > > all > >> the processors in there. > >> > >> Not exactly direct junit tests, but maybe this would do the job? > >> > >> Steve > >> > >> > >> > >> -----Original Message----- > >> From: Henrik Pettersen [mailto:[hidden email]] > >> Sent: 25 July 2006 14:04 > >> To: [hidden email] > >> Subject: [ops-users] JUnit test for SimpleProcessor extension class > >> > >> All, > >> > >> I would like to be able to write junit tests for all my custom java > >> processors that extends the SimpleProcessor class. Has anyone done > >> this before? Does anyone know how to approach this / have some code? > >> > >> Thanks! > >> > >> Sincerely, > >> Henrik Pettersen > >> Advanced Computation Laboratory , Cancer Research UK > >> http://www.acl.icnet.uk/lab/index.html > >> > >> Here is one example class that I would like to test: > >> > >> package org.cruk.aspic.editor.api.orbeon; > >> > >> import org.cruk.aspic.editor.exception.EditorException; > >> import org.cruk.aspic.editor.model.User; > >> import org.cruk.aspic.editor.util.OrbeonUtil; > >> import org.dom4j.Document; > >> import org.dom4j.DocumentHelper; > >> import org.dom4j.Node; > >> import org.dom4j.XPath; > >> import org.orbeon.oxf.pipeline.api.PipelineContext; > >> import org.orbeon.oxf.processor.ProcessorInputOutputInfo; > >> import org.orbeon.oxf.processor.SimpleProcessor; > >> import org.xml.sax.ContentHandler; > >> import org.xml.sax.SAXException; > >> > >> > >> public class AddUser extends SimpleProcessor { > >> > >> private static final XPath mXPath = > > DocumentHelper.createXPath("/"); > >> static { > >> mXPath.setNamespaceURIs(OrbeonUtil.NAMESPACE_MAP); > >> } > >> > >> public AddUser() { > >> addInputInfo(new ProcessorInputOutputInfo(INPUT_DATA)); > >> } > >> > >> public void generateData(PipelineContext context, > >> ContentHandler contentHandler) throws SAXException, > >> EditorException > >> { > >> Document inputDoc = readInputAsDOM4J(context, INPUT_DATA); > >> Node node = mXPath.selectSingleNode(inputDoc); > >> User pUser = (User) > > OrbeonUtil.fromXml((Document)node.clone()); > >> org.cruk.aspic.editor.workflow.AddUser.execute(pUser); > >> } > >> } > >> > >> > >> > >> > >> > >> > >> -- > >> You receive this message as a subscriber of the > > [hidden email] mailing list. > >> To unsubscribe: mailto:[hidden email] > >> For general help: mailto:[hidden email]?subject=help > >> ObjectWeb mailing lists service home page: > > http://www.objectweb.org/wws > >> > >> > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > -- > > You receive this message as a subscriber of the [hidden email] mailing list. > > To unsubscribe: mailto:[hidden email] > > For general help: mailto:[hidden email]?subject=help > > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws > > > -- > Orbeon - XForms Everywhere: > http://www.orbeon.com/blog/ > > > > > -- > You receive this message as a subscriber of the [hidden email] mailing list. > To unsubscribe: mailto:[hidden email] > For general help: mailto:[hidden email]?subject=help > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws > > > -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
In reply to this post by Erik Bruchez
All,
In fact, if someone has the time, there could be some major benefits from integrating XMLUnit into the OPS package for unit testing: http://xmlunit.sourceforge.net/ Henrik On 8/9/06, Erik Bruchez <[hidden email]> wrote: He he, thanks for pointing that out, I had almost forgotten about that -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
Henrik,
What major benefits would there be? (BTW I am not cynical, I just haven't looked at XMLUnit recently ;-) -Erik Henrik Pettersen wrote: > All, > > In fact, if someone has the time, there could be some major benefits > from integrating XMLUnit into the OPS package for unit testing: > > http://xmlunit.sourceforge.net/ <http://xmlunit.sourceforge.net/> > > Henrik > > > On 8/9/06, *Erik Bruchez* <[hidden email] > <mailto:[hidden email]>> wrote: > > He he, thanks for pointing that out, I had almost forgotten about that > post myself. > > -Erik > > Stephen Bayliss wrote: > > Hi Henrik > > > > No probs. Found this post by Erik with more details: > > http://www.orbeon.com/blog/2005/02/22/xml-unit-testing/ > > > > I have used it myself, but not exactly extensively! > > > > Steve > > > > -----Original Message----- > > From: Henrik Pettersen [mailto:[hidden email] > <mailto:[hidden email]>] > > Sent: 08 August 2006 15:23 > > To: [hidden email] <mailto:[hidden email]> > > Subject: Re: [ops-users] JUnit test for SimpleProcessor extension > class > > > > Thanks, Stephen! Looking at this now... I don't suppose there are any > > documentation for this anywhere? > > > > Thanks! > > > > Henrik > > > > On 7/25/06, Stephen Bayliss <[hidden email] > <mailto:[hidden email]>> wrote: > >> Hi Henrik > >> > >> Could you use the same structure as the current processor unit > tests, > >> these are found in /orbeon/src/examples/web/ops/unit-tests > >> > >> tests.xml is the overall configuration file, you'll see examples > for > > all > >> the processors in there. > >> > >> Not exactly direct junit tests, but maybe this would do the job? > >> > >> Steve > >> > >> > >> > >> -----Original Message----- > >> From: Henrik Pettersen [mailto:[hidden email] > <mailto:[hidden email]>] > >> Sent: 25 July 2006 14:04 > >> To: [hidden email] <mailto:[hidden email]> > >> Subject: [ops-users] JUnit test for SimpleProcessor extension class > >> > >> All, > >> > >> I would like to be able to write junit tests for all my custom java > >> processors that extends the SimpleProcessor class. Has anyone done > >> this before? Does anyone know how to approach this / have some code? > >> > >> Thanks! > >> > >> Sincerely, > >> Henrik Pettersen > >> Advanced Computation Laboratory , Cancer Research UK > >> http://www.acl.icnet.uk/lab/index.html > >> > >> Here is one example class that I would like to test: > >> > >> package org.cruk.aspic.editor.api.orbeon ; > >> > >> import org.cruk.aspic.editor.exception.EditorException; > >> import org.cruk.aspic.editor.model.User; > >> import org.cruk.aspic.editor.util.OrbeonUtil; > >> import org.dom4j.Document ; > >> import org.dom4j.DocumentHelper; > >> import org.dom4j.Node; > >> import org.dom4j.XPath; > >> import org.orbeon.oxf.pipeline.api.PipelineContext; > >> import org.orbeon.oxf.processor.ProcessorInputOutputInfo ; > >> import org.orbeon.oxf.processor.SimpleProcessor; > >> import org.xml.sax.ContentHandler; > >> import org.xml.sax.SAXException; > >> > >> > >> public class AddUser extends SimpleProcessor { > >> > >> private static final XPath mXPath = > > DocumentHelper.createXPath("/"); > >> static { > >> mXPath.setNamespaceURIs(OrbeonUtil.NAMESPACE_MAP); > >> } > >> > >> public AddUser() { > >> addInputInfo(new ProcessorInputOutputInfo(INPUT_DATA)); > >> } > >> > >> public void generateData(PipelineContext context, > >> ContentHandler contentHandler) throws SAXException, > >> EditorException > >> { > >> Document inputDoc = readInputAsDOM4J(context, INPUT_DATA); > >> Node node = mXPath.selectSingleNode(inputDoc); > >> User pUser = (User) > > OrbeonUtil.fromXml((Document)node.clone()); > >> org.cruk.aspic.editor.workflow.AddUser.execute(pUser); > >> } > >> } > >> > >> > >> > >> > >> > >> > >> -- > >> You receive this message as a subscriber of the > > [hidden email] <mailto:[hidden email]> mailing > list. > >> To unsubscribe: mailto:[hidden email] > <mailto:[hidden email]> > >> For general help: mailto: [hidden email] > <mailto:[hidden email]>?subject=help > >> ObjectWeb mailing lists service home page: > > http://www.objectweb.org/wws > >> > >> > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > -- > > You receive this message as a subscriber of the > [hidden email] <mailto:[hidden email]> mailing list. > > To unsubscribe: mailto:[hidden email] > <mailto:[hidden email]> > > For general help: mailto:[hidden email] > <mailto:[hidden email]>?subject=help > > ObjectWeb mailing lists service home page: > http://www.objectweb.org/wws > > > -- > Orbeon - XForms Everywhere: > http://www.orbeon.com/blog/ > > > > > -- > You receive this message as a subscriber of the > [hidden email] <mailto:[hidden email]> mailing list. > To unsubscribe: mailto: [hidden email] > <mailto:[hidden email]> > For general help: mailto:[hidden email] > <mailto:[hidden email]>?subject=help > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws > > > > > ------------------------------------------------------------------------ > > > -- > You receive this message as a subscriber of the [hidden email] mailing list. > To unsubscribe: mailto:[hidden email] > For general help: mailto:[hidden email]?subject=help > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws -- Orbeon - XForms Everywhere: http://www.orbeon.com/blog/ -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Well, currently the ccomparison test done between expected and actual output is determined like this:
outputPassed = Dom4jUtils.domToString(expectedDataClone) .equals(Dom4jUtils.domToString (actualDataClone)); There are several issues with this approach: 1. There is not much flexibility specifying the expected input/output (see my 'verify=@false()' hack) 2. The current test does not allways get it right. e.g. if the actual output has an additional namespace decleration compared to the expected value, this test would fail (should it?) So let me quote from XMLUnit: *********************************************** XMLUnit for Java provides two JUnit extension classes,
XMLUnit for Java can also treat HTML content (even badly-formed HTML) as valid XML to allow these assertions to be made about the content of web pages too. **************************************************************************************** Writing XML comparison tests Let's say we have two pieces of XML that we wish to compare and assert that they are equal. We could write a simple test class like this: public class MyXMLTestCase extends XMLTestCase { public MyXMLTestCase(String name) { super(name); } public void testForEquality() throws Exception { String myControlXML = "<msg><uuid>0x00435A8C</uuid></msg>"; String myTestXML = "<msg><localId>2376</localId></msg>"; assertXMLEqual("Comparing test xml to control xml", myControlXML, myTestXML); } } The assertXMLEqual test will pass if the control and test XML are either similar or identical. Obviously in this case the pieces of XML are different and the test will fail. The failure message indicates both what the difference is and the Xpath locations of the nodes that were being compared: Comparing test xml to control xml [different] Expected element tag name 'uuid' but was 'localId' - comparing <uuid...> at /msg[1]/uuid[1] to <localId...> at /msg[1]/localId[1] When comparing pieces of XML, the XMLTestCase actually creates an instance of the Diff class. The Diff class stores the result of an XML comparison and makes it available through the methods similar() and identical(). The assertXMLEquals() method tests the value of Diff.similar() and the assertXMLIdentical() method tests the value of Diff.identical(). It is easy to create a Diff instance directly without using the XMLTestCase class as below: public void testXMLIdentical()throws Exception { String myControlXML = "<struct><int>3</int><boolean>false</boolean></struct>"; String myTestXML = "<struct><boolean>false</boolean><int>3</int></struct>"; Diff myDiff = new Diff(myControlXML, myTestXML); assertTrue("XML similar " + myDiff.toString (), myDiff.similar()); assertTrue("XML identical " + myDiff.toString(), myDiff.identical()); } This test fails as two pieces of XML are similar but not identical if their nodes occur in a different sequence. The failure message reported by JUnit from the call to myDiff.toString() looks like this: [not identical] Expected sequence of child nodes '0' but was '1' - comparing <int...> at /struct[1]/int[1] to <int...> at /struct[1]/int[1] etc... Hope this helps :-) Henrik On 8/17/06, Erik Bruchez <[hidden email]> wrote:
Henrik, -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
Cool, so could we simply use the XMLUnit comparison code? This would be
great. Regarding namespaces, it depends: sometime (especially when testing namespaces ;-) you may want to perform a strict comparison, as the XML Infoset considers that the namespaces _in scope_ for an element are part of the information set. In some other cases, you may not care much about this. So clearly, there should be an option, ideally. -Erik Henrik Pettersen wrote: > Well, currently the ccomparison test done between expected and actual > output is determined like this: > > outputPassed = Dom4jUtils.domToString(expectedDataClone) > .equals(Dom4jUtils.domToString > (actualDataClone)); > > There are several issues with this approach: > > 1. There is not much flexibility specifying the expected input/output > (see my 'verify=@false()' hack) > 2. The current test does not allways get it right. e.g. if the actual > output has an additional namespace decleration compared to the expected > value, this test would fail (should it?) > > > So let me quote from XMLUnit: > *********************************************** > > XMLUnit for Java provides two JUnit extension classes, |XMLAssert| and > |XMLTestCase|, and a set of supporting classes (e.g. |Diff|, > |DetailedDiff|,|Transform|,|SimpleXpathEngine|,|Validator|,|NodeTest|) > that allow assertions to be made about: > > * The differences between two pieces of XML > * The outcome of transforming a piece of XML using XSLT > * The evaluation of an XPath expression on a piece of XML > * The validity of a piece of XML > * Individual nodes in a piece of XML that are exposed by DOM Traversal > > > XMLUnit for Java can also treat HTML content (even badly-formed HTML) as > valid XML to allow these assertions to be made about the content of web > pages too. > > > And from the Documentation (http://xmlunit.sourceforge.net/XMLUnit.pdf): > **************************************************************************************** > > > Writing XML comparison tests > Let's say we have two pieces of XML that we wish to compare and assert > that they are equal. We could > write a simple test class like this: > > public class MyXMLTestCase extends XMLTestCase { > public MyXMLTestCase(String name) { > super(name); > } > public void testForEquality() throws Exception { > String myControlXML = "<msg><uuid>0x00435A8C</uuid></msg>"; > String myTestXML = "<msg><localId>2376</localId></msg>"; > assertXMLEqual("Comparing test xml to control xml", > myControlXML, myTestXML); > } > } > > The assertXMLEqual test will pass if the control and test XML are either > similar or identical. Obviously in > this case the pieces of XML are different and the test will fail. The > failure message indicates both what the > difference is and the Xpath locations of the nodes that were being compared: > > Comparing test xml to control xml > [different] Expected element tag name 'uuid' but was 'localId' - > comparing <uuid...> at /msg[1]/uuid[1] to <localId...> at > /msg[1]/localId[1] > > When comparing pieces of XML, the XMLTestCase actually creates an > instance of the Diff class. The Diff > class stores the result of an XML comparison and makes it available > through the methods similar() and > identical(). The assertXMLEquals() method tests the value of > Diff.similar() and the assertXMLIdentical() > method tests the value of Diff.identical(). > > It is easy to create a Diff instance directly without using the > XMLTestCase class as below: > > public void testXMLIdentical()throws Exception { > String myControlXML = > "<struct><int>3</int><boolean>false</boolean></struct>"; > String myTestXML = > "<struct><boolean>false</boolean><int>3</int></struct>"; > Diff myDiff = new Diff(myControlXML, myTestXML); > assertTrue("XML similar " + myDiff.toString (), > myDiff.similar()); > assertTrue("XML identical " + myDiff.toString(), > myDiff.identical()); > } > > This test fails as two pieces of XML are similar but not identical if > their nodes occur in a different > sequence. The failure message reported by JUnit from the call to > myDiff.toString() looks like this: > [not identical] Expected sequence of child nodes '0' but was '1' - > comparing <int...> at /struct[1]/int[1] to <int...> at /struct[1]/int[1] > > etc... > > > Hope this helps :-) > > Henrik > > > > On 8/17/06, *Erik Bruchez* <[hidden email] > <mailto:[hidden email]>> wrote: > > Henrik, > > What major benefits would there be? (BTW I am not cynical, I just > haven't looked at XMLUnit recently ;-) > > -Erik > > Henrik Pettersen wrote: > > All, > > > > In fact, if someone has the time, there could be some major benefits > > from integrating XMLUnit into the OPS package for unit testing: > > > > http://xmlunit.sourceforge.net/ <http://xmlunit.sourceforge.net/> > > > > Henrik > > > > > > On 8/9/06, *Erik Bruchez* <[hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] <mailto:[hidden email]>>> wrote: > > > > He he, thanks for pointing that out, I had almost forgotten > about that > > post myself. > > > > -Erik > > > > Stephen Bayliss wrote: > > > Hi Henrik > > > > > > No probs. Found this post by Erik with more details: > > > http://www.orbeon.com/blog/2005/02/22/xml-unit-testing/ > > > > > > I have used it myself, but not exactly extensively! > > > > > > Steve > > > > > > -----Original Message----- > > > From: Henrik Pettersen [mailto:[hidden email] > <mailto:[hidden email]> > > <mailto: [hidden email] > <mailto:[hidden email]>>] > > > Sent: 08 August 2006 15:23 > > > To: [hidden email] > <mailto:[hidden email]> <mailto: [hidden email] > <mailto:[hidden email]>> > > > Subject: Re: [ops-users] JUnit test for SimpleProcessor > extension > > class > > > > > > Thanks, Stephen! Looking at this now... I don't suppose > there are any > > > documentation for this anywhere? > > > > > > Thanks! > > > > > > Henrik > > > > > > On 7/25/06, Stephen Bayliss < > [hidden email] <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>>> wrote: > > >> Hi Henrik > > >> > > >> Could you use the same structure as the current processor > unit > > tests, > > >> these are found in /orbeon/src/examples/web/ops/unit-tests > > >> > > >> tests.xml is the overall configuration file, you'll see > examples > > for > > > all > > >> the processors in there. > > >> > > >> Not exactly direct junit tests, but maybe this would do > the job? > > >> > > >> Steve > > >> > > >> > > >> > > >> -----Original Message----- > > >> From: Henrik Pettersen [mailto:[hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>>] > > >> Sent: 25 July 2006 14:04 > > >> To: [hidden email] > <mailto:[hidden email]> <mailto:[hidden email] > <mailto:[hidden email]>> > > >> Subject: [ops-users] JUnit test for SimpleProcessor > extension class > > >> > > >> All, > > >> > > >> I would like to be able to write junit tests for all my > custom java > > >> processors that extends the SimpleProcessor class. Has > anyone done > > >> this before? Does anyone know how to approach this / have > some code? > > >> > > >> Thanks! > > >> > > >> Sincerely, > > >> Henrik Pettersen > > >> Advanced Computation Laboratory , Cancer Research UK > > >> http://www.acl.icnet.uk/lab/index.html > > >> > > >> Here is one example class that I would like to test: > > >> > > >> package org.cruk.aspic.editor.api.orbeon ; > > >> > > >> import org.cruk.aspic.editor.exception.EditorException; > > >> import org.cruk.aspic.editor.model.User ; > > >> import org.cruk.aspic.editor.util.OrbeonUtil; > > >> import org.dom4j.Document ; > > >> import org.dom4j.DocumentHelper; > > >> import org.dom4j.Node; > > >> import org.dom4j.XPath; > > >> import org.orbeon.oxf.pipeline.api.PipelineContext; > > >> import org.orbeon.oxf.processor.ProcessorInputOutputInfo ; > > >> import org.orbeon.oxf.processor.SimpleProcessor; > > >> import org.xml.sax.ContentHandler; > > >> import org.xml.sax.SAXException; > > >> > > >> > > >> public class AddUser extends SimpleProcessor { > > >> > > >> private static final XPath mXPath = > > > DocumentHelper.createXPath("/"); > > >> static { > > >> mXPath.setNamespaceURIs (OrbeonUtil.NAMESPACE_MAP); > > >> } > > >> > > >> public AddUser() { > > >> addInputInfo(new > ProcessorInputOutputInfo(INPUT_DATA)); > > >> } > > >> > > >> public void generateData(PipelineContext context, > > >> ContentHandler contentHandler) throws SAXException, > > >> EditorException > > >> { > > >> Document inputDoc = readInputAsDOM4J(context, > INPUT_DATA); > > >> Node node = mXPath.selectSingleNode(inputDoc); > > >> User pUser = (User) > > > OrbeonUtil.fromXml((Document)node.clone()); > > >> > org.cruk.aspic.editor.workflow.AddUser.execute(pUser); > > >> } > > >> } > > >> > > >> > > >> > > >> > > >> > > >> > > >> -- > > >> You receive this message as a subscriber of the > > > [hidden email] <mailto:[hidden email]> > <mailto:[hidden email] <mailto:[hidden email]>> > mailing > > list. > > >> To unsubscribe: mailto: > [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>> > > >> For general help: mailto: [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>>?subject=help > > >> ObjectWeb mailing lists service home page: > > > http://www.objectweb.org/wws > > >> > > >> > > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > > -- > > > You receive this message as a subscriber of the > > [hidden email] <mailto:[hidden email]> > <mailto:[hidden email] <mailto:[hidden email]>> > mailing list. > > > To unsubscribe: mailto: > [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>> > > > For general help: mailto: [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>>?subject=help > > > ObjectWeb mailing lists service home page: > > http://www.objectweb.org/wws > > > > > > -- > > Orbeon - XForms Everywhere: > > http://www.orbeon.com/blog/ > > > > > > > > > > -- > > You receive this message as a subscriber of the > > [hidden email] <mailto:[hidden email]> > <mailto:[hidden email] <mailto:[hidden email]>> > mailing list. > > To unsubscribe: mailto: [hidden email] > <mailto:[hidden email]> > > <mailto: [hidden email] > <mailto:[hidden email]>> > > For general help: mailto:[hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>>?subject=help > > ObjectWeb mailing lists service home page: > http://www.objectweb.org/wws > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > -- > > You receive this message as a subscriber of the > [hidden email] <mailto:[hidden email]> mailing list. > > To unsubscribe: mailto: [hidden email] > <mailto:[hidden email]> > > For general help: mailto:[hidden email] > <mailto:[hidden email]>?subject=help > > ObjectWeb mailing lists service home page: > http://www.objectweb.org/wws > > > -- > Orbeon - XForms Everywhere: > http://www.orbeon.com/blog/ > > > > > -- > You receive this message as a subscriber of the > [hidden email] <mailto:[hidden email]> mailing list. > To unsubscribe: mailto:[hidden email] > <mailto:[hidden email]> > For general help: mailto: [hidden email] > <mailto:[hidden email]>?subject=help > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws > > > > > ------------------------------------------------------------------------ > > > -- > You receive this message as a subscriber of the [hidden email] mailing list. > To unsubscribe: mailto:[hidden email] > For general help: mailto:[hidden email]?subject=help > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws -- Orbeon - XForms Everywhere: http://www.orbeon.com/blog/ -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Indeed. Much more flexible :-)
Let me know if you need a hand with implementing this... Henrik On 8/18/06, Erik Bruchez <[hidden email]> wrote:
Cool, so could we simply use the XMLUnit comparison code? This would be -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
Henrik, any help is definitely appreciated as we currently have so much
on our plate for the next release of OPS. -Erik Henrik Pettersen wrote: > Indeed. Much more flexible :-) > > Let me know if you need a hand with implementing this... > > Henrik > > On 8/18/06, *Erik Bruchez* < [hidden email] > <mailto:[hidden email]>> wrote: > > Cool, so could we simply use the XMLUnit comparison code? This would be > great. > > Regarding namespaces, it depends: sometime (especially when testing > namespaces ;-) you may want to perform a strict comparison, as the XML > Infoset considers that the namespaces _in scope_ for an element are > part > of the information set. In some other cases, you may not care much about > this. So clearly, there should be an option, ideally. > > -Erik > > Henrik Pettersen wrote: > > Well, currently the ccomparison test done between expected and > actual > > output is determined like this: > > > > outputPassed = Dom4jUtils.domToString(expectedDataClone) > > .equals(Dom4jUtils.domToString > > (actualDataClone)); > > > > There are several issues with this approach: > > > > 1. There is not much flexibility specifying the expected input/output > > (see my 'verify=@false()' hack) > > 2. The current test does not allways get it right. e.g. if the actual > > output has an additional namespace decleration compared to the > expected > > value, this test would fail (should it?) > > > > > > So let me quote from XMLUnit: > > *********************************************** > > > > XMLUnit for Java provides two JUnit extension classes, > |XMLAssert| and > > |XMLTestCase|, and a set of supporting classes (e.g. |Diff|, > > > |DetailedDiff|,|Transform|,|SimpleXpathEngine|,|Validator|,|NodeTest|) > > that allow assertions to be made about: > > > > * The differences between two pieces of XML > > * The outcome of transforming a piece of XML using XSLT > > * The evaluation of an XPath expression on a piece of XML > > * The validity of a piece of XML > > * Individual nodes in a piece of XML that are exposed by DOM > Traversal > > > > > > XMLUnit for Java can also treat HTML content (even badly-formed > HTML) as > > valid XML to allow these assertions to be made about the content > of web > > pages too. > > > > > > And from the Documentation ( > http://xmlunit.sourceforge.net/XMLUnit.pdf): > > > **************************************************************************************** > > > > > > Writing XML comparison tests > > Let's say we have two pieces of XML that we wish to compare and > assert > > that they are equal. We could > > write a simple test class like this: > > > > public class MyXMLTestCase extends XMLTestCase { > > public MyXMLTestCase(String name) { > > super(name); > > } > > public void testForEquality() throws Exception { > > String myControlXML = "<msg><uuid>0x00435A8C</uuid></msg>"; > > String myTestXML = "<msg><localId>2376</localId></msg>"; > > assertXMLEqual("Comparing test xml to control xml", > > myControlXML, myTestXML); > > } > > } > > > > The assertXMLEqual test will pass if the control and test XML are > either > > similar or identical. Obviously in > > this case the pieces of XML are different and the test will fail. > The > > failure message indicates both what the > > difference is and the Xpath locations of the nodes that were > being compared: > > > > Comparing test xml to control xml > > [different] Expected element tag name 'uuid' but was 'localId' - > > comparing <uuid...> at /msg[1]/uuid[1] to <localId...> at > > /msg[1]/localId[1] > > > > When comparing pieces of XML, the XMLTestCase actually creates an > > instance of the Diff class. The Diff > > class stores the result of an XML comparison and makes it available > > through the methods similar() and > > identical(). The assertXMLEquals() method tests the value of > > Diff.similar() and the assertXMLIdentical() > > method tests the value of Diff.identical(). > > > > It is easy to create a Diff instance directly without using the > > XMLTestCase class as below: > > > > public void testXMLIdentical()throws Exception { > > String myControlXML = > > "<struct><int>3</int><boolean>false</boolean></struct>"; > > String myTestXML = > > "<struct><boolean>false</boolean><int>3</int></struct>"; > > Diff myDiff = new Diff(myControlXML, myTestXML); > > assertTrue("XML similar " + myDiff.toString (), > > myDiff.similar()); > > assertTrue("XML identical " + myDiff.toString(), > > myDiff.identical()); > > } > > > > This test fails as two pieces of XML are similar but not identical if > > their nodes occur in a different > > sequence. The failure message reported by JUnit from the call to > > myDiff.toString() looks like this: > > [not identical] Expected sequence of child nodes '0' but was '1' - > > comparing <int...> at /struct[1]/int[1] to <int...> at > /struct[1]/int[1] > > > > etc... > > > > > > Hope this helps :-) > > > > Henrik > > > > > > > > On 8/17/06, *Erik Bruchez* <[hidden email] > <mailto:[hidden email]> > > <mailto: [hidden email] <mailto:[hidden email]>>> wrote: > > > > Henrik, > > > > What major benefits would there be? (BTW I am not cynical, I just > > haven't looked at XMLUnit recently ;-) > > > > -Erik > > > > Henrik Pettersen wrote: > > > All, > > > > > > In fact, if someone has the time, there could be some > major benefits > > > from integrating XMLUnit into the OPS package for unit > testing: > > > > > > http://xmlunit.sourceforge.net/ > <http://xmlunit.sourceforge.net/> > > > > > > Henrik > > > > > > > > > On 8/9/06, *Erik Bruchez* <[hidden email] > <mailto:[hidden email]> > > <mailto: [hidden email] <mailto:[hidden email]>> > > > <mailto:[hidden email] <mailto:[hidden email]> > <mailto:[hidden email] <mailto:[hidden email]>>>> wrote: > > > > > > He he, thanks for pointing that out, I had almost > forgotten > > about that > > > post myself. > > > > > > -Erik > > > > > > Stephen Bayliss wrote: > > > > Hi Henrik > > > > > > > > No probs. Found this post by Erik with more details: > > > > http://www.orbeon.com/blog/2005/02/22/xml-unit-testing/ > > > > > > > > I have used it myself, but not exactly extensively! > > > > > > > > Steve > > > > > > > > -----Original Message----- > > > > From: Henrik Pettersen > [mailto:[hidden email] <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>> > > > <mailto: [hidden email] > <mailto:[hidden email]> > > <mailto: [hidden email] > <mailto:[hidden email]>>>] > > > > Sent: 08 August 2006 15:23 > > > > To: [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>> <mailto: [hidden email] > <mailto:[hidden email]> > > <mailto: [hidden email] > <mailto:[hidden email]>>> > > > > Subject: Re: [ops-users] JUnit test for SimpleProcessor > > extension > > > class > > > > > > > > Thanks, Stephen! Looking at this now... I don't > suppose > > there are any > > > > documentation for this anywhere? > > > > > > > > Thanks! > > > > > > > > Henrik > > > > > > > > On 7/25/06, Stephen Bayliss < > > [hidden email] > <mailto:[hidden email]> > <mailto:[hidden email] > <mailto:[hidden email]>> > > > <mailto:[hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>>>> wrote: > > > >> Hi Henrik > > > >> > > > >> Could you use the same structure as the current > processor > > unit > > > tests, > > > >> these are found in > /orbeon/src/examples/web/ops/unit-tests > > > >> > > > >> tests.xml is the overall configuration file, > you'll see > > examples > > > for > > > > all > > > >> the processors in there. > > > >> > > > >> Not exactly direct junit tests, but maybe this > would do > > the job? > > > >> > > > >> Steve > > > >> > > > >> > > > >> > > > >> -----Original Message----- > > > >> From: Henrik Pettersen > [mailto:[hidden email] <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>> > > > <mailto:[hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>>>] > > > >> Sent: 25 July 2006 14:04 > > > >> To: [hidden email] > <mailto:[hidden email]> > > <mailto: [hidden email] > <mailto:[hidden email]>> <mailto:[hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>>> > > > >> Subject: [ops-users] JUnit test for SimpleProcessor > > extension class > > > >> > > > >> All, > > > >> > > > >> I would like to be able to write junit tests for > all my > > custom java > > > >> processors that extends the SimpleProcessor class. Has > > anyone done > > > >> this before? Does anyone know how to approach this > / have > > some code? > > > >> > > > >> Thanks! > > > >> > > > >> Sincerely, > > > >> Henrik Pettersen > > > >> Advanced Computation Laboratory , Cancer Research UK > > > >> http://www.acl.icnet.uk/lab/index.html > > > >> > > > >> Here is one example class that I would like to test: > > > >> > > > >> package org.cruk.aspic.editor.api.orbeon ; > > > >> > > > >> import > org.cruk.aspic.editor.exception.EditorException; > > > >> import org.cruk.aspic.editor.model.User ; > > > >> import org.cruk.aspic.editor.util.OrbeonUtil ; > > > >> import org.dom4j.Document ; > > > >> import org.dom4j.DocumentHelper; > > > >> import org.dom4j.Node; > > > >> import org.dom4j.XPath; > > > >> import org.orbeon.oxf.pipeline.api.PipelineContext; > > > >> import > org.orbeon.oxf.processor.ProcessorInputOutputInfo ; > > > >> import org.orbeon.oxf.processor.SimpleProcessor; > > > >> import org.xml.sax.ContentHandler; > > > >> import org.xml.sax.SAXException; > > > >> > > > >> > > > >> public class AddUser extends SimpleProcessor { > > > >> > > > >> private static final XPath mXPath = > > > > DocumentHelper.createXPath ("/"); > > > >> static { > > > >> mXPath.setNamespaceURIs > (OrbeonUtil.NAMESPACE_MAP); > > > >> } > > > >> > > > >> public AddUser() { > > > >> addInputInfo(new > > ProcessorInputOutputInfo(INPUT_DATA)); > > > >> } > > > >> > > > >> public void generateData(PipelineContext context, > > > >> ContentHandler contentHandler) throws > SAXException, > > > >> EditorException > > > >> { > > > >> Document inputDoc = readInputAsDOM4J(context, > > INPUT_DATA); > > > >> Node node = mXPath.selectSingleNode > (inputDoc); > > > >> User pUser = (User) > > > > OrbeonUtil.fromXml((Document)node.clone()); > > > >> > > org.cruk.aspic.editor.workflow.AddUser.execute (pUser); > > > >> } > > > >> } > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> -- > > > >> You receive this message as a subscriber of the > > > > [hidden email] > <mailto:[hidden email]> <mailto:[hidden email] > <mailto:[hidden email]>> > > <mailto:[hidden email] > <mailto:[hidden email]> <mailto: [hidden email] > <mailto:[hidden email]>>> > > mailing > > > list. > > > >> To unsubscribe: mailto: > > [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>> > > > <mailto:[hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>>> > > > >> For general help: mailto: [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] <mailto:[hidden email]>> > > > <mailto:[hidden email] <mailto:[hidden email]> > > <mailto: [hidden email] > <mailto:[hidden email]>>>?subject=help > > > >> ObjectWeb mailing lists service home page: > > > > http://www.objectweb.org/wws > > > >> > > > >> > > > > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > > > > > -- > > > > You receive this message as a subscriber of the > > > [hidden email] > <mailto:[hidden email]> <mailto:[hidden email] > <mailto:[hidden email]>> > > <mailto: [hidden email] > <mailto:[hidden email]> <mailto:[hidden email] > <mailto:[hidden email]>>> > > mailing list. > > > > To unsubscribe: mailto: > > [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>> > > > <mailto: [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>>> > > > > For general help: mailto: [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] <mailto:[hidden email]>> > > > <mailto:[hidden email] <mailto:[hidden email]> > > <mailto: [hidden email] > <mailto:[hidden email]>>>?subject=help > > > > ObjectWeb mailing lists service home page: > > > http://www.objectweb.org/wws > <http://www.objectweb.org/wws> > > > > > > > > > -- > > > Orbeon - XForms Everywhere: > > > http://www.orbeon.com/blog/ > > > > > > > > > > > > > > > -- > > > You receive this message as a subscriber of the > > > [hidden email] > <mailto:[hidden email]> <mailto:[hidden email] > <mailto:[hidden email]>> > > <mailto:[hidden email] > <mailto:[hidden email]> <mailto: [hidden email] > <mailto:[hidden email]>>> > > mailing list. > > > To unsubscribe: mailto: > [hidden email] > <mailto:[hidden email]> > > <mailto: [hidden email] > <mailto:[hidden email]>> > > > <mailto: [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>>> > > > For general help: mailto:[hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] <mailto:[hidden email]>> > > > <mailto:[hidden email] <mailto:[hidden email]> > > <mailto: [hidden email] > <mailto:[hidden email]>>>?subject=help > > > ObjectWeb mailing lists service home page: > > http://www.objectweb.org/wws > > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > > > > -- > > > You receive this message as a subscriber of the > > [hidden email] <mailto:[hidden email]> > <mailto:[hidden email] <mailto:[hidden email]>> > mailing list. > > > To unsubscribe: mailto: > [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>> > > > For general help: mailto: [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>>?subject=help > > > ObjectWeb mailing lists service home page: > > http://www.objectweb.org/wws > > > > > > -- > > Orbeon - XForms Everywhere: > > http://www.orbeon.com/blog/ <http://www.orbeon.com/blog/> > > > > > > > > > > -- > > You receive this message as a subscriber of the > > [hidden email] <mailto:[hidden email]> > <mailto: [hidden email] <mailto:[hidden email]>> > mailing list. > > To unsubscribe: mailto:[hidden email] > <mailto:[hidden email]> > > <mailto: [hidden email] > <mailto:[hidden email]>> > > For general help: mailto: [hidden email] > <mailto:[hidden email]> > > <mailto:[hidden email] > <mailto:[hidden email]>>?subject=help > > ObjectWeb mailing lists service home page: > http://www.objectweb.org/wws > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > -- > > You receive this message as a subscriber of the > [hidden email] <mailto:[hidden email]> mailing list. > > To unsubscribe: mailto: [hidden email] > <mailto:[hidden email]> > > For general help: mailto:[hidden email] > <mailto:[hidden email]>?subject=help > > ObjectWeb mailing lists service home page: > http://www.objectweb.org/wws > > > -- > Orbeon - XForms Everywhere: > http://www.orbeon.com/blog/ > > > > > -- > You receive this message as a subscriber of the > [hidden email] <mailto:[hidden email]> mailing list. > To unsubscribe: mailto:[hidden email] > <mailto:[hidden email]> > For general help: mailto: [hidden email] > <mailto:[hidden email]>?subject=help > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws > > > > > ------------------------------------------------------------------------ > > > -- > You receive this message as a subscriber of the [hidden email] mailing list. > To unsubscribe: mailto:[hidden email] > For general help: mailto:[hidden email]?subject=help > ObjectWeb mailing lists service home page: http://www.objectweb.org/wws -- Orbeon - XForms Everywhere: http://www.orbeon.com/blog/ -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Free forum by Nabble | Edit this page |