View Javadoc

1   package org.apache.maven.archiva.consumers.database;
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 org.apache.commons.io.FileUtils;
23  import org.apache.maven.archiva.configuration.ArchivaConfiguration;
24  import org.apache.maven.archiva.configuration.Configuration;
25  import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
26  import org.apache.maven.archiva.model.ArchivaArtifact;
27  import org.apache.maven.archiva.model.ArchivaArtifactModel;
28  import org.apache.maven.archiva.model.ArchivaProjectModel;
29  import org.apache.maven.archiva.repository.RepositoryContentFactory;
30  import org.codehaus.plexus.spring.PlexusInSpringTestCase;
31  
32  import java.io.File;
33  
34  /**
35   */
36  public abstract class AbstractDatabaseCleanupTest
37      extends PlexusInSpringTestCase
38  {
39      ArchivaConfiguration archivaConfig;
40      
41      RepositoryContentFactory repositoryFactory;
42  
43      public static final String TEST_GROUP_ID = "org.apache.maven.archiva";
44  
45      public static final String TEST_ARTIFACT_ID = "cleanup-artifact-test";
46  
47      public static final String TEST_VERSION = "1.0";
48  
49      public static final String TEST_REPO_ID = "test-repo";
50  
51      public void setUp()
52          throws Exception
53      {
54          super.setUp();
55  
56          // archiva configuration (need to update the repository url)
57          File userFile = getTestFile( "target/test/repository-manager.xml" );
58          userFile.delete();
59          assertFalse( userFile.exists() );
60  
61          userFile.getParentFile().mkdirs();
62          FileUtils.copyFileToDirectory( getTestFile( "src/test/conf/repository-manager.xml" ),
63                                         userFile.getParentFile() );
64  
65          archivaConfig = (ArchivaConfiguration) lookup( ArchivaConfiguration.class, "database-cleanup" );
66  
67          Configuration configuration = archivaConfig.getConfiguration();
68          ManagedRepositoryConfiguration repo = configuration.findManagedRepositoryById( TEST_REPO_ID );
69          repo.setLocation( new File( getBasedir(), "src/test/resources/test-repo" ).toString() );
70  
71          archivaConfig.save( configuration );
72          
73          repositoryFactory = (RepositoryContentFactory) lookup( RepositoryContentFactory.class );
74      }
75  
76      protected ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String type )
77      {
78          ArchivaArtifactModel model = new ArchivaArtifactModel();
79          model.setGroupId( groupId );
80          model.setArtifactId( artifactId );
81          model.setVersion( version );
82          model.setType( type );
83          model.setRepositoryId( TEST_REPO_ID );
84  
85          return new ArchivaArtifact( model );
86      }
87  
88      protected ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version )
89      {
90          ArchivaProjectModel projectModel = new ArchivaProjectModel();
91          projectModel.setGroupId( groupId );
92          projectModel.setArtifactId( artifactId );
93          projectModel.setVersion( version );
94  
95          return projectModel;
96      }
97  }