1 package org.apache.maven.archiva.consumers.core.repository;
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 org.codehaus.plexus.PlexusTestCase;
23 import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
24 import org.codehaus.plexus.jdo.JdoFactory;
25 import org.apache.maven.archiva.configuration.RepositoryConfiguration;
26 import org.apache.maven.archiva.model.ArchivaRepository;
27 import org.apache.maven.archiva.model.ArchivaArtifact;
28 import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
29 import org.apache.maven.archiva.repository.layout.LayoutException;
30 import org.apache.maven.archiva.repository.layout.DefaultBidirectionalRepositoryLayout;
31 import org.apache.maven.archiva.database.ArtifactDAO;
32 import org.apache.maven.archiva.database.ArchivaDatabaseException;
33 import org.jpox.SchemaTool;
35 import javax.jdo.PersistenceManagerFactory;
36 import javax.jdo.PersistenceManager;
37 import java.util.Properties;
38 import java.util.Iterator;
40 import java.util.List;
41 import java.util.Date;
46 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
48 public class AbstractRepositoryPurgeTest
49 extends PlexusTestCase
51 public static final String TEST_REPO_ID = "test-repo";
53 public static final String TEST_REPO_NAME = "Test Repository";
55 public static final String TEST_REPO_URL = "file://" + getBasedir() + "/target/test/test-repo/";
57 public static final int TEST_RETENTION_COUNT = 2;
59 public static final int TEST_DAYS_OLDER = 30;
61 public static final String PATH_TO_BY_DAYS_OLD_ARTIFACT =
62 "org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar";
64 public static final String PATH_TO_BY_RETENTION_COUNT_ARTIFACT =
65 "org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar";
67 public static final String PATH_TO_BY_RETENTION_COUNT_POM =
68 "org/codehaus/castor/castor-anttasks/1.1.2-SNAPSHOT/castor-anttasks-1.1.2-20070506.163513-2.pom";
70 public static final String PATH_TO_RELEASED_SNAPSHOT =
71 "org/apache/maven/plugins/maven-plugin-plugin/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar";
73 public static final String PATH_TO_HIGHER_SNAPSHOT_EXISTS =
74 "org/apache/maven/plugins/maven-source-plugin/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar";
76 private RepositoryConfiguration config;
78 private ArchivaRepository repo;
80 private BidirectionalRepositoryLayout layout;
82 protected ArtifactDAO dao;
84 protected RepositoryPurge repoPurge;
86 protected void setUp()
91 DefaultConfigurableJdoFactory jdoFactory = (DefaultConfigurableJdoFactory) lookup( JdoFactory.ROLE, "archiva" );
92 assertEquals( DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName() );
94 jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
96 jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.hsqldb.jdbcDriver" ) );
97 jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:hsqldb:mem:testdb" ) );
99 jdoFactory.setUserName( System.getProperty( "jdo.test.user", "sa" ) );
101 jdoFactory.setPassword( System.getProperty( "jdo.test.pass", "" ) );
103 jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
105 jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" );
107 jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" );
109 jdoFactory.setProperty( "javax.jdo.option.RetainValues", "true" );
111 jdoFactory.setProperty( "javax.jdo.option.RestoreValues", "true" );
113 // jdoFactory.setProperty( "org.jpox.autoCreateColumns", "true" );
115 jdoFactory.setProperty( "org.jpox.validateTables", "true" );
117 jdoFactory.setProperty( "org.jpox.validateColumns", "true" );
119 jdoFactory.setProperty( "org.jpox.validateConstraints", "true" );
121 Properties properties = jdoFactory.getProperties();
123 for ( Iterator it = properties.entrySet().iterator(); it.hasNext(); )
125 Map.Entry entry = (Map.Entry) it.next();
127 System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
130 URL jdoFileUrls[] = new URL[]{getClass().getResource( "/org/apache/maven/archiva/model/package.jdo" )};
132 if ( ( jdoFileUrls == null ) || ( jdoFileUrls[0] == null ) )
134 fail( "Unable to process test " + getName() + " - missing package.jdo." );
137 File propsFile = null; // intentional
138 boolean verbose = true;
140 SchemaTool.deleteSchemaTables( jdoFileUrls, new URL[]{}, propsFile, verbose );
141 SchemaTool.createSchemaTables( jdoFileUrls, new URL[]{}, propsFile, verbose, null );
143 PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
145 assertNotNull( pmf );
147 PersistenceManager pm = pmf.getPersistenceManager();
151 dao = (ArtifactDAO) lookup( ArtifactDAO.class.getName(), "jdo" );
154 public RepositoryConfiguration getRepoConfiguration()
156 if ( config == null )
158 config = new RepositoryConfiguration();
161 config.setId( TEST_REPO_ID );
162 config.setName( TEST_REPO_NAME );
163 config.setDaysOlder( TEST_DAYS_OLDER );
164 config.setUrl( TEST_REPO_URL );
165 config.setReleases( true );
166 config.setSnapshots( true );
167 config.setRetentionCount( TEST_RETENTION_COUNT );
172 public ArchivaRepository getRepository()
176 repo = new ArchivaRepository( TEST_REPO_ID, TEST_REPO_NAME, TEST_REPO_URL );
182 public BidirectionalRepositoryLayout getLayout()
183 throws LayoutException
185 if ( layout == null )
187 layout = new DefaultBidirectionalRepositoryLayout();
193 protected void populateDb( String groupId, String artifactId, List versions )
194 throws ArchivaDatabaseException
196 for( Iterator iter = versions.iterator(); iter.hasNext(); )
198 String version = (String) iter.next();
200 ArchivaArtifact artifact =
201 dao.createArtifact( groupId, artifactId, version, "", "jar" );
202 assertNotNull( artifact );
203 artifact.getModel().setLastModified( new Date() );
204 artifact.getModel().setOrigin( "test" );
205 ArchivaArtifact savedArtifact = dao.saveArtifact( artifact );
206 assertNotNull( savedArtifact );
210 dao.createArtifact( groupId, artifactId, version, "", "pom" );
211 assertNotNull( artifact );
212 artifact.getModel().setLastModified( new Date() );
213 artifact.getModel().setOrigin( "test" );
214 savedArtifact = dao.saveArtifact( artifact );
215 assertNotNull( savedArtifact );