]> source.dussan.org Git - archiva.git/blob
b8f6d55e1e5ea492185ebbc3f1f3f6a70723fbd0
[archiva.git] /
1 package org.apache.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.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.repository.RepositoryRegistry;
29 import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
30 import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
31 import org.apache.archiva.repository.base.managed.ManagedRepositoryHandler;
32 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
33 import org.apache.commons.lang3.StringUtils;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.springframework.context.ApplicationContext;
39 import org.springframework.test.annotation.DirtiesContext;
40 import org.springframework.test.context.ContextConfiguration;
41
42 import javax.inject.Inject;
43 import java.nio.file.Path;
44 import java.nio.file.Paths;
45
46 import static org.junit.Assert.*;
47
48 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
49 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
50 public abstract class AbstractArtifactConsumerTest
51 {
52     private Path repoLocation;
53
54     protected KnownRepositoryContentConsumer consumer;
55
56     @Inject
57     protected ApplicationContext applicationContext;
58
59     @Inject
60     ArchivaConfiguration archivaConfiguration;
61
62     @SuppressWarnings( "unused" )
63     @Inject
64     RepositoryRegistry repositoryRegistry;
65
66     @SuppressWarnings( "unused" )
67     @Inject
68     RepositoryGroupHandler repositoryGroupHandler;
69
70     @SuppressWarnings( "unused" )
71     @Inject
72     ManagedRepositoryHandler managedRepositoryHandler;
73
74
75     @Before
76     public void setUp()
77         throws Exception
78     {
79         FileType fileType =
80             archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
81         assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
82         fileType.addPattern( "**/*.xml" );
83         archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("MD5");
84         archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("SHA1");
85         archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("SHA256");
86
87         repoLocation = Paths.get( "target/test-" + getName() + "/test-repo" );
88     }
89
90
91     @SuppressWarnings( "deprecation" )
92     @Test
93     public void testConsumption()
94     {
95         Path localFile =
96             repoLocation.resolve( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
97
98         ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
99         BaseFile baseFile = new BaseFile( repoLocation.toFile(), localFile.toFile() );
100         predicate.setBasefile( baseFile );
101
102         assertFalse( predicate.evaluate( consumer ) );
103     }
104
105     @SuppressWarnings( "deprecation" )
106     @Test
107     public void testConsumptionOfOtherMetadata()
108     {
109         Path localFile =
110             repoLocation.resolve( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" );
111
112         ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
113         BaseFile baseFile = new BaseFile( repoLocation.toFile(), localFile.toFile() );
114         predicate.setBasefile( baseFile );
115
116         assertFalse( predicate.evaluate( consumer ) );
117     }
118     
119     public String getName()
120     {
121         return StringUtils.substringAfterLast( getClass().getName(), "." );
122     }
123 }