View Javadoc

1   package org.apache.maven.archiva.database.jdo;
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 javax.jdo.JDOHelper;
25  
26  import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
27  import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO;
28  import org.apache.maven.archiva.database.constraints.RepositoryContentStatisticsByRepositoryConstraint;
29  import org.apache.maven.archiva.model.RepositoryContentStatistics;
30  
31  /**
32   * JdoRepositoryContentStatisticsDAOTest
33   * 
34   * @version
35   */
36  public class JdoRepositoryContentStatisticsDAOTest
37      extends AbstractArchivaDatabaseTestCase
38  {
39      public void testCRUD()
40          throws Exception
41      {
42          RepositoryContentStatisticsDAO repoContentStatisticsDAO = dao.getRepositoryContentStatisticsDAO();
43  
44          // create
45          RepositoryContentStatistics savedStats =
46             repoContentStatisticsDAO.saveRepositoryContentStatistics( createStats( "internal", "2007/10/21 8:00:00",
47             20000, 12000, 400 ) );
48          assertNotNull( savedStats );
49  
50          String savedKeyId = JDOHelper.getObjectId( savedStats ).toString();
51          assertEquals( "1[OID]org.apache.maven.archiva.model.RepositoryContentStatistics", savedKeyId );
52  
53          // query
54          List<RepositoryContentStatistics> results =
55             repoContentStatisticsDAO.queryRepositoryContentStatistics( new RepositoryContentStatisticsByRepositoryConstraint(
56                                                                                                                                "internal" ) );
57          assertNotNull( results );
58          assertEquals( 1, results.size() );
59  
60          RepositoryContentStatistics stats = (RepositoryContentStatistics) results.get( 0 );
61          assertEquals( "internal", stats.getRepositoryId() );
62  
63          // delete
64          repoContentStatisticsDAO.deleteRepositoryContentStatistics( stats );
65  
66          assertEquals( 0, repoContentStatisticsDAO.queryRepositoryContentStatistics(
67              new RepositoryContentStatisticsByRepositoryConstraint( "internal" ) ).size() );
68      }
69  
70      private RepositoryContentStatistics createStats( String repoId, String timestamp, long duration, long totalfiles,
71                                                       long newfiles )
72          throws Exception
73      {
74          RepositoryContentStatistics stats = new RepositoryContentStatistics();
75          stats.setRepositoryId( repoId );
76          stats.setDuration( duration );
77          stats.setNewFileCount( newfiles );
78          stats.setTotalFileCount( totalfiles );
79          stats.setWhenGathered( toDate( timestamp ) );
80  
81          return stats;
82      }
83  }