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

1 package hudson.model;
2
3 import hudson.matrix.AxisList;
4 import hudson.matrix.MatrixConfiguration;
5 import hudson.matrix.MatrixProject;
6 import hudson.matrix.TextAxis;
7 import org.jvnet.hudson.test.HudsonTestCase;
8
9 import java.util.Arrays;
10 import java.util.TreeSet;
11
12 /**
13 * @author Kohsuke Kawaguchi
14 */
15 public class AutoCompletionCandidatesTest extends HudsonTestCase {
16 public void testCompletion() throws Exception {
17 FreeStyleProject foo = jenkins.createProject(FreeStyleProject.class, "foo");
18 MatrixProject bar = jenkins.createProject(MatrixProject.class, "bar");
19 bar.setAxes(new AxisList(new TextAxis("x","1","2","3")));
20 MatrixConfiguration x3 = bar.getItem("x=3");
21
22 AutoCompletionCandidates c;
23
24 c = AutoCompletionCandidates.ofJobNames(Item.class, "", foo, jenkins);
25 assertContains(c, "foo", "bar");
26
27 c = AutoCompletionCandidates.ofJobNames(Item.class, "ba", foo, jenkins);
28 assertContains(c, "bar");
29
30 c = AutoCompletionCandidates.ofJobNames(Item.class, "bar/", foo, jenkins);
31 assertContains(c, "bar/x=1", "bar/x=2", "bar/x=3");
32
33
34 c = AutoCompletionCandidates.ofJobNames(FreeStyleProject.class, "", foo, jenkins);
35 assertContains(c, "foo");
36
37 c = AutoCompletionCandidates.ofJobNames(MatrixConfiguration.class, "bar/", foo, jenkins);
38 assertContains(c, "bar/x=1", "bar/x=2", "bar/x=3");
39
40 c = AutoCompletionCandidates.ofJobNames(Item.class, "", x3, x3.getParent());
41 assertContains(c, "x=1", "x=2", "x=3");
42
43 c = AutoCompletionCandidates.ofJobNames(Item.class, "/", x3, x3.getParent());
44 assertContains(c, "/foo", "/bar");
45
46 c = AutoCompletionCandidates.ofJobNames(Item.class, "/bar/", x3, x3.getParent());
47 assertContains(c, "/bar/x=1", "/bar/x=2", "/bar/x=3");
48
49 // relative path
50 c = AutoCompletionCandidates.ofJobNames(Item.class, "../", x3, x3.getParent());
51 assertContains(c, "../bar", "../foo");
52 }
53
54 private void assertContains(AutoCompletionCandidates c, String... values) {
55 assertEquals(new TreeSet<String>(Arrays.asList(values)), new TreeSet<String>(c.getValues()));
56 }
57 }
58