From: <bo...@us...> - 2010-04-29 06:46:14
|
Revision: 364 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=364&view=rev Author: bodewig Date: 2010-04-29 06:46:08 +0000 (Thu, 29 Apr 2010) Log Message: ----------- additional convenience builder methods Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java trunk/xmlunit/src/main/net-core/builder/Input.cs trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java trunk/xmlunit/src/tests/net-core/builder/InputTest.cs Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java 2010-04-29 06:44:42 UTC (rev 363) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java 2010-04-29 06:46:08 UTC (rev 364) @@ -141,6 +141,7 @@ public static interface TransformationBuilder extends Builder { TransformationBuilder withStylesheet(Source s); + TransformationBuilder withStylesheet(Builder b); TransformationBuilder withParameter(String name, Object value); TransformationBuilder withOutputProperty(String name, String value); } @@ -158,6 +159,9 @@ styleSheet = s; return this; } + public TransformationBuilder withStylesheet(Builder b) { + return withStylesheet(b.build()); + } public TransformationBuilder withOutputProperty(String name, String value) { output.setProperty(name, value); @@ -196,4 +200,8 @@ public static TransformationBuilder byTransforming(Source s) { return new Transformation(s); } + + public static TransformationBuilder byTransforming(Builder b) { + return byTransforming(b.build()); + } } Modified: trunk/xmlunit/src/main/net-core/builder/Input.cs =================================================================== --- trunk/xmlunit/src/main/net-core/builder/Input.cs 2010-04-29 06:44:42 UTC (rev 363) +++ trunk/xmlunit/src/main/net-core/builder/Input.cs 2010-04-29 06:46:08 UTC (rev 364) @@ -83,6 +83,7 @@ public interface ITransformationBuilder : IBuilder { ITransformationBuilder WithStylesheet(ISource s); + ITransformationBuilder WithStylesheet(IBuilder b); ITransformationBuilder WithExtensionObject(string namespaceUri, object extension); ITransformationBuilder WithParameter(string name, @@ -101,6 +102,9 @@ this.styleSheet = s; return this; } + public ITransformationBuilder WithStylesheet(IBuilder b) { + return WithStylesheet(b.Build()); + } public ITransformationBuilder WithExtensionObject(string namespaceUri, object extension) { @@ -137,5 +141,8 @@ public static ITransformationBuilder ByTransforming(ISource s) { return new Transformation(s); } + public static ITransformationBuilder ByTransforming(IBuilder b) { + return ByTransforming(b.Build()); + } } } Modified: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java =================================================================== --- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java 2010-04-29 06:44:42 UTC (rev 363) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java 2010-04-29 06:46:08 UTC (rev 364) @@ -107,7 +107,7 @@ allIsWellFor(Input.fromURL(new URL("file:" + TEST_FILE)).build()); } - @Test public void shouldParseATransformation() throws Exception { + @Test public void shouldParseATransformationFromSource() throws Exception { Source input = Input.fromMemory("<animal>furry</animal>").build(); Source s = Input.byTransforming(input) .withStylesheet(Input.fromFile("src/tests/resources/animal.xsl") @@ -122,6 +122,20 @@ assertThat(d2.getDocumentElement().getTagName(), is("furry")); } + @Test public void shouldParseATransformationFromBuilder() throws Exception { + Input.Builder input = Input.fromMemory("<animal>furry</animal>"); + Source s = Input.byTransforming(input) + .withStylesheet(Input.fromFile("src/tests/resources/animal.xsl")) + .build(); + // again, transformed is a DOMSource, cannot use parse() + assertThat(s, instanceOf(DOMSource.class)); + Object o = ((DOMSource) s).getNode(); + assertThat(o, instanceOf(Document.class)); + Document d2 = (Document) o; + assertThat(d2, notNullValue()); + assertThat(d2.getDocumentElement().getTagName(), is("furry")); + } + private static void allIsWellFor(Source s) throws Exception { assertThat(s, notNullValue()); Document d = parse(s); Modified: trunk/xmlunit/src/tests/net-core/builder/InputTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/builder/InputTest.cs 2010-04-29 06:44:42 UTC (rev 363) +++ trunk/xmlunit/src/tests/net-core/builder/InputTest.cs 2010-04-29 06:46:08 UTC (rev 364) @@ -71,7 +71,7 @@ AllIsWellFor(Input.FromURI(new Uri("file:" + TEST_FILE)).Build()); } - [Test] public void ShouldParseATransformation() { + [Test] public void ShouldParseATransformationFromSource() { ISource input = Input.FromMemory("<animal>furry</animal>").Build(); ISource s = Input.ByTransforming(input) .WithStylesheet(Input.FromFile("../../../src/tests/resources/animal.xsl") @@ -83,6 +83,17 @@ Assert.That(d.DocumentElement.Name, Is.EqualTo("furry")); } + [Test] public void ShouldParseATransformationFromBuilder() { + Input.IBuilder input = Input.FromMemory("<animal>furry</animal>"); + ISource s = Input.ByTransforming(input) + .WithStylesheet(Input.FromFile("../../../src/tests/resources/animal.xsl")) + .Build(); + Assert.That(s, Is.Not.Null); + XmlDocument d = Parse(s); + Assert.That(d, Is.Not.Null); + Assert.That(d.DocumentElement.Name, Is.EqualTo("furry")); + } + private static void AllIsWellFor(ISource s) { Assert.That(s, Is.Not.Null); XmlDocument d = Parse(s); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |