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