KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > usability > InvalidArtifactDiagnoserTest


1 package org.apache.maven.usability;
2
3 import org.apache.maven.artifact.Artifact;
4 import org.apache.maven.artifact.factory.ArtifactFactory;
5 import org.codehaus.plexus.PlexusTestCase;
6
7 /*
8  * Copyright 2001-2005 The Apache Software Foundation.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */

22
23 public class InvalidArtifactDiagnoserTest
24     extends PlexusTestCase
25 {
26     private InvalidArtifactDiagnoser diagnoser = new InvalidArtifactDiagnoser();
27
28     public void testShouldDiagnoseArtifactWithMissingGroupId() throws Throwable JavaDoc
29     {
30         testDiagnosis( "Test diagnosis for missing groupId", null, "test-artifact", "1.0", "jar" );
31     }
32
33     public void testShouldDiagnoseArtifactWithMissingArtifactId() throws Throwable JavaDoc
34     {
35         testDiagnosis( "Test diagnosis for missing artifactId", "test.group.id", null, "1.0", "jar" );
36     }
37
38     public void testShouldDiagnoseArtifactWithMissingVersion() throws Throwable JavaDoc
39     {
40         testDiagnosis( "Test diagnosis for missing version", "test.group.id", "test-artifact", null, "jar" );
41     }
42
43     public void testShouldDiagnoseArtifactWithMissingType() throws Throwable JavaDoc
44     {
45         testDiagnosis( "Test diagnosis for missing type", "test.group.id", "test-artifact", "1.0", null );
46     }
47
48     public void testShouldDiagnoseArtifactWithMissingGroupIdAndArtifactId() throws Throwable JavaDoc
49     {
50         testDiagnosis( "Test diagnosis for missing groupId and artifactId", null, null, "1.0", "jar" );
51     }
52
53     private void testDiagnosis( String JavaDoc testHeader, String JavaDoc groupId, String JavaDoc artifactId, String JavaDoc version, String JavaDoc type )
54         throws Throwable JavaDoc
55     {
56         System.out.println( "------------------------------------------------------------" );
57         System.out.println( "| " + testHeader );
58         System.out.println( "------------------------------------------------------------" );
59         System.out.println();
60
61         try
62         {
63             createArtifact( groupId, artifactId, version, type );
64
65             fail( "artifact creation did not fail; nothing to diagnose." );
66         }
67         catch ( Throwable JavaDoc error )
68         {
69             assertTrue( "Unexpected error while constructing artifact: " + error, diagnoser.canDiagnose( error ) );
70
71             if ( diagnoser.canDiagnose( error ) )
72             {
73                 System.out.println( diagnoser.diagnose( error ) );
74             }
75             else
76             {
77                 throw error;
78             }
79         }
80     }
81
82     private Artifact createArtifact( String JavaDoc groupId, String JavaDoc artifactId, String JavaDoc version, String JavaDoc type )
83         throws Exception JavaDoc
84     {
85         ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
86         return artifactFactory.createBuildArtifact( groupId, artifactId, version, type );
87     }
88
89 }
90
Popular Tags