cleanup use jsoup to parse html result

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1555674 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2014-01-06 05:31:58 +00:00
parent d0bd0ec118
commit 69c9ae20de
3 changed files with 35 additions and 60 deletions

View File

@ -88,7 +88,7 @@ public class ArchivaIndexingTaskExecutor
/**
* depending on current {@link Task} you have.
* If {@link org.apache.archiva.scheduler.indexing.ArtifactIndexingTask.Action.FINISH} && isExecuteOnEntireRepo:
* If {@link org.apache.archiva.scheduler.indexing.ArtifactIndexingTask.Action#FINISH} && isExecuteOnEntireRepo:
* repository will be scanned.
*
* @param task

View File

@ -28,21 +28,16 @@ import junit.framework.Assert;
import junit.framework.TestCase;
import net.sf.ehcache.CacheManager;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.archiva.webdav.util.MavenIndexerCleaner;
import org.apache.archiva.webdav.util.ReinitServlet;
import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.deploy.ApplicationParameter;
import org.apache.catalina.startup.Tomcat;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
@ -63,11 +58,7 @@ import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletConfig;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.inject.Inject;
import javax.servlet.Servlet;
@ -101,12 +92,15 @@ public abstract class AbstractRepositoryServletTestCase
protected File repoRootLegacy;
@Inject
protected ArchivaConfiguration archivaConfiguration;
@Inject
protected ApplicationContext applicationContext;
@Inject
protected ManagedRepositoryAdmin managedRepositoryAdmin;
protected Logger log = LoggerFactory.getLogger( getClass() );
@ -141,7 +135,6 @@ public abstract class AbstractRepositoryServletTestCase
}
FileUtils.copyFile( testConf, testConfDest );
archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class );
repoRootInternal = new File( appserverBase, "data/repositories/internal" );
repoRootLegacy = new File( appserverBase, "data/repositories/legacy" );
@ -152,6 +145,8 @@ public abstract class AbstractRepositoryServletTestCase
config.addManagedRepository(
createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal, true ) );
managedRepositoryAdmin.createIndexContext( managedRepositoryAdmin.getManagedRepository( REPOID_INTERNAL ) );
config.addManagedRepository(
createManagedRepository( REPOID_LEGACY, "Legacy Format Test Repo", repoRootLegacy, "legacy", true ) );
@ -174,32 +169,6 @@ public abstract class AbstractRepositoryServletTestCase
protected void startRepository()
throws Exception
{
/*
tomcat = new Tomcat();
tomcat.setBaseDir( System.getProperty( "java.io.tmpdir" ) );
tomcat.setPort( 0 );
context = StandardContext.class.cast( tomcat.addContext( "", System.getProperty( "java.io.tmpdir" ) ) );
ApplicationParameter applicationParameter = new ApplicationParameter();
applicationParameter.setName( "contextConfigLocation" );
applicationParameter.setValue( getSpringConfigLocation() );
context.addApplicationParameter( applicationParameter );
context.addApplicationListener( ContextLoaderListener.class.getName() );
context.addApplicationListener( MavenIndexerCleaner.class.getName() );
Tomcat.addServlet( context, "repository", new UnauthenticatedRepositoryServlet() );
context.addServletMapping( "/repository/*", "repository" );
Tomcat.addServlet( context, "reinitservlet", new ReinitServlet() );
context.addServletMapping( "/reinit/*", "reinitservlet" );
tomcat.start();
this.port = tomcat.getConnector().getLocalPort();
*/
final MockServletContext mockServletContext = new MockServletContext();
@ -556,13 +525,8 @@ public abstract class AbstractRepositoryServletTestCase
request.setMethod( webRequest.getHttpMethod().name() );
/*
if (webRequest.getHttpMethod() == HttpMethod.PUT)
{
request.set
} */
final MockHttpServletResponse response = execute( request );
return new WebResponse( null, null, 1 )
{
@Override

View File

@ -22,16 +22,21 @@ package org.apache.archiva.webdav;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.WebResponse;
import org.fest.assertions.api.Assertions;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.Before;
import org.junit.Test;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.Arrays;
import java.util.List;
/**
* RepositoryServletBrowseTest
*
*
*/
public class RepositoryServletBrowseTest
extends AbstractRepositoryServletTestCase
@ -61,9 +66,12 @@ public class RepositoryServletBrowseTest
// dumpResponse( response );
String expectedLinks[] = new String[]{ ".indexer/", "commons-lang/", "net/", "org/" };
// @FIXME
//assertLinks( expectedLinks, response.getLinks() );
List<String> expectedLinks = Arrays.asList( ".indexer/", "commons-lang/", "net/", "org/" );
Document document = Jsoup.parse( response.getContentAsString() );
Elements elements = document.getElementsByTag( "a" );
assertLinks( expectedLinks, elements );
}
@Test
@ -74,9 +82,12 @@ public class RepositoryServletBrowseTest
WebResponse response = getServletUnitClient().getResponse( request );
assertEquals( "Response", HttpServletResponse.SC_OK, response.getStatusCode() );
String expectedLinks[] = new String[]{ "../", "apache/", "codehaus/" };
// @FIXME
//assertLinks( expectedLinks, response.getLinks() );
List<String> expectedLinks = Arrays.asList( "../", "apache/", "codehaus/" );
Document document = Jsoup.parse( response.getContentAsString() );
Elements elements = document.getElementsByTag( "a" );
assertLinks( expectedLinks, elements );
}
@Test
@ -106,15 +117,15 @@ public class RepositoryServletBrowseTest
assertEquals( "4th Response", HttpServletResponse.SC_NOT_FOUND, response.getStatusCode() );
}
// @FIXME
/*
private void assertLinks( String expectedLinks[], WebLink actualLinks[] )
private void assertLinks( List<String> expectedLinks, Elements actualLinks )
{
assertEquals( "Links.length", expectedLinks.length, actualLinks.length );
for ( int i = 0; i < actualLinks.length; i++ )
Assertions.assertThat( actualLinks ).hasSize( expectedLinks.size() );
for ( int i = 0; i < actualLinks.size(); i++ )
{
assertEquals( "Link[" + i + "]", expectedLinks[i], actualLinks[i].getURLString() );
Element element = actualLinks.get( i );
assertEquals( "Link[" + i + "]", expectedLinks.get( i ), element.attr( "href" ) );
}
}
*/
}