]> source.dussan.org Git - archiva.git/commitdiff
cleanup use jsoup to parse html result
authorOlivier Lamy <olamy@apache.org>
Mon, 6 Jan 2014 05:31:58 +0000 (05:31 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 6 Jan 2014 05:31:58 +0000 (05:31 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1555674 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletBrowseTest.java

index ed455b08b85a5717bc619da2a60da2b875948952..4108cc9ac6151da2ba513b0307f59d5f0de41382 100644 (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
index 15ac543263a39c9c2c782ce8da8905da6660fac8..5eaccf4a16d3cb86c439de48b4e67b9d37babf27 100644 (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
index 04a0e55052e0fd0ba8e1229b61ac15338de06c87..b468c867ff1b903179ef5db7eb6642b22b988be7 100644 (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" ) );
         }
     }
-    */
+
 }