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 java.util.List;
23
24 import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
25 import org.apache.maven.archiva.database.Constraint;
26 import org.apache.maven.archiva.model.RepositoryContentStatistics;
27
28
29
30
31
32
33 public class RepositoryContentStatisticsByRepositoryConstraintTest
34 extends AbstractArchivaDatabaseTestCase
35 {
36 private RepositoryContentStatistics createStats( String repoId, String timestamp, long duration, long totalfiles,
37 long newfiles )
38 throws Exception
39 {
40 RepositoryContentStatistics stats = new RepositoryContentStatistics();
41 stats.setRepositoryId( repoId );
42 stats.setDuration( duration );
43 stats.setNewFileCount( newfiles );
44 stats.setTotalFileCount( totalfiles );
45 stats.setWhenGathered( toDate( timestamp ) );
46
47 return stats;
48 }
49
50 @Override
51 protected void setUp()
52 throws Exception
53 {
54 super.setUp();
55
56 dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics(
57 createStats( "internal", "2007/10/21 8:00:00", 20000, 12000, 400 ) );
58 dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics(
59 createStats( "internal", "2007/10/20 8:00:00", 20000, 11800, 0 ) );
60 dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics(
61 createStats( "internal", "2007/10/19 8:00:00", 20000, 11800, 100 ) );
62 dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics(
63 createStats( "internal", "2007/10/18 8:00:00", 20000, 11700, 320 ) );
64 }
65
66 public void testStats()
67 throws Exception
68 {
69 Constraint constraint = new RepositoryContentStatisticsByRepositoryConstraint( "internal" );
70 List<RepositoryContentStatistics> results = dao.getRepositoryContentStatisticsDAO().queryRepositoryContentStatistics( constraint );
71 assertNotNull( "Stats: results (not null)", results );
72 assertEquals( "Stats: results.size", 4, results.size() );
73
74 assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 0 ) ).getRepositoryId() );
75 assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 1 ) ).getRepositoryId() );
76 assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 2 ) ).getRepositoryId() );
77 assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 3 ) ).getRepositoryId() );
78 }
79
80 public void testStatsWithDateRange()
81 throws Exception
82 {
83 Constraint constraint =
84 new RepositoryContentStatisticsByRepositoryConstraint( "internal", toDate( "2007/10/18 8:00:00" ),
85 toDate( "2007/10/20 8:00:00" ) );
86 List<RepositoryContentStatistics> results = dao.getRepositoryContentStatisticsDAO().queryRepositoryContentStatistics( constraint );
87 assertNotNull( "Stats: results (not null)", results );
88 assertEquals( "Stats: results.size", 3, results.size() );
89
90 assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 0 ) ).getRepositoryId() );
91 assertEquals( toDate( "2007/10/20 8:00:00" ),
92 ( (RepositoryContentStatistics) results.get( 0 ) ).getWhenGathered() );
93
94 assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 1 ) ).getRepositoryId() );
95 assertEquals( toDate( "2007/10/19 8:00:00" ),
96 ( (RepositoryContentStatistics) results.get( 1 ) ).getWhenGathered() );
97
98 assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 2 ) ).getRepositoryId() );
99 assertEquals( toDate( "2007/10/18 8:00:00" ),
100 ( (RepositoryContentStatistics) results.get( 2 ) ).getWhenGathered() );
101 }
102 }