1 package org.apache.maven.it;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.it.util.ResourceExtractor;
23
24 import java.io.File;
25 import java.util.Properties;
26
27
28
29
30
31
32 public class MavenITmng4615ValidateRequiredPluginParameterTest
33 extends AbstractMavenIntegrationTestCase
34 {
35
36 public MavenITmng4615ValidateRequiredPluginParameterTest()
37 {
38 super( "[2.0.3,3.0-alpha-1),[3.0-beta-2,)" );
39 }
40
41
42
43
44
45
46
47 public void testitAllSet()
48 throws Exception
49 {
50 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4615/test-0" );
51
52 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
53 verifier.setAutoclean( false );
54 verifier.deleteDirectory( "target" );
55 verifier.executeGoal( "validate" );
56 verifier.verifyErrorFreeLog();
57 verifier.resetStreams();
58
59 Properties props = verifier.loadProperties( "target/config.properties" );
60 assertEquals( "one", props.get( "requiredParam" ) );
61 assertEquals( "two", props.get( "requiredParamWithDefault" ) );
62 }
63
64
65
66
67
68
69
70 public void testitExprMissing()
71 throws Exception
72 {
73 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4615/test-1" );
74
75 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
76 verifier.setAutoclean( false );
77 verifier.deleteDirectory( "target" );
78 verifier.setLogFileName( "log-a.txt" );
79 try
80 {
81 verifier.executeGoal( "validate" );
82 verifier.verifyErrorFreeLog();
83 fail( "Build did not fail despite required plugin parameter missing" );
84 }
85 catch ( VerificationException e )
86 {
87
88 }
89
90 verifier.resetStreams();
91 }
92
93
94
95
96
97
98
99 public void testitExprSet()
100 throws Exception
101 {
102 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4615/test-1" );
103
104 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
105 verifier.setAutoclean( false );
106 verifier.deleteDirectory( "target" );
107 verifier.setSystemProperty( "config.requiredParam", "CLI" );
108 verifier.setLogFileName( "log-b.txt" );
109 verifier.executeGoal( "validate" );
110 verifier.verifyErrorFreeLog();
111 verifier.resetStreams();
112
113 Properties props = verifier.loadProperties( "target/config.properties" );
114 assertEquals( "CLI", props.get( "requiredParam" ) );
115 assertEquals( "two", props.get( "requiredParamWithDefault" ) );
116 }
117
118
119
120
121
122
123
124 public void testitPomValMissing()
125 throws Exception
126 {
127
128 requiresMavenVersion( "[3.0-beta-2,)" );
129
130 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4615/test-2a" );
131
132 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
133 verifier.setAutoclean( false );
134 verifier.deleteDirectory( "target" );
135 try
136 {
137 verifier.executeGoal( "validate" );
138 verifier.verifyErrorFreeLog();
139 fail( "Build did not fail despite required plugin parameter missing" );
140 }
141 catch ( VerificationException e )
142 {
143
144 }
145
146 verifier.resetStreams();
147 }
148
149
150
151
152
153
154
155 public void testitPomValSet()
156 throws Exception
157 {
158 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4615/test-2b" );
159
160 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
161 verifier.setAutoclean( false );
162 verifier.deleteDirectory( "target" );
163 verifier.executeGoal( "validate" );
164 verifier.verifyErrorFreeLog();
165 verifier.resetStreams();
166
167 Properties props = verifier.loadProperties( "target/config.properties" );
168 assertEquals( "one", props.get( "requiredParam" ) );
169 assertEquals( "http://foo.bar/", props.get( "requiredParamWithDefault" ) );
170 }
171
172 }