Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<ban-junit4-imports.skip>false</ban-junit4-imports.skip>
</properties>
<name>Oracle Java SE Development Kit Installer Plugin</name>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/hudson/model/DownloadServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
import java.util.ArrayList;
import java.util.List;
import net.sf.json.JSONObject;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

/**
* @author Kohsuke Kawaguchi
*/
public class DownloadServiceTest {
class DownloadServiceTest {

@Test
public void testReduceFunctionWithJDKJsons() throws Exception {
void testReduceFunctionWithJDKJsons() throws Exception {
URL resource1 = DownloadServiceTest.class.getResource("hudson.tools.JDKInstaller1.json");
URL resource2 = DownloadServiceTest.class.getResource("hudson.tools.JDKInstaller2.json");
URL resource3 = DownloadServiceTest.class.getResource("hudson.tools.JDKInstaller3.json");
Expand Down
15 changes: 7 additions & 8 deletions src/test/java/hudson/tools/JDKInstallerCascTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
import hudson.model.JDK;
import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
import org.junit.Rule;
import org.junit.Test;
import io.jenkins.plugins.casc.misc.junit.jupiter.WithJenkinsConfiguredWithCode;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class JDKInstallerCascTest {
@Rule
public JenkinsConfiguredWithCodeRule r = new JenkinsConfiguredWithCodeRule();
@WithJenkinsConfiguredWithCode
class JDKInstallerCascTest {

@ConfiguredWithCode("casc.yaml")
@Test
public void configuredByCasC() {
void configuredByCasC(JenkinsConfiguredWithCodeRule r) {
final JDK.DescriptorImpl descriptor = ExtensionList.lookupSingleton(JDK.DescriptorImpl.class);
assertEquals(1, descriptor.getInstallations().length);

Expand Down
72 changes: 39 additions & 33 deletions src/test/java/hudson/tools/JDKInstallerTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package hudson.tools;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;

import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlFormUtil;
Expand All @@ -10,10 +11,10 @@

import java.io.InputStream;
import java.nio.file.Files;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import hudson.model.JDK;
import hudson.model.TaskListener;
import hudson.util.StreamTaskListener;
Expand All @@ -23,37 +24,41 @@
import hudson.Launcher.LocalLauncher;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.logging.Logger;

import org.junit.rules.TemporaryFolder;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

/**
* @author Kohsuke Kawaguchi
*/
public class JDKInstallerTest {
@WithJenkins
class JDKInstallerTest {

private static final Logger LOGGER = Logger.getLogger(JDKInstallerTest.class.getName());

@Rule
public JenkinsRule j = new JenkinsRule();
private JenkinsRule j;

@Rule
public TemporaryFolder tmp = new TemporaryFolder();
@TempDir
private File tmp;

@BeforeEach
void beforeEach(JenkinsRule rule) throws Exception {
j = rule;

@Before
public void setUp() throws Exception {
File f = new File(new File(System.getProperty("user.home")),".jenkins-ci.org");
if (!f.exists()) {
LOGGER.warning(f+" doesn't exist. Skipping JDK installation tests");
LOGGER.warning(f + " doesn't exist. Skipping JDK installation tests");
} else {
Properties prop = new Properties();
try (InputStream in = Files.newInputStream(f.toPath())) {
prop.load(in);
String u = prop.getProperty("oracle.userName");
String p = prop.getProperty("oracle.password");
if (u==null || p==null) {
LOGGER.warning(f+" doesn't contain oracle.userName and oracle.password. Skipping JDK installation tests.");
if (u == null || p == null) {
LOGGER.warning(f + " doesn't contain oracle.userName and oracle.password. Skipping JDK installation tests.");
} else {
DescriptorImpl d = j.jenkins.getDescriptorByType(DescriptorImpl.class);
d.doPostCredential(u,p);
Expand All @@ -63,7 +68,7 @@ public void setUp() throws Exception {
}

@Test
public void enterCredential() throws Exception {
void enterCredential() throws Exception {
HtmlPage p = j.createWebClient().goTo("descriptorByName/hudson.tools.JDKInstaller/enterCredential");
HtmlForm form = p.getFormByName("postCredential");
form.getInputByName("username").setValue("foo");
Expand All @@ -79,43 +84,44 @@ public void enterCredential() throws Exception {
* Tests the configuration round trip.
*/
@Test
public void configRoundtrip() throws Exception {
void configRoundtrip() throws Exception {
JDKInstaller installer = new JDKInstaller("jdk-6u13-oth-JPR@CDS-CDS_Developer", true);

j.jenkins.getJDKs().add(new JDK("test",tmp.getRoot().getAbsolutePath(), Arrays.asList(
new InstallSourceProperty(Arrays.<ToolInstaller>asList(installer)))));
j.jenkins.getJDKs().add(new JDK("test", tmp.getAbsolutePath(), List.of(
new InstallSourceProperty(List.of(installer)))));

j.submit(j.createWebClient().goTo("configureTools").getFormByName("config"));

JDK jdk = j.jenkins.getJDK("test");
InstallSourceProperty isp = jdk.getProperties().get(InstallSourceProperty.class);
assertEquals(1,isp.installers.size());
assertEquals(1, isp.installers.size());
j.assertEqualBeans(installer, isp.installers.get(JDKInstaller.class), "id,acceptLicense");
}

/**
* Fake installation on Unix.
*/
@Test
public void fakeUnixInstall() throws Exception {
Assume.assumeFalse("If we're on Windows, don't bother doing this", Functions.isWindows());
void fakeUnixInstall() throws Exception {
assumeFalse(Functions.isWindows(), "If we're on Windows, don't bother doing this");

File bundle = File.createTempFile("fake-jdk-by-hudson","sh");
try {
new FilePath(bundle).write(
"#!/bin/bash -ex\n" +
"mkdir -p jdk1.6.0_dummy/bin\n" +
"touch jdk1.6.0_dummy/bin/java","ASCII");
"""
#!/bin/bash -ex
mkdir -p jdk1.6.0_dummy/bin
touch jdk1.6.0_dummy/bin/java
""",
"ASCII");
TaskListener l = StreamTaskListener.fromStdout();

new JDKInstaller("",true).install(new LocalLauncher(l),Platform.LINUX,
new JDKInstaller.FilePathFileSystem(j.jenkins),l,tmp.getRoot().getPath(),bundle.getPath());
new JDKInstaller("",true).install(new LocalLauncher(l), Platform.LINUX,
new JDKInstaller.FilePathFileSystem(j.jenkins), l, tmp.getPath(), bundle.getPath());

assertTrue(new File(tmp.getRoot(),"bin/java").exists());
assertTrue(new File(tmp,"bin/java").exists());
} finally {
bundle.delete();
}
}

private static final Logger LOGGER = Logger.getLogger(JDKInstallerTest.class.getName());
}
Loading