1 package org.apache.maven.archiva.web.action;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import com.opensymphony.xwork2.Action;
23 import org.apache.archiva.metadata.model.ArtifactMetadata;
24 import org.apache.archiva.metadata.repository.MetadataRepository;
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
27 import org.apache.maven.archiva.configuration.Configuration;
28 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
29 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
30 import org.apache.maven.archiva.repository.RepositoryContentFactory;
31 import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
32 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
33 import org.easymock.MockControl;
34 import org.easymock.classextension.MockClassControl;
37 import java.util.ArrayList;
38 import java.util.Collection;
40 public class DeleteArtifactActionTest
41 extends PlexusInSpringTestCase
43 private DeleteArtifactAction action;
45 private ArchivaConfiguration configuration;
47 private MockControl configurationControl;
49 private RepositoryContentFactory repositoryFactory;
51 private MockControl repositoryFactoryControl;
53 private MetadataRepository metadataRepository;
55 private MockControl metadataRepositoryControl;
57 private static final String REPOSITORY_ID = "test-repo";
59 private static final String GROUP_ID = "org.apache.archiva";
61 private static final String ARTIFACT_ID = "npe-metadata";
63 private static final String VERSION = "1.0";
65 private static final String REPO_LOCATION = getBasedir() + "/target/test-classes/test-repo";
68 protected void setUp()
73 action = (DeleteArtifactAction) lookup( Action.class.getName(), "deleteArtifactAction" );
74 assertNotNull( action );
76 configurationControl = MockControl.createControl( ArchivaConfiguration.class );
77 configuration = ( ArchivaConfiguration ) configurationControl.getMock();
79 repositoryFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
80 repositoryFactory = ( RepositoryContentFactory ) repositoryFactoryControl.getMock();
82 metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
83 metadataRepository = ( MetadataRepository ) metadataRepositoryControl.getMock();
85 action.setConfiguration( configuration );
86 action.setRepositoryFactory( repositoryFactory );
87 action.setMetadataRepository( metadataRepository );
91 protected void tearDown()
99 public void testGetListeners()
102 assertNotNull( action.getListeners() );
103 assertFalse( action.getListeners().isEmpty() );
106 public void testNPEInDeleteArtifact()
109 action.setGroupId( GROUP_ID );
110 action.setArtifactId( ARTIFACT_ID );
111 action.setVersion( VERSION );
112 action.setRepositoryId( REPOSITORY_ID );
114 Configuration config = createConfiguration();
116 ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
117 repoContent.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
119 configurationControl.expectAndReturn( configuration.getConfiguration(), config );
120 repositoryFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( REPOSITORY_ID ), repoContent );
121 metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( REPOSITORY_ID, GROUP_ID, ARTIFACT_ID, VERSION ),
122 new ArrayList<ArtifactMetadata>() );
124 configurationControl.replay();
125 repositoryFactoryControl.replay();
126 metadataRepositoryControl.replay();
130 String artifactPath = REPO_LOCATION + "/" + StringUtils.replace( GROUP_ID, ".", "/" ) + "/" +
131 StringUtils.replace( ARTIFACT_ID, ".", "/" ) + "/" + VERSION + "/" + ARTIFACT_ID + "-" + VERSION;
133 assertFalse( new File( artifactPath + ".jar" ).exists() );
134 assertFalse( new File( artifactPath + ".jar.sha1" ).exists() );
135 assertFalse( new File( artifactPath + ".jar.md5" ).exists() );
137 assertFalse( new File( artifactPath + ".pom" ).exists() );
138 assertFalse( new File( artifactPath + ".pom.sha1" ).exists() );
139 assertFalse( new File( artifactPath + ".pom.md5" ).exists() );
142 private Configuration createConfiguration()
144 ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
145 managedRepo.setId( REPOSITORY_ID );
146 managedRepo.setName( "Test Repository" );
148 managedRepo.setLocation( REPO_LOCATION );
149 managedRepo.setReleases( true );
151 Configuration config = new Configuration();
152 config.addManagedRepository( managedRepo );