View Javadoc

1   package org.apache.maven.plugin.dependency;
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.repository.ArtifactRepository;
25  import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
26  import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
27  import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout;
28  import org.apache.maven.plugin.MojoFailureException;
29  import org.apache.maven.plugin.testing.stubs.StubArtifactRepository;
30  
31  public class TestGetMojo
32      extends AbstractDependencyMojoTestCase
33  {
34      GetMojo mojo;
35  
36      protected void setUp()
37          throws Exception
38      {
39          // required for mojo lookups to work
40          super.setUp( "markers", false );
41  
42          File testPom = new File( getBasedir(), "target/test-classes/unit/get-test/plugin-config.xml" );
43          assert testPom.exists();
44          mojo = (GetMojo) lookupMojo( "get", testPom );
45  
46          assertNotNull( mojo );
47          setVariableValueToObject( mojo, "localRepository", new StubArtifactRepository( testDir.getAbsolutePath() ) );
48      }
49  
50      /**
51       * Test transitive parameter
52       * 
53       * @throws Exception
54       */
55      public void testTransitive()
56          throws Exception
57      {
58          // Set properties, transitive = default value = true
59          setVariableValueToObject( mojo, "transitive", Boolean.FALSE );
60          setVariableValueToObject( mojo, "repositoryUrl", "http://repo1.maven.apache.org/maven2" );
61          setVariableValueToObject( mojo, "groupId", "org.apache.maven" );
62          setVariableValueToObject( mojo, "artifactId", "maven-model" );
63          setVariableValueToObject( mojo, "version", "2.0.9" );
64  
65          mojo.execute();
66  
67          // Set properties, transitive = false
68          setVariableValueToObject( mojo, "transitive", Boolean.FALSE );
69          mojo.execute();
70      }
71  
72      /**
73       * Test remote repositories parameter
74       * 
75       * @throws Exception
76       */
77      public void testRemoteRepositories()
78          throws Exception
79      {
80          setVariableValueToObject( mojo, "remoteRepositories", "central::default::http://repo1.maven.apache.org/maven2,"
81              + "central::::http://repo1.maven.apache.org/maven2," + "http://repo1.maven.apache.org/maven2" );
82          setVariableValueToObject( mojo, "groupId", "org.apache.maven" );
83          setVariableValueToObject( mojo, "artifactId", "maven-model" );
84          setVariableValueToObject( mojo, "version", "2.0.9" );
85  
86          mojo.execute();
87      }
88  
89      /**
90       * Test parsing of the remote repositories parameter
91       * 
92       * @throws Exception
93       */
94      public void testParseRepository()
95          throws Exception
96      {
97          ArtifactRepository repo;
98          ArtifactRepositoryPolicy policy = null;
99          repo = mojo.parseRepository( "central::default::http://repo1.maven.apache.org/maven2", policy );
100         assertEquals( "central", repo.getId() );
101         assertEquals( DefaultRepositoryLayout.class, repo.getLayout().getClass() );
102         assertEquals( "http://repo1.maven.apache.org/maven2", repo.getUrl() );
103 
104         repo = mojo.parseRepository( "central::legacy::http://repo1.maven.apache.org/maven2", policy );
105         assertEquals( "central", repo.getId() );
106         assertEquals( LegacyRepositoryLayout.class, repo.getLayout().getClass() );
107         assertEquals( "http://repo1.maven.apache.org/maven2", repo.getUrl() );
108 
109         repo = mojo.parseRepository( "central::::http://repo1.maven.apache.org/maven2", policy );
110         assertEquals( "central", repo.getId() );
111         assertEquals( DefaultRepositoryLayout.class, repo.getLayout().getClass() );
112         assertEquals( "http://repo1.maven.apache.org/maven2", repo.getUrl() );
113 
114         repo = mojo.parseRepository( "http://repo1.maven.apache.org/maven2", policy );
115         assertEquals( "temp", repo.getId() );
116         assertEquals( DefaultRepositoryLayout.class, repo.getLayout().getClass() );
117         assertEquals( "http://repo1.maven.apache.org/maven2", repo.getUrl() );
118 
119         try
120         {
121             repo = mojo.parseRepository( "::::http://repo1.maven.apache.org/maven2", policy );
122             fail( "Exception expected" );
123         }
124         catch ( MojoFailureException e )
125         {
126             // expected
127         }
128 
129         try
130         {
131             repo = mojo.parseRepository( "central::http://repo1.maven.apache.org/maven2", policy );
132             fail( "Exception expected" );
133         }
134         catch ( MojoFailureException e )
135         {
136             // expected
137         }
138     }
139 }