diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonConfigurationException.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonConfigurationException.java new file mode 100644 index 0000000000..1f9a17da7c --- /dev/null +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonConfigurationException.java @@ -0,0 +1,60 @@ +package org.apache.maven.artifact.manager; + +/* + * 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.maven.wagon.TransferFailedException; + + +public class WagonConfigurationException + extends TransferFailedException +{ + + static final long serialVersionUID = 1; + + private final String originalMessage; + private final String repositoryId; + + public WagonConfigurationException( String repositoryId, String message, Throwable cause ) + { + super( "While configuring wagon for \'" + repositoryId + "\': " + message, cause ); + + this.repositoryId = repositoryId; + this.originalMessage = message; + } + + public WagonConfigurationException( String repositoryId, String message ) + { + super( "While configuring wagon for \'" + repositoryId + "\': " + message ); + + this.repositoryId = repositoryId; + this.originalMessage = message; + } + + public final String getRepositoryId() + { + return repositoryId; + } + + public final String getOriginalMessage() + { + return originalMessage; + } + +} diff --git a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java new file mode 100644 index 0000000000..a6dcfcf2d4 --- /dev/null +++ b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java @@ -0,0 +1,150 @@ +package org.apache.maven.artifact.manager; + +/* + * 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.maven.wagon.UnsupportedProtocolException; +import org.apache.maven.wagon.Wagon; +import org.apache.maven.wagon.repository.Repository; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +/** + * @author Michal Maczka + * @version $Id$ + */ +public class DefaultWagonManagerTest + extends PlexusTestCase +{ + + private WagonManager wagonManager; + + protected void setUp() + throws Exception + { + super.setUp(); + + wagonManager = (WagonManager) lookup( WagonManager.ROLE ); + } + + public void testDefaultWagonManager() + throws Exception + { + assertWagon( "a" ); + + assertWagon( "b1" ); + + assertWagon( "b2" ); + + assertWagon( "c" ); + + try + { + assertWagon( "d" ); + + fail( "Expected :" + UnsupportedProtocolException.class.getName() ); + } + catch ( UnsupportedProtocolException e ) + { + //ok + assertTrue( true ); + } + } + + public void testGetWagonRepository() + throws Exception + { + assertWagonRepository( "a" ); + + assertWagonRepository( "b1" ); + + assertWagonRepository( "b2" ); + + assertWagonRepository( "c" ); + + try + { + assertWagonRepository( "d" ); + + fail( "Expected :" + UnsupportedProtocolException.class.getName() ); + } + catch ( UnsupportedProtocolException e ) + { + //ok + assertTrue( true ); + } + } + + public void testGetWagonRepositoryNullProtocol() + throws Exception + { + try + { + Repository repository = new Repository(); + + repository.setProtocol( null ); + + Wagon wagon = (Wagon) wagonManager.getWagon( repository ); + + fail( "Expected :" + UnsupportedProtocolException.class.getName() ); + } + catch ( UnsupportedProtocolException e ) + { + //ok + assertTrue( true ); + } + } + + private void assertWagon( String protocol ) + throws Exception + { + Wagon wagon = wagonManager.getWagon( protocol ); + + assertNotNull( "Check wagon, protocol=" + protocol, wagon ); + } + + private void assertWagonRepository( String protocol ) + throws Exception + { + Repository repository = new Repository(); + + String s = "value=" + protocol; + + repository.setId( "id=" + protocol ); + + repository.setProtocol( protocol ); + + Xpp3Dom conf = new Xpp3Dom( "configuration" ); + + Xpp3Dom configurableField = new Xpp3Dom( "configurableField" ); + + configurableField.setValue( s ); + + conf.addChild( configurableField ); + + wagonManager.addConfiguration( repository.getId(), conf ); + + WagonMock wagon = (WagonMock) wagonManager.getWagon( repository ); + + assertNotNull( "Check wagon, protocol=" + protocol, wagon ); + + assertEquals( "Check configuration for wagon, protocol=" + protocol, s, wagon.getConfigurableField() ); + } + +}