You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by th...@apache.org on 2008/10/10 14:10:27 UTC
svn commit: r703434 - in
/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher:
AbstractStructurer.java TestStructurer.java TestStructurerAXIOM.java
Author: thorsten
Date: Fri Oct 10 05:10:27 2008
New Revision: 703434
URL: http://svn.apache.org/viewvc?rev=703434&view=rev
Log:
Extracting an abstract class to better reuse the code and keep it in one place. Adopting latest changes to the config
Added:
forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/AbstractStructurer.java (with props)
Modified:
forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/TestStructurer.java
forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/TestStructurerAXIOM.java
Added: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/AbstractStructurer.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/AbstractStructurer.java?rev=703434&view=auto
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/AbstractStructurer.java (added)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/AbstractStructurer.java Fri Oct 10 05:10:27 2008
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.forrest.dispatcher;
+
+import java.io.InputStream;
+import java.util.HashMap;
+
+import javax.xml.transform.ErrorListener;
+import javax.xml.transform.TransformerFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.forrest.dispatcher.api.Structurer;
+import org.apache.forrest.dispatcher.config.WritableDispatcherBean;
+import org.apache.forrest.dispatcher.impl.ClassPathResolver;
+import org.apache.forrest.dispatcher.impl.helper.LoggingErrorListener;
+import org.apache.forrest.dispatcher.impl.helper.StAX;
+
+public abstract class AbstractStructurer extends TestCase {
+
+ protected final Log log = LogFactory.getLog(this.getClass()
+ .getCanonicalName());
+ protected HashMap<String, Object> properties;
+ protected WritableDispatcherBean config;
+
+ public AbstractStructurer() {
+ super();
+ }
+
+ public AbstractStructurer(String name) {
+ super(name);
+ }
+
+ protected void prepareStructurer(boolean allowXml){
+ TransformerFactory transFact = TransformerFactory.newInstance();
+ ErrorListener listener = new LoggingErrorListener(log);
+ transFact.setErrorListener(listener);
+ config = new WritableDispatcherBean();
+ config.setTransFact(transFact);
+ config.setStaxHelper(new StAX());
+ config.setAllowXmlProperties(allowXml);
+ config.setResolver(new ClassPathResolver());
+ config.setContractUriPrefix("/org/apache/forrest/dispatcher/");
+ properties = new HashMap<String, Object>();
+ }
+
+ protected abstract Structurer getStructurer(boolean allowXml);
+
+ protected InputStream getStream() {
+ InputStream dataStream = this.getClass()
+ .getResourceAsStream(getUrl());
+ return dataStream;
+ }
+
+ public abstract String getUrl();
+}
\ No newline at end of file
Propchange: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/AbstractStructurer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/TestStructurer.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/TestStructurer.java?rev=703434&r1=703433&r2=703434&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/TestStructurer.java (original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/TestStructurer.java Fri Oct 10 05:10:27 2008
@@ -1,52 +1,41 @@
package org.apache.forrest.dispatcher;
-import java.io.InputStream;
-import java.util.HashMap;
+
import org.apache.forrest.dispatcher.api.Structurer;
-import org.apache.forrest.dispatcher.config.DispatcherBean;
import org.apache.forrest.dispatcher.exception.DispatcherException;
-import org.apache.forrest.dispatcher.impl.ClassPathResolver;
import org.apache.forrest.dispatcher.impl.XMLStructurer;
-import org.apache.forrest.dispatcher.impl.helper.StAX;
-import junit.framework.TestCase;
-public class TestStructurer extends TestCase {
- private static final String STRUCTURER_XML = "master.structurer.xml";
+public class TestStructurer extends AbstractStructurer {
public void testStructurer() throws DispatcherException {
String format = "html";
- Structurer structurer = prepareStructurer(false);
+ Structurer structurer = getStructurer(false);
structurer.execute(getStream(), format);
}
public void testStructurerWithXmlProperties() throws DispatcherException {
String format = "html";
- Structurer structurer = prepareStructurer(true);
+ Structurer structurer = getStructurer(true);
structurer.execute(getStream(), format);
}
public void testStructurerXmlFormat() throws DispatcherException {
String format = "xml";
- Structurer structurer = prepareStructurer(false);
+ Structurer structurer = getStructurer(false);
structurer.execute(getStream(), format);
}
- private Structurer prepareStructurer(boolean allowXml) {
- DispatcherBean config = new DispatcherBean();
- config.setStaxHelper(new StAX());
- config.setAllowXmlProperties(allowXml);
- config.setResolver(new ClassPathResolver());
- config.setContractUriPrefix("/org/apache/forrest/dispatcher/");
- HashMap <String,Object> map = new HashMap<String, Object>();
- Structurer structurer = new XMLStructurer(config,map);
- return structurer;
+ @Override
+ public String getUrl() {
+ return "master.structurer.xml";
}
- private InputStream getStream() {
- InputStream dataStream = this.getClass()
- .getResourceAsStream(STRUCTURER_XML);
- return dataStream;
+ @Override
+ protected Structurer getStructurer(boolean allowXml) {
+ super.prepareStructurer(allowXml);
+ Structurer structurer = new XMLStructurer(config,properties);
+ return structurer;
}
}
Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/TestStructurerAXIOM.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/TestStructurerAXIOM.java?rev=703434&r1=703433&r2=703434&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/TestStructurerAXIOM.java (original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/testing/org/apache/forrest/dispatcher/TestStructurerAXIOM.java Fri Oct 10 05:10:27 2008
@@ -1,59 +1,43 @@
package org.apache.forrest.dispatcher;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.forrest.dispatcher.api.Structurer;
-import org.apache.forrest.dispatcher.config.DispatcherBean;
import org.apache.forrest.dispatcher.exception.DispatcherException;
-import org.apache.forrest.dispatcher.impl.ClassPathResolver;
import org.apache.forrest.dispatcher.impl.XMLStructurerAxiom;
-import org.apache.forrest.dispatcher.impl.helper.StAX;
-
-import junit.framework.TestCase;
-public class TestStructurerAXIOM extends TestCase {
- private static final String STRUCTURER_XML = "master.advanced.structurer.xml";
+public class TestStructurerAXIOM extends AbstractStructurer {
+ @Override
+ public String getUrl() {
+ return "master.advanced.structurer.xml";
+ }
public void testStructurer() throws DispatcherException {
String format = "html";
- Structurer structurer = prepareStructurer(false);
+ Structurer structurer = getStructurer(false);
structurer.execute(getStream(), format);
}
public void testStructurerWithXmlProperties() throws DispatcherException {
String format = "html";
- Structurer structurer = prepareStructurer(true);
+ Structurer structurer = getStructurer(true);
structurer.execute(getStream(), format);
}
public void testStructurerFo() throws DispatcherException {
String format = "fo";
- Structurer structurer = prepareStructurer(false);
+ Structurer structurer = getStructurer(false);
structurer.execute(getStream(), format);
}
public void testStructurerXmlFormat() throws DispatcherException {
String format = "xml";
- Structurer structurer = prepareStructurer(false);
+ Structurer structurer = getStructurer(false);
structurer.execute(getStream(), format);
}
- private Structurer prepareStructurer(boolean allowXml) {
- DispatcherBean config = new DispatcherBean();
- config.setStaxHelper(new StAX());
- config.setAllowXmlProperties(allowXml);
- config.setResolver(new ClassPathResolver());
- config.setContractUriPrefix("/org/apache/forrest/dispatcher/");
- Map<String, Object> properties = new HashMap<String, Object>();
+ @Override
+ protected Structurer getStructurer(boolean allowXml) {
+ super.prepareStructurer(allowXml);
Structurer structurer = new XMLStructurerAxiom(config,properties);
return structurer;
}
-
- private InputStream getStream() {
- InputStream dataStream = this.getClass()
- .getResourceAsStream(STRUCTURER_XML);
- return dataStream;
- }
}