]> source.dussan.org Git - archiva.git/blob
9b8bc8a1e2c1d41c551a33b9563f64dc66a8c414
[archiva.git] /
1 package org.apache.archiva.consumers.dependencytree;
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 java.io.File;
23 import java.io.IOException;
24
25 import org.apache.commons.io.FileUtils;
26 import org.apache.commons.io.IOUtils;
27 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
28 import org.apache.maven.archiva.consumers.ConsumerException;
29 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
30 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
31
32 public class DependencyTreeGeneratorConsumerTest
33     extends PlexusInSpringTestCase
34 {
35     private DependencyTreeGeneratorConsumer consumer;
36
37     private ManagedRepositoryConfiguration repository;
38
39     private File repositoryLocation;
40
41     private File generatedRepositoryLocation;
42
43     public void setUp()
44         throws Exception
45     {
46         super.setUp();
47         
48         consumer =
49             (DependencyTreeGeneratorConsumer) lookup( KnownRepositoryContentConsumer.class, "dependency-tree-generator" );
50
51         repositoryLocation = getTestFile( "target/test-" + getName() + "/test-repo" );
52         FileUtils.deleteDirectory( repositoryLocation );
53         FileUtils.copyDirectory( getTestFile( "target/test-classes/test-repo" ), repositoryLocation );
54
55         generatedRepositoryLocation = getTestFile( "target/test-" + getName() + "/generated-test-repo" );
56         FileUtils.deleteDirectory( generatedRepositoryLocation );
57
58         consumer.setGeneratedRepositoryLocation( generatedRepositoryLocation );
59
60         repository = new ManagedRepositoryConfiguration();
61         repository.setId( "dependency-tree" );
62         repository.setLocation( repositoryLocation.getAbsolutePath() );
63     }
64
65     public void testGenerateBasicTree()
66         throws IOException, ConsumerException
67     {
68         consumer.beginScan( repository );
69
70         String path = "org/apache/maven/maven-core/2.0/maven-core-2.0.pom";
71         consumer.processFile( path );
72
73         File generatedFile = new File( generatedRepositoryLocation, path + ".xml" );
74         assertEquals( IOUtils.toString( getClass().getResourceAsStream( "/test-data/maven-core-2.0-tree.xml" ) ),
75                       FileUtils.readFileToString( generatedFile ) );
76
77         consumer.completeScan();
78     }
79 }