File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\test\src\test\java\hudson\scm\ScmTest.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.scm;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.util.concurrent.ExecutionException;
29
30 import hudson.FilePath;
31 import hudson.Launcher;
32 import hudson.model.AbstractBuild;
33 import hudson.model.AbstractProject;
34 import hudson.model.BuildListener;
35 import hudson.model.FreeStyleBuild;
36 import hudson.model.FreeStyleProject;
37 import hudson.model.Node;
38 import hudson.model.Result;
39
40 import org.jvnet.hudson.test.Bug;
41 import org.jvnet.hudson.test.HudsonTestCase;
42
43 /**
44 * @author Kohsuke Kawaguchi
45 */
46 public class ScmTest extends HudsonTestCase {
47 /**
48 * Makes sure that {@link SCM#processWorkspaceBeforeDeletion(AbstractProject, FilePath, Node)} is called
49 * before a project deletion.
50 */
51 @Bug(2271)
52 public void testProjectDeletionAndCallback() throws Exception {
53 FreeStyleProject p = createFreeStyleProject();
54 final boolean[] callback = new boolean[1];
55 p.setScm(new NullSCM() {
56 public boolean processWorkspaceBeforeDeletion(AbstractProject<?, ?> project, FilePath workspace, Node node) {
57 callback[0] = true;
58 return true;
59 }
60
61 private Object writeReplace() { // don't really care about save
62 return new NullSCM();
63 }
64 });
65 p.scheduleBuild2(0).get();
66 p.delete();
67 assertTrue(callback[0]);
68 }
69
70 @Bug(4605)
71 public void testAbortDuringCheckoutMarksBuildAsAborted() throws IOException, InterruptedException, ExecutionException {
72 FreeStyleProject p = createFreeStyleProject();
73 p.setScm(new NullSCM() {
74 @Override
75 public boolean checkout(AbstractBuild<?, ?> build,
76 Launcher launcher, FilePath remoteDir,
77 BuildListener listener, File changeLogFile)
78 throws IOException, InterruptedException {
79 throw new InterruptedException();
80 }
81
82 private Object writeReplace() { // don't really care about save
83 return new NullSCM();
84 }
85 });
86
87 FreeStyleBuild build = p.scheduleBuild2(0).get();
88 assertEquals(Result.ABORTED, build.getResult());
89 }
90 }
91