Browse Source

[MRM-265]

- added method for deleting the artifacts in the db when a repo is deleted
- also deleted repo scan statistics when the repo is deleted
- created DAO that does retrieving, deleting and adding of RepositoryContentStatistics to the db
- added and updated tests



git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@586919 13f79535-47bb-0310-9956-ffa450edef68
tags/archiva-1.0-beta-3
Maria Odea B. Ching 16 years ago
parent
commit
21a61ab5f9
15 changed files with 754 additions and 24 deletions
  1. 1
    2
      archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java
  2. 5
    1
      archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java
  3. 49
    0
      archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraint.java
  4. 13
    1
      archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java
  5. 67
    0
      archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAO.java
  6. 79
    0
      archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraintTest.java
  7. 84
    0
      archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAOTest.java
  8. 3
    2
      archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java
  9. 86
    8
      archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java
  10. 11
    3
      archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java
  11. 90
    0
      archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java
  12. 25
    7
      archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java
  13. 85
    0
      archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryArchivaDAOStub.java
  14. 78
    0
      archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ProjectModelDAOStub.java
  15. 78
    0
      archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.xml

+ 1
- 2
archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java View File

@@ -166,8 +166,7 @@ public class ProjectModelToDatabaseConsumer

if ( isValidModel( model, repo, artifact ) )
{
getLogger().info( "Adding project model to database - " + Keys.toKey( model ) );

getLogger().info( "Adding project model to database - " + Keys.toKey( model ) );
dao.getProjectModelDAO().saveProjectModel( model );
}
else

+ 5
- 1
archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java View File

@@ -22,6 +22,8 @@ package org.apache.maven.archiva.database;
import java.io.Serializable;
import java.util.List;

import org.apache.maven.archiva.model.RepositoryContentStatistics;

/**
* ArchivaDAO - The interface for all content within the database.
*
@@ -47,10 +49,12 @@ public interface ArchivaDAO
* @return the post-serialized object.
*/
Object save( Serializable obj );
ArtifactDAO getArtifactDAO();

ProjectModelDAO getProjectModelDAO();

RepositoryProblemDAO getRepositoryProblemDAO();
RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO();
}

+ 49
- 0
archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraint.java View File

@@ -0,0 +1,49 @@
package org.apache.maven.archiva.database.constraints;

/*
* 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.
*/

/**
* RepositoryContentStatisticsByRepositoryConstraint
*
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
* @version
*/
public class RepositoryContentStatisticsByRepositoryConstraint
extends AbstractDeclarativeConstraint
{
private String whereClause;

public RepositoryContentStatisticsByRepositoryConstraint( String repoId )
{
whereClause = "repositoryId == repoId";
declParams = new String[] { "String repoId" };
params = new Object[] { repoId };
}

public String getSortColumn()
{
return "whenGathered";
}
public String getWhereCondition()
{
return whereClause;
}
}

+ 13
- 1
archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java View File

@@ -22,6 +22,7 @@ package org.apache.maven.archiva.database.jdo;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.ProjectModelDAO;
import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO;
import org.apache.maven.archiva.database.RepositoryProblemDAO;
import org.apache.maven.archiva.database.SimpleConstraint;
import org.codehaus.plexus.logging.AbstractLogEnabled;
@@ -60,6 +61,12 @@ public class JdoArchivaDAO
* @plexus.requirement role-hint="jdo"
*/
private RepositoryProblemDAO repositoryProblemDAO;
/**
* @plexus.requirement role-hint="jdo"
*/
private RepositoryContentStatisticsDAO repositoryContentStatisticsDAO;


