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