You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by br...@apache.org on 2007/08/28 08:53:42 UTC
svn commit: r570337 - in
/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src:
main/java/org/apache/maven/archiva/web/action/admin/repositories/
test/java/org/apache/maven/archiva/web/action/
test/java/org/apache/maven/archiva/web/action/admi...
Author: brett
Date: Mon Aug 27 23:53:41 2007
New Revision: 570337
URL: http://svn.apache.org/viewvc?rev=570337&view=rev
Log:
[MRM-462] add tests for RepositoriesAction
Added:
maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/
maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/
maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/
maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java (with props)
maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java (with props)
maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/
maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/
maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/
maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.xml (with props)
Modified:
maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java
Modified: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java?rev=570337&r1=570336&r2=570337&view=diff
==============================================================================
--- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java (original)
+++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java Mon Aug 27 23:53:41 2007
@@ -21,7 +21,6 @@
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.Preparable;
-import org.apache.commons.collections.Transformer;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
@@ -57,11 +56,6 @@
implements SecureAction, ServletRequestAware, Preparable
{
/**
- * @plexus.requirement role-hint="adminrepoconfig"
- */
- private Transformer repoConfigToAdmin;
-
- /**
* @plexus.requirement
*/
private ArchivaConfiguration archivaConfiguration;
@@ -77,11 +71,14 @@
*/
private ArchivaDAO dao;
+ /**
+ * Used to construct the repository WebDAV URL in the repository action.
+ */
private String baseUrl;
public void setServletRequest( HttpServletRequest request )
{
- // TODO! what is this?
+ // TODO: is there a better way to do this?
this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
}
Added: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java?rev=570337&view=auto
==============================================================================
--- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java (added)
+++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java Mon Aug 27 23:53:41 2007
@@ -0,0 +1,84 @@
+package org.apache.maven.archiva.web.action.admin.repositories;
+
+import junit.framework.Assert;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.ArtifactDAO;
+import org.apache.maven.archiva.database.ProjectModelDAO;
+import org.apache.maven.archiva.database.RepositoryDAO;
+import org.apache.maven.archiva.database.RepositoryProblemDAO;
+import org.apache.maven.archiva.database.SimpleConstraint;
+import org.apache.maven.archiva.model.RepositoryContentStatistics;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Stub class for Archiva DAO to avoid having to set up a database for tests.
+ *
+ * @todo a mock would be better, but that won't play nicely with Plexus injection.
+ */
+public class ArchivaDAOStub
+ implements ArchivaDAO
+{
+ private ArchivaConfiguration configuration;
+
+ public List query( SimpleConstraint constraint )
+ {
+ Assert.assertEquals( RepositoryContentStatistics.class, constraint.getResultClass() );
+
+ List<RepositoryContentStatistics> stats = new ArrayList<RepositoryContentStatistics>();
+ for ( String repo : configuration.getConfiguration().getManagedRepositoriesAsMap().keySet() )
+ {
+ RepositoryContentStatistics statistics = new RepositoryContentStatistics();
+ statistics.setRepositoryId( repo );
+ stats.add( statistics );
+ }
+ return stats;
+ }
+
+ public Object save( Serializable obj )
+ {
+ throw new UnsupportedOperationException( "query not implemented for stub" );
+ }
+
+ public ArtifactDAO getArtifactDAO()
+ {
+ throw new UnsupportedOperationException( "query not implemented for stub" );
+ }
+
+ public ProjectModelDAO getProjectModelDAO()
+ {
+ throw new UnsupportedOperationException( "query not implemented for stub" );
+ }
+
+ public RepositoryDAO getRepositoryDAO()
+ {
+ throw new UnsupportedOperationException( "query not implemented for stub" );
+ }
+
+ public RepositoryProblemDAO getRepositoryProblemDAO()
+ {
+ throw new UnsupportedOperationException( "query not implemented for stub" );
+ }
+}
Propchange: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java?rev=570337&view=auto
==============================================================================
--- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java (added)
+++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java Mon Aug 27 23:53:41 2007
@@ -0,0 +1,77 @@
+package org.apache.maven.archiva.web.action.admin.repositories;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.meterware.servletunit.ServletRunner;
+import com.meterware.servletunit.ServletUnitClient;
+import com.opensymphony.xwork.Action;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
+import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
+
+/**
+ * Test the repositories action returns the correct data.
+ */
+public class RepositoriesActionTest
+ extends PlexusTestCase
+{
+ private RepositoriesAction action;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ // TODO: purely to quiet logging - shouldn't be needed
+ String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath();
+ System.setProperty( "appserver.base", appserverBase );
+ action = (RepositoriesAction) lookup( Action.class.getName(), "repositoriesAction" );
+ }
+
+ public void testGetRepositories()
+ throws Exception
+ {
+ ServletRunner sr = new ServletRunner();
+ ServletUnitClient sc = sr.newClient();
+
+ action.setServletRequest( sc.newInvocation( "http://localhost/admin/repositories.action" ).getRequest() );
+ action.prepare();
+ action.execute();
+
+ // TODO: for some reason servletunit is not populating the port of the servlet request
+ assertEquals( "http://localhost:0/repository", action.getBaseUrl() );
+
+ assertNotNull( action.getManagedRepositories() );
+ assertNotNull( action.getRemoteRepositories() );
+ assertNotNull( action.getRepositoryStatistics() );
+
+ assertEquals( 2, action.getManagedRepositories().size() );
+ assertEquals( 2, action.getRemoteRepositories().size() );
+ assertEquals( 2, action.getRepositoryStatistics().size() );
+ }
+
+ public void testSecureActionBundle()
+ throws SecureActionException
+ {
+ SecureActionBundle bundle = action.getSecureActionBundle();
+ assertTrue( bundle.requiresAuthentication() );
+ assertEquals( 1, bundle.getAuthorizationTuples().size() );
+ }
+}
Propchange: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.xml?rev=570337&view=auto
==============================================================================
--- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.xml (added)
+++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.xml Mon Aug 27 23:53:41 2007
@@ -0,0 +1,57 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<plexus>
+ <components>
+ <component>
+ <role>org.codehaus.plexus.logging.LoggerManager</role>
+ <implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>
+ <lifecycle-handler>basic</lifecycle-handler>
+ </component>
+ <component>
+ <role>com.opensymphony.xwork.Action</role>
+ <role-hint>repositoriesAction</role-hint>
+ <implementation>org.apache.maven.archiva.web.action.admin.repositories.RepositoriesAction</implementation>
+ <instantiation-strategy>per-lookup</instantiation-strategy>
+ <description>Shows the Repositories Tab for the administrator.</description>
+ <requirements>
+ <requirement>
+ <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+ <field-name>archivaConfiguration</field-name>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.archiva.database.ArchivaDAO</role>
+ <role-hint>stub</role-hint>
+ <field-name>dao</field-name>
+ </requirement>
+ </requirements>
+ </component>
+ <component>
+ <role>org.apache.maven.archiva.database.ArchivaDAO</role>
+ <role-hint>stub</role-hint>
+ <implementation>org.apache.maven.archiva.web.action.admin.repositories.ArchivaDAOStub</implementation>
+ <requirements>
+ <requirement>
+ <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+ <field-name>configuration</field-name>
+ </requirement>
+ </requirements>
+ </component>
+ </components>
+</plexus>
Propchange: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.xml
------------------------------------------------------------------------------
svn:eol-style = native