1   package org.apache.maven.shared.test.plugin;
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  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.artifact.factory.ArtifactFactory;
26  import org.apache.maven.project.MavenProject;
27  import org.apache.maven.project.artifact.ProjectArtifactMetadata;
28  import org.apache.maven.shared.tools.easymock.TestFileManager;
29  import org.codehaus.plexus.PlexusTestCase;
30  
31  /**
32   * @version $Id: RepositoryToolTest.java 677115 2008-07-16 00:16:13Z vsiveton $
33   */
34  public class RepositoryToolTest
35      extends PlexusTestCase
36  {
37      private TestFileManager fileManager;
38  
39      public void setUp()
40          throws Exception
41      {
42          super.setUp();
43  
44          fileManager = new TestFileManager( "RepositoryToolTest.", "" );
45      }
46  
47      public void tearDown()
48          throws Exception
49      {
50          super.tearDown();
51  
52          fileManager.cleanUp();
53      }
54  
55      public void testCreateLocalRepositoryFromPlugin_ShouldWriteJarAndPom()
56          throws Exception
57      {
58          RepositoryTool repoTool = (RepositoryTool) lookup( RepositoryTool.ROLE, "default" );
59  
60          File tempDir = fileManager.createTempDir();
61  
62          String pomContent = "<project><modelVersion>4.0.0</modelVersion></project>";
63          String jarContent = "This is a test";
64  
65          File pom = fileManager.createFile( tempDir, "pom.xml", pomContent );
66          File jar = fileManager.createFile( tempDir, "artifact-test.jar", jarContent );
67  
68          MavenProject pluginProject = new MavenProject();
69  
70          ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
71  
72          Artifact pluginArtifact = artifactFactory.createArtifact( "group", "artifact", "test", null, "jar" );
73          pluginArtifact.setFile( jar );
74          pluginArtifact.addMetadata( new ProjectArtifactMetadata( pluginArtifact, pom ) );
75  
76          pluginProject.setArtifact( pluginArtifact );
77          pluginProject.setFile( pom );
78  
79          File targetLocalRepoBasedir = fileManager.createTempDir();
80  
81          repoTool.createLocalRepositoryFromComponentProject( pluginProject, pom, targetLocalRepoBasedir );
82  
83          fileManager.assertFileExistence( targetLocalRepoBasedir, "group/artifact/test/artifact-test.pom", true );
84          fileManager.assertFileContents( targetLocalRepoBasedir, "group/artifact/test/artifact-test.jar", jarContent );
85  
86      }
87  }