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
This commit is contained in:
aheritier 2006-11-20 23:23:42 +00:00
parent 0a639cb33b
commit 48fed834de
2 changed files with 50 additions and 26 deletions

View File

@ -24,31 +24,42 @@ import java.util.Map;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
/** /**
* @author Ben Walding * @author Ben Walding
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a> * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
*/ */
public class LinkCheckTest public class LinkCheckTest extends TestCase
extends TestCase
{ {
String baseDir; String baseDir;
public void setUp() /*
* (non-Javadoc)
*
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception
{ {
super.setUp();
baseDir = System.getProperty( "basedir" ); 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() public void testScan() throws Exception
throws Exception
{ {
File f = new File( baseDir + "/src/test-resources" ); File f = new File( baseDir + "/src/test-resources" );
LinkCheck lc = new LinkCheck(); LinkCheck lc = new LinkCheck();
lc.setBasedir( f ); lc.setBasedir( f );
lc.setOutput( new File( baseDir + "/target/linkcheck.xml" ) ); lc.setOutput( new File( baseDir + "/target/linkcheck.xml" ) );
lc.setOutputEncoding( "ISO8859-1" ); 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/," 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(); lc.doExecute();
Iterator iter = lc.getFiles().iterator(); Iterator iter = lc.getFiles().iterator();
@ -75,8 +86,9 @@ public class LinkCheckTest
FileToCheck ftc = (FileToCheck) map.get( fileName ); FileToCheck ftc = (FileToCheck) map.get( fileName );
assertEquals( "Excluded links", 2, ftc.getSuccessful() ); assertEquals( "Excluded links", 2, ftc.getSuccessful() );
//index-all.html should get parsed, but is currently having problems. // index-all.html should get parsed, but is currently having problems.
//check(map, "index-all.html", 1); // 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 ); ftc = (FileToCheck) map.get( name );
assertNotNull( name, ftc ); assertNotNull( name, ftc );
/*if (ftc.getResults().size() != linkCount) {
}*/
assertEquals( name + ".getLinks().size()", linkCount, ftc.getResults().size() ); assertEquals( name + ".getLinks().size()", linkCount, ftc.getResults().size() );
} }

View File

@ -21,29 +21,46 @@ import java.io.File;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
/** /**
* @author <a href="bwalding@apache.org">Ben Walding</a> * @author <a href="bwalding@apache.org">Ben Walding</a>
* @author <a href="aheritier@apache.org">Arnaud Heritier</a> * @author <a href="aheritier@apache.org">Arnaud Heritier</a>
* @version $Id$ * @version $Id$
*/ */
public class HTTPLinkValidatorTest public class HTTPLinkValidatorTest extends TestCase
extends TestCase
{ {
private LinkValidator hlv; private LinkValidator hlv;
private boolean mavenOnline = Boolean.getBoolean( "maven.mode.online" ); 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 ) if ( mavenOnline )
{ {
hlv = new OnlineHTTPLinkValidator( System.getProperty( "maven.linkcheck.method" ), System.getProperty( "maven.linkcheck.proxy.host" ), System hlv =
.getProperty( "maven.linkcheck.proxy.port" ), System.getProperty( "maven.linkcheck.proxy.username" ), new OnlineHTTPLinkValidator( System.getProperty( "maven.linkcheck.method" ),
System.getProperty( "maven.linkcheck.proxy.password" ), System System.getProperty( "maven.linkcheck.proxy.host" ),
.getProperty( "maven.linkcheck.proxy.ntlm.host" ), System System.getProperty( "maven.linkcheck.proxy.port" ),
.getProperty( "maven.linkcheck.proxy.ntlm.domain" ) ); 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.VALID, checkLink( "http://www.apache.org" ).getStatus() );
assertEquals( LinkValidationResult.ERROR, checkLink( "http://www.example.com>);" ).getStatus() ); assertEquals( LinkValidationResult.ERROR, checkLink( "http://www.example.com>);" ).getStatus() );
@ -58,12 +75,11 @@ public class HTTPLinkValidatorTest
} }
} }
protected LinkValidationResult checkLink( String link ) protected LinkValidationResult checkLink( String link ) throws Exception
throws Exception
{ {
LinkValidationItem lvi = new LinkValidationItem( new File( "." ), link ); LinkValidationItem lvi = new LinkValidationItem( new File( "." ), link );
return hlv.validateLink( lvi ); return hlv.validateLink( lvi );
} }
} }