1 package org.apache.archiva.consumers.dependencytree;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
23 import java.io.IOException;
25 import javax.xml.parsers.ParserConfigurationException;
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;
38 public class DependencyTreeGeneratorConsumerTest
39 extends PlexusInSpringTestCase
41 private DependencyTreeGeneratorConsumer consumer;
43 private ManagedRepositoryConfiguration repository;
45 private File repositoryLocation;
47 private File generatedRepositoryLocation;
55 (DependencyTreeGeneratorConsumer) lookup( KnownRepositoryContentConsumer.class, "dependency-tree-generator" );
57 repositoryLocation = getTestFile( "target/test-" + getName() + "/test-repo" );
58 FileUtils.deleteDirectory( repositoryLocation );
59 FileUtils.copyDirectory( getTestFile( "target/test-classes/test-repo" ), repositoryLocation );
61 generatedRepositoryLocation = getTestFile( "target/test-" + getName() + "/generated-test-repo" );
62 FileUtils.deleteDirectory( generatedRepositoryLocation );
64 consumer.setGeneratedRepositoryLocation( generatedRepositoryLocation );
66 repository = new ManagedRepositoryConfiguration();
67 repository.setId( "dependency-tree" );
68 repository.setLocation( repositoryLocation.getAbsolutePath() );
71 public void testGenerateBasicTree()
72 throws IOException, ConsumerException, ParserConfigurationException, SAXException
74 consumer.beginScan( repository, null );
76 String path = "org/apache/maven/maven-core/2.0/maven-core-2.0.pom";
77 consumer.processFile( path );
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 ) );
83 consumer.completeScan();
86 public void testInvalidCoordinate()
87 throws IOException, ConsumerException
89 consumer.beginScan( repository, null );
91 String path = "openejb/jaxb-xjc/2.0EA3/jaxb-xjc-2.0EA3.pom";
94 consumer.processFile( path );
96 fail( "Should not have successfully processed the file" );
98 catch ( ConsumerException e )
100 File generatedFile = new File( generatedRepositoryLocation, path + ".xml" );
101 assertFalse( generatedFile.exists() );
104 consumer.completeScan();
107 public void testProfiles()
108 throws IOException, ConsumerException, ParserConfigurationException, SAXException
110 PlexusContainerAdapter container = new PlexusContainerAdapter();
111 container.setApplicationContext( getApplicationContext() );
113 DefaultProfileManager m = new DefaultProfileManager( container );
115 consumer.beginScan( repository, null );
117 String path = "org/apache/maven/surefire/surefire-testng/2.0/surefire-testng-2.0.pom";
118 consumer.processFile( path );
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 ) );
124 consumer.completeScan();