Skip to content
33 changes: 19 additions & 14 deletions test/src/test/java/hudson/PluginManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ class PluginManagerTest {
private File tmp;
private boolean signatureCheck;

// a simple plugin with ideally no dependencies so the tests run quickly
private static final String TEST_PLUGIN_NAME = "commons-lang3-api";
private static final String TEST_PLUGIN = TEST_PLUGIN_NAME + ".jpi";
private static final String TEST_PLUGIN_HPI = TEST_PLUGIN_NAME + ".hpi";

@BeforeEach
void setUp() {
signatureCheck = DownloadService.signatureCheck;
Expand All @@ -142,11 +147,11 @@ void uploadJpi() throws Throwable {
HtmlForm f = page.getFormByName("uploadPlugin");
File dir = newFolder(tmp, "junit");
File plugin = new File(dir, "htmlpublisher.jpi");
FileUtils.copyURLToFile(getClass().getClassLoader().getResource("plugins/htmlpublisher.jpi"), plugin);
FileUtils.copyURLToFile(getClass().getClassLoader().getResource("plugins/" + TEST_PLUGIN), plugin);
f.getInputByName("name").setValue(plugin.getAbsolutePath());
r.submit(f);

assertTrue(new File(r.jenkins.getRootDir(), "plugins/htmlpublisher.jpi").exists());
assertTrue(new File(r.jenkins.getRootDir(), "plugins/" + TEST_PLUGIN).exists());
});
}

Expand All @@ -159,13 +164,13 @@ void uploadHpi() throws Throwable {
HtmlPage page = r.createWebClient().goTo("pluginManager/advanced");
HtmlForm f = page.getFormByName("uploadPlugin");
File dir = newFolder(tmp, "junit");
File plugin = new File(dir, "legacy.hpi");
FileUtils.copyURLToFile(getClass().getClassLoader().getResource("plugins/legacy.hpi"), plugin);
File plugin = new File(dir, TEST_PLUGIN_HPI);
FileUtils.copyURLToFile(getClass().getClassLoader().getResource("plugins/" + TEST_PLUGIN), plugin);
f.getInputByName("name").setValue(plugin.getAbsolutePath());
r.submit(f);

// uploaded legacy plugins get renamed to *.jpi
assertTrue(new File(r.jenkins.getRootDir(), "plugins/legacy.jpi").exists());
assertTrue(new File(r.jenkins.getRootDir(), "plugins/" + TEST_PLUGIN).exists());
});
}

Expand All @@ -174,10 +179,10 @@ void deployJpiFromUrl() throws Throwable {
session.then(r -> {
HtmlPage page = r.createWebClient().goTo("pluginManager/advanced");
HtmlForm f = page.getFormByName("uploadPlugin");
f.getInputByName("pluginUrl").setValue(Jenkins.get().getRootUrl() + "pluginManagerGetPlugin/htmlpublisher.jpi");
f.getInputByName("pluginUrl").setValue(Jenkins.get().getRootUrl() + "pluginManagerGetPlugin/" + TEST_PLUGIN);
r.submit(f);

assertTrue(new File(r.jenkins.getRootDir(), "plugins/htmlpublisher.jpi").exists());
assertTrue(new File(r.jenkins.getRootDir(), "plugins/" + TEST_PLUGIN).exists());
});
}

Expand All @@ -202,17 +207,17 @@ public String getUrlName() {
public void doDynamic(StaplerRequest2 staplerRequest, StaplerResponse2 staplerResponse) throws ServletException, IOException {
staplerResponse.setContentType("application/octet-stream");
staplerResponse.setStatus(200);
staplerResponse.serveFile(staplerRequest, PluginManagerTest.class.getClassLoader().getResource("plugins/htmlpublisher.jpi"));
staplerResponse.serveFile(staplerRequest, PluginManagerTest.class.getClassLoader().getResource("plugins/" + TEST_PLUGIN));
}
}

/**
* Tests the effect of {@link WithPlugin}.
*/
@WithPlugin("htmlpublisher.jpi")
@WithPlugin(TEST_PLUGIN)
@Test
void withRecipeJpi() throws Throwable {
session.then(r -> assertNotNull(r.jenkins.getPlugin("htmlpublisher")));
session.then(r -> assertNotNull(r.jenkins.getPlugin(TEST_PLUGIN_NAME)));
}

/**
Expand All @@ -230,7 +235,7 @@ void withRecipeHpi() throws Throwable {
* resolve all the classes in the system (for example, a plugin X can define an extension point
* other plugins implement, so when X loads its config it better sees all the implementations defined elsewhere)
*/
@WithPlugin("htmlpublisher.jpi")
@WithPlugin(TEST_PLUGIN)
@WithPluginManager(PluginManagerImpl_for_testUberClassLoaderIsAvailableDuringStart.class)
@Test
void uberClassLoaderIsAvailableDuringStart() throws Throwable {
Expand Down Expand Up @@ -522,7 +527,7 @@ void dynamicLoadRestartRequiredException() throws Throwable {
});
}

@WithPlugin("htmlpublisher.jpi")
@WithPlugin(TEST_PLUGIN)
@Test
void pluginListJSONApi() throws Throwable {
session.then(r -> {
Expand Down Expand Up @@ -802,7 +807,7 @@ void verifyUploadedPluginPermission() throws Throwable {
HtmlForm f = page.getFormByName("uploadPlugin");
File dir = newFolder(tmp, "junit");
File plugin = new File(dir, "htmlpublisher.jpi");
FileUtils.copyURLToFile(Objects.requireNonNull(getClass().getClassLoader().getResource("plugins/htmlpublisher.jpi")), plugin);
FileUtils.copyURLToFile(Objects.requireNonNull(getClass().getClassLoader().getResource("plugins/" + TEST_PLUGIN)), plugin);
f.getInputByName("name").setValue(plugin.getAbsolutePath());
r.submit(f);

Expand Down Expand Up @@ -957,7 +962,7 @@ public String getUrlName() {
public void doDynamic(StaplerRequest2 staplerRequest, StaplerResponse2 staplerResponse) throws ServletException, IOException {
staplerResponse.setContentType("application/octet-stream");
staplerResponse.setStatus(200);
staplerResponse.serveFile(staplerRequest, PluginManagerTest.class.getClassLoader().getResource("plugins/htmlpublisher.jpi"));
staplerResponse.serveFile(staplerRequest, PluginManagerTest.class.getClassLoader().getResource("plugins/" + TEST_PLUGIN));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ void setUp(JenkinsRule rule) {
}

private JenkinsRule.WebClient getWebClient() {
var wc = j.createWebClient();
wc.getOptions().setJavaScriptEnabled(false);
return wc;
return j.createWebClient();
}

/**
Expand Down
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binary file not shown.