public List query( SimpleConstraint constraint )
{
@@ -70,7 +77,7 @@ public class JdoArchivaDAO
{
return jdo.saveObject( obj );
}
public ArtifactDAO getArtifactDAO()
{
return artifactDAO;
@@ -85,4 +92,9 @@ public class JdoArchivaDAO
{
return repositoryProblemDAO;
}
public RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO()
{
return repositoryContentStatisticsDAO;
}
}

+ 67
- 0
archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAO.java View File

@@ -0,0 +1,67 @@
package org.apache.maven.archiva.database.jdo;

/*
* 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.util.List;

import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.Constraint;
import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO;
import org.apache.maven.archiva.model.RepositoryContentStatistics;

/**
* JdoRepositoryContentStatisticsDAO
*
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
* @version
*
* @plexus.component role-hint="jdo"
*/
public class JdoRepositoryContentStatisticsDAO
implements RepositoryContentStatisticsDAO
{
/**
* @plexus.requirement role-hint="archiva"
*/
private JdoAccess jdo;
public void deleteRepositoryContentStatistics( RepositoryContentStatistics stats )
throws ArchivaDatabaseException
{
jdo.removeObject( stats );
}

public List queryRepositoryContentStatistics( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException
{
List results = jdo.queryObjects( RepositoryContentStatistics.class, constraint );
return results;
}

public RepositoryContentStatistics saveRepositoryContentStatistics( RepositoryContentStatistics stats )
{
RepositoryContentStatistics savedStats = (RepositoryContentStatistics) jdo.saveObject( stats );
return savedStats;
}

}

+ 79
- 0
archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraintTest.java View File

@@ -0,0 +1,79 @@
package org.apache.maven.archiva.database.constraints;

/*
* 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.util.List;

import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
import org.apache.maven.archiva.database.Constraint;
import org.apache.maven.archiva.model.RepositoryContentStatistics;

/**
* RepositoryContentStatisticsByRepositoryConstraintTest
*
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
* @version
*/
public class RepositoryContentStatisticsByRepositoryConstraintTest
extends AbstractArchivaDatabaseTestCase
{
private RepositoryContentStatistics createStats( String repoId, String timestamp, long duration, long totalfiles,
long newfiles )
throws Exception
{
RepositoryContentStatistics stats = new RepositoryContentStatistics();
stats.setRepositoryId( repoId );
stats.setDuration( duration );
stats.setNewFileCount( newfiles );
stats.setTotalFileCount( totalfiles );
stats.setWhenGathered( toDate( timestamp ) );

return stats;
}

protected void setUp()
throws Exception
{
super.setUp();

dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics(
createStats( "internal", "2007/10/21 8:00:00", 20000, 12000, 400 ) );
dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics(
createStats( "internal", "2007/10/20 8:00:00", 20000, 11800, 0 ) );
dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics(
createStats( "internal", "2007/10/19 8:00:00", 20000, 11800, 100 ) );
dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics(
createStats( "internal", "2007/10/18 8:00:00", 20000, 11700, 320 ) );
}

public void testStats()
throws Exception
{
Constraint constraint = new RepositoryContentStatisticsByRepositoryConstraint( "internal" );
List results = dao.getRepositoryContentStatisticsDAO().queryRepositoryContentStatistics( constraint );
assertNotNull( "Stats: results (not null)", results );
assertEquals( "Stats: results.size", 4, results.size() );

assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 0 ) ).getRepositoryId() );
assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 1 ) ).getRepositoryId() );
assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 2 ) ).getRepositoryId() );
assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 3 ) ).getRepositoryId() );
}
}

+ 84
- 0
archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAOTest.java View File

@@ -0,0 +1,84 @@
package org.apache.maven.archiva.database.jdo;

