From 9acde9b594de05eca16a005a7d39d4912fc26980 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 7 Sep 2011 20:35:00 +0000 Subject: [PATCH] MRM-1507 : api to configure ProxyConnector : use it in the webapp git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1166392 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva-repository-admin/pom.xml | 10 ++ .../DefaultProxyConnectorAdmin.java | 29 ++++- .../proxyconnector/ProxyConnectorAdmin.java | 14 ++- .../ProxyConnectorAdminTest.java | 24 ++++ .../AbstractProxyConnectorFormAction.java | 1 + .../proxy/AddProxyConnectorAction.java | 11 +- .../proxy/DeleteProxyConnectorAction.java | 29 +++-- .../proxy/DisableProxyConnectorAction.java | 11 +- .../proxy/EditProxyConnectorAction.java | 31 +++-- .../proxy/EnableProxyConnectorAction.java | 12 +- .../proxy/ProxyConnectorsAction.java | 37 +++--- .../proxy/SortProxyConnectorsAction.java | 29 +++-- .../proxy/AddProxyConnectorActionTest.java | 35 ++++-- .../proxy/DeleteProxyConnectorActionTest.java | 44 ++++--- .../DisableProxyConnectorActionTest.java | 38 +++--- .../proxy/EditProxyConnectorActionTest.java | 118 ++++++++++-------- .../proxy/EnableProxyConnectorActionTest.java | 80 ++++++------ .../proxy/ProxyConnectorsActionTest.java | 15 ++- .../proxy/SortProxyConnectorsActionTest.java | 60 ++++----- archiva-modules/pom.xml | 10 -- pom.xml | 22 +++- 21 files changed, 402 insertions(+), 258 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-admin/pom.xml b/archiva-modules/archiva-base/archiva-repository-admin/pom.xml index 2efa25bd2..541eb7f70 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/pom.xml +++ b/archiva-modules/archiva-base/archiva-repository-admin/pom.xml @@ -51,6 +51,16 @@ net.sf.beanlib beanlib + + + cglib + cglib + + + aopalliance + aopalliance + + org.springframework diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java index d49e80744..c83a57766 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java @@ -140,6 +140,19 @@ public class DefaultProxyConnectorAdmin return Boolean.TRUE; } + public Boolean updateProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation ) + throws RepositoryAdminException + { + Configuration configuration = getArchivaConfiguration().getConfiguration(); + ProxyConnectorConfiguration proxyConnectorConfiguration = + findProxyConnector( proxyConnector.getSourceRepoId(), proxyConnector.getTargetRepoId(), configuration ); + configuration.removeProxyConnector( proxyConnectorConfiguration ); + configuration.addProxyConnector( getProxyConnectorConfiguration( proxyConnector ) ); + triggerAuditEvent( proxyConnector.getSourceRepoId() + "-" + proxyConnector.getTargetRepoId(), null, + AuditEvent.MODIFY_PROXY_CONNECTOR, auditInformation ); + return Boolean.TRUE; + } + protected List unescapePatterns( List patterns ) { List rawPatterns = new ArrayList(); @@ -157,8 +170,7 @@ public class DefaultProxyConnectorAdmin public Map> getProxyConnectorAsMap() throws RepositoryAdminException { - java.util.Map> proxyConnectorMap = - new HashMap>(); + Map> proxyConnectorMap = new HashMap>(); Iterator it = getProxyConnectors().iterator(); while ( it.hasNext() ) @@ -166,7 +178,7 @@ public class DefaultProxyConnectorAdmin ProxyConnector proxyConfig = it.next(); String key = proxyConfig.getSourceRepoId(); - java.util.List connectors = proxyConnectorMap.get( key ); + List connectors = proxyConnectorMap.get( key ); if ( connectors == null ) { connectors = new ArrayList(); @@ -221,12 +233,17 @@ public class DefaultProxyConnectorAdmin proxyConnectorConfiguration.setSourceRepoId( proxyConnector.getSourceRepoId() ); proxyConnectorConfiguration.setTargetRepoId( proxyConnector.getTargetRepoId() ); return proxyConnectorConfiguration;*/ - return new BeanReplicator().replicateBean( proxyConnector, ProxyConnectorConfiguration.class ); + + return proxyConnector == null + ? null + : new BeanReplicator().replicateBean( proxyConnector, ProxyConnectorConfiguration.class ); } protected ProxyConnector getProxyConnector( ProxyConnectorConfiguration proxyConnectorConfiguration ) { - return new BeanReplicator().replicateBean( proxyConnectorConfiguration, ProxyConnector.class ); + return proxyConnectorConfiguration == null + ? null + : new BeanReplicator().replicateBean( proxyConnectorConfiguration, ProxyConnector.class ); } protected void validateProxyConnector( ProxyConnector proxyConnector ) @@ -246,6 +263,6 @@ public class DefaultProxyConnectorAdmin + " is not a RemoteRepository" ); } - // FIXME validate NetworkProxyConfiguration too + // FIXME validate NetworkProxyConfiguration too when available } } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdmin.java index 2eae5da1f..0228f9b73 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdmin.java @@ -25,7 +25,7 @@ import java.util.List; import java.util.Map; /** - * No update method here as id is : sourceRepoId and targetRepoId, use delete then add. + * No update method for changing source and target here as id is : sourceRepoId and targetRepoId, use delete then add. * * @author Olivier Lamy * @since 1.4 @@ -44,10 +44,22 @@ public interface ProxyConnectorAdmin Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation ) throws RepositoryAdminException; + /** + * only for enabled/disable or changing bean values except target/source + * @param proxyConnector + * @param auditInformation + * @return + * @throws RepositoryAdminException + */ + Boolean updateProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation ) + throws RepositoryAdminException; + + Map> getProxyConnectorAsMap() throws RepositoryAdminException; ProxyConnector findProxyConnector( String sourceId, String targetId ) throws RepositoryAdminException; + } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdminTest.java index 97b0b12d3..af35ff36c 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdminTest.java @@ -136,4 +136,28 @@ public class ProxyConnectorAdminTest assertNotNull( proxyConnector ); } + @Test + public void updateProxyConnector() + throws Exception + { + ProxyConnector proxyConnector = proxyConnectorAdmin.findProxyConnector( "internal", "central" ); + assertNotNull( proxyConnector ); + proxyConnector.setDisabled( false ); + proxyConnectorAdmin.updateProxyConnector( proxyConnector, getFakeAuditInformation() ); + proxyConnector = proxyConnectorAdmin.findProxyConnector( "internal", "central" ); + assertFalse( proxyConnector.isDisabled() ); + + + proxyConnector.setDisabled( true ); + proxyConnectorAdmin.updateProxyConnector( proxyConnector, getFakeAuditInformation() ); + proxyConnector = proxyConnectorAdmin.findProxyConnector( "internal", "central" ); + assertTrue( proxyConnector.isDisabled() ); + + proxyConnector.setOrder( 4 ); + proxyConnectorAdmin.updateProxyConnector( proxyConnector, getFakeAuditInformation() ); + proxyConnector = proxyConnectorAdmin.findProxyConnector( "internal", "central" ); + assertEquals( 4, proxyConnector.getOrder() ); + + } + } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java index 5a44dea36..6f92a879b 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java @@ -485,6 +485,7 @@ public abstract class AbstractProxyConnectorFormAction } } + // FIXME remove public ArchivaConfiguration getArchivaConfiguration() { return archivaConfiguration; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorAction.java index 9d295cf88..40455de43 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorAction.java @@ -19,8 +19,9 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; * under the License. */ +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.proxyconnector.ProxyConnector; import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; @@ -36,9 +37,10 @@ public class AddProxyConnectorAction { @Override public void prepare() + throws RepositoryAdminException { super.prepare(); - connector = new ProxyConnectorConfiguration(); + connector = new ProxyConnector(); } @Override @@ -55,6 +57,7 @@ public class AddProxyConnectorAction } public String commit() + throws RepositoryAdminException { /* Too complex for webwork's ${Action}-validation.xml techniques. * Not appropriate for use with webwork's implements Validatable, as that validates regardless of @@ -65,7 +68,7 @@ public class AddProxyConnectorAction String sourceId = connector.getSourceRepoId(); String targetId = connector.getTargetRepoId(); - ProxyConnectorConfiguration otherConnector = findProxyConnector( sourceId, targetId ); + ProxyConnector otherConnector = findProxyConnector( sourceId, targetId ); if ( otherConnector != null ) { addActionError( @@ -90,6 +93,6 @@ public class AddProxyConnectorAction connector.setWhiteListPatterns( unescapePatterns( connector.getWhiteListPatterns() ) ); addProxyConnector( connector ); - return saveConfiguration(); + return SUCCESS; } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DeleteProxyConnectorAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DeleteProxyConnectorAction.java index 72cc99e64..d0ec3885d 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DeleteProxyConnectorAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DeleteProxyConnectorAction.java @@ -19,15 +19,16 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; * under the License. */ +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.proxyconnector.ProxyConnector; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; /** - * DeleteProxyConnectorAction + * DeleteProxyConnectorAction * * @version $Id$ - * */ @Controller( "deleteProxyConnectorAction" ) @Scope( "prototype" ) @@ -38,17 +39,19 @@ public class DeleteProxyConnectorAction private String target; - private ProxyConnectorConfiguration proxyConfig; + private ProxyConnector proxyConfig; public String confirmDelete() + throws RepositoryAdminException { this.proxyConfig = findProxyConnector( source, target ); // Not set? Then there is nothing to delete. if ( this.proxyConfig == null ) { - addActionError( "Unable to delete proxy configuration, configuration with source [" + source - + "], and target [" + target + "] does not exist." ); + addActionError( + "Unable to delete proxy configuration, configuration with source [" + source + "], and target [" + + target + "] does not exist." ); return ERROR; } @@ -56,14 +59,16 @@ public class DeleteProxyConnectorAction } public String delete() + throws RepositoryAdminException { this.proxyConfig = findProxyConnector( source, target ); // Not set? Then there is nothing to delete. if ( this.proxyConfig == null ) { - addActionError( "Unable to delete proxy configuration, configuration with source [" + source - + "], and target [" + target + "] does not exist." ); + addActionError( + "Unable to delete proxy configuration, configuration with source [" + source + "], and target [" + + target + "] does not exist." ); return ERROR; } @@ -71,14 +76,14 @@ public class DeleteProxyConnectorAction { return ERROR; } - - removeProxyConnector( proxyConfig ); + + getProxyConnectorAdmin().deleteProxyConnector( proxyConfig, getAuditInformation() ); addActionMessage( "Successfully removed proxy connector [" + source + " , " + target + " ]" ); setSource( null ); setTarget( null ); - - return saveConfiguration(); + + return SUCCESS; } public String getSource() @@ -101,7 +106,7 @@ public class DeleteProxyConnectorAction this.target = id; } - public ProxyConnectorConfiguration getProxyConfig() + public ProxyConnector getProxyConfig() { return proxyConfig; } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DisableProxyConnectorAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DisableProxyConnectorAction.java index a8c349219..d8c214ca5 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DisableProxyConnectorAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DisableProxyConnectorAction.java @@ -1,6 +1,7 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; -import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.proxyconnector.ProxyConnector; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; @@ -25,7 +26,6 @@ import org.springframework.stereotype.Controller; /** * DisableProxyConnectorAction - * */ @Controller( "disableProxyConnectorAction" ) @Scope( "prototype" ) @@ -36,9 +36,10 @@ public class DisableProxyConnectorAction private String target; - private ProxyConnectorConfiguration proxyConfig; + private ProxyConnector proxyConfig; public String confirmDisable() + throws RepositoryAdminException { this.proxyConfig = findProxyConnector( source, target ); @@ -55,6 +56,7 @@ public class DisableProxyConnectorAction } public String disable() + throws RepositoryAdminException { this.proxyConfig = findProxyConnector( source, target ); @@ -79,7 +81,8 @@ public class DisableProxyConnectorAction setSource( null ); setTarget( null ); - return saveConfiguration(); + getProxyConnectorAdmin().updateProxyConnector( proxyConfig, getAuditInformation() ); + return SUCCESS; } public String getSource() diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorAction.java index 5d884f221..21f572520 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorAction.java @@ -19,18 +19,18 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; * under the License. */ -import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.proxyconnector.ProxyConnector; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; /** - * EditProxyConnectorAction + * EditProxyConnectorAction * * @version $Id$ - * */ @Controller( "editProxyConnectorAction" ) -@Scope( "prototype") +@Scope( "prototype" ) public class EditProxyConnectorAction extends AbstractProxyConnectorFormAction { @@ -46,24 +46,26 @@ public class EditProxyConnectorAction @Override public void prepare() + throws RepositoryAdminException { super.prepare(); - connector = findProxyConnector( source, target ); + connector = findProxyConnector( source, target ); } public String input() { if ( connector == null ) { - addActionError( "Unable to edit non existant proxy connector with source [" + source + "] and target [" - + target + "]" ); + addActionError( + "Unable to edit non existant proxy connector with source [" + source + "] and target [" + target + + "]" ); return ERROR; } - - if( connector != null ) + + if ( connector != null ) { - // MRM-1135 + // MRM-1135 connector.setBlackListPatterns( escapePatterns( connector.getBlackListPatterns() ) ); connector.setWhiteListPatterns( escapePatterns( connector.getWhiteListPatterns() ) ); } @@ -72,6 +74,7 @@ public class EditProxyConnectorAction } public String commit() + throws RepositoryAdminException { validateConnector(); @@ -83,7 +86,7 @@ public class EditProxyConnectorAction String sourceId = connector.getSourceRepoId(); String targetId = connector.getTargetRepoId(); - ProxyConnectorConfiguration otherConnector = findProxyConnector( sourceId, targetId ); + ProxyConnector otherConnector = findProxyConnector( sourceId, targetId ); if ( otherConnector != null ) { // Remove the previous connector. @@ -95,12 +98,8 @@ public class EditProxyConnectorAction return INPUT; } - // MRM-1135 - connector.setBlackListPatterns( unescapePatterns( connector.getBlackListPatterns() ) ); - connector.setWhiteListPatterns( unescapePatterns( connector.getWhiteListPatterns() ) ); - addProxyConnector( connector ); - return saveConfiguration(); + return SUCCESS; } public String getSource() diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EnableProxyConnectorAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EnableProxyConnectorAction.java index 4dcda02a5..c06597a3f 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EnableProxyConnectorAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EnableProxyConnectorAction.java @@ -1,6 +1,7 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; -import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.proxyconnector.ProxyConnector; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; @@ -35,9 +36,10 @@ public class EnableProxyConnectorAction private String target; - private ProxyConnectorConfiguration proxyConfig; + private ProxyConnector proxyConfig; public String confirmEnable() + throws RepositoryAdminException { this.proxyConfig = findProxyConnector( source, target ); @@ -53,7 +55,7 @@ public class EnableProxyConnectorAction return INPUT; } - public String enable() + public String enable() throws RepositoryAdminException { this.proxyConfig = findProxyConnector( source, target ); @@ -73,12 +75,14 @@ public class EnableProxyConnectorAction proxyConfig.setDisabled( false ); + getProxyConnectorAdmin().updateProxyConnector( proxyConfig, getAuditInformation() ); + addActionMessage( "Successfully enabled proxy connector [" + source + " , " + target + " ]" ); setSource( null ); setTarget( null ); - return saveConfiguration(); + return SUCCESS; } public String getSource() diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ProxyConnectorsAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ProxyConnectorsAction.java index c9b70f98f..90c98ee63 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ProxyConnectorsAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ProxyConnectorsAction.java @@ -20,10 +20,9 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; */ import com.opensymphony.xwork2.Preparable; - -import org.apache.maven.archiva.configuration.AbstractRepositoryConfiguration; -import org.apache.maven.archiva.configuration.Configuration; -import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; +import org.apache.archiva.admin.repository.AbstractRepository; +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.proxyconnector.ProxyConnector; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; @@ -35,7 +34,6 @@ import java.util.Map; * ProxyConnectorsAction * * @version $Id$ - * */ @Controller( "proxyConnectorsAction" ) @Scope( "prototype" ) @@ -43,42 +41,43 @@ public class ProxyConnectorsAction extends AbstractProxyConnectorAction implements Preparable { - private Map repoMap; + private Map repoMap; /** * boolean to indicate that remote repo is present. Used for Add Link */ - private boolean remoteRepoExists=false; - + private boolean remoteRepoExists = false; + /** * Map of Proxy Connectors. */ - private Map> proxyConnectorMap; + private Map> proxyConnectorMap; public void prepare() + throws RepositoryAdminException { - Configuration config = archivaConfiguration.getConfiguration(); - - repoMap = new HashMap(); - repoMap.putAll( config.getRemoteRepositoriesAsMap() ); - repoMap.putAll( config.getManagedRepositoriesAsMap() ); + repoMap = new HashMap(); + repoMap.putAll( getRemoteRepositoryAdmin().getRemoteRepositoriesAsMap() ); + // FIXME olamy : are we sure we want Managed too ??? + repoMap.putAll( getManagedRepositoryAdmin().getManagedRepositoriesAsMap() ); proxyConnectorMap = createProxyConnectorMap(); - - remoteRepoExists=config.getRemoteRepositories().size()>0; + + remoteRepoExists = getRemoteRepositoryAdmin().getRemoteRepositories().size() > 0; } - public Map getRepoMap() + public Map getRepoMap() { return repoMap; } - public Map> getProxyConnectorMap() + public Map> getProxyConnectorMap() { return proxyConnectorMap; } - public boolean getRemoteRepoExists() + // FIXME olamy should be is ! + public boolean getRemoteRepoExists() { return remoteRepoExists; } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/SortProxyConnectorsAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/SortProxyConnectorsAction.java index 401bb58b2..d37894cb5 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/SortProxyConnectorsAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/SortProxyConnectorsAction.java @@ -19,8 +19,9 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; * under the License. */ +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.proxyconnector.ProxyConnector; import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; @@ -61,8 +62,9 @@ public class SortProxyConnectorsAction } public String sortDown() + throws RepositoryAdminException { - List connectors = createProxyConnectorMap().get( source ); + List connectors = createProxyConnectorMap().get( source ); int idx = findTargetConnector( connectors, target ); @@ -72,12 +74,17 @@ public class SortProxyConnectorsAction decrementConnectorOrder( connectors, idx + 1 ); } - return saveConfiguration(); + for ( ProxyConnector proxyConnector : connectors ) + { + getProxyConnectorAdmin().updateProxyConnector( proxyConnector, getAuditInformation() ); + } + return SUCCESS; } public String sortUp() + throws RepositoryAdminException { - List connectors = createProxyConnectorMap().get( source ); + List connectors = createProxyConnectorMap().get( source ); int idx = findTargetConnector( connectors, target ); @@ -87,10 +94,14 @@ public class SortProxyConnectorsAction incrementConnectorOrder( connectors, idx - 1 ); } - return saveConfiguration(); + for ( ProxyConnector proxyConnector : connectors ) + { + getProxyConnectorAdmin().updateProxyConnector( proxyConnector, getAuditInformation() ); + } + return SUCCESS; } - private void decrementConnectorOrder( List connectors, int idx ) + private void decrementConnectorOrder( List connectors, int idx ) { if ( !validIndex( connectors, idx ) ) { @@ -102,7 +113,7 @@ public class SortProxyConnectorsAction connectors.get( idx ).setOrder( Math.max( 1, order - 1 ) ); } - private int findTargetConnector( List connectors, String targetRepoId ) + private int findTargetConnector( List connectors, String targetRepoId ) { int idx = ( -1 ); @@ -118,7 +129,7 @@ public class SortProxyConnectorsAction return idx; } - private void incrementConnectorOrder( List connectors, int idx ) + private void incrementConnectorOrder( List connectors, int idx ) { if ( !validIndex( connectors, idx ) ) { @@ -130,7 +141,7 @@ public class SortProxyConnectorsAction connectors.get( idx ).setOrder( order + 1 ); } - private boolean validIndex( List connectors, int idx ) + private boolean validIndex( List connectors, int idx ) { return ( idx >= 0 ) && ( idx < connectors.size() ); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorActionTest.java index b1e1f3d0c..e3b99dc32 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorActionTest.java @@ -20,6 +20,10 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; */ import com.opensymphony.xwork2.Action; +import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin; +import org.apache.archiva.admin.repository.proxyconnector.ProxyConnector; +import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; @@ -61,11 +65,16 @@ public class AddProxyConnectorActionTest super.setUp(); action = (AddProxyConnectorAction) getActionProxy( "/admin/addProxyConnector.action" ).getAction(); - //action = (AddProxyConnectorAction) lookup( Action.class.getName(), "addProxyConnectorAction" ); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); action.setArchivaConfiguration( archivaConfiguration ); + ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration( + archivaConfiguration ); } public void testAddBlackListPattern() @@ -76,7 +85,7 @@ public class AddProxyConnectorActionTest // Prepare Test. action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); populateProxyConnector( connector ); // Perform Test w/no values. @@ -107,7 +116,7 @@ public class AddProxyConnectorActionTest // Prepare Test. action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); populateProxyConnector( connector ); // Perform Test w/no values. @@ -135,15 +144,17 @@ public class AddProxyConnectorActionTest public void testAddProxyConnectorCommit() throws Exception { - expectConfigurationRequests( 7 ); + expectConfigurationRequests( 9 ); archivaConfigurationControl.replay(); // Prepare Test. action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); populateProxyConnector( connector ); // forms will use an array - connector.getProperties().put( "eat-a", new String[] { "gramov-a-bits" } ); + //connector.getProperties().put( "eat-a", new String[] { "gramov-a-bits" } ); + // FIXME olamy check the array mode !!! + connector.getProperties().put( "eat-a", "gramov-a-bits" ); // Create the input screen. assertRequestStatus( action, Action.SUCCESS, "commit" ); @@ -171,7 +182,7 @@ public class AddProxyConnectorActionTest archivaConfigurationControl.replay(); action.prepare(); - ProxyConnectorConfiguration configuration = action.getConnector(); + ProxyConnector configuration = action.getConnector(); assertNotNull( configuration ); assertNull( configuration.getProxyId() ); assertNull( configuration.getSourceRepoId() ); @@ -193,7 +204,7 @@ public class AddProxyConnectorActionTest // Prepare Test. action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); populateProxyConnector( connector ); // Perform Test w/no values. @@ -224,7 +235,7 @@ public class AddProxyConnectorActionTest // Prepare Test. action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); populateProxyConnector( connector ); // Add some arbitrary blacklist patterns. @@ -270,7 +281,7 @@ public class AddProxyConnectorActionTest // Prepare Test. action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); populateProxyConnector( connector ); // Add some arbitrary properties. @@ -316,7 +327,7 @@ public class AddProxyConnectorActionTest // Prepare Test. action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); populateProxyConnector( connector ); // Add some arbitrary whitelist patterns. @@ -401,7 +412,7 @@ public class AddProxyConnectorActionTest } @SuppressWarnings("unchecked") - private void populateProxyConnector( ProxyConnectorConfiguration connector ) + private void populateProxyConnector( ProxyConnector connector ) { connector.setProxyId( AbstractProxyConnectorFormAction.DIRECT_CONNECTION ); connector.setSourceRepoId( "corporate" ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DeleteProxyConnectorActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DeleteProxyConnectorActionTest.java index 04bac9f45..d5efb2576 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DeleteProxyConnectorActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DeleteProxyConnectorActionTest.java @@ -20,7 +20,9 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; */ import com.opensymphony.xwork2.Action; - +import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin; +import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; @@ -28,12 +30,12 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.web.action.AbstractWebworkTestCase; -import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.plexus.registry.RegistryException; +import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.easymock.MockControl; /** - * DeleteProxyConnectorActionTest + * DeleteProxyConnectorActionTest * * @version $Id$ */ @@ -50,6 +52,24 @@ public class DeleteProxyConnectorActionTest private ArchivaConfiguration archivaConfiguration; + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + action = (DeleteProxyConnectorAction) getActionProxy( "/admin/deleteProxyConnector.action" ).getAction(); + + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + } + public void testConfirmDelete() throws Exception { @@ -71,7 +91,7 @@ public class DeleteProxyConnectorActionTest expectConfigurationRequests( 4 ); archivaConfigurationControl.replay(); - // Attempt to show the confirm delete screen, but provide + // Attempt to show the confirm delete screen, but provide // a bad source id or target id to actually delete preRequest( action ); @@ -105,7 +125,7 @@ public class DeleteProxyConnectorActionTest expectConfigurationRequests( 1 ); archivaConfigurationControl.replay(); - // Attempt to show the confirm delete screen, but don't provide + // Attempt to show the confirm delete screen, but don't provide // the source id or target id to actually delete preRequest( action ); @@ -209,18 +229,4 @@ public class DeleteProxyConnectorActionTest archivaConfiguration.save( config ); } - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - //action = (DeleteProxyConnectorAction) lookup( Action.class.getName(), "deleteProxyConnectorAction" ); - - action = (DeleteProxyConnectorAction) getActionProxy( "/admin/deleteProxyConnector.action" ).getAction(); - - archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); - archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); - action.setArchivaConfiguration( archivaConfiguration ); - } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DisableProxyConnectorActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DisableProxyConnectorActionTest.java index 32178a548..a9c4773f1 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DisableProxyConnectorActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DisableProxyConnectorActionTest.java @@ -18,6 +18,9 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; import com.opensymphony.xwork2.Action; +import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin; +import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; @@ -42,13 +45,30 @@ public class DisableProxyConnectorActionTest private ArchivaConfiguration archivaConfiguration; + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + action = (DisableProxyConnectorAction) getActionProxy( "/admin/disableProxyConnector.action" ).getAction(); + + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration( archivaConfiguration ); + } + public void testConfirmDisableBadSourceOrTarget() throws Exception { expectConfigurationRequests( 4 ); archivaConfigurationControl.replay(); - // Attempt to show the confirm disable screen, but provide + // Attempt to show the confirm disable screen, but provide // a bad source id or target id to actually delete preRequest( action ); @@ -82,7 +102,7 @@ public class DisableProxyConnectorActionTest expectConfigurationRequests( 1 ); archivaConfigurationControl.replay(); - // Attempt to show the confirm disable screen, but don't provide + // Attempt to show the confirm disable screen, but don't provide // the source id or target id to actually delete preRequest( action ); @@ -205,18 +225,4 @@ public class DisableProxyConnectorActionTest archivaConfiguration.save( config ); } - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - //action = (DisableProxyConnectorAction) lookup( Action.class.getName(), "disableProxyConnectorAction" ); - action = (DisableProxyConnectorAction) getActionProxy( "/admin/disableProxyConnector.action" ).getAction(); - - archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); - archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); - action.setArchivaConfiguration( archivaConfiguration ); - } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorActionTest.java index b8343c0e5..6562995ab 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorActionTest.java @@ -20,6 +20,10 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; */ import com.opensymphony.xwork2.Action; +import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin; +import org.apache.archiva.admin.repository.proxyconnector.ProxyConnector; +import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; @@ -33,15 +37,15 @@ import org.apache.maven.archiva.policies.PropagateErrorsOnUpdateDownloadPolicy; import org.apache.maven.archiva.policies.ReleasesPolicy; import org.apache.maven.archiva.policies.SnapshotsPolicy; import org.apache.maven.archiva.web.action.AbstractWebworkTestCase; -import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.plexus.registry.RegistryException; +import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.easymock.MockControl; import java.util.List; import java.util.Map; /** - * EditProxyConnectorActionTest + * EditProxyConnectorActionTest * * @version $Id$ */ @@ -58,6 +62,51 @@ public class EditProxyConnectorActionTest private ArchivaConfiguration archivaConfiguration; + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + //action = (EditProxyConnectorAction) lookup( Action.class.getName(), "editProxyConnectorAction" ); + action = (EditProxyConnectorAction) getActionProxy( "/admin/editProxyConnector.action" ).getAction(); + + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + action.setArchivaConfiguration( archivaConfiguration ); + + /* Configuration will be requested at least 3 times. */ + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( new Configuration(), 3 ); + + ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + } + + private void expectConfigurationRequests( int requestConfigCount ) + throws RegistryException, IndeterminateConfigurationException + { + expectConfigurationRequests( requestConfigCount, 1 ); + } + + private void expectConfigurationRequests( int requestConfigCount, int saveRequestCount ) + throws RegistryException, IndeterminateConfigurationException + { + Configuration config = createInitialConfiguration(); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( config, requestConfigCount ); + + for ( int i = 0; i <= saveRequestCount; i++ ) + { + archivaConfiguration.save( config ); + } + } + public void testAddBlackListPattern() throws Exception { @@ -68,7 +117,7 @@ public class EditProxyConnectorActionTest action.setSource( TEST_SOURCE_ID ); action.setTarget( TEST_TARGET_ID ); action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); assertInitialProxyConnector( connector ); // Perform Test w/no values. @@ -101,7 +150,7 @@ public class EditProxyConnectorActionTest action.setSource( TEST_SOURCE_ID ); action.setTarget( TEST_TARGET_ID ); action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); assertInitialProxyConnector( connector ); // Perform Test w/no values. @@ -136,7 +185,7 @@ public class EditProxyConnectorActionTest action.setSource( TEST_SOURCE_ID ); action.setTarget( TEST_TARGET_ID ); action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); assertInitialProxyConnector( connector ); // Perform Test w/no values. @@ -159,21 +208,23 @@ public class EditProxyConnectorActionTest assertEquals( 1, connector.getWhiteListPatterns().size() ); } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) public void testEditProxyConnectorCommit() throws Exception { - expectConfigurationRequests( 7 ); + expectConfigurationRequests( 9, 2 ); archivaConfigurationControl.replay(); // Prepare Test. action.setSource( TEST_SOURCE_ID ); action.setTarget( TEST_TARGET_ID ); action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); assertInitialProxyConnector( connector ); // forms will use an array - connector.getProperties().put( "eat-a", new String[] { "gramov-a-bits" } ); + //connector.getProperties().put( "eat-a", new String[]{ "gramov-a-bits" } ); + // FIXME check the array mode + connector.getProperties().put( "eat-a", "gramov-a-bits" ); // Create the input screen. assertRequestStatus( action, Action.SUCCESS, "commit" ); @@ -203,7 +254,7 @@ public class EditProxyConnectorActionTest action.setSource( TEST_SOURCE_ID ); action.setTarget( TEST_TARGET_ID ); action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); assertInitialProxyConnector( connector ); String status = action.input(); @@ -220,7 +271,7 @@ public class EditProxyConnectorActionTest action.setSource( TEST_SOURCE_ID ); action.setTarget( TEST_TARGET_ID ); action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); assertInitialProxyConnector( connector ); // Add some arbitrary blacklist patterns. @@ -268,7 +319,7 @@ public class EditProxyConnectorActionTest action.setSource( TEST_SOURCE_ID ); action.setTarget( TEST_TARGET_ID ); action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); assertInitialProxyConnector( connector ); // Add some arbitrary properties. @@ -316,7 +367,7 @@ public class EditProxyConnectorActionTest action.setSource( TEST_SOURCE_ID ); action.setTarget( TEST_TARGET_ID ); action.prepare(); - ProxyConnectorConfiguration connector = action.getConnector(); + ProxyConnector connector = action.getConnector(); assertInitialProxyConnector( connector ); // Add some arbitrary whitelist patterns. @@ -365,7 +416,7 @@ public class EditProxyConnectorActionTest assertEquals( 1, bundle.getAuthorizationTuples().size() ); } - private void assertInitialProxyConnector( ProxyConnectorConfiguration connector ) + private void assertInitialProxyConnector( ProxyConnector connector ) { assertNotNull( connector ); assertNotNull( connector.getBlackListPatterns() ); @@ -376,7 +427,7 @@ public class EditProxyConnectorActionTest assertEquals( TEST_TARGET_ID, connector.getTargetRepoId() ); } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) private Configuration createInitialConfiguration() { Configuration config = new Configuration(); @@ -397,7 +448,7 @@ public class EditProxyConnectorActionTest ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration(); connector.setSourceRepoId( TEST_SOURCE_ID ); connector.setTargetRepoId( TEST_TARGET_ID ); - + // TODO: Set these options programatically via list of available policies. Map policies = connector.getPolicies(); policies.put( "releases", new ReleasesPolicy().getDefaultOption() ); @@ -411,39 +462,4 @@ public class EditProxyConnectorActionTest return config; } - - private void expectConfigurationRequests( int requestConfigCount ) - throws RegistryException, IndeterminateConfigurationException - { - Configuration config = createInitialConfiguration(); - - for ( int i = 0; i < requestConfigCount; i++ ) - { - archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( config ); - } - - archivaConfiguration.save( config ); - } - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - //action = (EditProxyConnectorAction) lookup( Action.class.getName(), "editProxyConnectorAction" ); - action = (EditProxyConnectorAction) getActionProxy( "/admin/editProxyConnector.action" ).getAction(); - - archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); - archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); - action.setArchivaConfiguration( archivaConfiguration ); - - /* Configuration will be requested at least 3 times. */ - for ( int i = 0; i < 3; i++ ) - { - archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( new Configuration() ); - } - } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EnableProxyConnectorActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EnableProxyConnectorActionTest.java index 0f21df77a..1dfa3fce4 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EnableProxyConnectorActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EnableProxyConnectorActionTest.java @@ -18,6 +18,9 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; import com.opensymphony.xwork2.Action; +import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin; +import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; @@ -29,25 +32,51 @@ import org.codehaus.plexus.registry.RegistryException; import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.easymock.MockControl; -public class EnableProxyConnectorActionTest extends AbstractWebworkTestCase +public class EnableProxyConnectorActionTest + extends AbstractWebworkTestCase { private static final String TEST_TARGET_ID = "central"; private static final String TEST_SOURCE_ID = "corporate"; - + private EnableProxyConnectorAction action; - + private MockControl archivaConfigurationControl; private ArchivaConfiguration archivaConfiguration; - public void testConfirmDeleteBadSourceOrTarget() + @Override + protected void setUp() + throws Exception + { + super.setUp(); + action = (EnableProxyConnectorAction) getActionProxy( "/admin/enableProxyConnector.action" ).getAction(); + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration( archivaConfiguration ); + } + + private void expectConfigurationRequests( int requestConfigCount ) + throws RegistryException, IndeterminateConfigurationException + { + Configuration config = createInitialConfiguration(); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( config, requestConfigCount ); + archivaConfiguration.save( config ); + } + + public void testConfirmDeleteBadSourceOrTarget() throws Exception { expectConfigurationRequests( 4 ); archivaConfigurationControl.replay(); - // Attempt to show the confirm enable screen, but provide + // Attempt to show the confirm enable screen, but provide // a bad source id or target id to actually enable preRequest( action ); @@ -81,7 +110,7 @@ public class EnableProxyConnectorActionTest extends AbstractWebworkTestCase expectConfigurationRequests( 1 ); archivaConfigurationControl.replay(); - // Attempt to show the confirm enable screen, but don't provide + // Attempt to show the confirm enable screen, but don't provide // the source id or target id to actually delete preRequest( action ); @@ -132,8 +161,9 @@ public class EnableProxyConnectorActionTest extends AbstractWebworkTestCase // Test the configuration. assertEquals( 1, archivaConfiguration.getConfiguration().getProxyConnectors().size() ); - ProxyConnectorConfiguration config = (ProxyConnectorConfiguration)archivaConfiguration.getConfiguration().getProxyConnectors().get(0); - assertFalse(config.isDisabled()); + ProxyConnectorConfiguration config = + (ProxyConnectorConfiguration) archivaConfiguration.getConfiguration().getProxyConnectors().get( 0 ); + assertFalse( config.isDisabled() ); } public void testSecureActionBundle() @@ -146,7 +176,7 @@ public class EnableProxyConnectorActionTest extends AbstractWebworkTestCase assertTrue( bundle.requiresAuthentication() ); assertEquals( 1, bundle.getAuthorizationTuples().size() ); } - + public void testConfirmEnable() throws Exception { @@ -161,7 +191,7 @@ public class EnableProxyConnectorActionTest extends AbstractWebworkTestCase assertEquals( Action.INPUT, status ); assertNoErrors( action ); } - + private Configuration createInitialConfiguration() { Configuration config = new Configuration(); @@ -182,38 +212,10 @@ public class EnableProxyConnectorActionTest extends AbstractWebworkTestCase ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration(); connector.setSourceRepoId( TEST_SOURCE_ID ); connector.setTargetRepoId( TEST_TARGET_ID ); - connector.setDisabled(true); + connector.setDisabled( true ); config.addProxyConnector( connector ); return config; } - - private void expectConfigurationRequests( int requestConfigCount ) - throws RegistryException, IndeterminateConfigurationException - { - Configuration config = createInitialConfiguration(); - - for ( int i = 0; i < requestConfigCount; i++ ) - { - archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( config ); - } - - archivaConfiguration.save( config ); - } - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - //action = (EnableProxyConnectorAction) lookup( Action.class.getName(), "enableProxyConnectorAction" ); - - action = (EnableProxyConnectorAction) getActionProxy( "/admin/enableProxyConnector.action" ).getAction(); - archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); - archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); - action.setArchivaConfiguration( archivaConfiguration ); - } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ProxyConnectorsActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ProxyConnectorsActionTest.java index a73607bb5..91fb44b19 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ProxyConnectorsActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ProxyConnectorsActionTest.java @@ -21,6 +21,9 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; import com.opensymphony.xwork2.Action; +import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin; +import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; @@ -58,19 +61,21 @@ public class ProxyConnectorsActionTest { super.setUp(); - //action = (ProxyConnectorsAction) lookup( Action.class.getName(), "proxyConnectorsAction" ); - action = (ProxyConnectorsAction) getActionProxy("/admin/proxyConnectors.action" ).getAction(); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); - action.setArchivaConfiguration( archivaConfiguration ); + ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration( archivaConfiguration ); } public void testSecureActionBundle() throws Exception { - expectConfigurationRequests( 3 ); + expectConfigurationRequests( 4 ); archivaConfigurationControl.replay(); action.prepare(); @@ -82,7 +87,7 @@ public class ProxyConnectorsActionTest public void testExecute() throws Exception { - expectConfigurationRequests( 3 ); + expectConfigurationRequests( 5 ); archivaConfigurationControl.replay(); action.prepare(); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/SortProxyConnectorsActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/SortProxyConnectorsActionTest.java index bb0d3ac0c..6149fd19c 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/SortProxyConnectorsActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/SortProxyConnectorsActionTest.java @@ -20,6 +20,9 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy; */ import com.opensymphony.xwork2.Action; +import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin; +import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; @@ -58,6 +61,35 @@ public class SortProxyConnectorsActionTest private ArchivaConfiguration archivaConfiguration; + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + action = (SortProxyConnectorsAction) getActionProxy( "/admin/sortUpProxyConnector.action" ).getAction(); + + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration( + archivaConfiguration ); + } + + private void expectConfigurationRequests( int requestConfigCount ) + throws RegistryException, IndeterminateConfigurationException + { + Configuration config = createInitialConfiguration(); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( config, requestConfigCount ); + + archivaConfiguration.save( config ); + } + public void testSecureActionBundle() throws Exception { @@ -221,32 +253,4 @@ public class SortProxyConnectorsActionTest return config; } - - private void expectConfigurationRequests( int requestConfigCount ) - throws RegistryException, IndeterminateConfigurationException - { - Configuration config = createInitialConfiguration(); - - for ( int i = 0; i < requestConfigCount; i++ ) - { - archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( config ); - } - - archivaConfiguration.save( config ); - } - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - //action = (SortProxyConnectorsAction) lookup( Action.class.getName(), "sortProxyConnectorsAction" ); - action = (SortProxyConnectorsAction) getActionProxy( "/admin/sortUpProxyConnector.action" ).getAction(); - - archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); - archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); - action.setArchivaConfiguration( archivaConfiguration ); - } } diff --git a/archiva-modules/pom.xml b/archiva-modules/pom.xml index f38236274..f228472d8 100644 --- a/archiva-modules/pom.xml +++ b/archiva-modules/pom.xml @@ -36,16 +36,6 @@ metadata plugins - - - - org.mockito - mockito-all - 1.8.3 - test - - - diff --git a/pom.xml b/pom.xml index 135ccf522..f4327e557 100644 --- a/pom.xml +++ b/pom.xml @@ -464,6 +464,16 @@ net.sf.beanlib beanlib 5.0.2beta + + + cglib + cglib + + + aopalliance + aopalliance + + commons-codec @@ -565,6 +575,11 @@ + + jpox + jpox-ehcache + 1.1.9 + javax.servlet jsp-api @@ -1244,9 +1259,10 @@ test - jpox - jpox-ehcache - 1.1.9 + org.mockito + mockito-core + 1.8.3 + test -- 2.39.5