Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Java 17 and 2.475; adapt test suite to EE 9 #182

Merged
merged 2 commits into from
Oct 23, 2024
Merged
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
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
buildPlugin(useContainerAgent: true, configurations: [
[ platform: 'linux', jdk: '11' ],
])
[ platform: 'linux', jdk: '17' ],
])
17 changes: 12 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
<properties>
<revision>2.5.3</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.375.3</jenkins.version>
<jenkins.version>2.475</jenkins.version>
<!-- TODO JENKINS-73339 until in parent POM -->
<jenkins-test-harness.version>2254.vcff7a_d4969e5</jenkins-test-harness.version>
<maven.compiler.release>17</maven.compiler.release>
<checkstyle.version>3.1.1</checkstyle.version>
<no-test-jar>false</no-test-jar>
</properties>
Expand Down Expand Up @@ -210,7 +213,6 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>parameterized-trigger</artifactId>
<scope>test</scope>
<version>2.45</version>
<optional>true</optional>
</dependency>
<dependency>
Expand Down Expand Up @@ -277,18 +279,23 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>metrics</artifactId>
<version>4.2.18-439.v86a_20b_a_8318b_</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.375.x</artifactId>
<version>2179.v0884e842b_859</version>
<artifactId>bom-2.462.x</artifactId>
<version>3234.v5ca_5154341ef</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<!-- TODO JENKINS-73339 until in parent POM, work around https://github.com/jenkinsci/plugin-pom/issues/936 -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
import jenkins.model.Jenkins;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;
import org.kohsuke.stapler.verb.POST;
import java.io.IOException;

