1   package org.apache.maven.artifact.resolver;
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.util.Arrays;
23  import java.util.List;
24  
25  import junit.framework.TestCase;
26  
27  /**
28   * Test the artifact resolution exception message
29   *
30   * @author Mauro Talevi
31   */
32  public class ArtifactResolutionExceptionTest
33      extends TestCase
34  {
35      private static final String LS = System.getProperty( "line.separator" );
36  
37      public void testMissingArtifactMessageFormat()
38      {
39          String message = "Missing artifact";
40          String indentation = "  ";
41          String groupId = "aGroupId";
42          String artifactId = "anArtifactId";
43          String version = "aVersion";
44          String type = "jar";
45          String classifier = "aClassifier";
46          String downloadUrl = "http://somewhere.com/download";
47          List path = Arrays.asList(new String[]{"dependency1", "dependency2"});
48          String expected = "Missing artifact" + LS +
49          		LS +
50          		"  Try downloading the file manually from: " + LS +
51          		"      http://somewhere.com/download" + LS +
52          		LS +
53          		"  Then, install it using the command: " + LS +
54          		"      mvn install:install-file -DgroupId=aGroupId -DartifactId=anArtifactId -Dversion=aVersion "+
55          		"-Dclassifier=aClassifier -Dpackaging=jar -Dfile=/path/to/file" + LS +
56          		LS +
57          		"  Alternatively, if you host your own repository you can deploy the file there: " + LS +
58          		"      mvn deploy:deploy-file -DgroupId=aGroupId -DartifactId=anArtifactId"+
59          		" -Dversion=aVersion -Dclassifier=aClassifier -Dpackaging=jar -Dfile=/path/to/file"+
60          		" -Durl=[url] -DrepositoryId=[id]" + LS +
61          		LS +
62          		"  Path to dependency: " + LS +
63          		"  \t1) dependency1" + LS +
64          		"  \t2) dependency2" + LS + 
65          		LS;
66          String actual = AbstractArtifactResolutionException.constructMissingArtifactMessage(message, indentation, groupId, artifactId, version, type, classifier, downloadUrl, path);
67          assertEquals(expected, actual);
68      }
69  }