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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2010-2011, Alan Harder
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.matrix;
25
26 import hudson.model.Item;
27 import hudson.security.AuthorizationMatrixProperty;
28 import hudson.security.ProjectMatrixAuthorizationStrategy;
29 import java.util.Collections;
30 import org.acegisecurity.context.SecurityContextHolder;
31 import com.gargoylesoftware.htmlunit.xml.XmlPage;
32 import org.jvnet.hudson.test.HudsonTestCase;
33 import org.jvnet.hudson.test.Bug;
34
35 /**
36 * @author Alan Harder
37 */
38 public class MatrixTest extends HudsonTestCase {
39
40 /**
41 * Test that spaces are encoded as %20 for project name, axis name and axis value.
42 */
43 public void testSpaceInUrl() {
44 MatrixProject mp = new MatrixProject("matrix test");
45 MatrixConfiguration mc = new MatrixConfiguration(mp, Combination.fromString("foo bar=baz bat"));
46 assertEquals("job/matrix%20test/", mp.getUrl());
47 assertTrue("Invalid: " + mc.getUrl(),
48 "job/matrix%20test/foo%20bar=baz%20bat/".equals(mc.getUrl())
49 || "job/matrix%20test/./foo%20bar=baz%20bat/".equals(mc.getUrl()));
50 }
51
52 /**
53 * Test that project level permissions apply to child configurations as well.
54 */
55 @Bug(9293)
56 public void testConfigurationACL() throws Exception {
57 jenkins.setAuthorizationStrategy(new ProjectMatrixAuthorizationStrategy());
58 MatrixProject mp = createMatrixProject();
59 mp.setAxes(new AxisList(new Axis("foo", "a", "b")));
60 MatrixConfiguration mc = mp.getItem("foo=a");
61 assertNotNull(mc);
62 SecurityContextHolder.clearContext();
63 assertFalse(mc.getACL().hasPermission(Item.READ));
64 mp.addProperty(new AuthorizationMatrixProperty(
65 Collections.singletonMap(Item.READ, Collections.singleton("anonymous"))));
66 // Project-level permission should apply to single configuration too:
67 assertTrue(mc.getACL().hasPermission(Item.READ));
68 }
69
70 public void testApi() throws Exception {
71 MatrixProject project = createMatrixProject();
72 project.setAxes(new AxisList(
73 new Axis("FOO", "abc", "def"),
74 new Axis("BAR", "uvw", "xyz")));
75 XmlPage xml = new WebClient().goToXml(project.getUrl() + "api/xml");
76 assertEquals(4, xml.getByXPath("//matrixProject/activeConfiguration").size());
77 }
78 }
79