/*
* 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.util.List;

import javax.jdo.JDOHelper;

import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO;
import org.apache.maven.archiva.database.constraints.RepositoryContentStatisticsByRepositoryConstraint;
import org.apache.maven.archiva.model.RepositoryContentStatistics;

/**
* JdoRepositoryContentStatisticsDAOTest
*
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
* @version
*/
public class JdoRepositoryContentStatisticsDAOTest
extends AbstractArchivaDatabaseTestCase
{
public void testCRUD()
throws Exception
{
RepositoryContentStatisticsDAO repoContentStatisticsDAO = dao.getRepositoryContentStatisticsDAO();

// create
RepositoryContentStatistics savedStats =
repoContentStatisticsDAO.saveRepositoryContentStatistics( createStats( "internal", "2007/10/21 8:00:00",
20000, 12000, 400 ) );
assertNotNull( savedStats );

String savedKeyId = JDOHelper.getObjectId( savedStats ).toString();
assertEquals( "1[OID]org.apache.maven.archiva.model.RepositoryContentStatistics", savedKeyId );

// query
List results =
repoContentStatisticsDAO.queryRepositoryContentStatistics( new RepositoryContentStatisticsByRepositoryConstraint(
"internal" ) );
assertNotNull( results );
assertEquals( 1, results.size() );

RepositoryContentStatistics stats = (RepositoryContentStatistics) results.get( 0 );
assertEquals( "internal", stats.getRepositoryId() );

// delete
repoContentStatisticsDAO.deleteRepositoryContentStatistics( stats );

assertEquals( 0, repoContentStatisticsDAO.queryRepositoryContentStatistics(
new RepositoryContentStatisticsByRepositoryConstraint( "internal" ) ).size() );
}

private RepositoryContentStatistics createStats( String repoId, String timestamp, long duration, long totalfiles,
long newfiles )
throws Exception
{
RepositoryContentStatistics stats = new RepositoryContentStatistics();
stats.setRepositoryId( repoId );
stats.setDuration( duration );
stats.setNewFileCount( newfiles );
stats.setTotalFileCount( totalfiles );
stats.setWhenGathered( toDate( timestamp ) );

return stats;
}
}

+ 3
- 2
archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java View File

@@ -24,6 +24,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.constraints.MostRecentRepositoryScanStatistics;
import org.apache.maven.archiva.model.RepositoryContentStatistics;
import org.apache.maven.archiva.repository.RepositoryException;
@@ -114,11 +115,11 @@ public class ArchivaRepositoryScanningTaskExecutor
dbstats.setTotalFileCount( stats.getTotalFileCount() );
dbstats.setWhenGathered( stats.getWhenGathered() );
dao.save( dbstats );
dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( dbstats );
}
catch ( RepositoryException e )
{
throw new TaskExecutionException( "Repository error when executing repository job.", e );
}
}
}
}

+ 86
- 8
archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java View File

@@ -24,18 +24,29 @@ import com.opensymphony.xwork.Preparable;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;

import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.Constraint;
import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint;
import org.apache.maven.archiva.database.constraints.RepositoryContentStatisticsByRepositoryConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.RepositoryContentStatistics;

import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;

import org.codehaus.plexus.redback.role.RoleManagerException;

import java.io.IOException;
import java.util.List;

/**
* DeleteManagedRepositoryAction
*
* DeleteManagedRepositoryAction
*
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
* @version $Id$
*
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteManagedRepositoryAction"
*/
public class DeleteManagedRepositoryAction
@@ -46,6 +57,11 @@ public class DeleteManagedRepositoryAction

private String repoid;

/**
* @plexus.requirement role-hint="jdo"
*/
private ArchivaDAO archivaDAO;

