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