1 package org.apache.maven.archiva.database.constraints;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
23 import org.apache.maven.archiva.model.RepositoryContentStatistics;
24
25 import java.util.List;
26
27
28
29
30
31
32 public class MostRecentRepositoryScanStatisticsTest
33 extends AbstractArchivaDatabaseTestCase
34 {
35 private RepositoryContentStatistics createStats( String repoId, String timestamp, long duration, long totalfiles,
36 long newfiles )
37 throws Exception
38 {
39 RepositoryContentStatistics stats = new RepositoryContentStatistics();
40 stats.setRepositoryId( repoId );
41 stats.setDuration( duration );
42 stats.setNewFileCount( newfiles );
43 stats.setTotalFileCount( totalfiles );
44 stats.setWhenGathered( toDate( timestamp ) );
45
46 return stats;
47 }
48
49 @Override
50 protected void setUp()
51 throws Exception
52 {
53 super.setUp();
54
55 dao.save( createStats( "internal", "2007/02/21 10:00:00", 20000, 12000, 400 ) );
56 dao.save( createStats( "internal", "2007/02/20 10:00:00", 20000, 11800, 0 ) );
57 dao.save( createStats( "internal", "2007/02/19 10:00:00", 20000, 11800, 100 ) );
58 dao.save( createStats( "internal", "2007/02/18 10:00:00", 20000, 11700, 320 ) );
59 }
60
61 @SuppressWarnings("unchecked")
62 public void testNotProcessedYet()
63 throws Exception
64 {
65 List<RepositoryContentStatistics> results = (List<RepositoryContentStatistics>) dao.query( new MostRecentRepositoryScanStatistics( "central" ) );
66 assertNotNull( "Not Processed Yet", results );
67 assertTrue( "Not Processed Yet", results.isEmpty() );
68 }
69
70 @SuppressWarnings("unchecked")
71 public void testStats()
72 throws Exception
73 {
74 List<RepositoryContentStatistics> results = (List<RepositoryContentStatistics>) dao.query( new MostRecentRepositoryScanStatistics( "internal" ) );
75 assertNotNull( "Stats: results (not null)", results );
76 assertEquals( "Stats: results.size", 1, results.size() );
77
78 Object o = results.get( 0 );
79 assertTrue( "Stats: result[0] instanceof RepositoryScanStatistics", o instanceof RepositoryContentStatistics );
80 RepositoryContentStatistics stats = (RepositoryContentStatistics) o;
81 assertEquals( "Stats: id", "internal", stats.getRepositoryId() );
82 assertEquals( "Stats: when gathered", "2007/02/21 10:00:00", fromDate( stats.getWhenGathered() ) );
83 assertEquals( "Stats: duration", 20000, stats.getDuration() );
84 assertEquals( "Stats: total file count", 12000, stats.getTotalFileCount() );
85 assertEquals( "Stats: new file count", 400, stats.getNewFileCount() );
86 }
87
88 }