1 package org.apache.archiva.consumers.core;
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.archiva.common.utils.BaseFile;
23 import org.apache.archiva.configuration.ArchivaConfiguration;
24 import org.apache.archiva.configuration.FileType;
25 import org.apache.archiva.configuration.FileTypes;
26 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
27 import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate;
28 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
29 import org.apache.commons.lang.StringUtils;
30 import org.apache.maven.index.NexusIndexer;
31 import org.apache.maven.index.context.IndexingContext;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.springframework.context.ApplicationContext;
37 import org.springframework.test.context.ContextConfiguration;
39 import javax.inject.Inject;
42 import static org.junit.Assert.assertEquals;
43 import static org.junit.Assert.assertFalse;
45 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
46 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
47 public abstract class AbstractArtifactConsumerTest
49 private File repoLocation;
51 protected KnownRepositoryContentConsumer consumer;
54 protected ApplicationContext applicationContext;
57 ArchivaConfiguration archivaConfiguration;
60 protected PlexusSisuBridge plexusSisuBridge;
68 (FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
69 assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
70 fileType.addPattern( "**/*.xml" );
72 repoLocation = new File( "target/test-" + getName() + "/test-repo" );
76 public void tearDown()
79 NexusIndexer nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
80 for ( IndexingContext indexingContext : nexusIndexer.getIndexingContexts().values() )
82 nexusIndexer.removeIndexingContext( indexingContext, false );
88 public void testConsumption()
91 new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
93 ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
94 BaseFile baseFile = new BaseFile( repoLocation, localFile );
95 predicate.setBasefile( baseFile );
97 assertFalse( predicate.evaluate( consumer ) );
101 public void testConsumptionOfOtherMetadata()
104 new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" );
106 ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
107 BaseFile baseFile = new BaseFile( repoLocation, localFile );
108 predicate.setBasefile( baseFile );
110 assertFalse( predicate.evaluate( consumer ) );
113 public String getName()
115 return StringUtils.substringAfterLast( getClass().getName(), "." );