fix unit test with adding mocks

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1583324 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2014-03-31 13:23:20 +00:00
parent 0a691774f3
commit 4d70362d9d
7 changed files with 173 additions and 15 deletions

View File

@ -27,7 +27,6 @@ import org.apache.archiva.metadata.repository.filter.Filter;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.policies.ProxyDownloadException;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.archiva.xml.XMLException;
import java.util.Collection;

View File

@ -20,8 +20,8 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>plugins</artifactId>
<groupId>org.apache.archiva</groupId>
<artifactId>plugins</artifactId>
<version>2.0.2-SNAPSHOT</version>
</parent>
<artifactId>maven2-repository</artifactId>

View File

@ -35,7 +35,6 @@ import org.apache.archiva.maven2.metadata.MavenMetadataReader;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.metadata.repository.filter.Filter;
import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
import org.apache.archiva.metadata.repository.storage.RelocationException;
@ -74,7 +73,6 @@ import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.wagon.PathUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -111,6 +109,9 @@ import java.util.Map;
public class Maven2RepositoryStorage
implements RepositoryStorage
{
private static final Logger LOGGER = LoggerFactory.getLogger( Maven2RepositoryStorage.class );
private ModelBuilder builder;
@Inject
@ -139,8 +140,6 @@ public class Maven2RepositoryStorage
@Named( value = "pathParser#default" )
private PathParser pathParser;
private static final Logger log = LoggerFactory.getLogger( Maven2RepositoryStorage.class );
private static final String METADATA_FILENAME_START = "maven-metadata";
private static final String METADATA_FILENAME = METADATA_FILENAME_START + ".xml";
@ -173,10 +172,9 @@ public class Maven2RepositoryStorage
// olamy: in case of browsing via the ui we can mix repos (parent of a SNAPSHOT can come from release repo)
if ( !readMetadataRequest.isBrowsingRequest() )
{
if ( VersionUtil.isSnapshot(
artifactVersion ) ) // skygo trying to improve speed by honoring managed configuration MRM-1658
if ( VersionUtil.isSnapshot( artifactVersion ) )
{
// skygo trying to improve speed by honoring managed configuration MRM-1658
if ( managedRepository.isReleases() && !managedRepository.isSnapshots() )
{
throw new RepositoryStorageRuntimeException( "lookforsnaponreleaseonly",
@ -214,8 +212,8 @@ public class Maven2RepositoryStorage
}
catch ( XMLException e )
{
// unable to parse metadata - log it, and continue with the version as the original SNAPSHOT version
log.warn( "Invalid metadata: {} - {}", metadataFile, e.getMessage() );
// unable to parse metadata - LOGGER it, and continue with the version as the original SNAPSHOT version
LOGGER.warn( "Invalid metadata: {} - {}", metadataFile, e.getMessage() );
}
}
@ -301,8 +299,8 @@ public class Maven2RepositoryStorage
if ( ( problem.getException() instanceof FileNotFoundException && e.getModelId() != null &&
!e.getModelId().equals( problem.getModelId() ) ) )
{
log.warn( "The artifact's parent POM file '{}' cannot be resolved. "
+ "Using defaults for project version metadata..", file );
LOGGER.warn( "The artifact's parent POM file '{}' cannot be resolved. "
+ "Using defaults for project version metadata..", file );
ProjectVersionMetadata metadata = new ProjectVersionMetadata();
metadata.setId( readMetadataRequest.getProjectVersion() );
@ -871,7 +869,7 @@ public class Maven2RepositoryStorage
}
catch ( IOException e )
{
log.error( "Unable to checksum file {}: {},MD5", file, e.getMessage() );
LOGGER.error( "Unable to checksum file {}: {},MD5", file, e.getMessage() );
}
try
{
@ -879,7 +877,7 @@ public class Maven2RepositoryStorage
}
catch ( IOException e )
{
log.error( "Unable to checksum file {}: {},SHA1", file, e.getMessage() );
LOGGER.error( "Unable to checksum file {}: {},SHA1", file, e.getMessage() );
}
metadata.setSize( file.length() );
}

View File

@ -277,6 +277,7 @@
<configuration>
<systemPropertyVariables>
<cassandra.port>${cassandraPort}</cassandra.port>
<archiva.repositorySessionFactory.id>cassandra</archiva.repositorySessionFactory.id>
</systemPropertyVariables>
</configuration>
</plugin>

View File

@ -22,4 +22,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="repositoryStorage#maven2" class="org.apache.archiva.metadata.repository.cassandra.MockRepositoryStorage"/>
<bean name="mockrepo#listener" class="org.apache.archiva.metadata.repository.cassandra.MockRepositoryStorage"/>
</beans>

View File

@ -0,0 +1,147 @@
package org.apache.archiva.metadata.repository.cassandra;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.filter.Filter;
import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
import org.apache.archiva.metadata.repository.storage.RelocationException;
import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataException;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.policies.ProxyDownloadException;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.events.RepositoryListener;
import org.apache.archiva.xml.XMLException;
import java.util.Collection;
/**
* @author Olivier Lamy
*/
public class MockRepositoryStorage
implements RepositoryStorage, RepositoryListener
{
@Override
public ProjectMetadata readProjectMetadata( String repoId, String namespace, String projectId )
{
return null;
}
@Override
public ProjectVersionMetadata readProjectVersionMetadata( ReadMetadataRequest readMetadataRequest )
throws RepositoryStorageMetadataInvalidException, RepositoryStorageMetadataNotFoundException,
RepositoryStorageRuntimeException
{
return null;
}
@Override
public Collection<String> listRootNamespaces( String repoId, Filter<String> filter )
throws RepositoryStorageRuntimeException
{
return null;
}
@Override
public Collection<String> listNamespaces( String repoId, String namespace, Filter<String> filter )
throws RepositoryStorageRuntimeException
{
return null;
}
@Override
public Collection<String> listProjects( String repoId, String namespace, Filter<String> filter )
throws RepositoryStorageRuntimeException
{
return null;
}
@Override
public Collection<String> listProjectVersions( String repoId, String namespace, String projectId,
Filter<String> filter )
throws RepositoryStorageRuntimeException
{
return null;
}
@Override
public Collection<ArtifactMetadata> readArtifactsMetadata( ReadMetadataRequest readMetadataRequest )
throws RepositoryStorageRuntimeException
{
return null;
}
@Override
public ArtifactMetadata readArtifactMetadataFromPath( String repoId, String path )
throws RepositoryStorageRuntimeException
{
return null;
}
@Override
public void applyServerSideRelocation( ManagedRepositoryContent managedRepository, ArtifactReference artifact )
throws ProxyDownloadException
{
}
@Override
public String getFilePath( String requestPath, ManagedRepository managedRepository )
{
return null;
}
@Override
public String getFilePathWithVersion( String requestPath, ManagedRepositoryContent managedRepositoryContent )
throws RelocationException, XMLException
{
return null;
}
@Override
public void deleteArtifact( MetadataRepository metadataRepository, String repositoryId, String namespace,
String project, String version, String id )
{
}
@Override
public void addArtifact( RepositorySession session, String repoId, String namespace, String projectId,
ProjectVersionMetadata metadata )
{
}
@Override
public void addArtifactProblem( RepositorySession session, String repoId, String namespace, String projectId,
String projectVersion, RepositoryStorageMetadataException exception )
{
}
}

View File

@ -113,6 +113,15 @@
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<archiva.repositorySessionFactory.id>file</archiva.repositorySessionFactory.id>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>