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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Yahoo!, Inc.
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.model;
25
26 import com.gargoylesoftware.htmlunit.Page;
27 import java.net.HttpURLConnection;
28 import org.jvnet.hudson.test.HudsonTestCase;
29 import org.jvnet.hudson.test.Bug;
30
31 /**
32 * @author Kohsuke Kawaguchi
33 */
34 public class ApiTest extends HudsonTestCase {
35
36 @Bug(2828)
37 public void testXPath() throws Exception {
38 new WebClient().goTo("api/xml?xpath=/*[1]","application/xml");
39 }
40
41 @Bug(3267)
42 public void testWrappedZeroItems() throws Exception {
43 Page page = new WebClient().goTo("api/xml?wrapper=root&xpath=/hudson/nonexistent", "application/xml");
44 assertEquals("<root/>", page.getWebResponse().getContentAsString());
45 }
46
47 @Bug(3267)
48 public void testWrappedOneItem() throws Exception {
49 Page page = new WebClient().goTo("api/xml?wrapper=root&xpath=/hudson/view/name", "application/xml");
50 assertEquals("<root><name>All</name></root>", page.getWebResponse().getContentAsString());
51 }
52
53 public void testWrappedMultipleItems() throws Exception {
54 createFreeStyleProject();
55 createFreeStyleProject();
56 Page page = new WebClient().goTo("api/xml?wrapper=root&xpath=/hudson/job/name", "application/xml");
57 assertEquals("<root><name>test0</name><name>test1</name></root>", page.getWebResponse().getContentAsString());
58 }
59
60 public void testUnwrappedZeroItems() throws Exception {
61 new WebClient().assertFails("api/xml?xpath=/hudson/nonexistent", HttpURLConnection.HTTP_NOT_FOUND);
62 }
63
64 public void testUnwrappedOneItem() throws Exception {
65 Page page = new WebClient().goTo("api/xml?xpath=/hudson/view/name", "application/xml");
66 assertEquals("<name>All</name>", page.getWebResponse().getContentAsString());
67 }
68
69 public void testUnwrappedLongString() throws Exception {
70 jenkins.setSystemMessage("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
71 Page page = new WebClient().goTo("api/xml?xpath=/hudson/description", "application/xml");
72 assertEquals(
73 "<description>"+jenkins.getSystemMessage()+"</description>",
74 page.getWebResponse().getContentAsString());
75 }
76
77 public void testUnwrappedMultipleItems() throws Exception {
78 createFreeStyleProject();
79 createFreeStyleProject();
80 new WebClient().assertFails("api/xml?xpath=/hudson/job/name", HttpURLConnection.HTTP_INTERNAL_ERROR);
81 }
82 }
83