1 package org.apache.maven.archiva.database.constraints;
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 java.util.List;
24 import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
25 import org.apache.maven.archiva.database.Constraint;
26 import org.apache.maven.archiva.model.RepositoryContentStatistics;
29 * RepositoryContentStatisticsByRepositoryConstraintTest
31 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
34 public class RepositoryContentStatisticsByRepositoryConstraintTest
35 extends AbstractArchivaDatabaseTestCase
37 private RepositoryContentStatistics createStats( String repoId, String timestamp, long duration, long totalfiles,
41 RepositoryContentStatistics stats = new RepositoryContentStatistics();
42 stats.setRepositoryId( repoId );
43 stats.setDuration( duration );
44 stats.setNewFileCount( newfiles );
45 stats.setTotalFileCount( totalfiles );
46 stats.setWhenGathered( toDate( timestamp ) );
51 protected void setUp()
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 ) );
66 public void testStats()
69 Constraint constraint = new RepositoryContentStatisticsByRepositoryConstraint( "internal" );
70 List results = dao.getRepositoryContentStatisticsDAO().queryRepositoryContentStatistics( constraint );
71 assertNotNull( "Stats: results (not null)", results );
72 assertEquals( "Stats: results.size", 4, results.size() );
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() );