View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugin;
20  
21  import java.util.Collections;
22  
23  import org.apache.maven.plugin.descriptor.MojoDescriptor;
24  import org.apache.maven.plugin.descriptor.Parameter;
25  import org.apache.maven.plugin.descriptor.PluginDescriptor;
26  import org.junit.jupiter.api.Test;
27  
28  import static org.junit.jupiter.api.Assertions.assertEquals;
29  
30  /**
31   * MNG-3131
32   *
33   * @author Robert Scholte
34   *
35   */
36  class PluginParameterExceptionTest {
37  
38      private final String LS = System.lineSeparator();
39  
40      @Test
41      void testMissingRequiredStringArrayTypeParameter() {
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(
59                  "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'" + LS
60                          + LS + "[0] Inside the definition for plugin 'artifactId', specify the following:"
61                          + LS
62                          + LS + "<configuration>"
63                          + LS + "  ..."
64                          + LS + "  <toAddresses>"
65                          + LS + "    <item>VALUE</item>"
66                          + LS + "  </toAddresses>"
67                          + LS + "</configuration>."
68                          + LS,
69                  exception.buildDiagnosticMessage());
70      }
71  
72      @Test
73      void testMissingRequiredCollectionTypeParameter() {
74          MojoDescriptor mojoDescriptor = new MojoDescriptor();
75          mojoDescriptor.setGoal("goal");
76          PluginDescriptor pluginDescriptor = new PluginDescriptor();
77          pluginDescriptor.setGoalPrefix("goalPrefix");
78          pluginDescriptor.setArtifactId("artifactId");
79          mojoDescriptor.setPluginDescriptor(pluginDescriptor);
80  
81          Parameter parameter = new Parameter();
82          parameter.setType("java.util.List");
83          parameter.setName("toAddresses");
84  
85          parameter.setRequired(true);
86  
87          PluginParameterException exception =
88                  new PluginParameterException(mojoDescriptor, Collections.singletonList(parameter));
89  
90          assertEquals(
91                  "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'" + LS
92                          + LS + "[0] Inside the definition for plugin 'artifactId', specify the following:"
93                          + LS
94                          + LS + "<configuration>"
95                          + LS + "  ..."
96                          + LS + "  <toAddresses>"
97                          + LS + "    <item>VALUE</item>"
98                          + LS + "  </toAddresses>"
99                          + LS + "</configuration>."
100                         + LS,
101                 exception.buildDiagnosticMessage());
102     }
103 
104     @Test
105     void testMissingRequiredMapTypeParameter() {
106         MojoDescriptor mojoDescriptor = new MojoDescriptor();
107         mojoDescriptor.setGoal("goal");
108         PluginDescriptor pluginDescriptor = new PluginDescriptor();
109         pluginDescriptor.setGoalPrefix("goalPrefix");
110         pluginDescriptor.setArtifactId("artifactId");
111         mojoDescriptor.setPluginDescriptor(pluginDescriptor);
112 
113         Parameter parameter = new Parameter();
114         parameter.setType("java.util.Map");
115         parameter.setName("toAddresses");
116 
117         parameter.setRequired(true);
118 
119         PluginParameterException exception =
120                 new PluginParameterException(mojoDescriptor, Collections.singletonList(parameter));
121 
122         assertEquals(
123                 "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'" + LS
124                         + LS + "[0] Inside the definition for plugin 'artifactId', specify the following:"
125                         + LS
126                         + LS + "<configuration>"
127                         + LS + "  ..."
128                         + LS + "  <toAddresses>"
129                         + LS + "    <KEY>VALUE</KEY>"
130                         + LS + "  </toAddresses>"
131                         + LS + "</configuration>."
132                         + LS,
133                 exception.buildDiagnosticMessage());
134     }
135 
136     @Test
137     void testMissingRequiredPropertiesTypeParameter() {
138         MojoDescriptor mojoDescriptor = new MojoDescriptor();
139         mojoDescriptor.setGoal("goal");
140         PluginDescriptor pluginDescriptor = new PluginDescriptor();
141         pluginDescriptor.setGoalPrefix("goalPrefix");
142         pluginDescriptor.setArtifactId("artifactId");
143         mojoDescriptor.setPluginDescriptor(pluginDescriptor);
144 
145         Parameter parameter = new Parameter();
146         parameter.setType("java.util.Properties");
147         parameter.setName("toAddresses");
148 
149         parameter.setRequired(true);
150 
151         PluginParameterException exception =
152                 new PluginParameterException(mojoDescriptor, Collections.singletonList(parameter));
153 
154         assertEquals(
155                 "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'" + LS
156                         + LS + "[0] Inside the definition for plugin 'artifactId', specify the following:"
157                         + LS
158                         + LS + "<configuration>"
159                         + LS + "  ..."
160                         + LS + "  <toAddresses>"
161                         + LS + "    <property>"
162                         + LS + "      <name>KEY</name>"
163                         + LS + "      <value>VALUE</value>"
164                         + LS + "    </property>"
165                         + LS + "  </toAddresses>"
166                         + LS + "</configuration>."
167                         + LS,
168                 exception.buildDiagnosticMessage());
169     }
170 }