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:04:46 UTC
cvs commit: xml-cocoon2/test/org/apache/cocoon/environment/commandline/test CommandLineContextTestCase.java package.html
huber 01/12/29 22:04:46
Added: test/org/apache/cocoon/environment/commandline/test
CommandLineContextTestCase.java package.html
Log:
initial version, junit tests
Revision Changes Path
1.1 xml-cocoon2/test/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java
Index: CommandLineContextTestCase.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.environment.commandline.test;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import junit.framework.TestCase;
import junit.swingui.TestRunner;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.cocoon.Constants;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.commandline.*;
import org.apache.log.Hierarchy;
import org.apache.log.LogTarget;
import org.apache.log.Logger;
import org.apache.log.Priority;
import org.apache.log.format.PatternFormatter;
import org.apache.log.output.io.StreamTarget;
/**
* A simple test case for CommandLineContext.
*
* @author <a href="mailto:berni_huber@a1.net">Bernhard Huber</a>
* @version CVS $Id: CommandLineContextTestCase.java,v 1.1 2001/12/30 06:04:46 huber Exp $
*/
public final class CommandLineContextTestCase
extends TestCase
{
///Format of default formatter
/**
*Description of the Field
*
* @since
*/
protected final static String FORMAT =
"%7.7{priority} %{time} [%8.8{category}] (%{context}): %{message}\\n%{throwable}";
/**
*Description of the Field
*
* @since
*/
protected Priority m_logPriority = Priority.INFO;
private String commandlineContextDir;
private CommandlineContext commandlineContext;
/**
*Constructor for the CommandLineContextTestCase object
*
* @since
*/
public CommandLineContextTestCase() {
this("CommandLineContextTestCase");
}
/**
*Constructor for the CommandLineContextTestCase object
*
* @param name Description of Parameter
* @since
*/
public CommandLineContextTestCase(String name) {
super(name);
}
/**
*The main program for the CommandLineContextTestCase 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 = {CommandLineContextTestCase.class.getName()};
TestRunner.main(testCaseName);
}
/**
*The JUnit setup method
*
* @exception Exception Description of Exception
* @since
*/
public void setUp() throws Exception {
commandlineContextDir = System.getProperty("java.io.tmpdir", "/tmp");
commandlineContext = new CommandlineContext(commandlineContextDir);
Logger logger = setupLogger();
commandlineContext.setLogger(logger);
}
/**
*The teardown method for JUnit
*
* @exception Exception Description of Exception
* @since
*/
public void tearDown() throws Exception { }
/**
* A unit test for <code>getResource()</code>
*
* @exception Exception Description of Exception
* @since
*/
public void testGetResource() throws Exception {
Object[] test_values = {
new String[]{"", commandlineContextDir},
new String[]{"/", commandlineContextDir},
new String[]{"foo", commandlineContextDir + File.separator + "foo"},
new String[]{"foo/bar", commandlineContextDir + File.separator + "foo/bar"}
};
for (int i = 0; i < test_values.length; i++) {
String tests[] = (String[]) test_values[i];
String test = tests[0];
File expected_file = new File(tests[1]);
URL expected = expected_file.toURL();
URL result = commandlineContext.getResource(test);
String message = "Test " +
"'" + test + "'";
assertEquals(message, expected, result);
}
}
/**
* A unit test for <code>getRealPath()</code>
*
* @exception Exception Description of Exception
* @since
*/
public void testGetRealPath() throws Exception {
Object[] test_values = {
new String[]{"", ""},
new String[]{"/", "/"},
new String[]{"foo", "foo"},
new String[]{"foo/bar", "foo/bar"}
};
for (int i = 0; i < test_values.length; i++) {
String tests[] = (String[]) test_values[i];
String test = tests[0];
File expected_file = new File(commandlineContextDir, tests[1]);
String expected = expected_file.getAbsolutePath();
String result = commandlineContext.getRealPath(test);
String message = "Test " +
"'" + test + "'";
assertEquals(message, expected, result);
}
}
/**
* A unit test for <code>getAttribute</code>,
* <code>setAttribute</code>, and <code>removeAttribute()</code>
*
* @exception Exception Description of Exception
* @since
*/
public void testAttributes() throws Exception {
Object[] test_values = {
new String[]{"a", "b"},
new String[]{"foo", "foo"},
new String[]{"foo/bar", "foo/bar"}
};
for (int i = 0; i < test_values.length; i++) {
String tests[] = (String[]) test_values[i];
String name = tests[0];
String expected = tests[1];
String message = "Test " +
"'" + name + "'" + ", " + "'" + expected + "'";
commandlineContext.setAttribute(name, expected);
String result = (String) commandlineContext.getAttribute(name);
assertEquals("Test " + "'" + "n" + "'", expected, result);
commandlineContext.removeAttribute(name);
result = (String) commandlineContext.getAttribute(name);
assertEquals("Test " + "'" + "<null>" + "'", null, result);
}
}
/**
* Setup a <code>Logger</code>.
* <p>
* Setup a logger needed by AbstractLoggable objects.
* </p>
*
* @return Logger for logging
* @since
*/
private final Logger setupLogger() {
//FIXME(GP): This method should setup a LogConfigurator and LogManager
// according to the configuration spec. not yet completed/implemented
// It will return a default logger for now.
final org.apache.log.Logger logger = Hierarchy.getDefaultHierarchy().getLoggerFor("Test");
logger.setPriority(m_logPriority);
final PatternFormatter formatter = new PatternFormatter(FORMAT);
final StreamTarget target = new StreamTarget(System.out, formatter);
logger.setLogTargets(new LogTarget[]{target});
return logger;
}
}
1.1 xml-cocoon2/test/org/apache/cocoon/environment/commandline/test/package.html
Index: package.html
===================================================================
<html>
<head>
<title>Search</title>
</head>
<body>
<h1>Test Cases Environement Commandline</h1>
<p>
This package provides Cocoon environment commandline test cases.
</p>
<p>
For more information @see org.apache.cocoon.environment.commandline
</p>
</body>
----------------------------------------------------------------------
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