Expand All @@ -65,7 +65,7 @@ public class CauseManagement implements RootAction {
public static final String URL_NAME = "failure-cause-management";
/**
* The reserved id for getting a new {@link FailureCause} from {@link #getDynamic(String,
* org.kohsuke.stapler.StaplerRequest, org.kohsuke.stapler.StaplerResponse)}.
* org.kohsuke.stapler.StaplerRequest2, org.kohsuke.stapler.StaplerResponse2)}.
*/
public static final String NEW_CAUSE_DYNAMIC_ID = "new";
/**
Expand Down Expand Up @@ -167,11 +167,11 @@ public Iterable<FailureCause> getShallowCauses() throws Exception {
* Sets an error message as an attribute to the current request.
*
* @param message the message to set.
* @see #getErrorMessage(org.kohsuke.stapler.StaplerRequest)
* @see #getErrorMessage(org.kohsuke.stapler.StaplerRequest2)
* @see #REQUEST_CAUSE_MANAGEMENT_ERROR
*/
private void setErrorMessage(String message) {
Stapler.getCurrentRequest().setAttribute(REQUEST_CAUSE_MANAGEMENT_ERROR, message);
Stapler.getCurrentRequest2().setAttribute(REQUEST_CAUSE_MANAGEMENT_ERROR, message);
}

/**
Expand All @@ -180,7 +180,7 @@ private void setErrorMessage(String message) {
* @param request the request where the message might be.
* @return true if there is an error message to display.
*/
public boolean isError(StaplerRequest request) {
public boolean isError(StaplerRequest2 request) {
return Util.fixEmpty((String)request.getAttribute(REQUEST_CAUSE_MANAGEMENT_ERROR)) != null;
}

Expand All @@ -190,7 +190,7 @@ public boolean isError(StaplerRequest request) {
* @param request the request where the message might be.
* @return the error message to show.
*/
public String getErrorMessage(StaplerRequest request) {
public String getErrorMessage(StaplerRequest2 request) {
return (String)request.getAttribute(REQUEST_CAUSE_MANAGEMENT_ERROR);
}

Expand All @@ -205,7 +205,7 @@ public String getErrorMessage(StaplerRequest request) {
*
* @throws Exception if communication with the knowledge base failed.
*/
public FailureCause getDynamic(String id, StaplerRequest request, StaplerResponse response) throws Exception {
public FailureCause getDynamic(String id, StaplerRequest2 request, StaplerResponse2 response) throws Exception {
if (NEW_CAUSE_DYNAMIC_ID.equalsIgnoreCase(id)) {
return new FailureCause(NEW_CAUSE_NAME, NEW_CAUSE_DESCRIPTION);
} else {
Expand All @@ -222,7 +222,7 @@ public FailureCause getDynamic(String id, StaplerRequest request, StaplerRespons
* @throws IOException if so during redirect.
*/
@POST
public void doRemoveConfirm(@QueryParameter String id, StaplerRequest request, StaplerResponse response)
public void doRemoveConfirm(@QueryParameter String id, StaplerRequest2 request, StaplerResponse2 response)
throws IOException {
Jenkins.getInstance().checkPermission(PluginImpl.REMOVE_PERMISSION);
id = Util.fixEmpty(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;
import org.kohsuke.stapler.interceptor.RequirePOST;
import org.mongojack.Id;
import org.mongojack.ObjectId;
Expand Down Expand Up @@ -245,7 +245,7 @@ public FormValidation doCheckName(@QueryParameter final String value) {
* @param response the response
* @throws Exception if it fails to save to the knowledge base or a validation error occurs.
*/
public synchronized void doConfigSubmit(StaplerRequest request, StaplerResponse response)
public synchronized void doConfigSubmit(StaplerRequest2 request, StaplerResponse2 response)
throws Exception {
logger.entering(getClass().getName(), "doConfigSubmit");
Jenkins.getInstance().checkPermission(PluginImpl.UPDATE_PERMISSION);
Expand Down Expand Up @@ -560,14 +560,14 @@ public List<Indication> getIndications() {
//CS IGNORE JavadocMethod FOR NEXT 8 LINES. REASON: The exception can be thrown.

/**
* Finds the {@link CauseManagement} ancestor of the {@link Stapler#getCurrentRequest() current request}.
* Finds the {@link CauseManagement} ancestor of the {@link Stapler#getCurrentRequest2() current request}.
*
* @return the management action or a derivative of it, or null if no management action is found.
* @throws IllegalStateException if no ancestor is found.
*/
@JsonIgnore
public CauseManagement getAncestorCauseManagement() {
StaplerRequest currentRequest = Stapler.getCurrentRequest();
StaplerRequest2 currentRequest = Stapler.getCurrentRequest2();
if (currentRequest == null) {
return null;
}
Expand Down Expand Up @@ -620,7 +620,7 @@ public static final class FailureCauseDescriptor extends Descriptor<FailureCause
* page was entered.
*/
public String getLastFailedBuildUrl() {
StaplerRequest staplerRequest = Stapler.getCurrentRequest();
StaplerRequest2 staplerRequest = Stapler.getCurrentRequest2();
if (staplerRequest != null) {
String answer = (String)staplerRequest.getSession(true).
getAttribute(LAST_FAILED_BUILD_URL_SESSION_ATTRIBUTE_NAME);
Expand All @@ -636,7 +636,7 @@ public String getLastFailedBuildUrl() {
* page was entered.
*/
public void setLastFailedBuildUrl() {
StaplerRequest staplerRequest = Stapler.getCurrentRequest();
StaplerRequest2 staplerRequest = Stapler.getCurrentRequest2();
if (staplerRequest != null) {
Job project = staplerRequest.findAncestorObject(Job.class);
if (project != null && project.getLastFailedBuild() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
import hudson.util.Secret;
import org.apache.commons.lang.StringUtils;
import org.jvnet.hudson.test.HudsonTestCase;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;

import javax.servlet.http.HttpSession;
import jakarta.servlet.http.HttpSession;
import java.text.DateFormat;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -308,8 +308,8 @@ private void verifyCorrectCauseEditPage(FailureCause expectedCause, HtmlPage edi
}

/**
* Tests {@link CauseManagement#doRemoveConfirm(String, org.kohsuke.stapler.StaplerRequest,
* org.kohsuke.stapler.StaplerResponse)}.
* Tests {@link CauseManagement#doRemoveConfirm(String, org.kohsuke.stapler.StaplerRequest2,
* org.kohsuke.stapler.StaplerResponse2)}.
* Assumes that the default {@link com.sonyericsson.jenkins.plugins.bfa.db.LocalFileKnowledgeBase} is used.
*
* @throws Exception if so.
Expand All @@ -325,10 +325,10 @@ public void testDoRemoveConfirm() throws Exception {
KnowledgeBase kb = spy(PluginImpl.getInstance().getKnowledgeBase());
Whitebox.setInternalState(PluginImpl.getInstance(), KnowledgeBase.class, kb);

StaplerRequest request = mock(StaplerRequest.class);
StaplerRequest2 request = mock(StaplerRequest2.class);
HttpSession session = mock(HttpSession.class);
when(request.getSession(anyBoolean())).thenReturn(session);
StaplerResponse response = mock(StaplerResponse.class);
StaplerResponse2 response = mock(StaplerResponse2.class);

CauseManagement.getInstance().doRemoveConfirm(cause1.getId(), request, response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;

import java.net.URL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
import org.jvnet.hudson.test.JenkinsRule;
import org.kohsuke.stapler.RequestImpl;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.WebApp;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -104,11 +104,11 @@ public void testBooleanConfigPersistence() throws Exception {
MongoDBKnowledgeBase mongoKB = new MongoDBKnowledgeBase("host", 27017, "dbname", "username",
Secret.fromString("password"), true, true);
instance.setKnowledgeBase(mongoKB);
// need an actual StaplerRequest implementation to test we're using bindJSON correctly
// need an actual StaplerRequest2 implementation to test we're using bindJSON correctly
WebApp webapp = new WebApp(mock(ServletContext.class));
Stapler stapler = mock(Stapler.class);
when(stapler.getWebApp()).thenReturn(webapp);
StaplerRequest sreq = new RequestImpl(stapler, mock(HttpServletRequest.class), Collections.emptyList(), null);
StaplerRequest2 sreq = new RequestImpl(stapler, mock(HttpServletRequest.class), Collections.emptyList(), null);
// flip configuration of all boolean values
JSONObject form = new JSONObject();
form.put("globalEnabled", !instance.isGlobalEnabled());
Expand Down Expand Up @@ -157,7 +157,7 @@ public void testGetKnowledgeBaseDescriptors() throws Exception {
}

/**
* Tests {@link PluginImpl#configure(org.kohsuke.stapler.StaplerRequest, net.sf.json.JSONObject)}. with a new
* Tests {@link PluginImpl#configure(org.kohsuke.stapler.StaplerRequest2, net.sf.json.JSONObject)}. with a new
* KnowledgeBase type.
*
* @throws Exception if so.
Expand All @@ -169,7 +169,7 @@ public void testConfigureConvert() throws Exception {
FailureCause cause = new FailureCause("Olle", "Olle");
cause.addIndication(new BuildLogIndication(".*olle"));
cause = prevKnowledgeBase.addCause(cause);
StaplerRequest sreq = mock(StaplerRequest.class);
StaplerRequest2 sreq = mock(StaplerRequest2.class);
DifferentKnowledgeBase knowledgeBase = new DifferentKnowledgeBase("Hello");

JSONObject form = createForm("x", PluginImpl.DEFAULT_NR_OF_SCAN_THREADS, true);
Expand All @@ -191,7 +191,7 @@ public void testConfigureConvert() throws Exception {
}

/**
* Tests {@link PluginImpl#configure(org.kohsuke.stapler.StaplerRequest, net.sf.json.JSONObject)}. with the same
* Tests {@link PluginImpl#configure(org.kohsuke.stapler.StaplerRequest2, net.sf.json.JSONObject)}. with the same
* KnowledgeBase type but different configuration.
*
* @throws Exception if so.
Expand All @@ -204,7 +204,7 @@ public void testConfigureConvertSameType() throws Exception {
cause = prevKnowledgeBase.addCause(cause);
PluginImpl instance = PluginImpl.getInstance();
Whitebox.setInternalState(instance, KnowledgeBase.class, prevKnowledgeBase);
StaplerRequest sreq = mock(StaplerRequest.class);
StaplerRequest2 sreq = mock(StaplerRequest2.class);
DifferentKnowledgeBase knowledgeBase = new DifferentKnowledgeBase("Hello Again");
when(sreq.bindJSON(eq(KnowledgeBase.class), isA(JSONObject.class))).thenReturn(knowledgeBase);

Expand All @@ -228,7 +228,7 @@ public void testConfigureConvertSameType() throws Exception {
}

/**
* Tests {@link PluginImpl#configure(org.kohsuke.stapler.StaplerRequest, net.sf.json.JSONObject)}.
* Tests {@link PluginImpl#configure(org.kohsuke.stapler.StaplerRequest2, net.sf.json.JSONObject)}.
* Tests that a LocalFileKnowledgebase is preserved through a reconfigure without changes.
*
* @throws Exception if so.
Expand All @@ -254,7 +254,7 @@ public void testConfigureIdenticalLocalKB() throws Exception {
//CS IGNORE MagicNumber FOR NEXT 17 LINES. REASON: Random test data

/**
* Tests {@link PluginImpl#configure(org.kohsuke.stapler.StaplerRequest, net.sf.json.JSONObject)}.
* Tests {@link PluginImpl#configure(org.kohsuke.stapler.StaplerRequest2, net.sf.json.JSONObject)}.
* Tests that a MongoDBKnowledgebase is preserved through a reconfigure without changes.
*
* @throws Exception if so.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package com.sonyericsson.jenkins.plugins.bfa.model;

import org.htmlunit.NicelyResynchronizingAjaxController;
import org.htmlunit.WebClientUtil;
import org.htmlunit.WebResponse;
import org.htmlunit.WebResponseListener;
import org.htmlunit.html.HtmlInput;
Expand Down Expand Up @@ -67,8 +67,8 @@ public class FailureCauseHudsonTest {


/**
* Happy test for {@link FailureCause#doConfigSubmit(org.kohsuke.stapler.StaplerRequest,
* org.kohsuke.stapler.StaplerResponse)}.
* Happy test for {@link FailureCause#doConfigSubmit(org.kohsuke.stapler.StaplerRequest2,
* org.kohsuke.stapler.StaplerResponse2)}.
*
* @throws Exception if so.
*/
Expand Down Expand Up @@ -118,8 +118,8 @@ public void testDoConfigSubmit() throws Exception {
}

/**
* Happy test for {@link FailureCause#doConfigSubmit(org.kohsuke.stapler.StaplerRequest,
* org.kohsuke.stapler.StaplerResponse)} with only one cause configured.
* Happy test for {@link FailureCause#doConfigSubmit(org.kohsuke.stapler.StaplerRequest2,
* org.kohsuke.stapler.StaplerResponse2)} with only one cause configured.
*
* @throws Exception if so.
*/
Expand Down Expand Up @@ -157,7 +157,6 @@ public void testDoConfigSubmitOne() throws Exception {
@Test
public void testDoCheckNameViaWebForm() throws Exception {
JenkinsRule.WebClient client = jenkins.createWebClient();
client.setAjaxController(new NicelyResynchronizingAjaxController());

WebResponseListener.StatusListener serverErrors =
new WebResponseListener.StatusListener(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Expand All @@ -172,6 +171,7 @@ public void testDoCheckNameViaWebForm() throws Exception {
HtmlInput input = page.getFormByName("causeForm").getInputByName("_.name");
input.setValue("Mööp");
input.fireEvent("change");
WebClientUtil.waitForJSExec(page.getWebClient());

assertTrue(serverErrors.getResponses().isEmpty());
WebResponse webResponse = success.getResponses().get(success.getResponses().size() - 1);
Expand All @@ -189,7 +189,6 @@ public void testDoCheckNameViaWebForm() throws Exception {
@Test
public void testDoCheckDescriptionViaWebForm() throws Exception {
JenkinsRule.WebClient client = jenkins.createWebClient();
client.setAjaxController(new NicelyResynchronizingAjaxController());

WebResponseListener.StatusListener serverErrors =
new WebResponseListener.StatusListener(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Expand All @@ -204,6 +203,7 @@ public void testDoCheckDescriptionViaWebForm() throws Exception {
HtmlTextArea input = page.getFormByName("causeForm").getTextAreaByName("_.description");
input.setText("Mööp");
input.fireEvent("change");
WebClientUtil.waitForJSExec(page.getWebClient());

assertTrue(serverErrors.getResponses().isEmpty());
WebResponse webResponse = success.getResponses().get(success.getResponses().size() - 1);
Expand Down
Loading