Skip to content

Commit 0d14dd6

Browse files
Migrate tests to JUnit5
* first batch of green tests
1 parent 66296a4 commit 0d14dd6

File tree

52 files changed

+1299
-1167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1299
-1167
lines changed

test/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ THE SOFTWARE.
442442
<artifactId>maven-surefire-plugin</artifactId>
443443
<!-- Version specified in grandparent POM -->
444444
<configuration>
445-
<groups>org.jvnet.hudson.test.SmokeTest</groups>
445+
<groups>SmokeTest</groups>
446446
</configuration>
447447
</plugin>
448448
</plugins>

test/src/test/java/hudson/ExtensionListRjrTest.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import static org.hamcrest.MatcherAssert.assertThat;
44
import static org.hamcrest.Matchers.empty;
55
import static org.hamcrest.Matchers.hasSize;
6-
import static org.junit.Assert.assertNotNull;
6+
import static org.junit.jupiter.api.Assertions.assertNotNull;
77

88
import java.util.Collection;
99
import jenkins.plugins.dependee.Dependee;
@@ -12,16 +12,17 @@
1212
import jenkins.plugins.dynamic_extension_loading.CustomExtensionLoadedViaListener;
1313
import jenkins.plugins.dynamic_extension_loading.CustomPeriodicWork;
1414
import jenkins.plugins.optional_depender.OptionalDepender;
15-
import org.junit.Rule;
16-
import org.junit.Test;
15+
import org.junit.jupiter.api.Test;
16+
import org.junit.jupiter.api.extension.RegisterExtension;
1717
import org.jvnet.hudson.test.Issue;
1818
import org.jvnet.hudson.test.JenkinsRule;
19-
import org.jvnet.hudson.test.RealJenkinsRule;
20-
import org.jvnet.hudson.test.RealJenkinsRule.SyntheticPlugin;
19+
import org.jvnet.hudson.test.junit.jupiter.RealJenkinsExtension;
20+
import org.jvnet.hudson.test.junit.jupiter.RealJenkinsExtension.SyntheticPlugin;
2121

