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.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 class ArtifactUpdateDatabaseConsumerTest
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          consumer =
53              (KnownRepositoryContentConsumer) lookup( KnownRepositoryContentConsumer.class, "update-db-artifact" );
54      }
55  
56      public void testConsumption()
57      {
58          File localFile =
59              new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
60  
61          ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
62          BaseFile baseFile = new BaseFile( repoLocation, localFile );
63          predicate.setBasefile( baseFile );
64  
65          assertFalse( predicate.evaluate( consumer ) );
66      }
67  
68      public void testConsumptionOfOtherMetadata()
69      {
70          File localFile =
71              new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" );
72  
73          ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
74          BaseFile baseFile = new BaseFile( repoLocation, localFile );
75          predicate.setBasefile( baseFile );
76  
77          assertFalse( predicate.evaluate( consumer ) );
78      }
79  }