From 2a795aa6bf69fc894e264c11cc33cd086254543c Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 7 Sep 2011 11:41:47 +0000 Subject: [PATCH] MRM-1507 : api to configure ProxyConnector : oops missed to add some files git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1166131 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractRepositoryConnector.java | 401 ++++++++++++++++++ .../DefaultProxyConnectorAdmin.java | 206 +++++++++ .../proxyconnector/ProxyConnector.java | 116 +++++ .../proxyconnector/ProxyConnectorAdmin.java | 46 ++ .../ProxyConnectorAdminTest.java | 126 ++++++ .../archiva-webapp/src/test/tomcat/log4j.xml | 81 ++++ 6 files changed, 976 insertions(+) create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryConnector.java create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnector.java create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdmin.java create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdminTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/test/tomcat/log4j.xml diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryConnector.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryConnector.java new file mode 100644 index 000000000..c5ecf32ec --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryConnector.java @@ -0,0 +1,401 @@ +package org.apache.archiva.admin.repository; +/* + * 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 java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +public abstract class AbstractRepositoryConnector + implements Serializable +{ + /** + * The Repository Source for this connector. + */ + private String sourceRepoId; + + /** + * The Repository Target for this connector. + */ + private String targetRepoId; + + /** + * The network proxy ID to use for this connector. + */ + private String proxyId; + + /** + * Field blackListPatterns. + */ + private List blackListPatterns; + + /** + * Field whiteListPatterns. + */ + private List whiteListPatterns; + + /** + * Field policies. + */ + private Map policies; + + /** + * Field properties. + */ + private Map properties; + + /** + * If the the repository proxy connector is disabled or not + */ + private boolean disabled = false; + + //-----------/ + //- Methods -/ + //-----------/ + + /** + * Method addBlackListPattern. + * + * @param string + */ + public void addBlackListPattern( String string ) + { + getBlackListPatterns().add( string ); + } + + /** + * Method addPolicy. + * + * @param key + * @param value + */ + public void addPolicy( String key, String value ) + { + getPolicies().put( key, value ); + } + + /** + * Method addProperty. + * + * @param key + * @param value + */ + public void addProperty( String key, String value ) + { + getProperties().put( key, value ); + } + + /** + * Method addWhiteListPattern. + * + * @param string + */ + public void addWhiteListPattern( String string ) + { + getWhiteListPatterns().add( string ); + } + + /** + * Method getBlackListPatterns. + * + * @return List + */ + public List getBlackListPatterns() + { + if ( this.blackListPatterns == null ) + { + this.blackListPatterns = new ArrayList(); + } + + return this.blackListPatterns; + } + + /** + * Method getPolicies. + * + * @return Map + */ + public Map getPolicies() + { + if ( this.policies == null ) + { + this.policies = new HashMap(); + } + + return this.policies; + } + + /** + * Method getProperties. + * + * @return Map + */ + public Map getProperties() + { + if ( this.properties == null ) + { + this.properties = new HashMap(); + } + + return this.properties; + } + + /** + * Get the network proxy ID to use for this connector. + * + * @return String + */ + public String getProxyId() + { + return this.proxyId; + } + + /** + * Get the Repository Source for this connector. + * + * @return String + */ + public String getSourceRepoId() + { + return this.sourceRepoId; + } + + /** + * Get the Repository Target for this connector. + * + * @return String + */ + public String getTargetRepoId() + { + return this.targetRepoId; + } + + /** + * Method getWhiteListPatterns. + * + * @return List + */ + public List getWhiteListPatterns() + { + if ( this.whiteListPatterns == null ) + { + this.whiteListPatterns = new ArrayList(); + } + + return this.whiteListPatterns; + } + + /** + * Get if the the repository proxy connector is disabled or not + * . + * + * @return boolean + */ + public boolean isDisabled() + { + return this.disabled; + } + + /** + * Method removeBlackListPattern. + * + * @param string + */ + public void removeBlackListPattern( String string ) + { + getBlackListPatterns().remove( string ); + } + + /** + * Method removeWhiteListPattern. + * + * @param string + */ + public void removeWhiteListPattern( String string ) + { + getWhiteListPatterns().remove( string ); + } + + /** + * Set the list of blacklisted patterns for this connector. + * + * @param blackListPatterns + */ + public void setBlackListPatterns( List blackListPatterns ) + { + this.blackListPatterns = blackListPatterns; + } + + /** + * Set if the the repository proxy connector is + * disabled or not + * . + * + * @param disabled + */ + public void setDisabled( boolean disabled ) + { + this.disabled = disabled; + } + + /** + * Set policy configuration for the connector. + * + * @param policies + */ + public void setPolicies( Map policies ) + { + this.policies = policies; + } + + /** + * Set configuration for the connector. + * + * @param properties + */ + public void setProperties( Map properties ) + { + this.properties = properties; + } + + /** + * Set the network proxy ID to use for this connector. + * + * @param proxyId + */ + public void setProxyId( String proxyId ) + { + this.proxyId = proxyId; + } + + /** + * Set the Repository Source for this connector. + * + * @param sourceRepoId + */ + public void setSourceRepoId( String sourceRepoId ) + { + this.sourceRepoId = sourceRepoId; + } + + /** + * Set the Repository Target for this connector. + * + * @param targetRepoId + */ + public void setTargetRepoId( String targetRepoId ) + { + this.targetRepoId = targetRepoId; + } + + /** + * Set + * The list of whitelisted patterns for this + * connector. + * + * @param whiteListPatterns + */ + public void setWhiteListPatterns( List whiteListPatterns ) + { + this.whiteListPatterns = whiteListPatterns; + } + + + /** + * Obtain a specific policy from the underlying connector. + * + * @param policyId the policy id to fetch. + * @param defaultValue the default value for the policy id. + * @return the configured policy value (or default value if not found). + */ + public String getPolicy( String policyId, String defaultValue ) + { + if ( this.getPolicies() == null ) + { + return null; + } + + String value = this.getPolicies().get( policyId ); + + if ( value == null ) + { + return defaultValue; + } + + return value; + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + AbstractRepositoryConnector that = (AbstractRepositoryConnector) o; + + if ( sourceRepoId != null ? !sourceRepoId.equals( that.sourceRepoId ) : that.sourceRepoId != null ) + { + return false; + } + if ( targetRepoId != null ? !targetRepoId.equals( that.targetRepoId ) : that.targetRepoId != null ) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = sourceRepoId != null ? sourceRepoId.hashCode() : 0; + result = 31 * result + ( targetRepoId != null ? targetRepoId.hashCode() : 0 ); + return result; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "AbstractRepositoryConnector" ); + sb.append( "{sourceRepoId='" ).append( sourceRepoId ).append( '\'' ); + sb.append( ", targetRepoId='" ).append( targetRepoId ).append( '\'' ); + sb.append( ", proxyId='" ).append( proxyId ).append( '\'' ); + sb.append( ", blackListPatterns=" ).append( blackListPatterns ); + sb.append( ", whiteListPatterns=" ).append( whiteListPatterns ); + sb.append( ", policies=" ).append( policies ); + sb.append( ", properties=" ).append( properties ); + sb.append( ", disabled=" ).append( disabled ); + sb.append( '}' ); + return sb.toString(); + } +} + 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 new file mode 100644 index 000000000..03ae1dfb9 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java @@ -0,0 +1,206 @@ +package org.apache.archiva.admin.repository.proxyconnector; +/* + * 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 org.apache.archiva.admin.AuditInformation; +import org.apache.archiva.admin.repository.AbstractRepositoryAdmin; +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.remote.RemoteRepositoryAdmin; +import org.apache.archiva.audit.AuditEvent; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; +import org.apache.maven.archiva.configuration.functors.ProxyConnectorSelectionPredicate; +import org.springframework.stereotype.Service; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +@Service( "proxyConnectorAdmin#default" ) +public class DefaultProxyConnectorAdmin + extends AbstractRepositoryAdmin + implements ProxyConnectorAdmin +{ + + @Inject + private ManagedRepositoryAdmin managedRepositoryAdmin; + + @Inject + private RemoteRepositoryAdmin remoteRepositoryAdmin; + + public List getProxyConnectors() + throws RepositoryAdminException + { + List proxyConnectorConfigurations = + getArchivaConfiguration().getConfiguration().getProxyConnectors(); + List proxyConnectors = new ArrayList( proxyConnectorConfigurations.size() ); + for ( ProxyConnectorConfiguration configuration : proxyConnectorConfigurations ) + { + ProxyConnector proxyConnector = new ProxyConnector(); + proxyConnectors.add( proxyConnector ); + proxyConnector.setOrder( configuration.getOrder() ); + proxyConnector.setBlackListPatterns( new ArrayList( configuration.getBlackListPatterns() ) ); + proxyConnector.setWhiteListPatterns( new ArrayList( configuration.getWhiteListPatterns() ) ); + proxyConnector.setDisabled( configuration.isDisabled() ); + proxyConnector.setPolicies( new HashMap( configuration.getPolicies() ) ); + proxyConnector.setProperties( new HashMap( configuration.getProperties() ) ); + proxyConnector.setProxyId( configuration.getProxyId() ); + proxyConnector.setSourceRepoId( configuration.getSourceRepoId() ); + proxyConnector.setTargetRepoId( configuration.getTargetRepoId() ); + } + + return proxyConnectors; + } + + public ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId ) + throws RepositoryAdminException + { + for ( ProxyConnector proxyConnector : getProxyConnectors() ) + { + if ( StringUtils.equals( sourceRepoId, proxyConnector.getSourceRepoId() ) && StringUtils.equals( + targetRepoId, proxyConnector.getTargetRepoId() ) ) + { + return proxyConnector; + } + } + return null; + } + + public Boolean addProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation ) + throws RepositoryAdminException + { + if ( getProxyConnector( proxyConnector.getSourceRepoId(), proxyConnector.getTargetRepoId() ) != null ) + { + throw new RepositoryAdminException( + "Unable to add proxy connector, as one already exists with source repository id [" + + proxyConnector.getSourceRepoId() + "] and target repository id [" + + proxyConnector.getTargetRepoId() + "]." ); + } + + validateProxyConnector( proxyConnector ); + + proxyConnector.setBlackListPatterns( unescapePatterns( proxyConnector.getBlackListPatterns() ) ); + proxyConnector.setWhiteListPatterns( unescapePatterns( proxyConnector.getWhiteListPatterns() ) ); + + Configuration configuration = getArchivaConfiguration().getConfiguration(); + + ProxyConnectorConfiguration proxyConnectorConfiguration = getProxyConnectorConfiguration( proxyConnector ); + configuration.addProxyConnector( proxyConnectorConfiguration ); + saveConfiguration( configuration ); + triggerAuditEvent( proxyConnector.getSourceRepoId() + "-" + proxyConnector.getTargetRepoId(), null, + AuditEvent.ADD_PROXY_CONNECTOR, auditInformation ); + return Boolean.TRUE; + + } + + public Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation ) + throws RepositoryAdminException + { + Configuration configuration = getArchivaConfiguration().getConfiguration(); + ProxyConnectorConfiguration proxyConnectorConfiguration = + findProxyConnector( proxyConnector.getSourceRepoId(), proxyConnector.getTargetRepoId(), configuration ); + if ( proxyConnectorConfiguration == null ) + { + throw new RepositoryAdminException( + "unable to find ProxyConnector with source " + proxyConnector.getSourceRepoId() + " and target " + + proxyConnector.getTargetRepoId() ); + } + configuration.removeProxyConnector( proxyConnectorConfiguration ); + saveConfiguration( configuration ); + triggerAuditEvent( proxyConnector.getSourceRepoId() + "-" + proxyConnector.getTargetRepoId(), null, + AuditEvent.DELETE_PROXY_CONNECTOR, auditInformation ); + return Boolean.TRUE; + } + + protected List unescapePatterns( List patterns ) + { + List rawPatterns = new ArrayList(); + if ( patterns != null ) + { + for ( String pattern : patterns ) + { + rawPatterns.add( StringUtils.replace( pattern, "\\\\", "\\" ) ); + } + } + + return rawPatterns; + } + + protected ProxyConnectorConfiguration findProxyConnector( String sourceId, String targetId, + Configuration configuration ) + { + if ( StringUtils.isBlank( sourceId ) ) + { + return null; + } + + if ( StringUtils.isBlank( targetId ) ) + { + return null; + } + + ProxyConnectorSelectionPredicate selectedProxy = new ProxyConnectorSelectionPredicate( sourceId, targetId ); + return (ProxyConnectorConfiguration) CollectionUtils.find( configuration.getProxyConnectors(), selectedProxy ); + } + + protected ProxyConnectorConfiguration getProxyConnectorConfiguration( ProxyConnector proxyConnector ) + { + ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration(); + proxyConnectorConfiguration.setOrder( proxyConnector.getOrder() ); + proxyConnectorConfiguration.setBlackListPatterns( + new ArrayList( proxyConnector.getBlackListPatterns() ) ); + proxyConnectorConfiguration.setWhiteListPatterns( + new ArrayList( proxyConnector.getWhiteListPatterns() ) ); + proxyConnectorConfiguration.setDisabled( proxyConnector.isDisabled() ); + proxyConnectorConfiguration.setPolicies( new HashMap( proxyConnector.getPolicies() ) ); + proxyConnectorConfiguration.setProperties( new HashMap( proxyConnector.getProperties() ) ); + proxyConnectorConfiguration.setProxyId( proxyConnector.getProxyId() ); + proxyConnectorConfiguration.setSourceRepoId( proxyConnector.getSourceRepoId() ); + proxyConnectorConfiguration.setTargetRepoId( proxyConnector.getTargetRepoId() ); + return proxyConnectorConfiguration; + } + + protected void validateProxyConnector( ProxyConnector proxyConnector ) + throws RepositoryAdminException + { + // validate source a Managed target a Remote + if ( managedRepositoryAdmin.getManagedRepository( proxyConnector.getSourceRepoId() ) == null ) + { + throw new RepositoryAdminException( + "non valid ProxyConnector sourceRepo with id " + proxyConnector.getSourceRepoId() + + " is not a ManagedRepository" ); + } + if ( remoteRepositoryAdmin.getRemoteRepository( proxyConnector.getTargetRepoId() ) == null ) + { + throw new RepositoryAdminException( + "non valid ProxyConnector sourceRepo with id " + proxyConnector.getTargetRepoId() + + " is not a RemoteRepository" ); + } + + // FIXME validate NetworkProxyConfiguration too + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnector.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnector.java new file mode 100644 index 000000000..5c811963b --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnector.java @@ -0,0 +1,116 @@ +package org.apache.archiva.admin.repository.proxyconnector; +/* + * 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 org.apache.archiva.admin.repository.AbstractRepositoryConnector; + +import java.io.Serializable; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +public class ProxyConnector + extends AbstractRepositoryConnector + implements Serializable +{ + /** + * The order id for UNORDERED + */ + public static final int UNORDERED = 0; + + /** + * The policy key {@link #getPolicies()} for error handling. + * See {@link org.apache.maven.archiva.policies.DownloadErrorPolicy} + * for details on potential values to this policy key. + */ + public static final String POLICY_PROPAGATE_ERRORS = "propagate-errors"; + + /** + * The policy key {@link #getPolicies()} for error handling when an artifact is present. + * See {@link org.apache.maven.archiva.policies.DownloadErrorPolicy} + * for details on potential values to this policy key. + */ + public static final String POLICY_PROPAGATE_ERRORS_ON_UPDATE = "propagate-errors-on-update"; + + /** + * The policy key {@link #getPolicies()} for snapshot handling. + * See {@link org.apache.maven.archiva.policies.SnapshotsPolicy} + * for details on potential values to this policy key. + */ + public static final String POLICY_SNAPSHOTS = "snapshots"; + + /** + * The policy key {@link #getPolicies()} for releases handling. + * See {@link org.apache.maven.archiva.policies.ReleasesPolicy} + * for details on potential values to this policy key. + */ + public static final String POLICY_RELEASES = "releases"; + + /** + * The policy key {@link #getPolicies()} for checksum handling. + * See {@link org.apache.maven.archiva.policies.ChecksumPolicy} + * for details on potential values to this policy key. + */ + public static final String POLICY_CHECKSUM = "checksum"; + + /** + * The policy key {@link #getPolicies()} for cache-failures handling. + * See {@link org.apache.maven.archiva.policies.CachedFailuresPolicy} + * for details on potential values to this policy key. + */ + public static final String POLICY_CACHE_FAILURES = "cache-failures"; + +/** + * + * The order of the proxy connectors. (0 means no order specified) + * . + */ + private int order = 0; + + /** + * Get the order of the proxy connectors. (0 means no order specified) + * @return int + */ + public int getOrder() + { + return this.order; + } + + + /** + * Set the order of the proxy connectors. (0 means no order specified) + * @param order + */ + public void setOrder( int order ) + { + this.order = order; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "ProxyConnector" ); + sb.append( "{order=" ).append( order ); + sb.append( '}' ); + sb.append( super.toString() ); + return sb.toString(); + } +} 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 new file mode 100644 index 000000000..e598eb28f --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdmin.java @@ -0,0 +1,46 @@ +package org.apache.archiva.admin.repository.proxyconnector; +/* + * 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 org.apache.archiva.admin.AuditInformation; +import org.apache.archiva.admin.repository.RepositoryAdminException; + +import java.util.List; + +/** + * No update method here as id is : sourceRepoId and targetRepoId, use delete then add. + * + * @author Olivier Lamy + * @since 1.4 + */ +public interface ProxyConnectorAdmin +{ + List getProxyConnectors() + throws RepositoryAdminException; + + ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId ) + throws RepositoryAdminException; + + Boolean addProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation ) + throws RepositoryAdminException; + + Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation ) + 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 new file mode 100644 index 000000000..4cedef2b0 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdminTest.java @@ -0,0 +1,126 @@ +package org.apache.archiva.admin.repository.proxyconnector; +/* + * 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 org.apache.archiva.admin.repository.AbstractRepositoryAdminTest; +import org.apache.archiva.admin.repository.remote.RemoteRepository; +import org.apache.archiva.audit.AuditEvent; +import org.junit.Test; + +/** + * @author Olivier Lamy + */ +public class ProxyConnectorAdminTest + extends AbstractRepositoryAdminTest +{ + + @Test + public void addAndDelete() + throws Exception + { + assertEquals( "not proxyConnectors 2 " + proxyConnectorAdmin.getProxyConnectors(), 2, + proxyConnectorAdmin.getProxyConnectors().size() ); + assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() ); + ProxyConnector proxyConnector = new ProxyConnector(); + proxyConnector.setSourceRepoId( "snapshots" ); + proxyConnector.setTargetRepoId( "central" ); + proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() ); + + assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() ); + assertEquals( 3, proxyConnectorAdmin.getProxyConnectors().size() ); + + assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) ); + + proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() ); + + assertEquals( 2, proxyConnectorAdmin.getProxyConnectors().size() ); + assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() ); + + assertEquals( 2, mockAuditListener.getAuditEvents().size() ); + + assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 0 ).getAction() ); + assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() ); + assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() ); + + assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 1 ).getAction() ); + assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() ); + + assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) ); + + mockAuditListener.clearEvents(); + } + + @Test + public void addAndUpdateAndDelete() + throws Exception + { + + RemoteRepository remoteRepository = getRemoteRepository( "test-new-one" ); + + remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() ); + + assertEquals( "not proxyConnectors 2 " + proxyConnectorAdmin.getProxyConnectors(), 2, + proxyConnectorAdmin.getProxyConnectors().size() ); + assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() ); + ProxyConnector proxyConnector = new ProxyConnector(); + proxyConnector.setSourceRepoId( "snapshots" ); + proxyConnector.setTargetRepoId( "central" ); + proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() ); + + assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() ); + assertEquals( 3, proxyConnectorAdmin.getProxyConnectors().size() ); + + assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) ); + + proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() ); + + proxyConnector.setTargetRepoId( remoteRepository.getId() ); + proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() ); + + assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) ); + assertNotNull( remoteRepository.getId(), + proxyConnectorAdmin.getProxyConnector( "snapshots", remoteRepository.getId() ) ); + + proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() ); + + assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) ); + + assertEquals( 2, proxyConnectorAdmin.getProxyConnectors().size() ); + assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() ); + + assertEquals( 5, mockAuditListener.getAuditEvents().size() ); + + assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() ); + + assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 1 ).getAction() ); + assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() ); + assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 2 ).getRemoteIP() ); + + assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 2 ).getAction() ); + + assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 3 ).getAction() ); + + assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 4 ).getAction() ); + assertEquals( "root", mockAuditListener.getAuditEvents().get( 4 ).getUserId() ); + + remoteRepositoryAdmin.deleteRemoteRepository( remoteRepository.getId(), getFakeAuditInformation() ); + mockAuditListener.clearEvents(); + } + +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/tomcat/log4j.xml b/archiva-modules/archiva-web/archiva-webapp/src/test/tomcat/log4j.xml new file mode 100644 index 000000000..e8c1e7545 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/tomcat/log4j.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.39.5