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

1 package hudson.maven;
2
3 /*
4 * Olivier Lamy
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 */
22
23 import hudson.Launcher;
24 import hudson.model.*;
25 import hudson.tasks.Maven.MavenInstallation;
26
27 import java.io.File;
28 import java.io.FilenameFilter;
29 import java.io.IOException;
30
31 import hudson.tasks.test.AbstractTestResultAction;
32 import hudson.tasks.test.TestResultProjectAction;
33 import org.apache.commons.io.FileUtils;
34 import org.jvnet.hudson.test.Bug;
35 import org.jvnet.hudson.test.Email;
36 import org.jvnet.hudson.test.ExtractResourceSCM;
37 import org.jvnet.hudson.test.HudsonTestCase;
38
39 /**
40 * @author Olivier Lamy
41 */
42 public class Maven3BuildTest extends HudsonTestCase {
43
44 public void testSimpleMaven3Build() throws Exception {
45
46 MavenModuleSet m = createMavenProject();
47 MavenInstallation mavenInstallation = configureMaven3();
48 m.setMaven( mavenInstallation.getName() );
49 m.getReporters().add(new TestReporter());
50 m.setScm(new ExtractResourceSCM(getClass().getResource("maven3-project.zip")));
51 m.setGoals( "clean install" );
52 MavenModuleSetBuild b = buildAndAssertSuccess(m);
53 assertTrue( MavenUtil.maven3orLater( b.getMavenVersionUsed() ) );
54 }
55
56 public void testSimpleMaven3BuildRedeployPublisher() throws Exception {
57
58 MavenModuleSet m = createMavenProject();
59 MavenInstallation mavenInstallation = configureMaven3();
60 m.setMaven( mavenInstallation.getName() );
61 File repo = createTmpDir();
62 FileUtils.cleanDirectory( repo );
63 m.getReporters().add(new TestReporter());
64 m.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),true, false));
65 m.setScm(new ExtractResourceSCM(getClass().getResource("maven3-project.zip")));
66 m.setGoals( "clean install" );
67 MavenModuleSetBuild b = buildAndAssertSuccess(m);
68 assertTrue( MavenUtil.maven3orLater( b.getMavenVersionUsed() ) );
69 File artifactDir = new File(repo,"com/mycompany/app/my-app/1.7-SNAPSHOT/");
70 String[] files = artifactDir.list( new FilenameFilter()
71 {
72
73 public boolean accept( File dir, String name )
74 {
75 System.out.println("file name : " +name );
76 return name.endsWith( ".jar" );
77 }
78 });
79 assertTrue("SNAPSHOT exist",!files[0].contains( "SNAPSHOT" ));
80 assertTrue("file not ended with -1.jar", files[0].endsWith( "-1.jar" ));
81 }
82
83 public void testSiteBuildWithForkedMojo() throws Exception {
84 MavenModuleSet m = createMavenProject();
85 MavenInstallation mavenInstallation = configureMaven3();
86 m.setMaven( mavenInstallation.getName() );
87 m.getReporters().add(new TestReporter());
88 m.setScm(new ExtractResourceSCM(getClass().getResource("maven3-project.zip")));
89 m.setGoals( "clean site" );
90 MavenModuleSetBuild b = buildAndAssertSuccess(m);
91 assertTrue( MavenUtil.maven3orLater( b.getMavenVersionUsed() ) );
92 }
93
94 @Bug(value=8395)
95 public void testMaven3BuildWrongScope() throws Exception {
96
97 File pom = new File(this.getClass().getResource("test-pom-8395.xml").toURI());
98 MavenModuleSet m = createMavenProject();
99 MavenInstallation mavenInstallation = configureMaven3();
100 m.setMaven( mavenInstallation.getName() );
101 m.getReporters().add(new TestReporter());
102 m.setRootPOM(pom.getAbsolutePath());
103 m.setGoals( "clean validate" );
104 MavenModuleSetBuild mmsb = m.scheduleBuild2( 0 ).get();
105 assertBuildStatus( Result.FAILURE, mmsb );
106 System.out.println("mmsb.getProject().getModules " + mmsb.getProject().getModules() );
107 assertTrue( mmsb.getProject().getModules().isEmpty());
108 }
109
110 @Bug(value=8390)
111 public void testMaven3BuildWrongInheritence() throws Exception {
112
113 MavenModuleSet m = createMavenProject();
114 MavenInstallation mavenInstallation = configureMaven3();
115 m.setMaven( mavenInstallation.getName() );
116 m.getReporters().add(new TestReporter());
117 m.setScm(new ExtractResourceSCM(getClass().getResource("incorrect-inheritence-testcase.zip")));
118 m.setGoals( "clean validate" );
119 MavenModuleSetBuild mmsb = m.scheduleBuild2( 0 ).get();
120 assertBuildStatus( Result.FAILURE, mmsb );
121 System.out.println("mmsb.getProject().getModules " + mmsb.getProject().getModules() );
122 assertTrue( mmsb.getProject().getModules().isEmpty());
123 }
124
125 @Bug(value=8445)
126 public void testMavenSeveralModulesInDirectory() throws Exception {
127
128 MavenModuleSet m = createMavenProject();
129 MavenInstallation mavenInstallation = configureMaven3();
130 m.setMaven( mavenInstallation.getName() );
131 m.getReporters().add(new TestReporter());
132 m.setScm(new ExtractResourceSCM(getClass().getResource("several-modules-in-directory.zip")));
133 m.setGoals( "clean validate" );
134 MavenModuleSetBuild mmsb = buildAndAssertSuccess(m);
135 assertFalse( mmsb.getProject().getModules().isEmpty());
136 }
137
138 @Email("https://groups.google.com/d/msg/hudson-users/Xhw00UopVN0/FA9YqDAIsSYJ")
139 public void testMavenWithDependencyVersionInEnvVar() throws Exception {
140
141 MavenModuleSet m = createMavenProject();
142 MavenInstallation mavenInstallation = configureMaven3();
143 ParametersDefinitionProperty parametersDefinitionProperty =
144 new ParametersDefinitionProperty(new StringParameterDefinition( "JUNITVERSION", "3.8.2" ));
145
146 m.addProperty( parametersDefinitionProperty );
147 m.setMaven( mavenInstallation.getName() );
148 m.getReporters().add(new TestReporter());
149 m.setScm(new ExtractResourceSCM(getClass().getResource("envars-maven-project.zip")));
150 m.setGoals( "clean test-compile" );
151 MavenModuleSetBuild mmsb = buildAndAssertSuccess(m);
152 assertFalse( mmsb.getProject().getModules().isEmpty());
153 }
154
155 @Bug(8484)
156 public void testMultiModMavenNonRecursive() throws Exception {
157 MavenInstallation mavenInstallation = configureMaven3();
158 MavenModuleSet m = createMavenProject();
159 m.setMaven( mavenInstallation.getName() );
160 m.getReporters().add(new TestReporter());
161 m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimod.zip")));
162 m.setGoals( "-N validate" );
163 assertTrue("MavenModuleSet.isNonRecursive() should be true", m.isNonRecursive());
164 buildAndAssertSuccess(m);
165 assertEquals("not only one module", 1, m.getModules().size());
166 }
167
168 @Bug(8573)
169 public void testBuildTimeStampProperty() throws Exception {
170 MavenInstallation mavenInstallation = configureMaven3();
171 MavenModuleSet m = createMavenProject();
172 m.setMaven( mavenInstallation.getName() );
173 m.getReporters().add(new TestReporter());
174 m.setScm(new ExtractResourceSCM(getClass().getResource("JENKINS-8573.zip")));
175 m.setGoals( "process-resources" );
176 buildAndAssertSuccess(m);
177 String content = m.getLastBuild().getWorkspace().child( "target/classes/test.txt" ).readToString();
178 assertFalse( content.contains( "${maven.build.timestamp}") );
179 assertFalse( content.contains( "${maven.build.timestamp}") );
180 }
181
182 @Bug(1557)
183 public void testDuplicateTestResults() throws Exception {
184 MavenInstallation mavenInstallation = configureMaven3();
185 MavenModuleSet m = createMavenProject();
186 m.setMaven( mavenInstallation.getName() );
187 m.getReporters().add(new TestReporter());
188 m.setScm(new ExtractResourceSCM(getClass().getResource("JENKINS-1557.zip")));
189 m.setGoals("verify");
190 buildAndAssertSuccess(m);
191
192 int totalCount = m.getModules().iterator().next()
193 .getAction(TestResultProjectAction.class).getLastTestResultAction().getTotalCount();
194 assertEquals(4, totalCount);
195 }
196
197 @Bug(9326)
198 public void testTychoTestResults() throws Exception {
199 MavenInstallation mavenInstallation = configureMaven3();
200 MavenModuleSet m = createMavenProject();
201 m.setRootPOM( "org.foobar.build/pom.xml" );
202 m.setMaven( mavenInstallation.getName() );
203 m.getReporters().add(new TestReporter());
204 m.setScm(new ExtractResourceSCM(getClass().getResource("JENKINS-9326.zip"),"foobar"));
205 m.setGoals("verify");
206 buildAndAssertSuccess(m);
207
208 System.out.println("modules size " + m.getModules());
209
210
211 MavenModule testModule = null;
212 for (MavenModule mavenModule : m.getModules()) {
213 System.out.println("module " + mavenModule.getName() + "/" + mavenModule.getDisplayName());
214 if ("org.foobar:org.foobar.test".equals( mavenModule.getName() )) testModule = mavenModule;
215 }
216
217 AbstractTestResultAction trpa = testModule.getLastBuild().getTestResultAction();
218
219 int totalCount = trpa.getTotalCount();
220 assertEquals(1, totalCount);
221 }
222
223 @Bug(9326)
224 public void testTychoEclipseTestResults() throws Exception {
225 MavenInstallation mavenInstallation = configureMaven3();
226 MavenModuleSet m = createMavenProject();
227 m.setRootPOM( "org.foobar.build/pom.xml" );
228 m.setMaven( mavenInstallation.getName() );
229 m.getReporters().add(new TestReporter());
230 m.setScm(new ExtractResourceSCM(getClass().getResource("foobar_eclipse_with_fix.zip"),"foobar_eclipse"));
231 m.setGoals("verify");
232 buildAndAssertSuccess(m);
233
234 System.out.println("modules size " + m.getModules());
235
236
237 MavenModule testModule = null;
238 for (MavenModule mavenModule : m.getModules()) {
239 System.out.println("module " + mavenModule.getName() + "/" + mavenModule.getDisplayName());
240 if ("org.foobar:org.foobar.test".equals( mavenModule.getName() )) testModule = mavenModule;
241 }
242
243 AbstractTestResultAction trpa = testModule.getLastBuild().getTestResultAction();
244
245 int totalCount = trpa.getTotalCount();
246 assertEquals(1, totalCount);
247 }
248
249 private static class TestReporter extends MavenReporter {
250 @Override
251 public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
252 assertNotNull(build.getProject().getWorkspace());
253 assertNotNull(build.getWorkspace());
254 return true;
255 }
256 }
257
258 }
259