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