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