cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdami...@apache.org
Subject svn commit: r1412722 - /cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/SitemapComponentTestCase.java
Date Fri, 23 Nov 2012 00:01:58 GMT
Author: cdamioli
Date: Fri Nov 23 00:01:57 2012
New Revision: 1412722

URL: http://svn.apache.org/viewvc?rev=1412722&view=rev
Log:
COCOON-2290 Add a read method to the SitemapComponentTestCase 

Modified:
    cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/SitemapComponentTestCase.java

Modified: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/SitemapComponentTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/SitemapComponentTestCase.java?rev=1412722&r1=1412721&r2=1412722&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/SitemapComponentTestCase.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/SitemapComponentTestCase.java
Fri Nov 23 00:01:57 2012
@@ -48,6 +48,7 @@ import org.apache.cocoon.environment.moc
 import org.apache.cocoon.environment.mock.MockResponse;
 import org.apache.cocoon.generation.Generator;
 import org.apache.cocoon.matching.Matcher;
+import org.apache.cocoon.reading.Reader;
 import org.apache.cocoon.serialization.Serializer;
 import org.apache.cocoon.sitemap.PatternException;
 import org.apache.cocoon.transformation.Transformer;
@@ -449,6 +450,59 @@ public abstract class SitemapComponentTe
         return document.toByteArray();
     }
     
+    public final byte[] read(String type, Parameters parameters, String source) throws SAXException,
IOException, ProcessingException {
+        ServiceSelector selector = null;
+        Reader reader = null;
+        SourceResolver resolver = null;
+        Source inputsource = null;
+
+        assertNotNull("Test for component manager", this.getManager());
+
+        ByteArrayOutputStream document = null;
+
+        try {
+            selector = (ServiceSelector) this.lookup(Reader.ROLE+
+                "Selector");
+            assertNotNull("Test lookup of serializer selector", selector);
+
+            resolver = (SourceResolver) this.lookup(SourceResolver.ROLE);
+            assertNotNull("Test lookup of source resolver", resolver);
+
+            assertNotNull("Test if reader name is not null", type);
+            reader = (Reader) selector.select(type);
+            assertNotNull("Test lookup of reader", reader);
+            
+            reader.setup(new SourceResolverAdapter(resolver, getManager()),
+                    this.getObjectModel(), source, parameters);
+
+            document = new ByteArrayOutputStream();
+            reader.setOutputStream(document);
+
+            reader.generate();
+        } catch (ServiceException ce) {
+            getLogger().error("Could not retrieve serializer", ce);
+            fail("Could not retrieve serializer:"+ce.toString());
+        } finally {
+            if (reader!=null) {
+                selector.release(reader);
+            }
+
+            if (selector!=null) {
+                this.release(selector);
+            }
+
+            if (inputsource!=null) {
+                resolver.release(inputsource);
+            }
+
+            if (resolver!=null) {
+                this.release(resolver);
+            }
+        }
+
+        return document.toByteArray();
+    }
+    
     public String callFunction(String type, String source, String function, Map params) throws
Exception {
         
         redirector.reset();



Mime
View raw message