1 package org.apache.maven.archiva.database.jdo;
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 javax.jdo.JDOHelper;
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;
32 * JdoRepositoryContentStatisticsDAOTest
36 public class JdoRepositoryContentStatisticsDAOTest
37 extends AbstractArchivaDatabaseTestCase
39 public void testCRUD()
42 RepositoryContentStatisticsDAO repoContentStatisticsDAO = dao.getRepositoryContentStatisticsDAO();
45 RepositoryContentStatistics savedStats =
46 repoContentStatisticsDAO.saveRepositoryContentStatistics( createStats( "internal", "2007/10/21 8:00:00",
47 20000, 12000, 400 ) );
48 assertNotNull( savedStats );
50 String savedKeyId = JDOHelper.getObjectId( savedStats ).toString();
51 assertEquals( "1[OID]org.apache.maven.archiva.model.RepositoryContentStatistics", savedKeyId );
55 repoContentStatisticsDAO.queryRepositoryContentStatistics( new RepositoryContentStatisticsByRepositoryConstraint(
57 assertNotNull( results );
58 assertEquals( 1, results.size() );
60 RepositoryContentStatistics stats = (RepositoryContentStatistics) results.get( 0 );
61 assertEquals( "internal", stats.getRepositoryId() );
64 repoContentStatisticsDAO.deleteRepositoryContentStatistics( stats );
66 assertEquals( 0, repoContentStatisticsDAO.queryRepositoryContentStatistics(
67 new RepositoryContentStatisticsByRepositoryConstraint( "internal" ) ).size() );
70 private RepositoryContentStatistics createStats( String repoId, String timestamp, long duration, long totalfiles,
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 ) );