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

1 package hudson.model;
2
3 import hudson.model.DownloadService.Downloadable;
4 import net.sf.json.JSONObject;
5 import org.jvnet.hudson.test.Bug;
6 import org.jvnet.hudson.test.HudsonTestCase;
7 import org.kohsuke.stapler.StaplerResponse;
8
9 import java.io.IOException;
10
11 /**
12 * @author Kohsuke Kawaguchi
13 */
14 public class DownloadServiceTest extends HudsonTestCase {
15 private Downloadable job;
16
17 /**
18 * Makes sure that JavaScript on the client side for handling submission works.
19 */
20 @Override
21 protected void setUp() throws Exception {
22 super.setUp();
23 // this object receives the submission.
24 // to bypass the URL restriction, we'll trigger downloadService.download ourselves
25 job = new Downloadable("test", "UNUSED");
26 Downloadable.all().add(job);
27 }
28
29 @Override
30 protected void tearDown() throws Exception {
31 Downloadable.all().remove(job);
32 super.tearDown();
33 }
34
35 @Bug(5536)
36 public void testPost() throws Exception {
37 // initially it should fail because the data doesn't have a signature
38 assertNull(job.getData());
39 createWebClient().goTo("/self/testPost");
40 assertNull(job.getData());
41
42 // and now it should work
43 DownloadService.signatureCheck = false;
44 try {
45 createWebClient().goTo("/self/testPost");
46 JSONObject d = job.getData();
47 assertEquals(hashCode(),d.getInt("hello"));
48 } finally {
49 DownloadService.signatureCheck = true;
50 }
51
52 // TODO: test with a signature
53 }
54
55 /**
56 * This is where the browser should hit to retrieve data.
57 */
58 public void doData(StaplerResponse rsp) throws IOException {
59 rsp.setContentType("application/javascript");
60 rsp.getWriter().println("downloadService.post('test',{'hello':"+hashCode()+"})");
61 }
62 }
63