From 48fed834de939aeb02793d8be52665357268a2c2 Mon Sep 17 00:00:00 2001 From: aheritier Date: Mon, 20 Nov 2006 23:23:42 +0000 Subject: [PATCH] Put debug logs for unit tests Some cleanup git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@477398 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/plugin/linkcheck/LinkCheckTest.java | 34 +++++++++------ .../validation/HTTPLinkValidatorTest.java | 42 +++++++++++++------ 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java b/linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java index eaafab7e..e08463e8 100644 --- a/linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java +++ b/linkcheck/src/test/org/apache/maven/plugin/linkcheck/LinkCheckTest.java @@ -24,31 +24,42 @@ import java.util.Map; import junit.framework.TestCase; +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; + /** * @author Ben Walding * @author Carlos Sanchez */ -public class LinkCheckTest - extends TestCase +public class LinkCheckTest extends TestCase { String baseDir; - public void setUp() + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); baseDir = System.getProperty( "basedir" ); + // Setup log4J (We are in a forked JVM for tests) + BasicConfigurator.configure(); + Logger.getLogger( "org.apache.maven.plugin.linkcheck" ).setLevel( Level.DEBUG ); } - public void testScan() - throws Exception + public void testScan() throws Exception { File f = new File( baseDir + "/src/test-resources" ); LinkCheck lc = new LinkCheck(); lc.setBasedir( f ); lc.setOutput( new File( baseDir + "/target/linkcheck.xml" ) ); lc.setOutputEncoding( "ISO8859-1" ); - lc.setCache( baseDir + "/target/linkcheck-cache.xml" ); + lc.setCache( System.getProperty( "maven.linkcheck.cache" ) ); lc.setExclude( "http://cvs.apache.org/viewcvs.cgi/maven-pluginszz/," - + "http://cvs.apache.org/viewcvs.cgi/mavenzz/" ); + + "http://cvs.apache.org/viewcvs.cgi/mavenzz/" ); lc.doExecute(); Iterator iter = lc.getFiles().iterator(); @@ -75,8 +86,9 @@ public class LinkCheckTest FileToCheck ftc = (FileToCheck) map.get( fileName ); assertEquals( "Excluded links", 2, ftc.getSuccessful() ); - //index-all.html should get parsed, but is currently having problems. - //check(map, "index-all.html", 1); + // index-all.html should get parsed, but is currently having problems. + // There are 805 distinct links in this page + check( map, "index-all.html", 805 ); } @@ -87,10 +99,6 @@ public class LinkCheckTest ftc = (FileToCheck) map.get( name ); assertNotNull( name, ftc ); - /*if (ftc.getResults().size() != linkCount) { - - }*/ - assertEquals( name + ".getLinks().size()", linkCount, ftc.getResults().size() ); } diff --git a/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java b/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java index 804101ec..0b850f2e 100644 --- a/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java +++ b/linkcheck/src/test/org/apache/maven/plugin/linkcheck/validation/HTTPLinkValidatorTest.java @@ -21,29 +21,46 @@ import java.io.File; import junit.framework.TestCase; +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; + /** * @author Ben Walding * @author Arnaud Heritier * @version $Id$ */ -public class HTTPLinkValidatorTest - extends TestCase +public class HTTPLinkValidatorTest extends TestCase { private LinkValidator hlv; private boolean mavenOnline = Boolean.getBoolean( "maven.mode.online" ); - public void testValidateLink() - throws Exception + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + // Setup log4J (We are in a forked JVM for tests) + BasicConfigurator.configure(); + Logger.getLogger( "org.apache.maven.plugin.linkcheck" ).setLevel( Level.DEBUG ); + } + + public void testValidateLink() throws Exception { - System.err.println( "maven.mode.online : " + mavenOnline ); if ( mavenOnline ) { - hlv = new OnlineHTTPLinkValidator( System.getProperty( "maven.linkcheck.method" ), System.getProperty( "maven.linkcheck.proxy.host" ), System - .getProperty( "maven.linkcheck.proxy.port" ), System.getProperty( "maven.linkcheck.proxy.username" ), - System.getProperty( "maven.linkcheck.proxy.password" ), System - .getProperty( "maven.linkcheck.proxy.ntlm.host" ), System - .getProperty( "maven.linkcheck.proxy.ntlm.domain" ) ); + hlv = + new OnlineHTTPLinkValidator( System.getProperty( "maven.linkcheck.method" ), + System.getProperty( "maven.linkcheck.proxy.host" ), + System.getProperty( "maven.linkcheck.proxy.port" ), + System.getProperty( "maven.linkcheck.proxy.username" ), + System.getProperty( "maven.linkcheck.proxy.password" ), + System.getProperty( "maven.linkcheck.proxy.ntlm.host" ), + System.getProperty( "maven.linkcheck.proxy.ntlm.domain" ) ); assertEquals( LinkValidationResult.VALID, checkLink( "http://www.apache.org" ).getStatus() ); assertEquals( LinkValidationResult.ERROR, checkLink( "http://www.example.com>);" ).getStatus() ); @@ -58,12 +75,11 @@ public class HTTPLinkValidatorTest } } - protected LinkValidationResult checkLink( String link ) - throws Exception + protected LinkValidationResult checkLink( String link ) throws Exception { LinkValidationItem lvi = new LinkValidationItem( new File( "." ), link ); return hlv.validateLink( lvi ); } -} \ No newline at end of file +}