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

1 /*
2 * The MIT License
3 *
4 * Copyright 2012 Jesse Glick.
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
25 package hudson.model;
26
27 import hudson.model.UpdateSite.Data;
28 import hudson.util.FormValidation;
29 import hudson.util.PersistedList;
30 import java.net.URL;
31 import java.util.Arrays;
32 import java.util.HashSet;
33 import static org.junit.Assert.*;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.jvnet.hudson.test.JenkinsRule;
37
38 public class UpdateSiteTest {
39
40 @Rule public JenkinsRule j = new JenkinsRule();
41
42 @Test public void relativeURLs() throws Exception {
43 PersistedList<UpdateSite> sites = j.jenkins.getUpdateCenter().getSites();
44 sites.clear();
45 URL url = UpdateSiteTest.class.getResource("/plugins/tasks-update-center.json");
46 UpdateSite site = new UpdateSite(UpdateCenter.ID_DEFAULT, url.toString());
47 sites.add(site);
48 assertEquals(FormValidation.ok(), site.updateDirectly(false).get());
49 Data data = site.getData();
50 assertNotNull(data);
51 assertEquals(new URL(url, "jenkins.war").toString(), data.core.url);
52 assertEquals(new HashSet<String>(Arrays.asList("tasks", "dummy")), data.plugins.keySet());
53 assertEquals(new URL(url, "tasks.jpi").toString(), data.plugins.get("tasks").url);
54 assertEquals("http://nowhere.net/dummy.hpi", data.plugins.get("dummy").url);
55 }
56
57 @Test public void updateDirectlyWithJson() throws Exception {
58 UpdateSite us = new UpdateSite("default", UpdateSiteTest.class.getResource("update-center.json").toExternalForm());
59 assertNull(us.getPlugin("AdaptivePlugin"));
60 assertEquals(FormValidation.ok(), us.updateDirectly(true).get());
61 assertNotNull(us.getPlugin("AdaptivePlugin"));
62 }
63
64 @Test public void updateDirectlyWithHtml() throws Exception {
65 UpdateSite us = new UpdateSite("default", UpdateSiteTest.class.getResource("update-center.json.html").toExternalForm());
66 assertNull(us.getPlugin("AdaptivePlugin"));
67 assertEquals(FormValidation.ok(), us.updateDirectly(true).get());
68 assertNotNull(us.getPlugin("AdaptivePlugin"));
69 }
70 }
71