22-
public class ExtensionListRjrTest {
23-
@Rule
24-
public RealJenkinsRule rjr = new RealJenkinsRule();
22+
class ExtensionListRjrTest {
23+
24+
@RegisterExtension
25+
public RealJenkinsExtension rjr = new RealJenkinsExtension();
2526

2627
/**
2728
* Check that dynamically loading a plugin does not lead to extension lists with duplicate entries.
@@ -30,7 +31,7 @@ public class ExtensionListRjrTest {
3031
*/
3132
@Test
3233
@Issue("JENKINS-75232")
33-
public void checkDynamicLoad_singleRegistration() throws Throwable {
34+
void checkDynamicLoad_singleRegistration() throws Throwable {
3435
var pluginJpi = rjr.createSyntheticPlugin(new SyntheticPlugin(CustomPeriodicWork.class.getPackage())
3536
.shortName("dynamic-extension-loading")
3637
.header("Plugin-Dependencies", "variant:0"));
@@ -57,8 +58,8 @@ private static void assertSingleton(JenkinsRule r, String fqcn) throws Exception
5758
}
5859

5960
@Test
60-
@Issue({ "JENKINS-50336", "JENKINS-60449" })
61-
public void installDependedOptionalPluginWithoutRestart() throws Throwable {
61+
@Issue({"JENKINS-50336", "JENKINS-60449"})
62+
void installDependedOptionalPluginWithoutRestart() throws Throwable {
6263
var optionalDependerJpi = rjr.createSyntheticPlugin(new SyntheticPlugin(OptionalDepender.class.getPackage())
6364
.header("Plugin-Dependencies", "variant:0,dependee:0;resolution:=optional"));
6465
var dependeeJpi = rjr.createSyntheticPlugin(new SyntheticPlugin(Dependee.class.getPackage()).shortName("dependee"));

test/src/test/java/hudson/ProxyConfigurationManagerGUITest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,24 @@
2424

2525
package hudson;
2626

27-
import static org.junit.Assert.assertEquals;
28-
import static org.junit.Assert.assertNotNull;
29-
import static org.junit.Assert.assertNull;
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.assertNotNull;
29+
import static org.junit.jupiter.api.Assertions.assertNull;
3030

3131
import hudson.util.Secret;
3232
import java.io.File;
3333
import org.apache.commons.io.FileUtils;
34-
import org.junit.Rule;
35-
import org.junit.Test;
36-
import org.jvnet.hudson.test.JenkinsSessionRule;
34+
import org.junit.jupiter.api.Test;
35+
import org.junit.jupiter.api.extension.RegisterExtension;
36+
import org.jvnet.hudson.test.junit.jupiter.JenkinsSessionExtension;
3737

38-
public final class ProxyConfigurationManagerGUITest {
38+
class ProxyConfigurationManagerGUITest {
3939

40-
@Rule public JenkinsSessionRule rr = new JenkinsSessionRule();
40+
@RegisterExtension
41+
public JenkinsSessionExtension rr = new JenkinsSessionExtension();
4142

42-
@Test public void configRoundtrip() throws Throwable {
43+
@Test
44+
void configRoundtrip() throws Throwable {
4345
rr.then(r -> {
4446
assertNull(r.jenkins.proxy);
4547
r.jenkins.proxy = new ProxyConfiguration("proxy.mycorp", 80);

test/src/test/java/hudson/bugs/JnlpAccessWithSecuredHudsonTest.java

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
package hudson.bugs;
2626

27-
import static org.junit.Assert.assertFalse;
28-
import static org.junit.Assert.assertTrue;
27+
import static org.junit.jupiter.api.Assertions.assertFalse;
28+
import static org.junit.jupiter.api.Assertions.assertTrue;
2929

3030
import hudson.model.Slave;
3131
import hudson.model.User;
@@ -34,39 +34,50 @@
3434
import java.net.HttpURLConnection;
3535
import java.net.URL;
3636
import java.util.Locale;
37+
import jenkins.model.Jenkins;
3738
import jenkins.security.s2m.AdminWhitelistRule;
3839
import org.dom4j.Document;
3940
import org.dom4j.Element;
4041
import org.dom4j.io.DOMReader;
4142
import org.htmlunit.Page;
4243
import org.htmlunit.html.HtmlPage;
4344
import org.htmlunit.xml.XmlPage;
44-
import org.junit.Rule;
45-
import org.junit.Test;
45+
import org.junit.jupiter.api.BeforeEach;
46+
import org.junit.jupiter.api.Test;
47+
import org.junit.jupiter.api.extension.RegisterExtension;
4648
import org.jvnet.hudson.test.Email;
47-
import org.jvnet.hudson.test.InboundAgentRule;
4849
import org.jvnet.hudson.test.JenkinsRule;
49-
import org.jvnet.hudson.test.recipes.PresetData;
50-
import org.jvnet.hudson.test.recipes.PresetData.DataSet;
50+
import org.jvnet.hudson.test.MockAuthorizationStrategy;
51+
import org.jvnet.hudson.test.junit.jupiter.InboundAgentExtension;
52+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
5153

5254
/**
5355
* Makes sure that the jars that web start needs are readable, even when the anonymous user doesn't have any read access.
5456
*
5557
* @author Kohsuke Kawaguchi
5658
*/
57-
public class JnlpAccessWithSecuredHudsonTest {
59+
@WithJenkins
60+
class JnlpAccessWithSecuredHudsonTest {
5861

59-
@Rule
60-
public JenkinsRule r = new JenkinsRule();
62+
@RegisterExtension
63+
private final InboundAgentExtension inboundAgents = new InboundAgentExtension();
6164

62-
@Rule
63-
public InboundAgentRule inboundAgents = new InboundAgentRule();
65+
private JenkinsRule r;
66+
67+
@BeforeEach
68+
void setUp(JenkinsRule rule) {
69+
r = rule;
70+
}
6471

65-
@PresetData(DataSet.NO_ANONYMOUS_READACCESS)
6672
@Email("http://markmail.org/message/on4wkjdaldwi2atx")
6773
@Test
68-
public void anonymousCanAlwaysLoadJARs() throws Exception {
69-
inboundAgents.createAgent(r, InboundAgentRule.Options.newBuilder().name("test").skipStart().build());
74+
void anonymousCanAlwaysLoadJARs() throws Exception {
75+
JenkinsRule.DummySecurityRealm realm = r.createDummySecurityRealm();
76+
r.jenkins.setSecurityRealm(realm);
77+
r.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy()
78+
.grant(Jenkins.ADMINISTER).everywhere().toAuthenticated());
79+
80+
inboundAgents.createAgent(r, InboundAgentExtension.Options.newBuilder().name("test").skipStart().build());
7081
JenkinsRule.WebClient wc = r.createWebClient();
7182
HtmlPage p = wc.withBasicApiToken(User.getById("alice", true)).goTo("computer/test/");
7283

@@ -87,21 +98,30 @@ public void anonymousCanAlwaysLoadJARs() throws Exception {
8798
}
8899
}
89100

90-
@PresetData(DataSet.ANONYMOUS_READONLY)
91101
@Test
92-
public void anonymousCannotGetSecrets() throws Exception {
93-
inboundAgents.createAgent(r, InboundAgentRule.Options.newBuilder().name("test").skipStart().build());
102+
void anonymousCannotGetSecrets() throws Exception {
103+
JenkinsRule.DummySecurityRealm realm = r.createDummySecurityRealm();
104+
r.jenkins.setSecurityRealm(realm);
105+
r.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy()
106+
.grant(Jenkins.READ).everywhere().toEveryone()
107+
.grant(Jenkins.ADMINISTER).everywhere().toAuthenticated());
108+
109+
inboundAgents.createAgent(r, InboundAgentExtension.Options.newBuilder().name("test").skipStart().build());
94110
r.createWebClient().assertFails("computer/test/jenkins-agent.jnlp", HttpURLConnection.HTTP_FORBIDDEN);
95111
}
96112

97-
@PresetData(DataSet.NO_ANONYMOUS_READACCESS)
98113
@Test
99-
public void serviceUsingDirectSecret() throws Exception {
100-
Slave slave = inboundAgents.createAgent(r, InboundAgentRule.Options.newBuilder().name("test").secret().build());
114+
void serviceUsingDirectSecret() throws Exception {
115+
JenkinsRule.DummySecurityRealm realm = r.createDummySecurityRealm();
116+
r.jenkins.setSecurityRealm(realm);
117+
r.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy()
118+
.grant(Jenkins.ADMINISTER).everywhere().toAuthenticated());
119+
120+
Slave slave = inboundAgents.createAgent(r, InboundAgentExtension.Options.newBuilder().name("test").build());
101121
try {
102122
r.createWebClient().goTo("computer/test/jenkins-agent.jnlp?encrypt=true", "application/octet-stream");
103123
Channel channel = slave.getComputer().getChannel();
104-
assertFalse("SECURITY-206", channel.isRemoteClassLoadingAllowed());
124+
assertFalse(channel.isRemoteClassLoadingAllowed(), "SECURITY-206");
105125
r.jenkins.getExtensionList(AdminWhitelistRule.class).get(AdminWhitelistRule.class).setMasterKillSwitch(false);
106126
final File f = new File(r.jenkins.getRootDir(), "config.xml");
107127
assertTrue(f.exists());

0 commit comments

Comments
 (0)