Modified: jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/HttpFileDownloadStageTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/HttpFileDownloadStageTest.java?rev=436914&r1=436913&r2=436914&view=diff ============================================================================== --- jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/HttpFileDownloadStageTest.java (original) +++ jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/HttpFileDownloadStageTest.java Fri Aug 25 12:30:39 2006 @@ -20,11 +20,9 @@ import java.io.File; import java.io.FileReader; import java.net.URL; -import java.util.ArrayList; -import java.util.List; import junit.framework.*; -import org.apache.commons.pipeline.Pipeline; -import org.apache.commons.pipeline.Stage; +import org.apache.commons.pipeline.testFramework.TestFeeder; +import org.apache.commons.pipeline.testFramework.TestStageContext; /** @@ -32,28 +30,19 @@ */ public class HttpFileDownloadStageTest extends TestCase { - Pipeline pipeline; - List results; - URL fileUrl; - URL google; - + private URL google; + private URL fileUrl; public HttpFileDownloadStageTest(String testName) { super(testName); } protected void setUp() throws Exception { - results = new ArrayList(); - ArrayList<Stage> stages = new ArrayList<Stage>(); - stages.add(new HttpFileDownloadStage()); - stages.add(new AddToCollectionStage(results)); + super.setUp(); + this.google = new URL("http://www.google.com"); this.fileUrl = this.getClass().getClassLoader().getResource("http-download.txt"); - assertNotNull(fileUrl); - google = new URL("http://www.google.com"); - pipeline = new Pipeline(stages); - } - protected void tearDown() throws Exception { + assertNotNull(fileUrl); } public static Test suite() { @@ -63,77 +52,42 @@ } /** - * Test of process method, of class org.apache.commons.pipeline.stage.HttpFileDownloadStage. + * Test of process() method, of class org.apache.commons.pipeline.stage.HttpFileDownloadStage. */ -// public void testFileUrlStringProcess() throws Exception { -// pipeline.start(); -// pipeline.enqueue(this.fileUrl.toExternalForm()); -// pipeline.finish(); -// assertEquals(1,results.size()); -// Object o = results.get(0); -// assertNotNull(o); -// assertTrue(o instanceof File); -// File file = (File) o; -// -// FileReader rf = new FileReader(file); -// BufferedReader br = new BufferedReader(rf); -// try { -// String line = br.readLine(); -// assertNotNull(line); -// assertEquals("This is a test file.",line); -// } finally { -// rf.close(); -// br.close(); -// } -// -// -// } -// -// /** -// * Test of setWorkDir method, of class org.apache.commons.pipeline.stage.HttpFileDownloadStage. -// */ -// public void testFileUrlProcess() throws Exception { -// pipeline.start(); -// pipeline.enqueue(this.fileUrl); -// pipeline.finish(); -// assertEquals(1,results.size()); -// Object o = results.get(0); -// assertNotNull(o); -// assertTrue(o instanceof File); -// File file = (File) o; -// -// FileReader rf = new FileReader(file); -// BufferedReader br = new BufferedReader(rf); -// try { -// String line = br.readLine(); -// assertNotNull(line); -// assertEquals("This is a test file.",line); -// } finally { -// rf.close(); -// br.close(); -// } -// -// } + public void testHttpUrlProcess() throws Exception { + this.execTestHttpProcess(this.google); + this.execTestHttpProcess(this.google.toExternalForm()); + //this.execTestFileUrlProcess(this.fileUrl); + //this.execTestFileUrlProcess(this.fileUrl.toExternalForm()); + } /** - * Test of process() method, of class org.apache.commons.pipeline.stage.HttpFileDownloadStage. + * Utility method for testing processing of HTTP URLs. */ - public void testHttpUrlString() throws Exception { - pipeline.start(); - pipeline.enqueue(this.google.toExternalForm()); - pipeline.finish(); - assertEquals(1,results.size()); - Object o = results.get(0); + private void execTestHttpProcess(Object arg) throws Exception { + HttpFileDownloadStage stage = new HttpFileDownloadStage(); + + //initialize the testing context + TestStageContext testContext = new TestStageContext(); + TestFeeder testFeeder = new TestFeeder(); + testContext.registerDownstreamFeeder(stage, testFeeder); + stage.init(testContext); + + stage.process(arg); + + assertEquals(1, testFeeder.receivedValues.size()); + + Object o = testFeeder.receivedValues.get(0); assertNotNull(o); assertTrue(o instanceof File); - File file = (File) o; + File file = (File) o; FileReader rf = new FileReader(file); BufferedReader br = new BufferedReader(rf); try { String line = br.readLine(); assertNotNull(line); - assertTrue("actual line:" + line,line.contains("oogle")); + assertTrue("actual line:" + line, line.contains("oogle")); } finally { rf.close(); br.close(); @@ -141,14 +95,22 @@ } /** - * Test of process() method, of class org.apache.commons.pipeline.stage.HttpFileDownloadStage. + * Utility method for testing processing of system/file URLs. */ - public void testHttpUrl() throws Exception { - pipeline.start(); - pipeline.enqueue(this.google); - pipeline.finish(); - assertEquals(1,results.size()); - Object o = results.get(0); + public void execTestFileUrlProcess(Object arg) throws Exception { + HttpFileDownloadStage stage = new HttpFileDownloadStage(); + + //initialize the testing context + TestStageContext testContext = new TestStageContext(); + TestFeeder testFeeder = new TestFeeder(); + testContext.registerDownstreamFeeder(stage, testFeeder); + stage.init(testContext); + + stage.process(arg); + + assertEquals(1, testFeeder.receivedValues.size()); + + Object o = testFeeder.receivedValues.get(0); assertNotNull(o); assertTrue(o instanceof File); File file = (File) o; @@ -158,10 +120,12 @@ try { String line = br.readLine(); assertNotNull(line); - assertTrue("actual line:" + line,line.contains("oogle")); + assertEquals("This is a test file.", line); } finally { rf.close(); br.close(); } + } + }
Modified: jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/InputStreamLineBreakStageTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/InputStreamLineBreakStageTest.java?rev=436914&r1=436913&r2=436914&view=diff ============================================================================== --- jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/InputStreamLineBreakStageTest.java (original) +++ jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/InputStreamLineBreakStageTest.java Fri Aug 25 12:30:39 2006 @@ -16,46 +16,18 @@ package org.apache.commons.pipeline.stage; -import java.net.URL; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; +import java.io.InputStream; import junit.framework.*; -import org.apache.commons.pipeline.Pipeline; -import org.apache.commons.pipeline.Stage; /** * Test cases for InputStreamLineBreakStage. */ -public class InputStreamLineBreakStageTest extends TestCase { - - List results; - Pipeline pipe; - URL url; +public class InputStreamLineBreakStageTest extends AbstractStageTest { public InputStreamLineBreakStageTest(String testName) { super(testName); } - protected void setUp() throws Exception { - url = this.getClass().getClassLoader().getResource("url-input-to-stream-test.txt"); - assertNotNull(url); - - URLToInputStreamStage stage1 = new URLToInputStreamStage(); - InputStreamLineBreakStage stage2 = new InputStreamLineBreakStage(); - results = new ArrayList(); - Stage stage3 = new AddToCollectionStage(results); - ArrayList stages = new ArrayList(); - stages.add(stage1); - stages.add(stage2); - stages.add(stage3); - pipe = new Pipeline(stages); - } - - protected void tearDown() throws Exception { - } - public static Test suite() { TestSuite suite = new TestSuite(InputStreamLineBreakStageTest.class); @@ -66,17 +38,49 @@ * Test of process method, of class org.apache.commons.pipeline.stage.InputStreamLineBreakStage. */ public void testProcess() throws Exception { - pipe.start(); - pipe.enqueue(url); - pipe.finish(); + InputStreamLineBreakStage stage = new InputStreamLineBreakStage(); + this.init(stage); - assertEquals(3,results.size()); - String s0 = (String) results.get(0); - assertEquals("line 1", s0); - String s1 = (String) results.get(1); - assertEquals("line 2", s1); - String s2 = (String) results.get(2); - assertEquals("line 3", s2); + InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("url-input-to-stream-test.txt"); + try { + stage.process(in); + } finally { + in.close(); + } + + assertEquals(3, testFeeder.receivedValues.size()); + assertEquals("line 1", testFeeder.receivedValues.get(0)); + assertEquals("line 2", testFeeder.receivedValues.get(1)); + assertEquals("line 3", testFeeder.receivedValues.get(2)); } + +// /** +// * Test of isIgnoringBlankLines method, of class org.apache.commons.pipeline.stage.InputStreamLineBreakStage. +// */ +// public void testIsIgnoringBlankLines() { +// System.out.println("isIgnoringBlankLines"); +// +// InputStreamLineBreakStage instance = new InputStreamLineBreakStage(); +// +// boolean expResult = true; +// boolean result = instance.isIgnoringBlankLines(); +// assertEquals(expResult, result); +// +// fail("The test case is a prototype."); +// } +// +// /** +// * Test of setIgnoringBlankLines method, of class org.apache.commons.pipeline.stage.InputStreamLineBreakStage. +// */ +// public void testSetIgnoringBlankLines() { +// System.out.println("setIgnoringBlankLines"); +// +// boolean ignoringBlankLines = true; +// InputStreamLineBreakStage instance = new InputStreamLineBreakStage(); +// +// instance.setIgnoringBlankLines(ignoringBlankLines); +// +// fail("The test case is a prototype."); +// } } Added: jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/InvokeMethodStageTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/InvokeMethodStageTest.java?rev=436914&view=auto ============================================================================== --- jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/InvokeMethodStageTest.java (added) +++ jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/InvokeMethodStageTest.java Fri Aug 25 12:30:39 2006 @@ -0,0 +1,67 @@ +/* + * Copyright 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.commons.pipeline.stage; + +import junit.framework.*; +import java.lang.reflect.Method; +import java.util.ArrayList; + +/** + * + * @author tns + */ +public class InvokeMethodStageTest extends AbstractStageTest { + + public InvokeMethodStageTest(String testName) { + super(testName); + } + + public static Test suite() { + TestSuite suite = new TestSuite(InvokeMethodStageTest.class); + + return suite; + } + + /** + * Test of reflection-based constructor + */ + public void testReflectionConstructor() throws Exception { + InvokeMethodStage stage = new InvokeMethodStage("java.lang.String", "lastIndexOf", "foo"); + Method method = stage.getMethod(); + assertNotNull(method); + assertSame(String.class, method.getDeclaringClass()); + assertEquals("lastIndexOf", method.getName()); + } + + /** + * Test of process method, of class org.apache.commons.pipeline.stage.InvokeMethodStage. + */ + public void testProcess() throws Exception { + InvokeMethodStage stage = new InvokeMethodStage("java.lang.String", "toUpperCase", new Object[0]); + this.init(stage); + + stage.process("some text"); + + assertEquals(1, testFeeder.receivedValues.size()); + + Object o = testFeeder.receivedValues.get(0); + assertNotNull(o); + assertTrue(o instanceof String); + assertEquals("SOME TEXT", o); + } +} Added: jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/InvokeStaticMethodStageTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/InvokeStaticMethodStageTest.java?rev=436914&view=auto ============================================================================== --- jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/InvokeStaticMethodStageTest.java (added) +++ jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/InvokeStaticMethodStageTest.java Fri Aug 25 12:30:39 2006 @@ -0,0 +1,75 @@ +/* + * Copyright 2005 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.commons.pipeline.stage; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import junit.framework.*; +import org.apache.commons.pipeline.Pipeline; +import org.apache.commons.pipeline.driver.SynchronousStageDriver; + + +/** + * Test cases for InvokeStaticMethodStage. + */ +public class InvokeStaticMethodStageTest extends AbstractStageTest { + + public InvokeStaticMethodStageTest(String testName) { + super(testName); + } + + public static Test suite() { + TestSuite suite = new TestSuite(InvokeStaticMethodStageTest.class); + + return suite; + } + + /** + * Test for reflection-based constructor + */ + public void testConstructor() throws Exception { + InvokeStaticMethodStage stage = new InvokeStaticMethodStage("java.lang.Integer", "valueOf", "java.lang.String"); + + Method method = stage.getMethod(); + assertSame(Integer.class,method.getDeclaringClass()); + + Class[] params = method.getParameterTypes(); + assertNotNull(params); + assertEquals(1,params.length); + assertSame(String.class, params[0]); + assertEquals("valueOf",method.getName()); + } + + /** + * Test of process() method, of class org.apache.commons.pipeline.stage.InvokeStaticMethodStage. + */ + public void testProcess() throws Exception { + Class integerClass = Integer.class; + Method method = integerClass.getMethod("valueOf", String.class); + InvokeStaticMethodStage stage = new InvokeStaticMethodStage(method); + this.init(stage); + + stage.process("5"); + + assertEquals(1, testFeeder.receivedValues.size()); + + Object o = testFeeder.receivedValues.get(0); + assertNotNull(o); + assertTrue(o instanceof Integer); + assertEquals(5, o); + } +} Modified: jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/URLToInputStreamStageTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/URLToInputStreamStageTest.java?rev=436914&r1=436913&r2=436914&view=diff ============================================================================== --- jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/URLToInputStreamStageTest.java (original) +++ jakarta/commons/sandbox/pipeline/trunk/src/test/java/org/apache/commons/pipeline/stage/URLToInputStreamStageTest.java Fri Aug 25 12:30:39 2006 @@ -29,30 +29,18 @@ /** * Test cases for URLToInputStreamStaticStage. */ -public class URLToInputStreamStageTest extends TestCase { +public class URLToInputStreamStageTest extends AbstractStageTest { URL url; - URLToInputStreamStage stage; - Pipeline pipe; - List<InputStream> results; public URLToInputStreamStageTest(String testName) { super(testName); } protected void setUp() throws Exception { - url = this.getClass().getClassLoader().getResource("url-input-to-stream-test.txt"); + super.setUp(); + this.url = this.getClass().getClassLoader().getResource("url-input-to-stream-test.txt"); assertNotNull(url); - results = new ArrayList<InputStream>(); - Stage finalStage = new AddToCollectionStage<InputStream>(results); - stage = new URLToInputStreamStage(); - List<Stage> stages = new ArrayList<Stage>(); - stages.add(stage); - stages.add(finalStage); - pipe = new Pipeline(stages); - } - - protected void tearDown() throws Exception { } public static Test suite() { @@ -65,32 +53,42 @@ * Test of process method, of class org.apache.commons.pipeline.stage.URLToInputStreamStage. */ public void testProcess() throws Exception { - pipe.start(); - pipe.enqueue(url); - assertEquals(1,results.size()); - InputStream is = results.get(0); - assertNotNull(is); + URLToInputStreamStage stage = new URLToInputStreamStage(); + this.init(stage); + + stage.process(url); + + assertEquals(1, testFeeder.receivedValues.size()); + + InputStream in = (InputStream) testFeeder.receivedValues.get(0); + try { + assertNotNull(in); byte[] buffer = new byte[128]; - int bytes = is.read(buffer); - pipe.finish(); + int bytes = in.read(buffer); + } finally { + in.close(); + } } /** * Test of postprocess method, of class org.apache.commons.pipeline.stage.URLToInputStreamStage. */ public void testPostprocess() throws Exception { - pipe.start(); - pipe.enqueue(url); - pipe.finish(); - InputStream is = results.get(0); + URLToInputStreamStage stage = new URLToInputStreamStage(); + this.init(stage); + + stage.process(url); + stage.release(); + + assertEquals(1, testFeeder.receivedValues.size()); + + InputStream in = (InputStream) testFeeder.receivedValues.get(0); try { byte[] buffer = new byte[128]; - int bytes = is.read(buffer); + int bytes = in.read(buffer); fail("input stream should have been closed, so reading should throw an exception."); } catch (IOException expected){ - + // do nothing } - } - } Modified: jakarta/commons/sandbox/pipeline/trunk/src/test/resources/TestResources.properties URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/test/resources/TestResources.properties?rev=436914&r1=436913&r2=436914&view=diff ============================================================================== --- jakarta/commons/sandbox/pipeline/trunk/src/test/resources/TestResources.properties (original) +++ jakarta/commons/sandbox/pipeline/trunk/src/test/resources/TestResources.properties Fri Aug 25 12:30:39 2006 @@ -13,8 +13,9 @@ # limitations under the License. # # Resource bundle for test resources +test.log.directory=${log.directory} test.DigesterPipelineFactoryTest.configFile=test_conf.xml -test.DigesterPipelineFactoryTest.logConfig=log4j_conf.xml test.DigesterPipelineFactoryTest.stage0.class=org.apache.commons.pipeline.stage.FileFinderStage -test.DigesterPipelineFactoryTest.stage1.class=org.apache.commons.pipeline.stage.LogStage \ No newline at end of file +test.DigesterPipelineFactoryTest.stage1.class=org.apache.commons.pipeline.stage.LogStage +test.DigesterPipelineFactoryTest.stage2.class=org.apache.commons.pipeline.stage.RaiseEventStage Modified: jakarta/commons/sandbox/pipeline/trunk/src/test/resources/log4j_conf.xml URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/test/resources/log4j_conf.xml?rev=436914&r1=436913&r2=436914&view=diff ============================================================================== --- jakarta/commons/sandbox/pipeline/trunk/src/test/resources/log4j_conf.xml (original) +++ jakarta/commons/sandbox/pipeline/trunk/src/test/resources/log4j_conf.xml Fri Aug 25 12:30:39 2006 @@ -22,42 +22,29 @@ <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="log_app" class="org.apache.log4j.FileAppender"> - <param name="File" value="target/test-reports/pipeline.log" /> - <param name="Append" value="false" /> - <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/> - </layout> - </appender> - - <appender name="impl_app" class="org.apache.log4j.FileAppender"> - <param name="File" value="target/test-reports/impl.log" /> - <param name="Append" value="false" /> + <param name="File" value="${log.directory}/pipeline.log" /> + <param name="Append" value="true" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/> </layout> </appender> <appender name="external_app" class="org.apache.log4j.FileAppender"> - <param name="File" value="target/test-reports/external.log" /> - <param name="Append" value="false" /> + <param name="File" value="${log.directory}/external.log" /> + <param name="Append" value="true" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/> </layout> </appender> <category name="org.apache.commons.digester" additivity="false"> - <level value="info" /> + <level value="debug" /> <appender-ref ref="external_app" /> </category> <category name="org.apache.commons.beanutils" additivity="false"> <level value="info" /> <appender-ref ref="external_app" /> - </category> - - <category name="org.apache.commons.pipeline.stage" additivity="false"> - <level value="debug" /> - <appender-ref ref="impl_app" /> </category> <root> Modified: jakarta/commons/sandbox/pipeline/trunk/src/test/resources/test_conf.xml URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/pipeline/trunk/src/test/resources/test_conf.xml?rev=436914&r1=436913&r2=436914&view=diff ============================================================================== --- jakarta/commons/sandbox/pipeline/trunk/src/test/resources/test_conf.xml (original) +++ jakarta/commons/sandbox/pipeline/trunk/src/test/resources/test_conf.xml Fri Aug 25 12:30:39 2006 @@ -19,16 +19,18 @@ --> <pipeline> + <listener className="org.apache.commons.pipeline.listener.ObjectProcessedEventCounter"/> + <driverFactory className="org.apache.commons.pipeline.driver.DedicatedThreadStageDriverFactory" id="f1"/> - <stage className="org.apache.commons.pipeline.stage.FileFinderStage" filePattern=".*\.java"> - <stageDriver className="org.apache.commons.pipeline.driver.SingleThreadStageDriver"/> - <enqueue> - <value>src/java</value> - </enqueue> - </stage> + <stage className="org.apache.commons.pipeline.stage.FileFinderStage" driverFactoryId="f1" + filePattern=".*\.java" /> - <stage className="org.apache.commons.pipeline.stage.LogStage"> - <stageDriver className="org.apache.commons.pipeline.driver.SingleThreadStageDriver"/> - </stage> + <stage className="org.apache.commons.pipeline.stage.LogStage" driverFactoryId="f1" /> + <stage className="org.apache.commons.pipeline.stage.RaiseEventStage" driverFactoryId="f1" /> + + <feed> + <value>src/main/java</value> + <value>src/test/java</value> + </feed> </pipeline> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
