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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.maven;
25
26 import hudson.model.Result;
27 import hudson.tasks.Maven.MavenInstallation;
28
29 import org.apache.commons.io.FileUtils;
30 import org.apache.commons.lang.StringUtils;
31 import org.jvnet.hudson.test.Bug;
32 import org.jvnet.hudson.test.ExtractResourceSCM;
33 import org.jvnet.hudson.test.HudsonTestCase;
34 import org.jvnet.hudson.test.SingleFileSCM;
35 import org.jvnet.hudson.test.Email;
36
37 import java.io.File;
38 import java.io.FilenameFilter;
39 import java.util.Arrays;
40
41 /**
42 * @author Kohsuke Kawaguchi
43 */
44 public class RedeployPublisherTest extends HudsonTestCase {
45 @Bug(2593)
46 public void testBug2593() throws Exception {
47 configureDefaultMaven();
48 MavenModuleSet m2 = createMavenProject();
49 File repo = createTmpDir();
50
51 // a fake build
52 m2.setScm(new SingleFileSCM("pom.xml",getClass().getResource("big-artifact.pom")));
53 m2.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),true, false));
54
55 MavenModuleSetBuild b = m2.scheduleBuild2(0).get();
56 assertBuildStatus(Result.SUCCESS, b);
57
58 // TODO: confirm that the artifacts use a consistent timestamp
59 // TODO: we need to somehow introduce a large delay between deploy since timestamp is only second precision
60 // TODO: or maybe we could use a btrace like capability to count the # of invocations?
61
62 System.out.println(repo);
63 }
64
65 public void testConfigRoundtrip() throws Exception {
66 MavenModuleSet p = createMavenProject();
67 RedeployPublisher rp = new RedeployPublisher("theId", "http://some.url/", true, true);
68 p.getPublishersList().add(rp);
69 submit(new WebClient().getPage(p,"configure").getFormByName("config"));
70 assertEqualBeans(rp,p.getPublishersList().get(RedeployPublisher.class),"id,url,uniqueVersion,evenIfUnstable");
71 }
72
73 // /**
74 // * Makes sure that the webdav wagon component we bundle is compatible.
75 // */
76 // public void testWebDavDeployment() throws Exception {
77 // configureDefaultMaven();
78 // MavenModuleSet m2 = createMavenProject();
79 //
80 // // a fake build
81 // m2.setScm(new SingleFileSCM("pom.xml",getClass().getResource("big-artifact.pom")));
82 // m2.getPublishersList().add(new RedeployPublisher("","dav:http://localhost/dav/",true));
83 //
84 // MavenModuleSetBuild b = m2.scheduleBuild2(0).get();
85 // assertBuildStatus(Result.SUCCESS, b);
86 // }
87
88 /**
89 * Are we having a problem in handling file names with multiple extensions, like ".tar.gz"?
90 */
91 @Email("http://www.nabble.com/tar.gz-becomes-.gz-after-Hudson-deployment-td25391364.html")
92 @Bug(3814)
93 public void testTarGz() throws Exception {
94 configureDefaultMaven();
95 MavenModuleSet m2 = createMavenProject();
96 File repo = createTmpDir();
97
98 // a fake build
99 m2.setScm(new SingleFileSCM("pom.xml",getClass().getResource("targz-artifact.pom")));
100 m2.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),false, false));
101
102 MavenModuleSetBuild b = m2.scheduleBuild2(0).get();
103 assertBuildStatus(Result.SUCCESS, b);
104
105 assertTrue("tar.gz doesn't exist",new File(repo,"test/test/0.1-SNAPSHOT/test-0.1-SNAPSHOT-bin.tar.gz").exists());
106 }
107
108 public void testTarGzUniqueVersionTrue() throws Exception {
109 configureDefaultMaven();
110 MavenModuleSet m2 = createMavenProject();
111 File repo = createTmpDir();
112
113 FileUtils.cleanDirectory( repo );
114
115 // a fake build
116 m2.setScm(new SingleFileSCM("pom.xml",getClass().getResource("targz-artifact.pom")));
117 m2.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),true, false));
118
119 MavenModuleSetBuild b = m2.scheduleBuild2(0).get();
120 assertBuildStatus(Result.SUCCESS, b);
121
122 File artifactDir = new File(repo,"test/test/0.1-SNAPSHOT/");
123 String[] files = artifactDir.list( new FilenameFilter()
124 {
125
126 public boolean accept( File dir, String name )
127 {
128 System.out.print( "deployed file " + name );
129 return name.contains( "-bin.tar.gz" ) || name.endsWith( ".jar" ) || name.endsWith( "-bin.zip" );
130 }
131 });
132 System.out.println("deployed files " + Arrays.asList( files ));
133 assertFalse("tar.gz doesn't exist",new File(repo,"test/test/0.1-SNAPSHOT/test-0.1-SNAPSHOT-bin.tar.gz").exists());
134 assertTrue("tar.gz doesn't exist",!files[0].contains( "SNAPSHOT" ));
135 for (String file : files) {
136 if (file.endsWith( "-bin.tar.gz" )) {
137 String ver = StringUtils.remove( file, "-bin.tar.gz" );
138 ver = ver.substring( ver.length() - 1, ver.length() );
139 assertEquals("-bin.tar.gz not ended with 1 , file " + file , "1", ver);
140 }
141 if (file.endsWith( ".jar" )) {
142 String ver = StringUtils.remove( file, ".jar" );
143 ver = ver.substring( ver.length() - 1, ver.length() );
144 assertEquals(".jar not ended with 1 , file " + file , "1", ver);
145 }
146 if (file.endsWith( "-bin.zip" )) {
147 String ver = StringUtils.remove( file, "-bin.zip" );
148 ver = ver.substring( ver.length() - 1, ver.length() );
149 assertEquals("-bin.zip not ended with 1 , file " + file , "1", ver);
150 }
151 }
152
153 }
154
155 public void testTarGzMaven3() throws Exception {
156
157 MavenModuleSet m3 = createMavenProject();
158 MavenInstallation mvn = configureMaven3();
159 m3.setMaven( mvn.getName() );
160 File repo = createTmpDir();
161 FileUtils.cleanDirectory( repo );
162 // a fake build
163 m3.setScm(new SingleFileSCM("pom.xml",getClass().getResource("targz-artifact.pom")));
164 m3.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),false, false));
165
166 MavenModuleSetBuild b = m3.scheduleBuild2(0).get();
167 assertBuildStatus(Result.SUCCESS, b);
168
169 assertTrue( MavenUtil.maven3orLater( b.getMavenVersionUsed() ) );
170 File artifactDir = new File(repo,"test/test/0.1-SNAPSHOT/");
171 String[] files = artifactDir.list( new FilenameFilter()
172 {
173
174 public boolean accept( File dir, String name )
175 {
176 return name.endsWith( "tar.gz" );
177 }
178 });
179 assertFalse("tar.gz doesn't exist",new File(repo,"test/test/0.1-SNAPSHOT/test-0.1-SNAPSHOT-bin.tar.gz").exists());
180 assertTrue("tar.gz doesn't exist",!files[0].contains( "SNAPSHOT" ));
181 }
182
183 public void testTarGzUniqueVersionTrueMaven3() throws Exception {
184 MavenModuleSet m3 = createMavenProject();
185 MavenInstallation mvn = configureMaven3();
186 m3.setMaven( mvn.getName() );
187 File repo = createTmpDir();
188 FileUtils.cleanDirectory( repo );
189 // a fake build
190 m3.setScm(new SingleFileSCM("pom.xml",getClass().getResource("targz-artifact.pom")));
191 m3.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),true, false));
192
193 MavenModuleSetBuild b = m3.scheduleBuild2(0).get();
194 assertBuildStatus(Result.SUCCESS, b);
195
196 assertTrue( MavenUtil.maven3orLater( b.getMavenVersionUsed() ) );
197
198 File artifactDir = new File(repo,"test/test/0.1-SNAPSHOT/");
199 String[] files = artifactDir.list( new FilenameFilter()
200 {
201
202 public boolean accept( File dir, String name )
203 {
204 return name.contains( "-bin.tar.gz" ) || name.endsWith( ".jar" ) || name.endsWith( "-bin.zip" );
205 }
206 });
207 System.out.println("deployed files " + Arrays.asList( files ));
208 assertFalse("tar.gz doesn't exist",new File(repo,"test/test/0.1-SNAPSHOT/test-0.1-SNAPSHOT-bin.tar.gz").exists());
209 assertTrue("tar.gz doesn't exist",!files[0].contains( "SNAPSHOT" ));
210 for (String file : files) {
211 if (file.endsWith( "-bin.tar.gz" )) {
212 String ver = StringUtils.remove( file, "-bin.tar.gz" );
213 ver = ver.substring( ver.length() - 1, ver.length() );
214 assertEquals("-bin.tar.gz not ended with 1 , file " + file , "1", ver);
215 }
216 if (file.endsWith( ".jar" )) {
217 String ver = StringUtils.remove( file, ".jar" );
218 ver = ver.substring( ver.length() - 1, ver.length() );
219 assertEquals(".jar not ended with 1 , file " + file , "1", ver);
220 }
221 if (file.endsWith( "-bin.zip" )) {
222 String ver = StringUtils.remove( file, "-bin.zip" );
223 ver = ver.substring( ver.length() - 1, ver.length() );
224 assertEquals("-bin.zip not ended with 1 , file " + file , "1", ver);
225 }
226 }
227 }
228
229 @Bug(3773)
230 public void testDeployUnstable() throws Exception {
231 configureDefaultMaven();
232 MavenModuleSet m2 = createMavenProject();
233 File repo = createTmpDir();
234 FileUtils.cleanDirectory( repo );
235 // a build with a failing unit tests
236 m2.setScm(new ExtractResourceSCM(getClass().getResource("maven-test-failure-findbugs.zip")));
237 m2.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),false, true));
238
239 MavenModuleSetBuild b = m2.scheduleBuild2(0).get();
240 assertBuildStatus(Result.UNSTABLE, b);
241
242 assertTrue("Artifact should have been published even when the build is unstable",
243 new File(repo,"test/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar").exists());
244 }
245 }
246