View Javadoc

1   package org.apache.maven.archiva.database.constraints;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
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   * RepositoryContentStatisticsByRepositoryConstraintTest
30   * 
31   * @version
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 }