1 package org.apache.maven.archiva.scheduled.executors;
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.apache.maven.archiva.configuration.ArchivaConfiguration;
23 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
24 import org.apache.maven.archiva.database.ArchivaDAO;
25 import org.apache.maven.archiva.database.ArtifactDAO;
26 import org.apache.maven.archiva.database.constraints.ArtifactsProcessedConstraint;
27 import org.apache.maven.archiva.scheduled.tasks.RepositoryTask;
28 import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
29 import org.codehaus.plexus.jdo.JdoFactory;
30 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
31 import org.codehaus.plexus.taskqueue.execution.TaskExecutor;
32 import org.jpox.SchemaTool;
36 import java.util.Iterator;
37 import java.util.List;
39 import java.util.Properties;
41 import javax.jdo.PersistenceManager;
42 import javax.jdo.PersistenceManagerFactory;
45 * ArchivaRepositoryScanningTaskExecutorTest
49 public class ArchivaRepositoryScanningTaskExecutorTest
50 extends PlexusInSpringTestCase
52 private TaskExecutor taskExecutor;
54 protected ArchivaDAO dao;
56 protected void setUp()
61 DefaultConfigurableJdoFactory jdoFactory = (DefaultConfigurableJdoFactory) lookup( JdoFactory.ROLE, "archiva" );
62 assertEquals( DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName() );
64 jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
67 File derbyDbDir = new File( "target/plexus-home/testdb" );
68 if ( derbyDbDir.exists() )
70 FileUtils.deleteDirectory( derbyDbDir );
73 jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.apache.derby.jdbc.EmbeddedDriver" ) );
74 jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:derby:" + derbyDbDir.getAbsolutePath() + ";create=true" ) );
77 jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.hsqldb.jdbcDriver" ) );
78 jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:hsqldb:mem:" + getName() ) );
80 jdoFactory.setUserName( System.getProperty( "jdo.test.user", "sa" ) );
82 jdoFactory.setPassword( System.getProperty( "jdo.test.pass", "" ) );
84 jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
86 jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" );
88 jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" );
90 jdoFactory.setProperty( "javax.jdo.option.RetainValues", "true" );
92 jdoFactory.setProperty( "javax.jdo.option.RestoreValues", "true" );
94 // jdoFactory.setProperty( "org.jpox.autoCreateColumns", "true" );
96 jdoFactory.setProperty( "org.jpox.validateTables", "true" );
98 jdoFactory.setProperty( "org.jpox.validateColumns", "true" );
100 jdoFactory.setProperty( "org.jpox.validateConstraints", "true" );
102 Properties properties = jdoFactory.getProperties();
104 for ( Iterator it = properties.entrySet().iterator(); it.hasNext(); )
106 Map.Entry entry = (Map.Entry) it.next();
108 System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
111 URL jdoFileUrls[] = new URL[] { getClass()
112 .getResource( "/org/apache/maven/archiva/model/package.jdo" ) };
114 if ( ( jdoFileUrls == null ) || ( jdoFileUrls[0] == null ) )
116 fail( "Unable to process test " + getName() + " - missing package.jdo." );
119 File propsFile = null; // intentional
120 boolean verbose = true;
122 SchemaTool.deleteSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose );
123 SchemaTool.createSchemaTables( jdoFileUrls, new URL[] {}, propsFile, verbose, null );
125 PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory();
127 assertNotNull( pmf );
129 PersistenceManager pm = pmf.getPersistenceManager();
133 this.dao = (ArchivaDAO) lookup( ArchivaDAO.class.getName(), "jdo" );
135 taskExecutor = (TaskExecutor) lookup( TaskExecutor.class, "test-repository-scanning" );
138 public void testExecutor() throws Exception
140 File repoDir = new File( getBasedir(), "src/test/repositories/default-repository" );
142 assertTrue( "Default Test Repository should exist.", repoDir.exists() && repoDir.isDirectory() );
144 ArchivaConfiguration archivaConfig = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
145 assertNotNull( archivaConfig );
148 ManagedRepositoryConfiguration repo = createRepository( "testRepo", "Test Repository", repoDir );
149 assertNotNull( repo );
150 archivaConfig.getConfiguration().getManagedRepositories().clear();
151 archivaConfig.getConfiguration().addManagedRepository( repo );
153 RepositoryTask repoTask = new RepositoryTask();
155 repoTask.setName( "testRepoTask" );
156 repoTask.setRepositoryId( "testRepo" );
158 taskExecutor.executeTask( repoTask );
160 ArtifactDAO adao = dao.getArtifactDAO();
161 List unprocessedResultList = adao.queryArtifacts( new ArtifactsProcessedConstraint( false ) );
163 assertNotNull( unprocessedResultList );
164 assertEquals("Incorrect number of unprocessed artifacts detected.", 8, unprocessedResultList.size() );
167 protected ManagedRepositoryConfiguration createRepository( String id, String name, File location )
169 ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
171 repo.setName( name );
172 repo.setLocation( location.getAbsolutePath() );