1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.resolver.internal.ant.tasks;
20
21 import java.io.File;
22 import java.io.PrintStream;
23
24 import junit.framework.JUnit4TestAdapter;
25 import org.apache.tools.ant.BuildException;
26 import org.apache.tools.ant.BuildFileRule;
27 import org.apache.tools.ant.DefaultLogger;
28 import org.apache.tools.ant.Project;
29 import org.junit.Assert;
30 import org.junit.Rule;
31 import org.junit.Test;
32
33 public class CreatePomRainyDayTest {
34
35 public static junit.framework.Test suite() {
36 return new JUnit4TestAdapter(CreatePomRainyDayTest.class);
37 }
38
39 @Rule
40 public final BuildFileRule buildRule = new BuildFileRule();
41
42 public void configureProject(String filename, int logLevel) throws BuildException {
43 buildRule.configureProject(filename, logLevel);
44 DefaultLogger logger = new DefaultLogger() {
45 @Override
46 protected void printMessage(String message, PrintStream stream, int priority) {
47 message = System.currentTimeMillis() + " " + message;
48 super.printMessage(message, stream, priority);
49 }
50 };
51 logger.setMessageOutputLevel(logLevel);
52 logger.setOutputPrintStream(System.out);
53 logger.setErrorPrintStream(System.err);
54 buildRule.getProject().addBuildListener(logger);
55 }
56
57
58
59
60
61
62 @Test
63 public void testNoGroupId() {
64 configureProject("target/test-classes/ant/createPom/noGroupId.xml", Project.MSG_VERBOSE);
65
66 Assert.assertThrows(BuildException.class, () -> buildRule.executeTarget("setup"));
67
68
69 configureProject("target/test-classes/ant/createPom/noGroupIdSkipRegistration.xml", Project.MSG_VERBOSE);
70 buildRule.executeTarget("setup");
71 File pomFile = getPomFile();
72 Assert.assertTrue("The pom file should have been created at " + pomFile, pomFile.exists());
73 }
74
75
76
77
78
79
80 @Test
81 public void testNoArtifactId() {
82 configureProject("target/test-classes/ant/createPom/noArtifactId.xml", Project.MSG_VERBOSE);
83
84 Assert.assertThrows(BuildException.class, () -> buildRule.executeTarget("setup"));
85
86
87 configureProject("target/test-classes/ant/createPom/noArtifactIdSkipRegistration.xml", Project.MSG_VERBOSE);
88 buildRule.executeTarget("setup");
89 File pomFile = getPomFile();
90 Assert.assertTrue("The pom file should have been created at " + pomFile, pomFile.exists());
91 }
92
93 private File getPomFile() {
94 Project project = buildRule.getProject();
95 String pomPath = project.replaceProperties(project.getProperty("pomFile"));
96 Assert.assertNotNull("pomFile property should not be null", pomPath);
97 return new File(pomPath);
98 }
99 }