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