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;
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;
protected File repoRootLegacy;
-
+ @Inject
protected ArchivaConfiguration archivaConfiguration;
@Inject
protected ApplicationContext applicationContext;
+ @Inject
+ protected ManagedRepositoryAdmin managedRepositoryAdmin;
+
protected Logger log = LoggerFactory.getLogger( getClass() );
}
FileUtils.copyFile( testConf, testConfDest );
- archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class );
repoRootInternal = new File( appserverBase, "data/repositories/internal" );
repoRootLegacy = new File( appserverBase, "data/repositories/legacy" );
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 ) );
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();
request.setMethod( webRequest.getHttpMethod().name() );
- /*
- if (webRequest.getHttpMethod() == HttpMethod.PUT)
- {
- request.set
- } */
-
final MockHttpServletResponse response = execute( request );
+
return new WebResponse( null, null, 1 )
{
@Override
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
// 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
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
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" ) );
}
}
- */
+
}