public void prepare()
{
if ( StringUtils.isNotBlank( repoid ) )
@@ -89,13 +105,12 @@ public class DeleteManagedRepositoryAction
try
{
Configuration configuration = archivaConfiguration.getConfiguration();
cleanupRepositoryData( existingRepository );
removeRepository( repoid, configuration );
result = saveConfiguration( configuration );

if ( result.equals( SUCCESS ) )
{
cleanupRepositoryData( existingRepository );

if ( deleteContents )
{
removeContents( existingRepository );
@@ -112,19 +127,26 @@ public class DeleteManagedRepositoryAction
addActionError( "Unable to delete repository: " + e.getMessage() );
result = ERROR;
}
catch ( ArchivaDatabaseException e )
{
addActionError( "Unable to delete repositoy: " + e.getMessage() );
result = ERROR;
}

return result;
}

private void cleanupRepositoryData( ManagedRepositoryConfiguration cleanupRepository )
throws RoleManagerException
throws RoleManagerException, ArchivaDatabaseException
{
removeRepositoryRoles( cleanupRepository );

// TODO: [MRM-382] Remove index from artifacts of deleted managed repositories.

// TODO: [MRM-265] After removing a managed repository - Browse/Search still see it
// [MRM-265] After removing a managed repository - Browse/Search still see it
cleanupDatabase( cleanupRepository.getId() );
cleanupScanStats( cleanupRepository.getId() );

// [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
List<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
@@ -136,6 +158,52 @@ public class DeleteManagedRepositoryAction
}
}

private void cleanupDatabase( String repoId )
throws ArchivaDatabaseException
{
Constraint constraint = new ArtifactsByRepositoryConstraint( repoId );

List<ArchivaArtifact> artifacts = archivaDAO.getArtifactDAO().queryArtifacts( constraint );

for ( ArchivaArtifact artifact : artifacts )
{
getLogger().info( "Removing artifact " + artifact + " from the database." );
try
{
archivaDAO.getArtifactDAO().deleteArtifact( artifact );

ArchivaProjectModel projectModel =
archivaDAO.getProjectModelDAO().getProjectModel( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion() );

archivaDAO.getProjectModelDAO().deleteProjectModel( projectModel );
}
catch ( ObjectNotFoundException oe )
{
getLogger().info( "Project model of artifact " + artifact + " does not exist in the database. " +
"Moving on to the next artifact." );
}
catch ( ArchivaDatabaseException ae )
{
getLogger().info( "Unable to delete artifact " + artifact + " from the database. " +
"Moving on to the next artifact." );
}
}
}

private void cleanupScanStats( String repoId )
throws ArchivaDatabaseException
{
List<RepositoryContentStatistics> results =
archivaDAO.getRepositoryContentStatisticsDAO().queryRepositoryContentStatistics(
new RepositoryContentStatisticsByRepositoryConstraint( repoId ) );

for ( RepositoryContentStatistics stats : results )
{
archivaDAO.getRepositoryContentStatisticsDAO().deleteRepositoryContentStatistics( stats );
}
}

public ManagedRepositoryConfiguration getRepository()
{
return repository;
@@ -155,4 +223,14 @@ public class DeleteManagedRepositoryAction
{
this.repoid = repoid;
}

public void setArchivaDAO( ArchivaDAO archivaDAO )
{
this.archivaDAO = archivaDAO;
}

public ArchivaDAO getArchivaDAO()
{
return archivaDAO;
}
}

+ 11
- 3
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java View File

@@ -4,6 +4,7 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.ProjectModelDAO;
import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO;
import org.apache.maven.archiva.database.RepositoryProblemDAO;
import org.apache.maven.archiva.database.SimpleConstraint;
import org.apache.maven.archiva.model.RepositoryContentStatistics;
@@ -46,6 +47,7 @@ public class ArchivaDAOStub
public List query( SimpleConstraint constraint )
{
Assert.assertEquals( RepositoryContentStatistics.class, constraint.getResultClass() );

List<RepositoryContentStatistics> stats = new ArrayList<RepositoryContentStatistics>();
for ( String repo : configuration.getConfiguration().getManagedRepositoriesAsMap().keySet() )
@@ -64,16 +66,22 @@ public class ArchivaDAOStub

public ArtifactDAO getArtifactDAO()
{
throw new UnsupportedOperationException( "query not implemented for stub" );
throw new UnsupportedOperationException( "method not implemented for stub" );
}

public ProjectModelDAO getProjectModelDAO()
{
throw new UnsupportedOperationException( "query not implemented for stub" );
throw new UnsupportedOperationException( "method not implemented for stub" );
}

public RepositoryProblemDAO getRepositoryProblemDAO()
{
throw new UnsupportedOperationException( "query not implemented for stub" );
throw new UnsupportedOperationException( "method not implemented for stub" );
}
public RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO()
{
throw new UnsupportedOperationException( "method not implemented for stub" );
}
}

+ 90
- 0
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java View File

@@ -0,0 +1,90 @@
package org.apache.maven.archiva.web.action.admin.repositories;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import java.util.ArrayList;
import java.util.List;

import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.Constraint;
import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaArtifactModel;

/**
* ArtifactDAOStub
*
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
* @version
*/
public class ArtifactDAOStub
implements ArtifactDAO
{

public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier,
String type )
{
// TODO Auto-generated method stub
return null;
}

public void deleteArtifact( ArchivaArtifact artifact )
throws ArchivaDatabaseException
{
// TODO Auto-generated method stub

}

public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier,
String type )
throws ObjectNotFoundException, ArchivaDatabaseException
{
// TODO Auto-generated method stub
return null;
}

