You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by hu...@apache.org on 2001/12/30 07:05:30 UTC
cvs commit: xml-cocoon2/test/org/apache/cocoon/components/resolver/test package.html ResolverImplTestCase.java ResolverImplTestCase.xtest
huber 01/12/29 22:05:30
Added: test/org/apache/cocoon/components/resolver/test package.html
ResolverImplTestCase.java
ResolverImplTestCase.xtest
Log:
initial version, junit tests
Revision Changes Path
1.1 xml-cocoon2/test/org/apache/cocoon/components/resolver/test/package.html
Index: package.html
===================================================================
<html>
<head>
<title>Search</title>
</head>
<body>
<h1>Test Cases Search</h1>
<p>
This package provides Cocoon search test cases.
</p>
<p>
The test cases extends ExcaliburTestCase.
Each test case has an associated <code>xtest</code> file, defining
the avalon components needed for the test case.
</p>
<p>
For more information about ExcaliburTestCase see the
avalon api documentation.
</p>
</body>
1.1 xml-cocoon2/test/org/apache/cocoon/components/resolver/test/ResolverImplTestCase.java
Index: ResolverImplTestCase.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*/
package org.apache.cocoon.components.resolver.test;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Properties;
import junit.framework.TestCase;
import junit.swingui.TestRunner;
import org.apache.avalon.excalibur.testcase.CascadingAssertionFailedError;
import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.Constants;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.resolver.*;
import org.apache.cocoon.environment.commandline.CommandlineContext;
import org.apache.cocoon.util.IOUtils;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* A simple test case for SimpleLuceneCocoonIndexerImpl.
*
* @author <a href="mailto:berni_huber@a1.net">Bernhard Huber</a>
* @version CVS $Id: ResolverImplTestCase.java,v 1.1 2001/12/30 06:05:30 huber Exp $
*/
public final class ResolverImplTestCase
extends ExcaliburTestCase
implements Initializable, Disposable
{
/**
*Description of the Field
*
* @since
*/
protected final static String CATALOG_FILE_NAME = "catalog";
/**
*Description of the Field
*
* @since
*/
protected final static String CATALOG_ISONUM_PEN_FILE_NAME = "ISOnum.pen";
/**
*Description of the Field
*
* @since
*/
protected final static String CATALOG =
"-- this is the default OASIS catalog for Apache Cocoon --\n" +
"\n" +
"OVERRIDE YES\n" +
"\n" +
"-- ISO public identifiers for sets of character entities --\n" +
"PUBLIC \"ISO 8879-1986//ENTITIES Added Latin 1//EN//XML\" \"ISOlat1.pen\"\n" +
"PUBLIC \"ISO 8879:1986//ENTITIES Added Latin 1//EN//XML\" \"ISOlat1.pen\"\n" +
"PUBLIC \"ISO 9573-15:1993//ENTITIES Greek Letters//EN//XML\" \"ISOgrk1.pen\"\n" +
"PUBLIC \"ISO 8879:1986//ENTITIES Publishing//EN//XML\" \"ISOpub.pen\"\n" +
"PUBLIC \"ISO 8879:1986//ENTITIES General Technical//EN//XML\" \"ISOtech.pen\"\n" +
"PUBLIC \"ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN//XML\" \"ISOnum.pen\"\n" +
"\n" +
"-- Document Type Definitions --\n" +
"PUBLIC \"-//APACHE//DTD Documentation V1.0//EN\" \"document-v10.dtd\"\n" +
"PUBLIC \"-//APACHE//DTD Changes V1.0//EN\" \"changes-v10.dtd\"\n" +
"PUBLIC \"-//APACHE//DTD FAQ V1.0//EN\" \"faq-v10.dtd\"\n" +
"PUBLIC \"-//APACHE//DTD JavaDoc V1.0//EN\" \"javadoc-v04draft.dtd\"\n" +
"PUBLIC \"-//APACHE//DTD Specification V1.0//EN\" \"specification-v10.dtd\"\n" +
"PUBLIC \"-//APACHE//DTD Todo V1.0//EN\" \"todo-v10.dtd\"\n" +
"PUBLIC \"-//APACHE//DTD Cocoon Sitemap V0.2//EN\" \"sitemap-v02.dtd\"\n" +
"\n" +
"-- enabling validation during Cocoon's own \"build docs\" --\n" +
"-- all *.xml require DTD for validation during \"build docs\" --\n" +
"PUBLIC \"-//APACHE//DTD Cocoon Documentation Book V1.0//EN\" \"book-cocoon-v10.dtd\"\n" +
"\n" +
"-- Cocoon has extra <label/> element for documentation/svg/label-*.xml --\n" +
"-- which breaks validation against official svg10.dtd (why extra label?) --\n" +
"PUBLIC \"-//APACHE//DTD Cocoon SVG minimal V1.1//EN\" \"svg-cocoon-v11.dtd\"\n" +
"PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"svg10.dtd\"\n" +
"\n" +
"-- other DTDs that are yet without a Public Identifier --\n" +
"-- XMLSchema.dtd .. what is its purpose ? --\n" +
"\n" +
"-- Character entity set that is referenced by some DTDs --\n" +
"-- characters.ent --\n" +
"-- ... has no public identifier --\n" +
"-- should be OK because it will be resolved relative to the DTD --\n" +
"-- ... perhaps the DTD should use the ISO*.pen sets instead? --\n" +
"\n" +
"-- these entries are used for the catalog-demo sample application --\n" +
"OVERRIDE NO\n" +
"PUBLIC \"-//Arbortext//TEXT Test Override//EN\" \"catalog-demo/override.xml\"\n" +
"OVERRIDE YES\n" +
"PUBLIC \"-//Arbortext//TEXT Test Public Identifier//EN\" \"catalog-demo/testpub.xml\"\n" +
"SYSTEM \"urn:x-arbortext:test-system-identifier\" \"catalog-demo/testsys.xml\"\n" +
"PUBLIC \"-//Indexgeo//DTD Catalog Demo v1.0//EN\" \"catalog-demo/catalog-demo-v10.dtd\"\n" +
"-- end of entries for the catalog-demo sample application --\n" +
"";
/**
*Description of the Field
*
* @since
*/
protected final static String CATALOG_ISONUM_PEN =
"<!-- (C) International Organization for Standardization 1986\n" +
"Permission to copy in any form is granted for use with\n" +
"conforming SGML systems and applications as defined in\n" +
"ISO 8879, provided this notice is included in all copies.\n" +
"-->\n" +
"<!-- Character entity set. Typical invocation:\n" +
"<!ENTITY % ISOnum PUBLIC\n" +
"\"ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN//XML\">\n" +
"%ISOnum;\n" +
"-->\n" +
"<!-- This version of the entity set can be used with any SGML document\n" +
"which uses ISO 10646 as its document character set.\n" +
"This includes XML documents and ISO HTML documents.\n" +
"This entity set uses hexadecimal numeric character references.\n" +
" \n" +
"Creator: Rick Jelliffe, Allette Systems\n" +
" \n" +
"Version: 1997-07-07\n" +
"-->\n" +
"\n" +
"<!ENTITY half \"½\" ><!--=fraction one-half-->\n" +
"<!ENTITY frac12 \"½\" ><!--=fraction one-half-->\n" +
"<!ENTITY frac14 \"¼\" ><!--=fraction one-quarter-->\n" +
"<!ENTITY frac34 \"¾\" ><!--=fraction three-quarters-->\n" +
"<!ENTITY frac18 \"⅛\" >\n" +
"<!-- or \"±Ȃ⁄₈\" --><!--=fraction one-eighth-->\n" +
"<!ENTITY frac38 \"⅜\" >\n" +
"<!-- or \"³⁄₈\" --><!--=fraction three-eighths-->\n" +
"<!ENTITY frac58 \"⅝\" >\n" +
"<!-- or \"⁵⁄₈\" --><!--=fraction five-eighths-->\n" +
"<!ENTITY frac78 \"⅞\" >\n" +
"<!-- or \"⁷⁄₈\" --><!--=fraction seven-eighths-->\n" +
"\n" +
"<!ENTITY sup1 \"¹\" ><!--=superscript one-->\n" +
"<!ENTITY sup2 \"²\" ><!--=superscript two-->\n" +
"<!ENTITY sup3 \"³\" ><!--=superscript three-->\n" +
"\n" +
"<!ENTITY plus \"+\" ><!--=plus sign B:-->\n" +
"<!ENTITY plusmn \"±\" ><!--/pm B: =plus-or-minus sign-->\n" +
"<!ENTITY lt \"&#60;\" ><!--=less-than sign R:-->\n" +
"<!ENTITY equals \"=\" ><!--=equals sign R:-->\n" +
"<!ENTITY gt \">\" ><!--=greater-than sign R:-->\n" +
"<!ENTITY divide \"÷\" ><!--/div B: =divide sign-->\n" +
"<!ENTITY times \"×\" ><!--/times B: =multiply sign-->\n" +
"\n" +
"<!ENTITY curren \"¤\" ><!--=general currency sign-->\n" +
"<!ENTITY pound \"£\" ><!--=pound sign-->\n" +
"<!ENTITY dollar \"$\" ><!--=dollar sign-->\n" +
"<!ENTITY cent \"¢\" ><!--=cent sign-->\n" +
"<!ENTITY yen \"¥\" ><!--/yen =yen sign-->\n" +
"\n" +
"<!ENTITY num \"#\" ><!--=number sign-->\n" +
"<!ENTITY percnt \"%\" ><!--=percent sign-->\n" +
"<!ENTITY amp \"&#38;\" ><!--=ampersand-->\n" +
"<!ENTITY ast \"*\" ><!--/ast B: =asterisk-->\n" +
"<!ENTITY commat \"@\" ><!--=commercial at-->\n" +
"<!ENTITY lsqb \"[\" ><!--/lbrack O: =left square bracket-->\n" +
"<!ENTITY bsol \"\\\" ><!--/backslash =reverse solidus-->\n" +
"<!ENTITY rsqb \"]\" ><!--/rbrack C: =right square bracket-->\n" +
"<!ENTITY lcub \"{\" ><!--/lbrace O: =left curly bracket-->\n" +
"<!ENTITY horbar \"―\" ><!--=horizontal bar-->\n" +
"<!ENTITY verbar \"|\" ><!--/vert =vertical bar-->\n" +
"<!ENTITY rcub \"}\" ><!--/rbrace C: =right curly bracket-->\n" +
"<!ENTITY micro \"µ\" ><!--=micro sign-->\n" +
"<!ENTITY ohm \"ࡎ\" ><!--=ohm sign-->\n" +
"<!ENTITY deg \"°\" ><!--=degree sign-->\n" +
"<!ENTITY ordm \"º\" ><!--=ordinal indicator, masculine-->\n" +
"<!ENTITY ordf \"ª\" ><!--=ordinal indicator, feminine-->\n" +
"<!ENTITY sect \"§\" ><!--=section sign-->\n" +
"<!ENTITY para \"¶\" ><!--=pilcrow (paragraph sign)-->\n" +
"<!ENTITY middot \"·\" ><!--/centerdot B: =middle dot-->\n" +
"<!ENTITY larr \"←\" ><!--/leftarrow /gets A: =leftward arrow-->\n" +
"<!ENTITY rarr \"→\" ><!--/rightarrow /to A: =rightward arrow-->\n" +
"<!ENTITY uarr \"↑\" ><!--/uparrow A: =upward arrow-->\n" +
"<!ENTITY darr \"↓\" ><!--/downarrow A: =downward arrow-->\n" +
"<!ENTITY copy \"©\" ><!--=copyright sign-->\n" +
"<!ENTITY reg \"®\" ><!--/circledR =registered sign-->\n" +
"<!ENTITY trade \"™\" ><!--=trade mark sign-->\n" +
"<!ENTITY brvbar \"¦\" ><!--=bren (vertical) bar-->\n" +
"<!ENTITY not \"¬\" ><!--/neg /lnot =not sign-->\n" +
"<!ENTITY sung \"♪\" ><!--=music note (sung text sign)-->\n" +
"\n" +
"<!ENTITY excl \"!\" ><!--=exclamation mark-->\n" +
"<!ENTITY iexcl \"¡\" ><!--=inverted exclamation mark-->\n" +
"<!ENTITY quot '\"' ><!--=quotation mark-->\n" +
"<!ENTITY apos \"'\" ><!--=apostrophe-->\n" +
"<!ENTITY lpar \"(\" ><!--O: =left parenthesis-->\n" +
"<!ENTITY rpar \")\" ><!--C: =right parenthesis-->\n" +
"<!ENTITY comma \",\" ><!--P: =comma-->\n" +
"<!ENTITY lowbar \"_\" ><!--=low line-->\n" +
"<!ENTITY hyphen \"‐\" ><!--=hyphen-->\n" +
"<!ENTITY period \".\" ><!--=full stop, period-->\n" +
"<!ENTITY sol \"/\" ><!--=solidus-->\n" +
"<!ENTITY colon \":\" ><!--/colon P:-->\n" +
"<!ENTITY semi \";\" ><!--=semicolon P:-->\n" +
"<!ENTITY quest \"?\" ><!--=question mark-->\n" +
"<!ENTITY iquest \"¿\" ><!--=inverted question mark-->\n" +
"<!ENTITY laquo \"‹\" ><!--=angle quotation mark, left\n" +
"But note that Unicode 1 & Maler & el Andaloussi give « -->\n" +
"<!ENTITY raquo \"›\" ><!--=angle quotation mark, right\n" +
"But note that Unicode 1 & Maler & el Andaloussi give » -->\n" +
"<!ENTITY lsquo \"‘\" ><!--=single quotation mark, left-->\n" +
"<!ENTITY rsquo \"’\" ><!--=single quotation mark, right-->\n" +
"<!ENTITY ldquo \"“\" ><!--=double quotation mark, left-->\n" +
"<!ENTITY rdquo \"”\" ><!--=double quotation mark, right-->\n" +
"<!ENTITY nbsp \" \" ><!--=no break (required) space-->\n" +
"<!ENTITY shy \"­\" ><!--=soft hyphen-->\n" +
"";
private DefaultContext context;
private ResolverImpl resolverImpl;
private File workDir;
private File commandlineContextDir;
/**
* Constructor for the SearchGeneratorTestCase object
*
* @since
*/
public ResolverImplTestCase() {
this("ResolverImplTestCase");
}
/**
* Constructor for the SearchGeneratorTestCase object
*
* @param name Description of Parameter
* @since
*/
public ResolverImplTestCase(String name) {
super(name);
}
/**
*The main program for the SearchGeneratorTestCase class
*
* @param args The command line arguments
* @exception Exception Description of Exception
* @since
*/
public static void main(final String[] args) throws Exception {
final String[] testCaseName = {ResolverImplTestCase.class.getName()};
TestRunner.main(testCaseName);
}
/**
* The JUnit setup method
*
* @exception Exception Description of Exception
* @since
*/
public void setUp() throws Exception {
super.setUp();
// (2) lookup resolver, catalog should exist already
String role = Resolver.ROLE;
resolverImpl = (ResolverImpl) manager.lookup(role);
assertNotNull("ResolverImpl is null", resolverImpl);
}
/**
* Invoked before components are created.
*
* @exception Exception Description of Exception
* @since
*/
public void initialize() throws Exception {
workDir = new File(System.getProperty("java.io.tmpdir"), Constants.DEFAULT_WORK_DIR);
commandlineContextDir = new File(workDir.getAbsolutePath());
// create catalog releated files in context dir
getLogger().debug("Creating catalog files");
File f;
f = IOUtils.createFile(commandlineContextDir, CATALOG_FILE_NAME);
IOUtils.serializeString(f, CATALOG);
f = IOUtils.createFile(commandlineContextDir, CATALOG_ISONUM_PEN_FILE_NAME);
IOUtils.serializeString(f, CATALOG_ISONUM_PEN);
}
/**
* Invoked after components has been disposed.
*
* @since
*/
public void dispose() {
assertTrue( resolverImpl == null );
// remove catalog releated files in context dir
getLogger().debug("Removing catalog files");
File f;
f = new File(commandlineContextDir, CATALOG_ISONUM_PEN_FILE_NAME);
getLogger().debug("Removing catalog file " + f.toString());
if (!f.delete()) {
getLogger().warn("Cannot remove catalog file " + f.toString());
}
f = new File(commandlineContextDir, CATALOG_FILE_NAME);
getLogger().debug("Removing catalog file " + f.toString());
if (!f.delete()) {
getLogger().warn("Cannot remove catalog file " + f.toString());
}
f = new File(commandlineContextDir.toString());
getLogger().debug("Removing catalog file " + f.toString());
if (!f.delete()) {
getLogger().warn("Cannot remove catalog file " + f.toString());
}
}
/**
* The teardown method for JUnit
*
* @exception Exception Description of Exception
* @since
*/
public void tearDown() throws Exception {
super.tearDown();
if (resolverImpl != null) {
manager.release(resolverImpl);
resolverImpl = null;
}
}
/**
*A unit test for JUnit
*
* @exception Exception Description of Exception
* @since
*/
public void testCatalogProperiesAvailable() throws Exception {
Class clazz = this.getClass();
String catalog_manager_props_name = "/CatalogManager.properties";
InputStream is = clazz.getResourceAsStream(catalog_manager_props_name);
assertNotNull("Cannot access " + catalog_manager_props_name, is);
Properties catalog_manager_props = new Properties();
catalog_manager_props.load(is);
is.close();
}
/**
* A unit test for JUnit
*
* @exception Exception Description of Exception
* @since
*/
public void testAvailableResolveEntity() throws Exception {
assertNotNull("ResolverImpl is null", resolverImpl);
String public_id;
String system_id;
InputSource is;
public_id = "ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN//XML";
system_id = "ISOnum.pen";
is = resolverImpl.resolveEntity(public_id, system_id);
assertNotNull("InputSource is null for " +
"'" + public_id + "'" + ", " +
"'" + system_id + "'", is);
// close the entity stream, otherwise removing it will fail
java.io.Reader entity_r = is.getCharacterStream();
if (entity_r != null) {
entity_r.close();
}
java.io.InputStream entity_is = is.getByteStream();
if (entity_is != null) {
entity_is.close();
}
is = null;
}
/**
* A unit test for JUnit
*
* @exception Exception Description of Exception
* @since
*/
public void testNonAvailableResolveEntity() throws Exception {
assertNotNull("ResolverImpl is null", resolverImpl);
String public_id;
String system_id;
InputSource is;
public_id = "public-id which does not exist";
system_id = "system-id which does not exist";
is = resolverImpl.resolveEntity(public_id, system_id);
assertEquals("InputSource is null for " +
"'" + public_id + "'" + ", " +
"'" + system_id + "'", null, is);
is = null;
}
/**
* This method may be overwritten by subclasses to put additional objects
* into the context programmatically.
*
* @param context The feature to be added to the Context attribute
* @since
*/
protected void addContext(DefaultContext context) {
this.context = context;
context.put(Constants.CONTEXT_WORK_DIR, workDir);
CommandlineContext commandline_context = new CommandlineContext(commandlineContextDir.toString());
commandline_context.setLogger(getLogger());
context.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT, commandline_context);
}
}
1.1 xml-cocoon2/test/org/apache/cocoon/components/resolver/test/ResolverImplTestCase.xtest
Index: ResolverImplTestCase.xtest
===================================================================
<?xml version="1.0" ?>
<!DOCTYPE testcase [
<!ELEMENT testcase (annotation?,logkit,context?,roles,components)>
<!-- annotation describes the testcase
-->
<!ELEMENT annotation (#PCDATA)>
<!-- logkit define the logkit in use
-->
<!ELEMENT logkit (factories, targets, categories)>
<!ELEMENT factories (factory+)>
<!ELEMENT factory EMPTY>
<!ATTLIST factory
type CDATA #REQUIRED
class CDATA #REQUIRED
>
<!ELEMENT targets ANY>
<!ELEMENT file ANY>
<!ATTLIST file
id ID #REQUIRED>
<!ELEMENT filename (#PCDATA)>
<!ELEMENT format (#PCDATA)>
<!ATTLIST format
type (extended|raw) "extended"
>
<!ELEMENT categories (category+)>
<!ELEMENT category ANY>
<!ATTLIST category
name CDATA #REQUIRED
log-level (DEBUG|INFO|WARN|ERROR) "INFO"
>
<!ELEMENT log-target EMPTY>
<!ATTLIST log-target
id-ref CDATA #REQUIRED
>
<!-- the context used by the components
-->
<!ELEMENT context (entry*)>
<!ELEMENT entry EMPTY>
<!ATTLIST entry
name CDATA #REQUIRED
value CDATA #REQUIRED
>
<!-- the roles of the components
-->
<!ELEMENT roles (role+)>
<!ELEMENT role (hint*)>
<!ATTLIST role
name CDATA #IMPLIED
class CDATA #IMPLIED
shorthand CDATA #REQUIRED
default-class CDATA #REQUIRED
>
<!ELEMENT hint EMPTY>
<!ATTLIST hint
shorthand CDATA #REQUIRED
class CDATA #REQUIRED
>
<!-- define components element, attributes, and its children
-->
<!ELEMENT components (resolver)>
<!ATTLIST components
logger CDATA #IMPLIED
>
<!ELEMENT resolver (parameter*)>
<!ATTLIST resolver
logger CDATA #IMPLIED
>
<!ELEMENT parameter EMPTY>
<!ATTLIST parameter
name CDATA #REQUIRED
value CDATA #REQUIRED
>
]>
<testcase>
<annotation>
Resolver Tests
</annotation>
<logkit>
<factories>
<factory type="file" class="org.apache.avalon.excalibur.logger.factory.FileTargetFactory"/>
</factories>
<targets>
<file id="root">
<filename>resolver-test.log</filename>
<format type="extended">
%7.7{priority} %5.5{time} [%8.8{category}] (%{context}): %{message}\n%{throwable}
</format>
</file>
</targets>
<categories>
<category name="test" log-level="DEBUG">
<log-target id-ref="root"/>
</category>
</categories>
</logkit>
<context>
<entry name="foo" value="bar"/>
</context>
<roles>
<role name="org.apache.cocoon.components.resolver.Resolver"
shorthand="resolver"
default-class="org.apache.cocoon.components.resolver.ResolverImpl">
</role>
</roles>
<!--
-->
<components>
<resolver>
<parameter name="verbosity" value="10"/>
<parameter name="catalog" value="/catalog"/>
<parameter name="local-catalog" value="/local-catalog"/>
</resolver>
</components>
</testcase>
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org