21
21
import java .io .File ;
22
22
import java .nio .file .Files ;
23
23
import java .nio .file .Path ;
24
+ import java .nio .file .Paths ;
24
25
import java .util .ArrayList ;
25
26
import java .util .List ;
26
27
import java .util .concurrent .atomic .AtomicReference ;
33
34
import org .apache .maven .api .Session ;
34
35
import org .apache .maven .api .model .Model ;
35
36
import org .apache .maven .api .plugin .testing .InjectMojo ;
37
+ import org .apache .maven .api .plugin .testing .MojoExtension ;
38
+ import org .apache .maven .api .plugin .testing .MojoParameter ;
39
+ import org .apache .maven .api .plugin .testing .MojoParameters ;
36
40
import org .apache .maven .api .plugin .testing .MojoTest ;
37
41
import org .apache .maven .api .plugin .testing .stubs .ArtifactStub ;
38
42
import org .apache .maven .api .plugin .testing .stubs .SessionStub ;
41
45
import org .apache .maven .api .services .ArtifactManager ;
42
46
import org .apache .maven .api .services .ProjectBuilder ;
43
47
import org .apache .maven .api .services .ProjectManager ;
48
+ import org .apache .maven .internal .impl .InternalSession ;
44
49
import org .junit .jupiter .api .Test ;
45
50
46
51
import static org .apache .maven .api .plugin .testing .MojoExtension .getVariableValueFromObject ;
50
55
import static org .junit .jupiter .api .Assertions .assertTrue ;
51
56
import static org .mockito .ArgumentMatchers .any ;
52
57
import static org .mockito .Mockito .doAnswer ;
58
+ import static org .mockito .Mockito .when ;
53
59
54
60
/**
55
61
* @author <a href="mailto:[email protected] ">Allan Ramirez</a>
@@ -71,13 +77,27 @@ public class DeployFileMojoTest {
71
77
private ArtifactManager artifactManager ;
72
78
73
79
@ Test
74
- @ InjectMojo (goal = "deploy-file" , pom = "classpath:/unit/deploy-file/plugin-config-test.xml" )
80
+ @ InjectMojo (goal = "deploy-file" )
75
81
public void testDeployTestEnvironment (DeployFileMojo mojo ) {
76
82
assertNotNull (mojo );
77
83
}
78
84
79
85
@ Test
80
- @ InjectMojo (goal = "deploy-file" , pom = "classpath:/unit/deploy-file/plugin-config-test.xml" )
86
+ @ InjectMojo (goal = "deploy-file" )
87
+ @ MojoParameters ({
88
+ @ MojoParameter (name = "groupId" , value = "org.apache.maven.test" ),
89
+ @ MojoParameter (name = "artifactId" , value = "maven-deploy-file-test" ),
90
+ @ MojoParameter (name = "version" , value = "1.0" ),
91
+ @ MojoParameter (name = "packaging" , value = "jar" ),
92
+ @ MojoParameter (
93
+ name = "file" ,
94
+ value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test-1.0-SNAPSHOT.jar" ),
95
+ @ MojoParameter (name = "repositoryId" , value = "deploy-test" ),
96
+ @ MojoParameter (name = "url" , value = "file://${session.topDirectory}/target/remote-repo/deploy-file" ),
97
+ @ MojoParameter (name = "description" , value = "POM was created from deploy:deploy-file" ),
98
+ @ MojoParameter (name = "generatePom" , value = "true" ),
99
+ @ MojoParameter (name = "skip" , value = "snapshots" )
100
+ })
81
101
public void testBasicDeployFile (DeployFileMojo mojo ) throws Exception {
82
102
assertNotNull (mojo );
83
103
@@ -93,9 +113,9 @@ public void testBasicDeployFile(DeployFileMojo mojo) throws Exception {
93
113
assertEquals ("maven-deploy-file-test" , artifactId );
94
114
assertEquals ("1.0" , version );
95
115
assertEquals ("jar" , packaging );
96
- assertTrue (Files .exists (file ));
116
+ assertTrue (Files .exists (file ), file . toString () );
97
117
assertEquals ("deploy-test" , repositoryId );
98
- assertEquals ("file://" + getBasedir () + "/target/remote-repo/deploy-file-test " , url );
118
+ assertEquals ("file://" + getBasedir () + "/target/remote-repo/deploy-file" , url );
99
119
100
120
execute (mojo , request -> {
101
121
assertNotNull (request );
@@ -128,7 +148,20 @@ public void testBasicDeployFile(DeployFileMojo mojo) throws Exception {
128
148
}
129
149
130
150
@ Test
131
- @ InjectMojo (goal = "deploy-file" , pom = "classpath:/unit/deploy-file/plugin-config-classifier.xml" )
151
+ @ InjectMojo (goal = "deploy-file" )
152
+ @ MojoParameters ({
153
+ @ MojoParameter (name = "groupId" , value = "org.apache.maven.test" ),
154
+ @ MojoParameter (name = "artifactId" , value = "maven-deploy-file-test" ),
155
+ @ MojoParameter (name = "version" , value = "1.0" ),
156
+ @ MojoParameter (name = "packaging" , value = "jar" ),
157
+ @ MojoParameter (
158
+ name = "file" ,
159
+ value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test-1.0-SNAPSHOT.jar" ),
160
+ @ MojoParameter (name = "repositoryId" , value = "deploy-test" ),
161
+ @ MojoParameter (name = "url" , value = "file://${session.topDirectory}/target/remote-repo/deploy-file" ),
162
+ @ MojoParameter (name = "classifier" , value = "bin" ),
163
+ @ MojoParameter (name = "generatePom" , value = "true" )
164
+ })
132
165
public void testDeployIfClassifierIsSet (DeployFileMojo mojo ) throws Exception {
133
166
assertNotNull (mojo );
134
167
@@ -149,7 +182,7 @@ public void testDeployIfClassifierIsSet(DeployFileMojo mojo) throws Exception {
149
182
assertEquals (new ArtifactStub (groupId , artifactId , "bin" , version , "jar" ), a1 );
150
183
Path p1 = artifactManager .getPath (a1 ).orElse (null );
151
184
assertNotNull (p1 );
152
- assertTrue (p1 .toString ().endsWith ("deploy-test-file -1.0-SNAPSHOT.jar" ));
185
+ assertTrue (p1 .toString ().endsWith ("maven- deploy-test-1.0-SNAPSHOT.jar" ));
153
186
// second artifact
154
187
Artifact a2 = artifacts .get (1 );
155
188
assertEquals (new ArtifactStub (groupId , artifactId , "" , version , "pom" ), a2 );
@@ -162,7 +195,16 @@ public void testDeployIfClassifierIsSet(DeployFileMojo mojo) throws Exception {
162
195
}
163
196
164
197
@ Test
165
- @ InjectMojo (goal = "deploy-file" , pom = "classpath:/unit/deploy-file/plugin-config-artifact-not-jar.xml" )
198
+ @ InjectMojo (goal = "deploy-file" )
199
+ @ MojoParameters ({
200
+ @ MojoParameter (name = "groupId" , value = "org.apache.maven.test" ),
201
+ @ MojoParameter (name = "artifactId" , value = "maven-deploy-file-test" ),
202
+ @ MojoParameter (name = "version" , value = "1.0" ),
203
+ @ MojoParameter (name = "file" , value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test.zip" ),
204
+ @ MojoParameter (name = "repositoryId" , value = "deploy-test" ),
205
+ @ MojoParameter (name = "url" , value = "file://${session.topDirectory}/target/remote-repo/deploy-file" ),
206
+ @ MojoParameter (name = "generatePom" , value = "true" )
207
+ })
166
208
public void testDeployIfArtifactIsNotJar (DeployFileMojo mojo ) throws Exception {
167
209
assertNotNull (mojo );
168
210
@@ -183,7 +225,7 @@ public void testDeployIfArtifactIsNotJar(DeployFileMojo mojo) throws Exception {
183
225
Path p1 = artifactManager .getPath (a1 ).orElse (null );
184
226
Path p2 = artifactManager .getPath (a2 ).orElse (null );
185
227
assertNotNull (p1 );
186
- assertTrue (p1 .toString ().endsWith ("deploy-test-file .zip" ));
228
+ assertTrue (p1 .toString ().endsWith ("maven- deploy-test.zip" ));
187
229
assertNotNull (p2 );
188
230
assertTrue (p2 .toString ().endsWith (".pom" ));
189
231
@@ -213,31 +255,33 @@ private void execute(DeployFileMojo mojo, Consumer<ArtifactDeployerRequest> cons
213
255
@ Provides
214
256
@ Singleton
215
257
@ SuppressWarnings ("unused" )
216
- private Session getMockSession () {
217
- return SessionStub .getMockSession (LOCAL_REPO );
258
+ private InternalSession createSession () {
259
+ InternalSession session = SessionStub .getMockSession (LOCAL_REPO );
260
+ when (session .getTopDirectory ()).thenReturn (Paths .get (MojoExtension .getBasedir ()));
261
+ return session ;
218
262
}
219
263
220
264
@ Provides
221
265
@ SuppressWarnings ("unused" )
222
- private ArtifactDeployer getMockArtifactDeployer (Session session ) {
266
+ private ArtifactDeployer createArtifactDeployer (Session session ) {
223
267
return session .getService (ArtifactDeployer .class );
224
268
}
225
269
226
270
@ Provides
227
271
@ SuppressWarnings ("unused" )
228
- private ArtifactManager getMockArtifactManager (Session session ) {
272
+ private ArtifactManager createArtifactManager (Session session ) {
229
273
return session .getService (ArtifactManager .class );
230
274
}
231
275
232
276
@ Provides
233
277
@ SuppressWarnings ("unused" )
234
- private ProjectManager getMockProjectManager (Session session ) {
278
+ private ProjectManager createProjectManager (Session session ) {
235
279
return session .getService (ProjectManager .class );
236
280
}
237
281
238
282
@ Provides
239
283
@ SuppressWarnings ("unused" )
240
- private ProjectBuilder getMockProjectBuilder (Session session ) {
284
+ private ProjectBuilder createProjectBuilder (Session session ) {
241
285
return session .getService (ProjectBuilder .class );
242
286
}
243
287
}
0 commit comments