public List<ArchivaArtifact> queryArtifacts( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException
{

List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();

ArchivaArtifactModel model = new ArchivaArtifactModel();
model.setGroupId( "org.apache.maven.archiva" );
model.setArtifactId( "test-artifact" );
model.setVersion( "1.0" );
model.setType( "jar" );
model.setRepositoryId( "repo-ident" );

ArchivaArtifact artifact = new ArchivaArtifact( model );
artifacts.add( artifact );

return artifacts;
}

public ArchivaArtifact saveArtifact( ArchivaArtifact artifact )
throws ArchivaDatabaseException
{
// TODO Auto-generated method stub
return null;
}
}

+ 25
- 7
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java View File

@@ -25,8 +25,12 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;

import org.apache.maven.archiva.model.ArchivaProjectModel;

import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;

import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.redback.role.RoleManager;
@@ -57,7 +61,7 @@ public class DeleteManagedRepositoryActionTest
private MockControl archivaConfigurationControl;

private ArchivaConfiguration archivaConfiguration;
private static final String REPO_ID = "repo-ident";

private File location;
@@ -68,7 +72,7 @@ public class DeleteManagedRepositoryActionTest
super.setUp();

action = (DeleteManagedRepositoryAction) lookup( Action.class.getName(), "deleteManagedRepositoryAction" );
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
action.setArchivaConfiguration( archivaConfiguration );
@@ -76,7 +80,7 @@ public class DeleteManagedRepositoryActionTest
roleManagerControl = MockControl.createControl( RoleManager.class );
roleManager = (RoleManager) roleManagerControl.getMock();
action.setRoleManager( roleManager );
location = getTestFile( "target/test/location" );
location = getTestFile( "target/test/location" );
}

public void testSecureActionBundle()
@@ -119,11 +123,13 @@ public class DeleteManagedRepositoryActionTest

public void testDeleteRepositoryKeepContent()
throws Exception
{
{
prepareRoleManagerMock();
Configuration configuration = prepDeletionTest( createRepository(), 3 );
String status = action.deleteEntry();
Configuration configuration = prepDeletionTest( createRepository(), 3 );
String status = action.deleteEntry();
assertEquals( Action.SUCCESS, status );

assertTrue( configuration.getManagedRepositories().isEmpty() );
@@ -136,8 +142,10 @@ public class DeleteManagedRepositoryActionTest
{
prepareRoleManagerMock();
Configuration configuration = prepDeletionTest( createRepository(), 3 );
Configuration configuration = prepDeletionTest( createRepository(), 3 );
String status = action.deleteContents();
assertEquals( Action.SUCCESS, status );

assertTrue( configuration.getManagedRepositories().isEmpty() );
@@ -277,4 +285,14 @@ public class DeleteManagedRepositoryActionTest
roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
roleManagerControl.replay();
}
protected ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version )
{
ArchivaProjectModel projectModel = new ArchivaProjectModel();
projectModel.setGroupId( groupId );
projectModel.setArtifactId( artifactId );
projectModel.setVersion( version );

return projectModel;
}
}

+ 85
- 0
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryArchivaDAOStub.java View File

@@ -0,0 +1,85 @@
package org.apache.maven.archiva.web.action.admin.repositories;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import java.io.Serializable;
import java.util.List;

import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.ProjectModelDAO;
import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO;
import org.apache.maven.archiva.database.RepositoryProblemDAO;
import org.apache.maven.archiva.database.SimpleConstraint;

