diff --git a/Jenkinsfile b/Jenkinsfile
index 77c9ed7..cf3359f 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -1,4 +1,7 @@
#!/usr/bin/env groovy
/* `buildPlugin` step provided by: https://github.com/jenkins-infra/pipeline-library */
-buildPlugin()
+buildPlugin(useContainerAgent: true, configurations: [
+ [platform: 'linux', jdk: 21],
+ [platform: 'windows', jdk: 17]
+])
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index a001d20..5531b05 100755
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.jenkins-ci.plugins
plugin
- 4.40
+ 4.86
@@ -21,8 +21,11 @@
1.18
-SNAPSHOT
- 2.289.3
+ 2.472
jenkinsci/${project.artifactId}-plugin
+
+ 2250.v03a_1295b_0a_30
+ 17
@@ -55,8 +58,8 @@
io.jenkins.tools.bom
- bom-2.289.x
- 1362.v59f2f3db_80ee
+ bom-2.462.x
+ 3258.vcdcf15936a_fd
import
pom
@@ -66,9 +69,8 @@
- com.google.code.gson
- gson
- 2.9.0
+ io.jenkins.plugins
+ gson-api
org.jenkins-ci.plugins
@@ -126,13 +128,6 @@
org.mockito
mockito-core
- 4.8.0
- test
-
-
- org.mockito
- mockito-inline
- 4.8.0
test
diff --git a/src/main/java/com/tikal/hudson/plugins/notification/NotifyStep.java b/src/main/java/com/tikal/hudson/plugins/notification/NotifyStep.java
index 0214842..7fde269 100644
--- a/src/main/java/com/tikal/hudson/plugins/notification/NotifyStep.java
+++ b/src/main/java/com/tikal/hudson/plugins/notification/NotifyStep.java
@@ -5,7 +5,6 @@
import hudson.Util;
import hudson.model.Run;
import hudson.model.TaskListener;
-import org.eclipse.collections.impl.factory.Sets;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepContext;
@@ -123,8 +122,7 @@ public String getDisplayName() {
@Override
public Set extends Class>> getRequiredContext() {
- return Sets.immutable.of(FilePath.class, FlowNode.class, Run.class, TaskListener.class)
- .castToSet();
+ return Set.of(FilePath.class, FlowNode.class, Run.class, TaskListener.class);
}
}
}
diff --git a/src/test/java/com/tikal/hudson/plugins/notification/PhaseTest.java b/src/test/java/com/tikal/hudson/plugins/notification/PhaseTest.java
index 37412d0..f8fc751 100644
--- a/src/test/java/com/tikal/hudson/plugins/notification/PhaseTest.java
+++ b/src/test/java/com/tikal/hudson/plugins/notification/PhaseTest.java
@@ -38,10 +38,6 @@ public class PhaseTest {
@Mock
private EnvVars environment;
@Mock
- private Protocol protocol;
- @Mock
- private Format format;
- @Mock
private PrintStream logger;
@Mock
private Jenkins jenkins;
@@ -163,6 +159,16 @@ public void testRunPreviousRunUrlTypePublic() throws IOException, InterruptedExc
jenkinsMockedStatic.when(Jenkins::getInstanceOrNull).thenReturn(jenkins);
jenkinsMockedStatic.when(Jenkins::getInstance).thenReturn(jenkins);
+ Protocol httpProtocolSpy = spy(Protocol.HTTP);
+ when(endpoint.getProtocol()).thenReturn(httpProtocolSpy);
+ doNothing().when(httpProtocolSpy).send(anyString(), any(byte[].class), anyInt(), anyBoolean());
+
+ Format jsonFormatSpy = spy(Format.JSON);
+ JobState jobState = new JobState();
+ when(endpoint.getFormat()).thenReturn(jsonFormatSpy);
+ doReturn(data).when(jsonFormatSpy).serialize(isA(JobState.class));
+ assertEquals(data, jsonFormatSpy.serialize(jobState));
+
when(run.getParent()).thenReturn(job);
when(job.getProperty(HudsonNotificationProperty.class)).thenReturn(property);
when(property.getEndpoints()).thenReturn(asList(endpoint));
@@ -175,15 +181,12 @@ public void testRunPreviousRunUrlTypePublic() throws IOException, InterruptedExc
when(environment.containsKey("BRANCH_NAME")).thenReturn(true);
when(environment.get("BRANCH_NAME")).thenReturn("branchName");
when(listener.getLogger()).thenReturn(logger);
- when(endpoint.getProtocol()).thenReturn(protocol);
when(endpoint.getTimeout()).thenReturn(42);
- when(endpoint.getFormat()).thenReturn(format);
- when(format.serialize(isA(JobState.class))).thenReturn(data);
Phase.STARTED.handle(run, listener, 1L);
verify(logger).printf("Notifying endpoint with %s%n", "url 'expandedUrl'");
- verify(protocol).send("expandedUrl", data, 42, false);
+ verify(httpProtocolSpy).send("expandedUrl", data, 42, false);
verify(run).getPreviousCompletedBuild();
}
}
@@ -197,6 +200,16 @@ public void testRunPreviousRunUrlTypeSecret() throws IOException, InterruptedExc
jenkinsMockedStatic.when(Jenkins::getInstance).thenReturn(jenkins);
utilsMockedStatic.when(() -> Utils.getSecretUrl("credentialsId", jenkins)).thenReturn("$secretUrl");
+ Protocol httpProtocolSpy = spy(Protocol.HTTP);
+ when(endpoint.getProtocol()).thenReturn(httpProtocolSpy);
+ doNothing().when(httpProtocolSpy).send(anyString(), any(byte[].class), anyInt(), anyBoolean());
+
+ Format jsonFormatSpy = spy(Format.JSON);
+ JobState jobState = new JobState();
+ when(endpoint.getFormat()).thenReturn(jsonFormatSpy);
+ doReturn(data).when(jsonFormatSpy).serialize(isA(JobState.class));
+ assertEquals(data, jsonFormatSpy.serialize(jobState));
+
when(run.getParent()).thenReturn(job);
when(job.getProperty(HudsonNotificationProperty.class)).thenReturn(property);
when(property.getEndpoints()).thenReturn(asList(endpoint));
@@ -208,15 +221,12 @@ public void testRunPreviousRunUrlTypeSecret() throws IOException, InterruptedExc
when(urlInfo.getUrlType()).thenReturn(SECRET);
when(environment.expand("$secretUrl")).thenReturn("secretUrl");
when(listener.getLogger()).thenReturn(logger);
- when(endpoint.getProtocol()).thenReturn(protocol);
when(endpoint.getTimeout()).thenReturn(42);
- when(endpoint.getFormat()).thenReturn(format);
- when(format.serialize(isA(JobState.class))).thenReturn(data);
Phase.STARTED.handle(run, listener, 1L);
verify(logger).printf( "Notifying endpoint with %s%n","credentials id 'credentialsId'");
- verify(protocol).send("secretUrl", data, 42, false);
+ verify(httpProtocolSpy).send("secretUrl", data, 42, false);
verify(run).getPreviousCompletedBuild();
}
}
diff --git a/src/test/java/com/tikal/hudson/plugins/notification/ProtocolTest.java b/src/test/java/com/tikal/hudson/plugins/notification/ProtocolTest.java
index 0d5805b..bff0ef7 100644
--- a/src/test/java/com/tikal/hudson/plugins/notification/ProtocolTest.java
+++ b/src/test/java/com/tikal/hudson/plugins/notification/ProtocolTest.java
@@ -23,14 +23,15 @@
*/
package com.tikal.hudson.plugins.notification;
+import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.io.CharStreams;
import junit.framework.TestCase;
+import org.eclipse.jetty.ee8.servlet.ServletContextHandler;
+import org.eclipse.jetty.ee8.servlet.ServletHolder;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.servlet.ServletHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
@@ -92,7 +93,7 @@ public boolean equals(Object obj) {
@Override
public String toString() {
- return Objects.toStringHelper(this)
+ return MoreObjects.toStringHelper(this)
.add("url", url)
.add("method", method)
.add("body", body)
@@ -170,9 +171,10 @@ private UrlFactory startSecureServer(Servlet servlet, String path, String author
ServerConnector connector = new ServerConnector(server);
server.setConnectors(new Connector[] {connector});
- ServletHandler servletHandler = new ServletHandler();
- server.setHandler(servletHandler);
- servletHandler.addServletWithMapping(new ServletHolder(servlet), path);
+ ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
+ context.setContextPath("/");
+ context.addServlet(new ServletHolder(servlet), path);
+ server.setHandler(context);
server.start();
servers.add(server);