1 package org.apache.archiva.metadata.repository.stats;
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 junit.framework.TestCase;
23 import org.apache.archiva.metadata.model.ArtifactMetadata;
24 import org.apache.archiva.metadata.model.maven2.MavenArtifactFacet;
25 import org.apache.archiva.metadata.repository.MetadataRepository;
26 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
27 import org.easymock.IMocksControl;
29 import static org.easymock.EasyMock.*;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
35 import javax.jcr.Session;
36 import java.text.SimpleDateFormat;
37 import java.util.ArrayList;
38 import java.util.Arrays;
39 import java.util.Collections;
40 import java.util.Date;
41 import java.util.LinkedHashMap;
42 import java.util.List;
44 import java.util.TimeZone;
46 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
47 public class RepositoryStatisticsManagerTest
50 private DefaultRepositoryStatisticsManager repositoryStatisticsManager;
52 private static final String TEST_REPO_ID = "test-repo";
54 private IMocksControl metadataRepositoryControl;
56 private MetadataRepository metadataRepository;
58 private static final String FIRST_TEST_SCAN = "2009/12/01/123456.789";
60 private static final String SECOND_TEST_SCAN = "2009/12/02/012345.678";
62 private Map<String, RepositoryStatistics> statsCreated = new LinkedHashMap<String, RepositoryStatistics>();
64 private static final SimpleDateFormat TIMESTAMP_FORMAT = createTimestampFormat();
66 private static SimpleDateFormat createTimestampFormat()
68 SimpleDateFormat fmt = new SimpleDateFormat( RepositoryStatistics.SCAN_TIMESTAMP_FORMAT );
69 fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
80 repositoryStatisticsManager = new DefaultRepositoryStatisticsManager();
82 metadataRepositoryControl = createControl();
83 metadataRepository = metadataRepositoryControl.createMock( MetadataRepository.class );
87 public void testGetLatestStats()
90 Date startTime = TIMESTAMP_FORMAT.parse( SECOND_TEST_SCAN );
91 Date endTime = new Date( startTime.getTime() + 60000 );
93 RepositoryStatistics stats = new RepositoryStatistics();
94 stats.setScanStartTime( startTime );
95 stats.setScanEndTime( endTime );
96 stats.setTotalArtifactFileSize( 1314527915L );
97 stats.setNewFileCount( 123 );
98 stats.setTotalArtifactCount( 10386 );
99 stats.setTotalProjectCount( 2031 );
100 stats.setTotalGroupCount( 529 );
101 stats.setTotalFileCount( 56229 );
103 //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacets( TEST_REPO_ID,
104 // RepositoryStatistics.FACET_ID ),
105 // Arrays.asList( FIRST_TEST_SCAN, SECOND_TEST_SCAN ) );
106 expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn(
107 Arrays.asList( FIRST_TEST_SCAN, SECOND_TEST_SCAN ) );
108 //metadataRepositoryControl.expectAndReturn( metadataRepository.getMetadataFacet( TEST_REPO_ID,
109 // RepositoryStatistics.FACET_ID,
110 // SECOND_TEST_SCAN ), stats );
111 expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID,
112 SECOND_TEST_SCAN ) ).andReturn( stats );
114 metadataRepositoryControl.replay();
116 stats = repositoryStatisticsManager.getLastStatistics( metadataRepository, TEST_REPO_ID );
117 assertNotNull( stats );
118 assertEquals( 1314527915L, stats.getTotalArtifactFileSize() );
119 assertEquals( 123, stats.getNewFileCount() );
120 assertEquals( 10386, stats.getTotalArtifactCount() );
121 assertEquals( 2031, stats.getTotalProjectCount() );
122 assertEquals( 529, stats.getTotalGroupCount() );
123 assertEquals( 56229, stats.getTotalFileCount() );
124 assertEquals( SECOND_TEST_SCAN, TIMESTAMP_FORMAT.format( stats.getScanStartTime() ) );
125 assertEquals( SECOND_TEST_SCAN, stats.getName() );
126 assertEquals( endTime, stats.getScanEndTime() );
128 metadataRepositoryControl.verify();
132 public void testGetLatestStatsWhenEmpty()
135 //metadataRepositoryControl.expectAndReturn(
136 // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ),
137 // Collections.emptyList() );
138 expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn(
139 Collections.<String>emptyList() );
140 metadataRepositoryControl.replay();
142 RepositoryStatistics stats = repositoryStatisticsManager.getLastStatistics( metadataRepository, TEST_REPO_ID );
145 metadataRepositoryControl.verify();
149 public void testAddNewStats()
152 Date current = new Date();
153 Date startTime = new Date( current.getTime() - 12345 );
155 RepositoryStatistics stats = createTestStats( startTime, current );
159 metadataRepository.addMetadataFacet( TEST_REPO_ID, stats );
160 //metadataRepositoryControl.expectAndReturn(
161 // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ),
162 // Arrays.asList( stats.getName() ) );
163 expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn(
164 Arrays.asList( stats.getName() ) );
165 //metadataRepositoryControl.expectAndReturn(
166 // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats.getName() ),
168 expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID,
169 stats.getName() ) ).andReturn( stats );
170 //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false );
171 expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false );
173 metadataRepositoryControl.replay();
175 repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, TEST_REPO_ID, startTime, current, 56345,
178 stats = repositoryStatisticsManager.getLastStatistics( metadataRepository, TEST_REPO_ID );
179 assertNotNull( stats );
180 assertEquals( 246900, stats.getTotalArtifactFileSize() );
181 assertEquals( 45, stats.getNewFileCount() );
182 assertEquals( 20, stats.getTotalArtifactCount() );
183 assertEquals( 5, stats.getTotalProjectCount() );
184 assertEquals( 4, stats.getTotalGroupCount() );
185 assertEquals( 56345, stats.getTotalFileCount() );
186 assertEquals( current.getTime() - 12345, stats.getScanStartTime().getTime() );
187 assertEquals( current, stats.getScanEndTime() );
189 metadataRepositoryControl.verify();
193 public void testDeleteStats()
198 Date current = new Date();
200 Date startTime1 = new Date( current.getTime() - 12345 );
201 RepositoryStatistics stats1 = createTestStats( startTime1, new Date( current.getTime() - 6000 ) );
202 metadataRepository.addMetadataFacet( TEST_REPO_ID, stats1 );
204 Date startTime2 = new Date( current.getTime() - 3000 );
205 RepositoryStatistics stats2 = createTestStats( startTime2, current );
206 metadataRepository.addMetadataFacet( TEST_REPO_ID, stats2 );
208 //metadataRepositoryControl.expectAndReturn(
209 // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ),
210 // Arrays.asList( stats1.getName(), stats2.getName() ) );
211 expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn(
212 Arrays.asList( stats1.getName(), stats2.getName() ) );
213 //metadataRepositoryControl.expectAndReturn(
214 // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, stats2.getName() ),
216 expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID,
217 stats2.getName() ) ).andReturn( stats2 );
218 metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID );
220 //metadataRepositoryControl.expectAndReturn(
221 // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ),
222 // Collections.emptyList() );
223 expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn(
224 Collections.<String>emptyList() );
225 //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 2 );
226 expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false ).times( 2 );
227 metadataRepositoryControl.replay();
229 repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, TEST_REPO_ID, startTime1,
230 stats1.getScanEndTime(), 56345, 45 );
231 repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, TEST_REPO_ID, startTime2,
232 stats2.getScanEndTime(), 56345, 45 );
234 assertNotNull( repositoryStatisticsManager.getLastStatistics( metadataRepository, TEST_REPO_ID ) );
236 repositoryStatisticsManager.deleteStatistics( metadataRepository, TEST_REPO_ID );
238 assertNull( repositoryStatisticsManager.getLastStatistics( metadataRepository, TEST_REPO_ID ) );
240 metadataRepositoryControl.verify();
244 public void testDeleteStatsWhenEmpty()
247 //metadataRepositoryControl.expectAndReturn(
248 // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ),
249 // Collections.emptyList(), 2 );
250 expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn(
251 Collections.<String>emptyList() ).times( 2 );
252 metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID );
254 metadataRepositoryControl.replay();
256 assertNull( repositoryStatisticsManager.getLastStatistics( metadataRepository, TEST_REPO_ID ) );
258 repositoryStatisticsManager.deleteStatistics( metadataRepository, TEST_REPO_ID );
260 assertNull( repositoryStatisticsManager.getLastStatistics( metadataRepository, TEST_REPO_ID ) );
262 metadataRepositoryControl.verify();
266 public void testGetStatsRangeInside()
271 Date current = new Date();
273 addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
274 addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
275 addStats( new Date( current.getTime() - 1000 ), current );
277 ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() );
278 //metadataRepositoryControl.expectAndReturn(
279 // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys );
280 expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( keys );
282 // only match the middle one
283 String key = keys.get( 1 );
284 //metadataRepositoryControl.expectAndReturn(
285 // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
286 // statsCreated.get( key ) );
287 expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn(
288 statsCreated.get( key ) );
290 //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 );
291 expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false ).times( 3 );
293 metadataRepositoryControl.replay();
295 for ( RepositoryStatistics stats : statsCreated.values() )
297 repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, TEST_REPO_ID,
298 stats.getScanStartTime(), stats.getScanEndTime(), 56345,
302 List<RepositoryStatistics> list =
303 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, TEST_REPO_ID,
304 new Date( current.getTime() - 4000 ),
305 new Date( current.getTime() - 2000 ) );
307 assertEquals( 1, list.size() );
308 assertEquals( new Date( current.getTime() - 3000 ), list.get( 0 ).getScanStartTime() );
310 metadataRepositoryControl.verify();
314 public void testGetStatsRangeUpperOutside()
319 Date current = new Date();
321 addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
322 addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
323 addStats( new Date( current.getTime() - 1000 ), current );
325 List<String> keys = new ArrayList<String>( statsCreated.keySet() );
326 //metadataRepositoryControl.expectAndReturn(
327 // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys );
328 expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( keys );
330 String key = keys.get( 1 );
331 //metadataRepositoryControl.expectAndReturn(
332 // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
333 // statsCreated.get( key ) );
334 expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn(
335 statsCreated.get( key ) );
338 //metadataRepositoryControl.expectAndReturn(
339 // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
340 // statsCreated.get( key ) );
341 expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn(
342 statsCreated.get( key ) );
344 //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 );
345 expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false ).times( 3 );
347 metadataRepositoryControl.replay();
349 for ( RepositoryStatistics stats : statsCreated.values() )
351 repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, TEST_REPO_ID,
352 stats.getScanStartTime(), stats.getScanEndTime(), 56345,
356 List<RepositoryStatistics> list =
357 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, TEST_REPO_ID,
358 new Date( current.getTime() - 4000 ), current );
360 assertEquals( 2, list.size() );
361 assertEquals( new Date( current.getTime() - 3000 ), list.get( 1 ).getScanStartTime() );
362 assertEquals( new Date( current.getTime() - 1000 ), list.get( 0 ).getScanStartTime() );
364 metadataRepositoryControl.verify();
368 public void testGetStatsRangeLowerOutside()
373 Date current = new Date();
375 addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
376 addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
377 addStats( new Date( current.getTime() - 1000 ), current );
379 List<String> keys = new ArrayList<String>( statsCreated.keySet() );
380 //metadataRepositoryControl.expectAndReturn(
381 // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys );
382 expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( keys );
384 String key = keys.get( 0 );
385 //metadataRepositoryControl.expectAndReturn(
386 // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
387 // statsCreated.get( key ) );
388 expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn(
389 statsCreated.get( key ) );
391 //metadataRepositoryControl.expectAndReturn(
392 // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
393 // statsCreated.get( key ) );
394 expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn(
395 statsCreated.get( key ) );
396 //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 );
397 expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false ).times( 3 );
399 metadataRepositoryControl.replay();
401 for ( RepositoryStatistics stats : statsCreated.values() )
403 repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, TEST_REPO_ID,
404 stats.getScanStartTime(), stats.getScanEndTime(), 56345,
408 List<RepositoryStatistics> list =
409 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, TEST_REPO_ID,
410 new Date( current.getTime() - 20000 ),
411 new Date( current.getTime() - 2000 ) );
413 assertEquals( 2, list.size() );
414 assertEquals( new Date( current.getTime() - 12345 ), list.get( 1 ).getScanStartTime() );
415 assertEquals( new Date( current.getTime() - 3000 ), list.get( 0 ).getScanStartTime() );
417 metadataRepositoryControl.verify();
421 public void testGetStatsRangeLowerAndUpperOutside()
426 Date current = new Date();
428 addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
429 addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
430 addStats( new Date( current.getTime() - 1000 ), current );
432 ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() );
433 //metadataRepositoryControl.expectAndReturn(
434 // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys );
435 expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( keys );
437 String key = keys.get( 0 );
438 //metadataRepositoryControl.expectAndReturn(
439 // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
440 // statsCreated.get( key ) );
441 expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn(
442 statsCreated.get( key ) );
444 //metadataRepositoryControl.expectAndReturn(
445 // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
446 // statsCreated.get( key ) );
447 expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn(
448 statsCreated.get( key ) );
450 //metadataRepositoryControl.expectAndReturn(
451 // metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
452 // statsCreated.get( key ) );
453 expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ) ).andReturn(
454 statsCreated.get( key ) );
455 //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 );
456 expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false ).times( 3 );
458 metadataRepositoryControl.replay();
460 for ( RepositoryStatistics stats : statsCreated.values() )
462 repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, TEST_REPO_ID,
463 stats.getScanStartTime(), stats.getScanEndTime(), 56345,
467 List<RepositoryStatistics> list =
468 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, TEST_REPO_ID,
469 new Date( current.getTime() - 20000 ), current );
471 assertEquals( 3, list.size() );
472 assertEquals( new Date( current.getTime() - 12345 ), list.get( 2 ).getScanStartTime() );
473 assertEquals( new Date( current.getTime() - 3000 ), list.get( 1 ).getScanStartTime() );
474 assertEquals( new Date( current.getTime() - 1000 ), list.get( 0 ).getScanStartTime() );
476 metadataRepositoryControl.verify();
480 public void testGetStatsRangeNotInside()
485 Date current = new Date();
487 addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
488 addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
489 addStats( new Date( current.getTime() - 1000 ), current );
491 ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() );
492 //metadataRepositoryControl.expectAndReturn(
493 // metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys );
494 expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ) ).andReturn( keys );
495 //metadataRepositoryControl.expectAndReturn( metadataRepository.canObtainAccess( Session.class ), false, 3 );
496 expect( metadataRepository.canObtainAccess( Session.class ) ).andReturn( false ).times( 3 );
498 metadataRepositoryControl.replay();
500 for ( RepositoryStatistics stats : statsCreated.values() )
502 repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, TEST_REPO_ID,
503 stats.getScanStartTime(), stats.getScanEndTime(), 56345,
507 List<RepositoryStatistics> list =
508 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, TEST_REPO_ID,
509 new Date( current.getTime() - 20000 ),
510 new Date( current.getTime() - 16000 ) );
512 assertEquals( 0, list.size() );
514 metadataRepositoryControl.verify();
517 private void addStats( Date startTime, Date endTime )
520 RepositoryStatistics stats = createTestStats( startTime, endTime );
521 metadataRepository.addMetadataFacet( TEST_REPO_ID, stats );
522 statsCreated.put( stats.getName(), stats );
525 private ArtifactMetadata createArtifact( String namespace, String projectId, String projectVersion, String type )
527 ArtifactMetadata metadata = new ArtifactMetadata();
528 metadata.setRepositoryId( TEST_REPO_ID );
529 metadata.setId( projectId + "-" + projectVersion + "." + type );
530 metadata.setProject( projectId );
531 metadata.setSize( 12345L );
532 metadata.setProjectVersion( projectVersion );
533 metadata.setVersion( projectVersion );
534 metadata.setNamespace( namespace );
536 MavenArtifactFacet facet = new MavenArtifactFacet();
537 facet.setType( type );
538 metadata.addFacet( facet );
543 private RepositoryStatistics createTestStats( Date startTime, Date endTime )
545 RepositoryStatistics stats = new RepositoryStatistics();
546 stats.setRepositoryId( TEST_REPO_ID );
547 stats.setScanStartTime( startTime );
548 stats.setScanEndTime( endTime );
549 stats.setTotalArtifactFileSize( 20 * 12345L );
550 stats.setNewFileCount( 45 );
551 stats.setTotalArtifactCount( 20 );
552 stats.setTotalProjectCount( 5 );
553 stats.setTotalGroupCount( 4 );
554 stats.setTotalFileCount( 56345 );
555 stats.setTotalCountForType( "jar", 10 );
556 stats.setTotalCountForType( "pom", 10 );
560 private void walkRepository( int count )
563 for ( int i = 0; i < count; i++ )
565 //metadataRepositoryControl.expectAndReturn( metadataRepository.getRootNamespaces( TEST_REPO_ID ),
566 // Arrays.asList( "com", "org" ) );
567 expect( metadataRepository.getRootNamespaces( TEST_REPO_ID ) ).andReturn( Arrays.asList( "com", "org" ) );
568 //metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "com" ),
569 // Arrays.asList() );
570 expect( metadataRepository.getProjects( TEST_REPO_ID, "com" ) ).andReturn( Arrays.<String>asList() );
571 //metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "com" ),
572 // Arrays.asList( "example" ) );
573 expect( metadataRepository.getNamespaces( TEST_REPO_ID, "com" ) ).andReturn( Arrays.asList( "example" ) );
574 //metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "com.example" ),
575 // Arrays.asList() );
576 expect( metadataRepository.getNamespaces( TEST_REPO_ID, "com.example" ) ).andReturn(
577 Arrays.<String>asList() );
578 //metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "com.example" ),
579 // Arrays.asList( "example-project" ) );
580 expect( metadataRepository.getProjects( TEST_REPO_ID, "com.example" ) ).andReturn(
581 Arrays.asList( "example-project" ) );
582 //metadataRepositoryControl.expectAndReturn(
583 // metadataRepository.getProjectVersions( TEST_REPO_ID, "com.example", "example-project" ),
584 // Arrays.asList( "1.0", "1.1" ) );
585 expect( metadataRepository.getProjectVersions( TEST_REPO_ID, "com.example", "example-project" ) ).andReturn(
586 Arrays.asList( "1.0", "1.1" ) );
587 //metadataRepositoryControl.expectAndReturn(
588 // metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", "example-project", "1.0" ),
589 // Arrays.asList( createArtifact( "com.example", "example-project", "1.0", "jar" ),
590 // createArtifact( "com.example", "example-project", "1.0", "pom" ) ) );
592 metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", "example-project", "1.0" ) ).andReturn(
593 Arrays.asList( createArtifact( "com.example", "example-project", "1.0", "jar" ),
594 createArtifact( "com.example", "example-project", "1.0", "pom" ) ) );
595 //metadataRepositoryControl.expectAndReturn(
596 // metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", "example-project", "1.1" ),
597 // Arrays.asList( createArtifact( "com.example", "example-project", "1.1", "jar" ),
598 // createArtifact( "com.example", "example-project", "1.1", "pom" ) ) );
600 metadataRepository.getArtifacts( TEST_REPO_ID, "com.example", "example-project", "1.1" ) ).andReturn(
601 Arrays.asList( createArtifact( "com.example", "example-project", "1.1", "jar" ),
602 createArtifact( "com.example", "example-project", "1.1", "pom" ) ) );
604 //metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org" ),
605 // Arrays.asList( "apache", "codehaus" ) );
606 expect( metadataRepository.getNamespaces( TEST_REPO_ID, "org" ) ).andReturn( Arrays.asList( "apache", "codehaus" ) );
607 //metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache" ),
608 // Arrays.asList( "archiva", "maven" ) );
609 expect( metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache" ) ).andReturn( Arrays.asList( "archiva", "maven" ) );
610 //metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org.apache" ),
611 // Arrays.asList() );
612 expect( metadataRepository.getProjects( TEST_REPO_ID, "org.apache" ) ).andReturn( Arrays.<String>asList() );
613 //metadataRepositoryControl.expectAndReturn(
614 // metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache.archiva" ), Arrays.asList() );
615 expect( metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache.archiva" ) ).andReturn( Arrays.<String>asList() );
616 //metadataRepositoryControl.expectAndReturn(
617 // metadataRepository.getProjects( TEST_REPO_ID, "org.apache.archiva" ),
618 /// Arrays.asList( "metadata-repository-api", "metadata-model" ) );
619 expect( metadataRepository.getProjects( TEST_REPO_ID, "org.apache.archiva" ) ).andReturn( Arrays.asList( "metadata-repository-api", "metadata-model" ) );
620 //metadataRepositoryControl.expectAndReturn(
621 // metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api" ),
622 // Arrays.asList( "1.3-SNAPSHOT", "1.3" ) );
623 expect( metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api" ) )
624 .andReturn( Arrays.asList( "1.3-SNAPSHOT", "1.3" ) );
625 //metadataRepositoryControl.expectAndReturn(
626 // metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api",
628 // Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", "jar" ),
629 // createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT",
631 expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT" ) )
632 .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", "jar" ),
633 createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT",
635 //metadataRepositoryControl.expectAndReturn(
636 // metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3" ),
637 // Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "jar" ),
638 // createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "pom" ) ) );
639 expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3" ) )
640 .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "jar" ),
641 createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "pom" ) ) );
642 //metadataRepositoryControl.expectAndReturn(
643 // metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "metadata-model" ),
644 // Arrays.asList( "1.3-SNAPSHOT", "1.3" ) );
645 expect( metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "metadata-model" ) )
646 .andReturn( Arrays.asList( "1.3-SNAPSHOT", "1.3" ) );
647 //metadataRepositoryControl.expectAndReturn(
648 // metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT" ),
649 // Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "jar" ),
650 // createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "pom" ) ) );
651 expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT" ) )
652 .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "jar" ),
653 createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "pom" ) ) );
654 //metadataRepositoryControl.expectAndReturn(
655 // metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3" ),
656 // Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3", "jar" ),
657 // createArtifact( "org.apache.archiva", "metadata-model", "1.3", "pom" ) ) );
658 expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3" ) )
659 .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3", "jar" ),
660 createArtifact( "org.apache.archiva", "metadata-model", "1.3", "pom" ) ) );
661 //metadataRepositoryControl.expectAndReturn(
662 // metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache.maven" ), Arrays.asList() );
663 expect( metadataRepository.getNamespaces( TEST_REPO_ID, "org.apache.maven" ) ).andReturn( Arrays.<String>asList() );
664 //metadataRepositoryControl.expectAndReturn(
665 // metadataRepository.getProjects( TEST_REPO_ID, "org.apache.maven" ), Arrays.asList( "maven-model" ) );
666 expect( metadataRepository.getProjects( TEST_REPO_ID, "org.apache.maven" ) )
667 .andReturn( Arrays.asList( "maven-model" ) );
668 //metadataRepositoryControl.expectAndReturn(
669 // metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.maven", "maven-model" ),
670 // Arrays.asList( "2.2.1" ) );
671 expect( metadataRepository.getProjectVersions( TEST_REPO_ID, "org.apache.maven", "maven-model" ) )
672 .andReturn( Arrays.asList( "2.2.1" ) );
673 //metadataRepositoryControl.expectAndReturn(
674 // metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.maven", "maven-model", "2.2.1" ),
675 // Arrays.asList( createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "jar" ),
676 // createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "pom" ) ) );
677 expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.apache.maven", "maven-model", "2.2.1" ) )
678 .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "jar" ),
679 createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "pom" ) ) );
680 //metadataRepositoryControl.expectAndReturn( metadataRepository.getNamespaces( TEST_REPO_ID, "org.codehaus" ),
681 // Arrays.asList( "plexus" ) );
682 expect( metadataRepository.getNamespaces( TEST_REPO_ID, "org.codehaus" ) ).andReturn( Arrays.asList( "plexus" ) );
683 //metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org" ),
684 // Arrays.asList() );
685 expect( metadataRepository.getProjects( TEST_REPO_ID, "org" ) ).andReturn( Arrays.<String>asList( ) );
686 //metadataRepositoryControl.expectAndReturn( metadataRepository.getProjects( TEST_REPO_ID, "org.codehaus" ),
687 // Arrays.asList() );
688 expect( metadataRepository.getProjects( TEST_REPO_ID, "org.codehaus" ) )
689 .andReturn( Arrays.<String>asList( ) );
690 //metadataRepositoryControl.expectAndReturn(
691 // metadataRepository.getNamespaces( TEST_REPO_ID, "org.codehaus.plexus" ), Arrays.asList() );
692 expect( metadataRepository.getNamespaces( TEST_REPO_ID, "org.codehaus.plexus" ) )
693 .andReturn( Arrays.<String>asList( ) );
694 //metadataRepositoryControl.expectAndReturn(
695 // metadataRepository.getProjects( TEST_REPO_ID, "org.codehaus.plexus" ),
696 // Arrays.asList( "plexus-spring" ) );
697 expect( metadataRepository.getProjects( TEST_REPO_ID, "org.codehaus.plexus" ) )
698 .andReturn( Arrays.asList( "plexus-spring" ) );
700 //metadataRepositoryControl.expectAndReturn(
701 // metadataRepository.getProjectVersions( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring" ),
702 // Arrays.asList( "1.0", "1.1", "1.2" ) );
703 expect( metadataRepository.getProjectVersions( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring" ) )
704 .andReturn( Arrays.asList( "1.0", "1.1", "1.2" ) );
705 //metadataRepositoryControl.expectAndReturn(
706 // metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.0" ),
707 // Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "jar" ),
708 // createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "pom" ) ) );
709 expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.0" ) )
710 .andReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "jar" ),
711 createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "pom" ) ) );
712 //metadataRepositoryControl.expectAndReturn(
713 // metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.1" ),
714 // Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "jar" ),
715 // createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "pom" ) ) );
716 expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.1" ) )
717 .andReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "jar" ),
718 createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "pom" ) ) );
719 //metadataRepositoryControl.expectAndReturn(
720 // metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2" ),
721 // Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "jar" ),
722 // createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "pom" ) ) );
723 expect( metadataRepository.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2" ) )
724 .andReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "jar" ),
725 createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "pom" ) ) );