/**
* DeleteManagedRepositoryArchivaDAOStub
*
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
* @version
*/
public class DeleteManagedRepositoryArchivaDAOStub
implements ArchivaDAO
{
/**
* @plexus.requirement role-hint="jdo"
*/
private ProjectModelDAO projectModelDAO;

/**
* @plexus.requirement role-hint="jdo"
*/
private ArtifactDAO artifactDAO;

/**
* @plexus.requirement role-hint="jdo"
*/
private RepositoryContentStatisticsDAO repoContentStatisticsDAO;

public List query( SimpleConstraint constraint )
{
return null;
}

public Object save( Serializable obj )
{
throw new UnsupportedOperationException( "query not implemented for stub" );
}

public ArtifactDAO getArtifactDAO()
{
return artifactDAO;
}

public ProjectModelDAO getProjectModelDAO()
{
return projectModelDAO;
}

public RepositoryProblemDAO getRepositoryProblemDAO()
{
throw new UnsupportedOperationException( "query not implemented for stub" );
}

public RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO()
{
return repoContentStatisticsDAO;
}
}

+ 78
- 0
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ProjectModelDAOStub.java View File

@@ -0,0 +1,78 @@
package org.apache.maven.archiva.web.action.admin.repositories;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import java.util.List;

import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.Constraint;
import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.database.ProjectModelDAO;
import org.apache.maven.archiva.model.ArchivaProjectModel;

/**
* ProjectModelDAOStub
*
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
* @version
*/
public class ProjectModelDAOStub
implements ProjectModelDAO
{

public ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version )
{
// TODO Auto-generated method stub
return null;
}

public void deleteProjectModel( ArchivaProjectModel model )
throws ArchivaDatabaseException
{
// TODO Auto-generated method stub

}

public ArchivaProjectModel getProjectModel( String groupId, String artifactId, String version )
throws ObjectNotFoundException, ArchivaDatabaseException
{
ArchivaProjectModel projectModel = new ArchivaProjectModel();
projectModel.setGroupId( groupId );
projectModel.setArtifactId( artifactId );
projectModel.setVersion( version );

return projectModel;
}

public List queryProjectModels( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException
{
// TODO Auto-generated method stub
return null;
}

public ArchivaProjectModel saveProjectModel( ArchivaProjectModel model )
throws ArchivaDatabaseException
{
// TODO Auto-generated method stub
return null;
}

}

+ 78
- 0
archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.xml View File

@@ -0,0 +1,78 @@
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<plexus>
<components>
<component>
<role>org.codehaus.plexus.logging.LoggerManager</role>
<implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>
<lifecycle-handler>basic</lifecycle-handler>
</component>
<component>
<role>com.opensymphony.xwork.Action</role>
<role-hint>deleteManagedRepositoryAction</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.DeleteManagedRepositoryAction</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
<requirements>
<requirement>
<role>org.apache.maven.archiva.database.ArchivaDAO</role>
<role-hint>jdo</role-hint>
<field-name>archivaDAO</field-name>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.archiva.database.ArchivaDAO</role>
<role-hint>jdo</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.DeleteManagedRepositoryArchivaDAOStub</implementation>
<requirements>
<requirement>
<role>org.apache.maven.archiva.database.ArtifactDAO</role>
<role-hint>jdo</role-hint>
<field-name>artifactDAO</field-name>
</requirement>
<requirement>
<role>org.apache.maven.archiva.database.ProjectModelDAO</role>
<role-hint>jdo</role-hint>
<field-name>projectModelDAO</field-name>
</requirement>
<requirement>
<role>org.apache.maven.archiva.database.RepositoryContentStatisticsDAO</role>
<role-hint>jdo</role-hint>
<field-name>repoContentStatisticsDAO</field-name>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.archiva.database.ArtifactDAO</role>
<role-hint>jdo</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.ArtifactDAOStub</implementation>
</component>
<component>
<role>org.apache.maven.archiva.database.ProjectModelDAO</role>
<role-hint>jdo</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.ProjectModelDAOStub</implementation>
</component>
<component>
<role>org.apache.maven.archiva.database.RepositoryContentStatisticsDAO</role>
<role-hint>jdo</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.RepositoryContentStatisticsDAOStub</implementation>
</component>
</components>
</plexus>

Loading…
Cancel
Save