View Javadoc

1   package org.apache.maven.archiva.consumers.core;
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.maven.archiva.common.utils.BaseFile;
23  import org.apache.maven.archiva.configuration.ArchivaConfiguration;
24  import org.apache.maven.archiva.configuration.FileType;
25  import org.apache.maven.archiva.configuration.FileTypes;
26  import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
27  import org.apache.maven.archiva.repository.scanner.functors.ConsumerWantsFilePredicate;
28  import org.codehaus.plexus.spring.PlexusInSpringTestCase;
29  
30  import java.io.File;
31  
32  public abstract class AbstractArtifactConsumerTest
33      extends PlexusInSpringTestCase
34  {
35      private File repoLocation;
36  
37      protected KnownRepositoryContentConsumer consumer;
38  
39      protected void setUp()
40          throws Exception
41      {
42          super.setUp();
43  
44          ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.ROLE );
45          FileType fileType =
46              (FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
47          assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
48          fileType.addPattern( "**/*.xml" );
49  
50          repoLocation = getTestFile( "target/test-" + getName() + "/test-repo" );
51      }
52  
53      public void testConsumption()
54      {
55          File localFile =
56              new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
57  
58          ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
59          BaseFile baseFile = new BaseFile( repoLocation, localFile );
60          predicate.setBasefile( baseFile );
61  
62          assertFalse( predicate.evaluate( consumer ) );
63      }
64  
65      public void testConsumptionOfOtherMetadata()
66      {
67          File localFile =
68              new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" );
69  
70          ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
71          BaseFile baseFile = new BaseFile( repoLocation, localFile );
72          predicate.setBasefile( baseFile );
73  
74          assertFalse( predicate.evaluate( consumer ) );
75      }
76  }