File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\test\src\test\java\hudson\maven\MavenBuildTest.java.html

1 package hudson.maven;
2
3 import hudson.Launcher;
4 import hudson.model.BuildListener;
5 import hudson.model.ParametersDefinitionProperty;
6 import hudson.model.Result;
7 import hudson.model.StringParameterDefinition;
8 import hudson.tasks.Maven.MavenInstallation;
9
10 import java.io.File;
11 import java.io.IOException;
12
13 import org.jvnet.hudson.test.Bug;
14 import org.jvnet.hudson.test.Email;
15 import org.jvnet.hudson.test.ExtractResourceSCM;
16 import org.jvnet.hudson.test.HudsonTestCase;
17
18 /**
19 * @author Kohsuke Kawaguchi
20 */
21 public class MavenBuildTest extends HudsonTestCase {
22
23 /**
24 * NPE in {@code build.getProject().getWorkspace()} for {@link MavenBuild}.
25 */
26 @Bug(4192)
27 public void testMavenWorkspaceExists() throws Exception {
28 configureDefaultMaven();
29 MavenModuleSet m = createMavenProject();
30 m.getReporters().add(new TestReporter());
31 m.setScm(new ExtractResourceSCM(getClass().getResource("HUDSON-4192.zip")));
32 buildAndAssertSuccess(m);
33 }
34
35 /**
36 * {@link Result} getting set to SUCCESS even if there's a test failure, when the test failure
37 * does not happen in the final task segment.
38 */
39 @Bug(4177)
40 public void testTestFailureInEarlyTaskSegment() throws Exception {
41 configureDefaultMaven();
42 MavenModuleSet m = createMavenProject();
43 m.setGoals("clean install findbugs:findbugs");
44 m.setScm(new ExtractResourceSCM(getClass().getResource("maven-test-failure-findbugs.zip")));
45 assertBuildStatus(Result.UNSTABLE, m.scheduleBuild2(0).get());
46 }
47
48 /**
49 * Verify that a compilation error properly shows up as a failure.
50 */
51 public void testCompilationFailure() throws Exception {
52 configureDefaultMaven();
53 MavenModuleSet m = createMavenProject();
54 m.setGoals("clean install");
55 m.setScm(new ExtractResourceSCM(getClass().getResource("maven-compilation-failure.zip")));
56 assertBuildStatus(Result.FAILURE, m.scheduleBuild2(0).get());
57 }
58
59 /**
60 * Workspace determination problem on non-aggregator style build.
61 */
62 @Bug(4226)
63 public void testParallelModuleBuild() throws Exception {
64 configureDefaultMaven();
65 MavenModuleSet m = createMavenProject();
66 m.setScm(new ExtractResourceSCM(getClass().getResource("multimodule-maven.zip")));
67
68 buildAndAssertSuccess(m);
69
70 m.setAggregatorStyleBuild(false);
71
72 // run module builds
73 buildAndAssertSuccess(m.getModule("test$module1"));
74 buildAndAssertSuccess(m.getModule("test$module1"));
75 }
76
77 @Bug(value=8395)
78 public void testMaven2BuildWrongScope() throws Exception {
79
80 File pom = new File(this.getClass().getResource("test-pom-8395.xml").toURI());
81 MavenModuleSet m = createMavenProject();
82 MavenInstallation mavenInstallation = configureDefaultMaven();
83 m.setMaven( mavenInstallation.getName() );
84 m.getReporters().add(new TestReporter());
85 m.setRootPOM(pom.getAbsolutePath());
86 m.setGoals( "clean validate" );
87 MavenModuleSetBuild mmsb = buildAndAssertSuccess(m);
88 assertFalse( mmsb.getProject().getModules().isEmpty());
89 }
90
91 @Bug(value=8390)
92 public void testMaven2BuildWrongInheritence() throws Exception {
93
94 MavenModuleSet m = createMavenProject();
95 MavenInstallation mavenInstallation = configureDefaultMaven();
96 m.setMaven( mavenInstallation.getName() );
97 m.getReporters().add(new TestReporter());
98 m.setScm(new ExtractResourceSCM(getClass().getResource("incorrect-inheritence-testcase.zip")));
99 m.setGoals( "clean validate" );
100 MavenModuleSetBuild mmsb = buildAndAssertSuccess(m);
101 assertFalse( mmsb.getProject().getModules().isEmpty());
102 }
103
104 @Bug(value=8445)
105 public void testMaven2SeveralModulesInDirectory() throws Exception {
106
107 MavenModuleSet m = createMavenProject();
108 MavenInstallation mavenInstallation = configureDefaultMaven();
109 m.setMaven( mavenInstallation.getName() );
110 m.getReporters().add(new TestReporter());
111 m.setScm(new ExtractResourceSCM(getClass().getResource("several-modules-in-directory.zip")));
112 m.setGoals( "clean validate" );
113 MavenModuleSetBuild mmsb = buildAndAssertSuccess(m);
114 assertFalse( mmsb.getProject().getModules().isEmpty());
115 }
116
117 @Email("https://groups.google.com/d/msg/hudson-users/Xhw00UopVN0/FA9YqDAIsSYJ")
118 public void testMavenWithDependencyVersionInEnvVar() throws Exception {
119
120 MavenModuleSet m = createMavenProject();
121 MavenInstallation mavenInstallation = configureDefaultMaven();
122 ParametersDefinitionProperty parametersDefinitionProperty =
123 new ParametersDefinitionProperty(new StringParameterDefinition( "JUNITVERSION", "3.8.2" ));
124
125 m.addProperty( parametersDefinitionProperty );
126 m.setMaven( mavenInstallation.getName() );
127 m.getReporters().add(new TestReporter());
128 m.setScm(new ExtractResourceSCM(getClass().getResource("envars-maven-project.zip")));
129 m.setGoals( "clean test-compile" );
130 MavenModuleSetBuild mmsb = buildAndAssertSuccess(m);
131 assertFalse( mmsb.getProject().getModules().isEmpty());
132 }
133
134 @Bug(8573)
135 public void testBuildTimeStampProperty() throws Exception {
136 MavenInstallation mavenInstallation = configureDefaultMaven();
137 MavenModuleSet m = createMavenProject();
138 m.setMaven( mavenInstallation.getName() );
139 m.getReporters().add(new TestReporter());
140 m.setScm(new ExtractResourceSCM(getClass().getResource("JENKINS-8573.zip")));
141 m.setGoals( "process-resources" );
142 buildAndAssertSuccess(m);
143 String content = m.getLastBuild().getWorkspace().child( "target/classes/test.txt" ).readToString();
144 assertFalse( content.contains( "${maven.build.timestamp}") );
145 assertFalse( content.contains( "${maven.build.timestamp}") );
146
147 System.out.println( "content " + content );
148 }
149
150 private static class TestReporter extends MavenReporter {
151 private static final long serialVersionUID = 1L;
152
153 @Override
154 public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
155 assertNotNull(build.getWorkspace());
156 return true;
157 }
158 }
159
160 }
161