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 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;
34 public class DependencyTreeGeneratorConsumerTest
35 extends PlexusInSpringTestCase
37 private DependencyTreeGeneratorConsumer consumer;
39 private ManagedRepositoryConfiguration repository;
41 private File repositoryLocation;
43 private File generatedRepositoryLocation;
51 (DependencyTreeGeneratorConsumer) lookup( KnownRepositoryContentConsumer.class, "dependency-tree-generator" );
53 repositoryLocation = getTestFile( "target/test-" + getName() + "/test-repo" );
54 FileUtils.deleteDirectory( repositoryLocation );
55 FileUtils.copyDirectory( getTestFile( "target/test-classes/test-repo" ), repositoryLocation );
57 generatedRepositoryLocation = getTestFile( "target/test-" + getName() + "/generated-test-repo" );
58 FileUtils.deleteDirectory( generatedRepositoryLocation );
60 consumer.setGeneratedRepositoryLocation( generatedRepositoryLocation );
62 repository = new ManagedRepositoryConfiguration();
63 repository.setId( "dependency-tree" );
64 repository.setLocation( repositoryLocation.getAbsolutePath() );
67 public void testGenerateBasicTree()
68 throws IOException, ConsumerException
70 consumer.beginScan( repository, null );
72 String path = "org/apache/maven/maven-core/2.0/maven-core-2.0.pom";
73 consumer.processFile( path );
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 ) );
79 consumer.completeScan();
82 public void testInvalidCoordinate()
83 throws IOException, ConsumerException
85 consumer.beginScan( repository, null );
87 String path = "openejb/jaxb-xjc/2.0EA3/jaxb-xjc-2.0EA3.pom";
90 consumer.processFile( path );
92 fail( "Should not have successfully processed the file" );
94 catch ( ConsumerException e )
96 File generatedFile = new File( generatedRepositoryLocation, path + ".xml" );
97 assertFalse( generatedFile.exists() );
100 consumer.completeScan();
103 public void testProfiles()
104 throws IOException, ConsumerException
106 PlexusContainerAdapter container = new PlexusContainerAdapter();
107 container.setApplicationContext( getApplicationContext() );
109 DefaultProfileManager m = new DefaultProfileManager( container );
111 consumer.beginScan( repository, null );
113 String path = "org/apache/maven/surefire/surefire-testng/2.0/surefire-testng-2.0.pom";
114 consumer.processFile( path );
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 ) );
120 consumer.completeScan();