001package org.apache.maven.plugin; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.Collections; 023 024import org.apache.maven.plugin.descriptor.MojoDescriptor; 025import org.apache.maven.plugin.descriptor.Parameter; 026import org.apache.maven.plugin.descriptor.PluginDescriptor; 027 028import junit.framework.TestCase; 029 030/** 031 * MNG-3131 032 * 033 * @author Robert Scholte 034 * 035 */ 036public class PluginParameterExceptionTest 037 extends TestCase 038{ 039 040 public void testMissingRequiredStringArrayTypeParameter() 041 { 042 MojoDescriptor mojoDescriptor = new MojoDescriptor(); 043 mojoDescriptor.setGoal( "goal" ); 044 PluginDescriptor pluginDescriptor = new PluginDescriptor(); 045 pluginDescriptor.setGoalPrefix( "goalPrefix" ); 046 pluginDescriptor.setArtifactId( "artifactId" ); 047 mojoDescriptor.setPluginDescriptor( pluginDescriptor ); 048 049 Parameter parameter = new Parameter(); 050 parameter.setType( "java.lang.String[]" ); 051 parameter.setName( "toAddresses" ); 052 053 parameter.setRequired( true ); 054 055 PluginParameterException exception = 056 new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) ); 057 058 assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" + 059 "\n" + 060 "[0] Inside the definition for plugin 'artifactId', specify the following:\n" + 061 "\n" + 062 "<configuration>\n" + 063 " ...\n" + 064 " <toAddresses>\n" + 065 " <item>VALUE</item>\n" + 066 " </toAddresses>\n" + 067 "</configuration>.\n", exception.buildDiagnosticMessage() ); 068 } 069 070 public void testMissingRequiredCollectionTypeParameter() 071 { 072 MojoDescriptor mojoDescriptor = new MojoDescriptor(); 073 mojoDescriptor.setGoal( "goal" ); 074 PluginDescriptor pluginDescriptor = new PluginDescriptor(); 075 pluginDescriptor.setGoalPrefix( "goalPrefix" ); 076 pluginDescriptor.setArtifactId( "artifactId" ); 077 mojoDescriptor.setPluginDescriptor( pluginDescriptor ); 078 079 Parameter parameter = new Parameter(); 080 parameter.setType( "java.util.List" ); 081 parameter.setName( "toAddresses" ); 082 083 parameter.setRequired( true ); 084 085 PluginParameterException exception = 086 new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) ); 087 088 assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" + 089 "\n" + 090 "[0] Inside the definition for plugin 'artifactId', specify the following:\n" + 091 "\n" + 092 "<configuration>\n" + 093 " ...\n" + 094 " <toAddresses>\n" + 095 " <item>VALUE</item>\n" + 096 " </toAddresses>\n" + 097 "</configuration>.\n", exception.buildDiagnosticMessage() ); 098 } 099 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}