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 org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
23  import org.apache.maven.archiva.model.RepositoryContentStatistics;
24  
25  import java.util.List;
26  
27  /**
28   * MostRecentRepositoryScanStatisticsTest 
29   *
30   * @version $Id: MostRecentRepositoryScanStatisticsTest.java 755266 2009-03-17 14:28:40Z brett $
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  }