]> source.dussan.org Git - archiva.git/blob
c17d9ea2ad2d2684872f9a20689a423684770abd
[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.apache.maven.profiles.DefaultProfileManager;
31 import org.codehaus.plexus.spring.PlexusContainerAdapter;
32 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
33
34 public class DependencyTreeGeneratorConsumerTest
35     extends PlexusInSpringTestCase
36 {
37     private DependencyTreeGeneratorConsumer consumer;
38
39     private ManagedRepositoryConfiguration repository;
40
41     private File repositoryLocation;
42
43     private File generatedRepositoryLocation;
44
45     public void setUp()
46         throws Exception
47     {
48         super.setUp();
49
50         consumer =
51             (DependencyTreeGeneratorConsumer) lookup( KnownRepositoryContentConsumer.class, "dependency-tree-generator" );
52
53         repositoryLocation = getTestFile( "target/test-" + getName() + "/test-repo" );
54         FileUtils.deleteDirectory( repositoryLocation );
55         FileUtils.copyDirectory( getTestFile( "target/test-classes/test-repo" ), repositoryLocation );
56
57         generatedRepositoryLocation = getTestFile( "target/test-" + getName() + "/generated-test-repo" );
58         FileUtils.deleteDirectory( generatedRepositoryLocation );
59
60         consumer.setGeneratedRepositoryLocation( generatedRepositoryLocation );
61
62         repository = new ManagedRepositoryConfiguration();
63         repository.setId( "dependency-tree" );
64         repository.setLocation( repositoryLocation.getAbsolutePath() );
65     }
66
67     public void testGenerateBasicTree()
68         throws IOException, ConsumerException
69     {
70         consumer.beginScan( repository, null );
71
72         String path = "org/apache/maven/maven-core/2.0/maven-core-2.0.pom";
73         consumer.processFile( path );
74
75         File generatedFile = new File( generatedRepositoryLocation, path + ".xml" );
76         assertEquals( IOUtils.toString( getClass().getResourceAsStream( "/test-data/maven-core-2.0-tree.xml" ) ),
77                       FileUtils.readFileToString( generatedFile ) );
78
79         consumer.completeScan();
80     }
81
82     public void testInvalidCoordinate()
83         throws IOException, ConsumerException
84     {
85         consumer.beginScan( repository, null );
86
87         String path = "openejb/jaxb-xjc/2.0EA3/jaxb-xjc-2.0EA3.pom";
88         try
89         {
90             consumer.processFile( path );
91
92             fail( "Should not have successfully processed the file" );
93         }
94         catch ( ConsumerException e )
95         {
96             File generatedFile = new File( generatedRepositoryLocation, path + ".xml" );
97             assertFalse( generatedFile.exists() );
98         }
99
100         consumer.completeScan();
101     }
102
103     public void testProfiles()
104         throws IOException, ConsumerException
105     {
106         PlexusContainerAdapter container = new PlexusContainerAdapter();
107         container.setApplicationContext( getApplicationContext() );
108         
109         DefaultProfileManager m = new DefaultProfileManager( container );
110         
111         consumer.beginScan( repository, null );
112
113         String path = "org/apache/maven/surefire/surefire-testng/2.0/surefire-testng-2.0.pom";
114         consumer.processFile( path );
115
116         File generatedFile = new File( generatedRepositoryLocation, path + ".xml" );
117         assertEquals( IOUtils.toString( getClass().getResourceAsStream( "/test-data/surefire-testng-2.0-tree.xml" ) ),
118                       FileUtils.readFileToString( generatedFile ) );
119
120         consumer.completeScan();
121     }
122 }