View Javadoc
1   package org.apache.maven.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.util.Collections;
23  
24  import org.apache.maven.plugin.descriptor.MojoDescriptor;
25  import org.apache.maven.plugin.descriptor.Parameter;
26  import org.apache.maven.plugin.descriptor.PluginDescriptor;
27  
28  import junit.framework.TestCase;
29  
30  /**
31   * MNG-3131
32   *
33   * @author Robert Scholte
34   *
35   */
36  public class PluginParameterExceptionTest
37      extends TestCase
38  {
39  
40      public void testMissingRequiredStringArrayTypeParameter()
41      {
42          MojoDescriptor mojoDescriptor = new MojoDescriptor();
43          mojoDescriptor.setGoal( "goal" );
44          PluginDescriptor pluginDescriptor = new PluginDescriptor();
45          pluginDescriptor.setGoalPrefix( "goalPrefix" );
46          pluginDescriptor.setArtifactId( "artifactId" );
47          mojoDescriptor.setPluginDescriptor( pluginDescriptor );
48  
49          Parameter parameter = new Parameter();
50          parameter.setType( "java.lang.String[]" );
51          parameter.setName( "toAddresses" );
52  
53          parameter.setRequired( true );
54  
55          PluginParameterException exception =
56              new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) );
57  
58          assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" +
59          		"\n" +
60          		"[0] Inside the definition for plugin 'artifactId', specify the following:\n" +
61          		"\n" +
62          		"<configuration>\n" +
63          		"  ...\n" +
64          		"  <toAddresses>\n" +
65          		"    <item>VALUE</item>\n" +
66          		"  </toAddresses>\n" +
67          		"</configuration>.\n", exception.buildDiagnosticMessage() );
68      }
69  
70      public void testMissingRequiredCollectionTypeParameter()
71      {
72          MojoDescriptor mojoDescriptor = new MojoDescriptor();
73          mojoDescriptor.setGoal( "goal" );
74          PluginDescriptor pluginDescriptor = new PluginDescriptor();
75          pluginDescriptor.setGoalPrefix( "goalPrefix" );
76          pluginDescriptor.setArtifactId( "artifactId" );
77          mojoDescriptor.setPluginDescriptor( pluginDescriptor );
78  
79          Parameter parameter = new Parameter();
80          parameter.setType( "java.util.List" );
81          parameter.setName( "toAddresses" );
82  
83          parameter.setRequired( true );
84  
85          PluginParameterException exception =
86              new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) );
87  
88          assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" +
89                  "\n" +
90                  "[0] Inside the definition for plugin 'artifactId', specify the following:\n" +
91                  "\n" +
92                  "<configuration>\n" +
93                  "  ...\n" +
94                  "  <toAddresses>\n" +
95                  "    <item>VALUE</item>\n" +
96                  "  </toAddresses>\n" +
97                  "</configuration>.\n", exception.buildDiagnosticMessage() );
98      }
99  
100     public void testMissingRequiredMapTypeParameter()
101     {
102         MojoDescriptor mojoDescriptor = new MojoDescriptor();
103         mojoDescriptor.setGoal( "goal" );
104         PluginDescriptor pluginDescriptor = new PluginDescriptor();
105         pluginDescriptor.setGoalPrefix( "goalPrefix" );
106         pluginDescriptor.setArtifactId( "artifactId" );
107         mojoDescriptor.setPluginDescriptor( pluginDescriptor );
108 
109         Parameter parameter = new Parameter();
110         parameter.setType( "java.util.Map" );
111         parameter.setName( "toAddresses" );
112 
113         parameter.setRequired( true );
114 
115         PluginParameterException exception =
116             new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) );
117 
118         assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" +
119                 "\n" +
120                 "[0] Inside the definition for plugin 'artifactId', specify the following:\n" +
121                 "\n" +
122                 "<configuration>\n" +
123                 "  ...\n" +
124                 "  <toAddresses>\n" +
125                 "    <KEY>VALUE</KEY>\n" +
126                 "  </toAddresses>\n" +
127                 "</configuration>.\n", exception.buildDiagnosticMessage() );
128     }
129 
130     public void testMissingRequiredPropertiesTypeParameter()
131     {
132         MojoDescriptor mojoDescriptor = new MojoDescriptor();
133         mojoDescriptor.setGoal( "goal" );
134         PluginDescriptor pluginDescriptor = new PluginDescriptor();
135         pluginDescriptor.setGoalPrefix( "goalPrefix" );
136         pluginDescriptor.setArtifactId( "artifactId" );
137         mojoDescriptor.setPluginDescriptor( pluginDescriptor );
138 
139         Parameter parameter = new Parameter();
140         parameter.setType( "java.util.Properties" );
141         parameter.setName( "toAddresses" );
142 
143         parameter.setRequired( true );
144 
145         PluginParameterException exception =
146             new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) );
147 
148         assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" +
149                 "\n" +
150                 "[0] Inside the definition for plugin 'artifactId', specify the following:\n" +
151                 "\n" +
152                 "<configuration>\n" +
153                 "  ...\n" +
154                 "  <toAddresses>\n" +
155                 "    <property>\n" +
156                 "      <name>KEY</name>\n" +
157                 "      <value>VALUE</value>\n" +
158                 "    </property>\n" +
159                 "  </toAddresses>\n" +
160                 "</configuration>.\n", exception.buildDiagnosticMessage() );
161     }
162 
163 
164 }