1 package org.apache.maven.archiva.consumers.database;
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
23 import java.util.Iterator;
25 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
26 import org.apache.maven.archiva.configuration.Configuration;
27 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
28 import org.apache.maven.archiva.consumers.ConsumerException;
29 import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer;
30 import org.apache.maven.archiva.database.ArchivaDatabaseException;
31 import org.apache.maven.archiva.database.ObjectNotFoundException;
32 import org.apache.maven.archiva.database.ProjectModelDAO;
33 import org.apache.maven.archiva.model.ArchivaArtifact;
34 import org.apache.maven.archiva.model.ArchivaArtifactModel;
35 import org.apache.maven.archiva.model.ArchivaProjectModel;
36 import org.apache.maven.archiva.model.Dependency;
37 import org.apache.maven.archiva.model.Keys;
38 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
41 * Test for ProjectModelToDatabaseConsumerTest
44 public class ProjectModelToDatabaseConsumerTest
45 extends PlexusInSpringTestCase
47 private ProjectModelToDatabaseConsumer consumer;
49 private ProjectModelDAO modelDao;
56 ArchivaConfiguration archivaConfig = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
58 Configuration configuration = archivaConfig.getConfiguration();
59 ManagedRepositoryConfiguration repo = configuration.findManagedRepositoryById( "internal" );
60 repo.setLocation( new File( getBasedir(), "src/test/resources/test-repo" ).toString() );
63 (ProjectModelToDatabaseConsumer) lookup( DatabaseUnprocessedArtifactConsumer.class, "update-db-project" );
64 modelDao = (ProjectModelDAO) lookup( ProjectModelDAO.class, "jdo" );
67 public void testProcess()
70 ArchivaProjectModel model = processAndGetModel( "test-project", "test-project-endpoint-pom", "2.4.4" );
71 assertNotNull( model.getParentProject() );
72 assertEquals( "test-project:test-project:2.4.4", Keys.toKey( model.getParentProject() ) );
74 assertFalse( model.getDependencyManagement().isEmpty() );
76 model = processAndGetModel( "test-project", "test-project-endpoint-ejb", "2.4.4" );
77 assertNotNull( model.getParentProject() );
78 assertEquals( "test-project:test-project-endpoint-pom:2.4.4", Keys.toKey( model.getParentProject() ) );
79 assertTrue( hasDependency( model, "test-project:test-project-api:2.4.4" ) );
80 assertTrue( hasDependency( model, "commons-id:commons-id:0.1-dev" ) );
82 model = processAndGetModel( "test-project", "test-project", "2.4.4" );
83 assertFalse( model.getDependencyManagement().isEmpty() );
86 private boolean hasDependency( ArchivaProjectModel model, String key )
88 for ( Iterator i = model.getDependencies().iterator(); i.hasNext(); )
90 Dependency dependency = (Dependency) i.next();
91 if ( key.equals( Keys.toKey( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion() ) ) )
99 private ArchivaProjectModel processAndGetModel( String group, String artifactId, String version )
100 throws ConsumerException, ObjectNotFoundException, ArchivaDatabaseException
102 ArchivaArtifact artifact = createArtifact( group, artifactId, version, "pom" );
103 consumer.processArchivaArtifact( artifact );
105 ArchivaProjectModel model = modelDao.getProjectModel( group, artifactId, version );
106 assertEquals( group, model.getGroupId() );
107 assertEquals( artifactId, model.getArtifactId() );
108 assertEquals( version, model.getVersion() );
112 protected ArchivaArtifact createArtifact( String group, String artifactId, String version, String type )
114 ArchivaArtifactModel model = new ArchivaArtifactModel();
115 model.setGroupId( group );
116 model.setArtifactId( artifactId );
117 model.setVersion( version );
118 model.setType( type );
119 model.setRepositoryId( "internal" );
121 return new ArchivaArtifact( model );