diff --git a/core/src/test/java/jenkins/model/RunIdMigratorTest.java b/core/src/test/java/jenkins/model/RunIdMigratorTest.java
index 4b890ac50a..f51d0299b8 100644
--- a/core/src/test/java/jenkins/model/RunIdMigratorTest.java
+++ b/core/src/test/java/jenkins/model/RunIdMigratorTest.java
@@ -52,6 +52,7 @@ public class RunIdMigratorTest {
TimeZone.setDefault(TimeZone.getTimeZone("EST"));
}
+ // TODO could use LoggerRule only if it were extracted to an independent library
@BeforeClass public static void logging() {
RunIdMigrator.LOGGER.setLevel(Level.ALL);
Handler handler = new ConsoleHandler();
diff --git a/test/pom.xml b/test/pom.xml
index 9544d08dc3..96fb57ab53 100644
--- a/test/pom.xml
+++ b/test/pom.xml
@@ -62,7 +62,7 @@ THE SOFTWARE.
${project.groupId}
jenkins-test-harness
- 2.7
+ 2.13-SNAPSHOT
test
@@ -186,6 +186,13 @@ THE SOFTWARE.
4.0
test
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5
+ test
+ jar
+
diff --git a/test/src/test/java/hudson/model/JobPropertyTest.java b/test/src/test/java/hudson/model/JobPropertyTest.java
index b9cb9d135d..a6b56abfc5 100644
--- a/test/src/test/java/hudson/model/JobPropertyTest.java
+++ b/test/src/test/java/hudson/model/JobPropertyTest.java
@@ -30,34 +30,25 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.matrix.MatrixProject;
import hudson.maven.MavenModuleSet;
import hudson.model.Descriptor.FormException;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Handler;
import java.util.logging.Level;
-import java.util.logging.Logger;
import net.sf.json.JSONObject;
-import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
+import org.jvnet.hudson.test.LoggerRule;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
public class JobPropertyTest {
- private static final Logger logger = Logger.getLogger(Descriptor.class.getName());
- @BeforeClass
- public static void logging() {
- logger.setLevel(Level.ALL);
- Handler handler = new ConsoleHandler();
- handler.setLevel(Level.ALL);
- logger.addHandler(handler);
- }
-
@Rule
public JenkinsRule j = new JenkinsRule();
+ @Rule
+ public LoggerRule logs = new LoggerRule();
+
@Test
@Issue("JENKINS-2398")
public void jobPropertySummaryIsShownInMavenModuleSetIndexPage() throws Exception {
@@ -110,6 +101,7 @@ public class JobPropertyTest {
*/
@Test
public void configRoundtrip() throws Exception {
+ logs.record(Descriptor.class, Level.ALL);
FreeStyleProject p = j.createFreeStyleProject();
JobPropertyWithConfigImpl before = new JobPropertyWithConfigImpl("Duke");
p.addProperty(before);
diff --git a/test/src/test/java/hudson/model/MyViewTest.java b/test/src/test/java/hudson/model/MyViewTest.java
index 6dbf07a87d..be8ecd9902 100644
--- a/test/src/test/java/hudson/model/MyViewTest.java
+++ b/test/src/test/java/hudson/model/MyViewTest.java
@@ -30,15 +30,12 @@ import org.junit.Test;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import hudson.security.GlobalMatrixAuthorizationStrategy;
import java.io.IOException;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Handler;
import java.util.logging.Level;
-import java.util.logging.Logger;
import org.acegisecurity.context.SecurityContextHolder;
import org.junit.Rule;
import org.jvnet.hudson.test.JenkinsRule;
import static org.junit.Assert.*;
-import org.junit.BeforeClass;
+import org.jvnet.hudson.test.LoggerRule;
/**
*
@@ -49,19 +46,14 @@ public class MyViewTest {
@Rule
public JenkinsRule rule = new JenkinsRule();
+ @Rule
+ public LoggerRule logs = new LoggerRule();
+
@Before
public void setup() {
rule.jenkins.setSecurityRealm(rule.createDummySecurityRealm());
}
- private static final Logger logger = Logger.getLogger(AbstractItem.class.getName());
- @BeforeClass public static void logging() {
- logger.setLevel(Level.ALL);
- Handler handler = new ConsoleHandler();
- handler.setLevel(Level.ALL);
- logger.addHandler(handler);
- }
-
@Test
public void testContains() throws IOException, Exception{
@@ -80,6 +72,7 @@ public class MyViewTest {
@Test
public void testDoCreateItem() throws IOException, Exception{
+ logs.record(AbstractItem.class, Level.ALL);
MyView view = new MyView("My", rule.jenkins);
rule.jenkins.addView(view);
HtmlPage newItemPage = rule.createWebClient().goTo("view/" + view.getDisplayName() + "/newJob");
diff --git a/test/src/test/java/hudson/model/ParametersDefinitionPropertyTest.java b/test/src/test/java/hudson/model/ParametersDefinitionPropertyTest.java
index eea8b9898d..01c6aa61e5 100644
--- a/test/src/test/java/hudson/model/ParametersDefinitionPropertyTest.java
+++ b/test/src/test/java/hudson/model/ParametersDefinitionPropertyTest.java
@@ -25,37 +25,29 @@
package hudson.model;
import java.util.Locale;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Handler;
import java.util.logging.Level;
-import java.util.logging.Logger;
import net.sf.json.JSONObject;
import org.junit.Test;
import static org.junit.Assert.*;
-import org.junit.BeforeClass;
import org.junit.Rule;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
+import org.jvnet.hudson.test.LoggerRule;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.StaplerRequest;
public class ParametersDefinitionPropertyTest {
- private static final Logger logger = Logger.getLogger(Descriptor.class.getName());
- @BeforeClass
- public static void logging() {
- logger.setLevel(Level.ALL);
- Handler handler = new ConsoleHandler();
- handler.setLevel(Level.ALL);
- logger.addHandler(handler);
- }
-
@Rule
public JenkinsRule r = new JenkinsRule();
+ @Rule
+ public LoggerRule logs = new LoggerRule();
+
@Issue("JENKINS-31458")
@Test
public void customNewInstance() throws Exception {
+ logs.record(Descriptor.class, Level.ALL);
KrazyParameterDefinition kpd = new KrazyParameterDefinition("kpd", "desc", "KrAzY");
FreeStyleProject p = r.createFreeStyleProject();
ParametersDefinitionProperty pdp = new ParametersDefinitionProperty(kpd);
diff --git a/test/src/test/java/hudson/model/WorkspaceCleanupThreadTest.java b/test/src/test/java/hudson/model/WorkspaceCleanupThreadTest.java
index 0971276179..9e182f2e10 100644
--- a/test/src/test/java/hudson/model/WorkspaceCleanupThreadTest.java
+++ b/test/src/test/java/hudson/model/WorkspaceCleanupThreadTest.java
@@ -33,20 +33,17 @@ import hudson.util.StreamTaskListener;
import java.io.File;
import java.io.IOException;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Handler;
import java.util.logging.Level;
-import java.util.logging.Logger;
import jenkins.MasterToSlaveFileCallable;
import static org.junit.Assert.*;
import org.junit.Assume;
-import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
+import org.jvnet.hudson.test.LoggerRule;
import org.jvnet.hudson.test.MockFolder;
import org.jvnet.hudson.test.WithoutJenkins;
@@ -54,13 +51,7 @@ public class WorkspaceCleanupThreadTest {
@Rule public JenkinsRule r = new JenkinsRule();
- private static final Logger logger = Logger.getLogger(WorkspaceCleanupThread.class.getName());
- @BeforeClass public static void logging() {
- logger.setLevel(Level.ALL);
- Handler handler = new ConsoleHandler();
- handler.setLevel(Level.ALL);
- logger.addHandler(handler);
- }
+ @Rule public LoggerRule logs = new LoggerRule().record(WorkspaceCleanupThread.class, Level.ALL);
@Test public void cleanUpSlaves() throws Exception {
FreeStyleProject p = r.createFreeStyleProject();
diff --git a/test/src/test/java/hudson/slaves/NodePropertyTest.java b/test/src/test/java/hudson/slaves/NodePropertyTest.java
index 58985cd5bf..0810a40bcd 100644
--- a/test/src/test/java/hudson/slaves/NodePropertyTest.java
+++ b/test/src/test/java/hudson/slaves/NodePropertyTest.java
@@ -12,15 +12,12 @@ import com.gargoylesoftware.htmlunit.html.HtmlLabel;
import hudson.model.Descriptor;
import hudson.model.Descriptor.FormException;
import hudson.model.Slave;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Handler;
import java.util.logging.Level;
-import java.util.logging.Logger;
import net.sf.json.JSONObject;
-import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
+import org.jvnet.hudson.test.LoggerRule;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
@@ -30,20 +27,15 @@ import org.kohsuke.stapler.StaplerRequest;
*/
public class NodePropertyTest {
- private static final Logger logger = Logger.getLogger(Descriptor.class.getName());
- @BeforeClass
- public static void logging() {
- logger.setLevel(Level.ALL);
- Handler handler = new ConsoleHandler();
- handler.setLevel(Level.ALL);
- logger.addHandler(handler);
- }
-
@Rule
public JenkinsRule j = new JenkinsRule();
+ @Rule
+ public LoggerRule logs = new LoggerRule();
+
@Test
public void invisibleProperty() throws Exception {
+ logs.record(Descriptor.class, Level.ALL);
DumbSlave s = j.createSlave();
InvisibleProperty before = new InvisibleProperty();
s.getNodeProperties().add(before);
diff --git a/test/src/test/java/jenkins/model/StartupTest.java b/test/src/test/java/jenkins/model/StartupTest.java
index 3877813f73..2f488ce44b 100644
--- a/test/src/test/java/jenkins/model/StartupTest.java
+++ b/test/src/test/java/jenkins/model/StartupTest.java
@@ -23,50 +23,26 @@
*/
package jenkins.model;
-import hudson.util.RingBufferLogHandler;
-import java.util.ArrayList;
import java.util.Collections;
-import java.util.List;
-import java.util.logging.Formatter;
import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.logging.Logger;
-import java.util.logging.SimpleFormatter;
import org.junit.Test;
import static org.junit.Assert.*;
-import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Rule;
import org.jvnet.hudson.test.JenkinsRule;
+import org.jvnet.hudson.test.LoggerRule;
public class StartupTest {
- private static final Logger logger = Logger.getLogger("");
-
- private static final RingBufferLogHandler handler = new RingBufferLogHandler() {
- @Override
- public synchronized void publish(LogRecord record) {
- if (record.getLevel().intValue() >= Level.WARNING.intValue()) {
- super.publish(record);
- }
- }
- };
-
- @BeforeClass
- public static void logging() {
- logger.addHandler(handler);
- }
+ @ClassRule
+ public static LoggerRule logs = new LoggerRule().record("", Level.WARNING);
@Rule
public JenkinsRule r = new JenkinsRule();
@Test
public void noWarnings() throws Exception {
- Formatter f = new SimpleFormatter();
- List warnings = new ArrayList<>();
- for (LogRecord lr : handler.getView()) {
- warnings.add(f.format(lr).trim());
- }
- assertEquals(Collections.emptyList(), warnings);
+ assertEquals(Collections.emptyList(), logs.getRecordsFormatted());
}
}
diff --git a/test/src/test/java/jenkins/security/ApiTokenPropertyTest.java b/test/src/test/java/jenkins/security/ApiTokenPropertyTest.java
index a34038206c..091e8821f7 100644
--- a/test/src/test/java/jenkins/security/ApiTokenPropertyTest.java
+++ b/test/src/test/java/jenkins/security/ApiTokenPropertyTest.java
@@ -15,27 +15,27 @@ import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import com.gargoylesoftware.htmlunit.util.UrlUtils;
+import hidden.jth.org.apache.http.Header;
+import hidden.jth.org.apache.http.HttpEntity;
+import hidden.jth.org.apache.http.HttpHost;
+import hidden.jth.org.apache.http.auth.AuthScheme;
+import hidden.jth.org.apache.http.auth.AuthScope;
+import hidden.jth.org.apache.http.auth.Credentials;
+import hidden.jth.org.apache.http.auth.UsernamePasswordCredentials;
+import hidden.jth.org.apache.http.client.AuthCache;
+import hidden.jth.org.apache.http.client.CredentialsProvider;
+import hidden.jth.org.apache.http.client.methods.CloseableHttpResponse;
+import hidden.jth.org.apache.http.client.methods.HttpGet;
+import hidden.jth.org.apache.http.client.protocol.HttpClientContext;
+import hidden.jth.org.apache.http.impl.auth.BasicScheme;
+import hidden.jth.org.apache.http.impl.client.BasicAuthCache;
+import hidden.jth.org.apache.http.impl.client.BasicCredentialsProvider;
+import hidden.jth.org.apache.http.impl.client.CloseableHttpClient;
+import hidden.jth.org.apache.http.impl.client.HttpClientBuilder;
import hudson.Util;
import hudson.model.User;
import hudson.security.ACL;
import jenkins.model.Jenkins;
-import org.apache.http.Header;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpHost;
-import org.apache.http.auth.AuthScheme;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.Credentials;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.AuthCache;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.impl.auth.BasicScheme;
-import org.apache.http.impl.client.BasicAuthCache;
-import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;