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