From 1dad23aaf3d3a6fa10876a2363169b76b52608b9 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Mon, 7 Dec 2009 23:27:58 +0000 Subject: [PATCH] [MRM-1293] adjust the EditManagedRepositoryAction to delete statistics when the repository location changes. git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@888185 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/TestMetadataRepository.java | 5 ++ .../TestRepositoryStatisticsManager.java | 5 ++ .../EditManagedRepositoryAction.java | 42 ++------- .../EditManagedRepositoryActionTest.java | 83 +++-------------- .../repository/TestMetadataRepository.java | 5 ++ .../repository/MetadataRepository.java | 2 + .../file/FileMetadataRepository.java | 14 +++ .../file/FileMetadataRepositoryTest.java | 29 ++++++ .../DefaultRepositoryStatisticsManager.java | 5 ++ .../stats/RepositoryStatisticsManager.java | 2 + .../RepositoryStatisticsManagerTest.java | 88 ++++++++++++++++--- 11 files changed, 163 insertions(+), 117 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index 30ba168df..5cd2ef472 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -118,4 +118,9 @@ public class TestMetadataRepository { //To change body of implemented methods use File | Settings | File Templates. } + + public void removeMetadataFacets( String repositoryId, String facetId ) + { + //To change body of implemented methods use File | Settings | File Templates. + } } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestRepositoryStatisticsManager.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestRepositoryStatisticsManager.java index 7c2939b8e..470a5f998 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestRepositoryStatisticsManager.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestRepositoryStatisticsManager.java @@ -46,6 +46,11 @@ public class TestRepositoryStatisticsManager stats.add( repositoryStatistics ); } + public void deleteStatistics( String repositoryId ) + { + repoStats.remove( repositoryId ); + } + private List getStatsList( String repositoryId ) { List stats = repoStats.get( repositoryId ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java index 3f3c6b240..70ad2b241 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java @@ -21,19 +21,13 @@ package org.apache.maven.archiva.web.action.admin.repositories; import java.io.File; import java.io.IOException; -import java.util.List; import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.Validateable; +import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; 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.ObjectNotFoundException; -import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO; -import org.apache.maven.archiva.database.constraints.RepositoryContentStatisticsByRepositoryConstraint; -import org.apache.maven.archiva.model.RepositoryContentStatistics; import org.apache.maven.archiva.repository.audit.AuditEvent; import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.scheduler.CronExpressionValidator; @@ -58,9 +52,9 @@ public class EditManagedRepositoryAction private final String action = "editRepository"; /** - * @plexus.requirement role-hint="jdo" + * @plexus.requirement */ - private ArchivaDAO archivaDAO; + private RepositoryStatisticsManager repositoryStatisticsManager; public void prepare() { @@ -145,16 +139,6 @@ public class EditManagedRepositoryAction addActionError( "Role Manager Exception: " + e.getMessage() ); result = ERROR; } - catch ( ObjectNotFoundException e ) - { - addActionError( e.getMessage() ); - result = ERROR; - } - catch ( ArchivaDatabaseException e ) - { - addActionError( e.getMessage() ); - result = ERROR; - } return result; } @@ -171,20 +155,8 @@ public class EditManagedRepositoryAction } private void resetStatistics() - throws ObjectNotFoundException, ArchivaDatabaseException { - RepositoryContentStatisticsDAO repoContentStatsDao = archivaDAO.getRepositoryContentStatisticsDAO(); - - List contentStats = repoContentStatsDao.queryRepositoryContentStatistics( - new RepositoryContentStatisticsByRepositoryConstraint( repository.getId() ) ); - - if ( contentStats != null ) - { - for ( RepositoryContentStatistics stats : contentStats ) - { - repoContentStatsDao.deleteRepositoryContentStatistics( stats ); - } - } + repositoryStatisticsManager.deleteStatistics( repository.getId() ); } public String getRepoid() @@ -212,10 +184,8 @@ public class EditManagedRepositoryAction return action; } - // for testing - - public void setArchivaDAO( ArchivaDAO archivaDao ) + public void setRepositoryStatisticsManager( RepositoryStatisticsManager repositoryStatisticsManager ) { - this.archivaDAO = archivaDao; + this.repositoryStatisticsManager = repositoryStatisticsManager; } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java index e688f8a29..ec70cd62b 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java @@ -19,28 +19,22 @@ package org.apache.maven.archiva.web.action.admin.repositories; * under the License. */ +import java.io.File; +import java.io.IOException; +import java.util.Collections; + import com.opensymphony.xwork2.Action; +import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.maven.archiva.configuration.ArchivaConfiguration; 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.RepositoryContentStatisticsDAO; -import org.apache.maven.archiva.database.constraints.RepositoryContentStatisticsByRepositoryConstraint; -import org.apache.maven.archiva.model.RepositoryContentStatistics; import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.codehaus.plexus.redback.role.RoleManager; +import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionException; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - /** * EditManagedRepositoryActionTest * @@ -59,14 +53,6 @@ public class EditManagedRepositoryActionTest private ArchivaConfiguration archivaConfiguration; - private MockControl archivaDaoControl; - - private ArchivaDAO archivaDao; - - private MockControl repoContentStatsDaoControl; - - private RepositoryContentStatisticsDAO repoContentStatsDao; - private static final String REPO_ID = "repo-ident"; private File location; @@ -92,13 +78,6 @@ public class EditManagedRepositoryActionTest roleManager = (RoleManager) roleManagerControl.getMock(); action.setRoleManager( roleManager ); location = getTestFile( "target/test/location" ); - - archivaDaoControl = MockControl.createControl( ArchivaDAO.class ); - archivaDao = (ArchivaDAO) archivaDaoControl.getMock(); - action.setArchivaDAO( archivaDao ); - - repoContentStatsDaoControl = MockControl.createControl( RepositoryContentStatisticsDAO.class ); - repoContentStatsDao = (RepositoryContentStatisticsDAO) repoContentStatsDaoControl.getMock(); } public void testSecureActionBundle() @@ -204,24 +183,15 @@ public class EditManagedRepositoryActionTest archivaConfigurationControl.replay(); - archivaDaoControl.expectAndReturn( archivaDao.getRepositoryContentStatisticsDAO(), repoContentStatsDao ); + MockControl repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class ); + RepositoryStatisticsManager repositoryStatisticsManager = + (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock(); + action.setRepositoryStatisticsManager( repositoryStatisticsManager ); - archivaDaoControl.replay(); + repositoryStatisticsManager.deleteStatistics( REPO_ID ); - repoContentStatsDao.queryRepositoryContentStatistics( - new RepositoryContentStatisticsByRepositoryConstraint( REPO_ID ) ); - repoContentStatsDaoControl.setMatcher( MockControl.ALWAYS_MATCHER ); + repositoryStatisticsManagerControl.replay(); - List repoStats = createRepositoryContentStatisticsList(); - repoContentStatsDaoControl.setReturnValue( repoStats ); - - repoContentStatsDao.deleteRepositoryContentStatistics( repoStats.get( 0 ) ); - repoContentStatsDaoControl.setVoidCallable(); - repoContentStatsDao.deleteRepositoryContentStatistics( repoStats.get( 1 ) ); - repoContentStatsDaoControl.setVoidCallable(); - - repoContentStatsDaoControl.replay(); - action.setRepoid( REPO_ID ); action.prepare(); assertEquals( REPO_ID, action.getRepoid() ); @@ -236,8 +206,7 @@ public class EditManagedRepositoryActionTest roleManagerControl.verify(); archivaConfigurationControl.verify(); - archivaDaoControl.verify(); - repoContentStatsDaoControl.verify(); + repositoryStatisticsManagerControl.verify(); } private void assertRepositoryEquals( ManagedRepositoryConfiguration expectedRepository, @@ -288,30 +257,4 @@ public class EditManagedRepositoryActionTest repository.setScanned( false ); repository.setDeleteReleasedSnapshots( true ); } - - private List createRepositoryContentStatisticsList() - { - List repoStatsList = new ArrayList(); - - repoStatsList.add( createRepositoryContentStatistics() ); - repoStatsList.add( createRepositoryContentStatistics() ); - - return repoStatsList; - } - - private RepositoryContentStatistics createRepositoryContentStatistics() - { - RepositoryContentStatistics repoStats = new RepositoryContentStatistics(); - repoStats.setRepositoryId( REPO_ID ); - repoStats.setDuration( 1000 ); - repoStats.setTotalArtifactCount( 100 ); - repoStats.setTotalSize( 10 ); - repoStats.setTotalFileCount( 10 ); - repoStats.setTotalProjectCount( 2 ); - repoStats.setTotalGroupCount( 1 ); - repoStats.setNewFileCount( 3 ); - repoStats.setWhenGathered( new Date( System.currentTimeMillis() ) ); - - return repoStats; - } } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index 30ba168df..5cd2ef472 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -118,4 +118,9 @@ public class TestMetadataRepository { //To change body of implemented methods use File | Settings | File Templates. } + + public void removeMetadataFacets( String repositoryId, String facetId ) + { + //To change body of implemented methods use File | Settings | File Templates. + } } diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java index edf05c236..bc87cdbeb 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -54,4 +54,6 @@ public interface MetadataRepository MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name ); void addMetadataFacet( String repositoryId, String facetId, String name, MetadataFacet metadataFacet ); + + void removeMetadataFacets( String repositoryId, String facetId ); } diff --git a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java index b082e08f9..110790af3 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java +++ b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java @@ -49,6 +49,7 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.model.Scm; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -296,6 +297,19 @@ public class FileMetadataRepository } } + public void removeMetadataFacets( String repositoryId, String facetId ) + { + try + { + FileUtils.deleteDirectory( getMetadataDirectory( repositoryId, facetId ) ); + } + catch ( IOException e ) + { + // TODO! + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + } + private File getMetadataDirectory( String repositoryId, String facetId ) { return new File( this.directory, repositoryId + "/.meta/" + facetId ); diff --git a/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java index 561b18f19..489f38b66 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java +++ b/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java @@ -160,6 +160,35 @@ public class FileMetadataRepositoryTest assertTrue( facets.isEmpty() ); } + public void testRemoveFacets() + { + List facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); + assertTrue( facets.isEmpty() ); + + repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); + + facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); + assertTrue( facets.isEmpty() ); + } + + public void testRemoveFacetsWhenEmpty() + { + repository.addMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME, new TestMetadataFacet( TEST_VALUE ) ); + + List facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); + assertFalse( facets.isEmpty() ); + + repository.removeMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); + + facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); + assertTrue( facets.isEmpty() ); + } + + public void testRemoveFacetsWhenUnknown() + { + repository.removeMetadataFacets( TEST_REPO_ID, UNKNOWN ); + } + private static class TestMetadataFacet implements MetadataFacet { diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java index 5289b6438..65b9c2f1b 100644 --- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java +++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java @@ -73,6 +73,11 @@ public class DefaultRepositoryStatisticsManager repositoryStatistics ); } + public void deleteStatistics( String repositoryId ) + { + metadataRepository.removeMetadataFacets( repositoryId, RepositoryStatistics.FACET_ID ); + } + public void setMetadataRepository( MetadataRepository metadataRepository ) { this.metadataRepository = metadataRepository; diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java index 15ba27802..24b9135ed 100644 --- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java +++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java @@ -24,4 +24,6 @@ public interface RepositoryStatisticsManager RepositoryStatistics getLastStatistics( String repositoryId ); void addStatisticsAfterScan( String repositoryId, RepositoryStatistics repositoryStatistics ); + + void deleteStatistics( String repositoryId ); } diff --git a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java index 0dbda2eb5..8cff40848 100644 --- a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java +++ b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java @@ -113,24 +113,17 @@ public class RepositoryStatisticsManagerTest Date current = new Date(); Date startTime = new Date( current.getTime() - 12345 ); - RepositoryStatistics stats = new RepositoryStatistics(); - stats.setScanStartTime( startTime ); - stats.setScanEndTime( current ); - stats.setTotalArtifactFileSize( 1400032000L ); - stats.setNewFileCount( 45 ); - stats.setTotalArtifactCount( 10412 ); - stats.setTotalProjectCount( 2036 ); - stats.setTotalGroupCount( 531 ); - stats.setTotalFileCount( 56345 ); + RepositoryStatistics stats1 = createTestStats( startTime, current ); String startTimeAsString = DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( startTime ); - metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString, stats ); + metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString, stats1 ); metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), Arrays.asList( startTimeAsString ) ); metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString ), - stats ); + stats1 ); + RepositoryStatistics stats = stats1; metadataRepositoryControl.replay(); @@ -149,4 +142,77 @@ public class RepositoryStatisticsManagerTest metadataRepositoryControl.verify(); } + + public void testDeleteStats() + { + Date current = new Date(); + + Date startTime1 = new Date( current.getTime() - 12345 ); + RepositoryStatistics stats1 = createTestStats( startTime1, new Date( current.getTime() - 6000 ) ); + String startTimeAsString1 = DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( startTime1 ); + metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString1, stats1 ); + + Date startTime2 = new Date( current.getTime() - 3000 ); + RepositoryStatistics stats2 = createTestStats( startTime2, current ); + String startTimeAsString2 = DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( startTime2 ); + metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString2, stats2 ); + + metadataRepositoryControl.expectAndReturn( + metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), + Arrays.asList( startTimeAsString1, startTimeAsString2 ) ); + metadataRepositoryControl.expectAndReturn( + metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString2 ), + stats2 ); + + metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ); + + metadataRepositoryControl.expectAndReturn( + metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), + Collections.emptyList() ); + + metadataRepositoryControl.replay(); + + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats1 ); + repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats2 ); + + assertNotNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) ); + + repositoryStatisticsManager.deleteStatistics( TEST_REPO_ID ); + + assertNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) ); + + metadataRepositoryControl.verify(); + } + + public void testDeleteStatsWhenEmpty() + { + metadataRepositoryControl.expectAndReturn( + metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), + Collections.emptyList(), 2 ); + metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ); + + metadataRepositoryControl.replay(); + + assertNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) ); + + repositoryStatisticsManager.deleteStatistics( TEST_REPO_ID ); + + assertNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) ); + + metadataRepositoryControl.verify(); + } + + private RepositoryStatistics createTestStats( Date startTime, Date endTime ) + { + RepositoryStatistics stats = new RepositoryStatistics(); + stats.setScanStartTime( startTime ); + stats.setScanEndTime( endTime ); + stats.setTotalArtifactFileSize( 1400032000L ); + stats.setNewFileCount( 45 ); + stats.setTotalArtifactCount( 10412 ); + stats.setTotalProjectCount( 2036 ); + stats.setTotalGroupCount( 531 ); + stats.setTotalFileCount( 56345 ); + return stats; + } }