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
19 changes: 6 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>A business-friendly OSS license</comments>
</license>
Expand All @@ -31,27 +31,27 @@
<name>Mark Berner</name>
<email>markb@tikalk.com</email>
<organization>Tikal Knowledge</organization>
<organizationUrl>http://tikalk.com</organizationUrl>
<organizationUrl>https://tikalk.com</organizationUrl>
</developer>
<developer>
<id>hagzag</id>
<name>Haggai Philip Zagury</name>
<email>hagzag@tikalk.com</email>
<organization>Tikal Knowledge</organization>
<organizationUrl>http://tikalk.com</organizationUrl>
<organizationUrl>https://tikalk.com</organizationUrl>
</developer>
<developer>
<id>evgenyg</id>
<name>Evgeny Goldin</name>
<email>evgenyg@gmail.com</email>
<organization>AKQA</organization>
<organizationUrl>http://akqa.com</organizationUrl>
<organizationUrl>https://akqa.com</organizationUrl>
</developer>
<developer>
<id>cohencil</id>
<name>Chen Cohen</name>
<email>chenc@tikalk.com</email>
<organizationUrl>http://tikalk.com</organizationUrl>
<organizationUrl>https://tikalk.com</organizationUrl>
</developer>
</developers>

Expand Down Expand Up @@ -109,7 +109,6 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>s3</artifactId>
<version>496.v320cdd5a_1f65</version>
<optional>true</optional>
<exclusions>
<exclusion>
Expand All @@ -135,15 +134,9 @@
<artifactId>token-macro</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>1.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
108 changes: 54 additions & 54 deletions src/test/java/com/tikal/hudson/plugins/notification/PhaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static com.tikal.hudson.plugins.notification.UrlType.PUBLIC;
import static com.tikal.hudson.plugins.notification.UrlType.SECRET;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyInt;
Expand All @@ -27,14 +27,14 @@
import java.lang.reflect.Method;
import java.util.List;
import jenkins.model.Jenkins;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

@RunWith(MockitoJUnitRunner.class)
public class PhaseTest {
@ExtendWith(MockitoExtension.class)
class PhaseTest {
@Mock
private Run run;

Expand Down Expand Up @@ -63,115 +63,115 @@ public class PhaseTest {
private Jenkins jenkins;

@Test
public void testIsRun() throws ReflectiveOperationException {
void testIsRun() throws ReflectiveOperationException {
Endpoint endPoint = new Endpoint(null);
Method isRunMethod = Phase.class.getDeclaredMethod("isRun", Endpoint.class, Result.class, Result.class);
isRunMethod.setAccessible(true);

assertEquals(
"returns true for null endpoint event",
Boolean.TRUE,
isRunMethod.invoke(Phase.QUEUED, endPoint, null, null),
Boolean.TRUE);
"returns true for null endpoint event");

endPoint.setEvent("all");
for (Phase phaseValue : Phase.values()) {
assertEquals(
"all Event returns true for Phase " + phaseValue.toString(),
Boolean.TRUE,
isRunMethod.invoke(phaseValue, endPoint, null, null),
Boolean.TRUE);
"all Event returns true for Phase " + phaseValue.toString());
}

endPoint.setEvent("queued");
assertEquals(
"queued Event returns true for Phase Queued",
Boolean.TRUE,
isRunMethod.invoke(Phase.QUEUED, endPoint, null, null),
Boolean.TRUE);
"queued Event returns true for Phase Queued");
assertEquals(
"queued Event returns false for Phase Started",
Boolean.FALSE,
isRunMethod.invoke(Phase.STARTED, endPoint, null, null),
Boolean.FALSE);
"queued Event returns false for Phase Started");

endPoint.setEvent("started");
assertEquals(
"started Event returns true for Phase Started",
Boolean.TRUE,
isRunMethod.invoke(Phase.STARTED, endPoint, null, null),
Boolean.TRUE);
"started Event returns true for Phase Started");
assertEquals(
"started Event returns false for Phase Completed",
Boolean.FALSE,
isRunMethod.invoke(Phase.COMPLETED, endPoint, null, null),
Boolean.FALSE);
"started Event returns false for Phase Completed");

endPoint.setEvent("completed");
assertEquals(
"completed Event returns true for Phase Completed",
Boolean.TRUE,
isRunMethod.invoke(Phase.COMPLETED, endPoint, null, null),
Boolean.TRUE);
"completed Event returns true for Phase Completed");
assertEquals(
"completed Event returns false for Phase Finalized",
Boolean.FALSE,
isRunMethod.invoke(Phase.FINALIZED, endPoint, null, null),
Boolean.FALSE);
"completed Event returns false for Phase Finalized");

endPoint.setEvent("finalized");
assertEquals(
"finalized Event returns true for Phase Finalized",
Boolean.TRUE,
isRunMethod.invoke(Phase.FINALIZED, endPoint, null, null),
Boolean.TRUE);
"finalized Event returns true for Phase Finalized");
assertEquals(
"finalized Event returns true for Phase Queued",
Boolean.FALSE,
isRunMethod.invoke(Phase.QUEUED, endPoint, null, null),
Boolean.FALSE);
"finalized Event returns true for Phase Queued");

endPoint.setEvent("failed");
assertEquals(
"failed Event returns false for Phase Finalized and no status",
Boolean.FALSE,
isRunMethod.invoke(Phase.FINALIZED, endPoint, null, null),
Boolean.FALSE);
"failed Event returns false for Phase Finalized and no status");
assertEquals(
"failed Event returns false for Phase Finalized and success status",
Boolean.FALSE,
isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.SUCCESS, null),
Boolean.FALSE);
"failed Event returns false for Phase Finalized and success status");
assertEquals(
"failed Event returns true for Phase Finalized and success failure",
Boolean.TRUE,
isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.FAILURE, null),
Boolean.TRUE);
"failed Event returns true for Phase Finalized and success failure");
assertEquals(
"failed Event returns false for Phase not Finalized and success failure",
Boolean.FALSE,
isRunMethod.invoke(Phase.COMPLETED, endPoint, Result.FAILURE, null),
Boolean.FALSE);
"failed Event returns false for Phase not Finalized and success failure");

endPoint.setEvent("failedAndFirstSuccess");
assertEquals(
"failedAndFirstSuccess Event returns false for Phase Finalized and no status",
Boolean.FALSE,
isRunMethod.invoke(Phase.FINALIZED, endPoint, null, null),
Boolean.FALSE);
"failedAndFirstSuccess Event returns false for Phase Finalized and no status");
assertEquals(
"failedAndFirstSuccess Event returns false for Phase Finalized and no previous status",
Boolean.FALSE,
isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.SUCCESS, null),
Boolean.FALSE);
"failedAndFirstSuccess Event returns false for Phase Finalized and no previous status");
assertEquals(
"failedAndFirstSuccess Event returns true for Phase Finalized and no previous status and failed status",
Boolean.TRUE,
isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.FAILURE, null),
Boolean.TRUE);
"failedAndFirstSuccess Event returns true for Phase Finalized and no previous status and failed status");
assertEquals(
"failedAndFirstSuccess Event returns true for Phase Finalized and failed status",
Boolean.TRUE,
isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.FAILURE, Result.FAILURE),
Boolean.TRUE);
"failedAndFirstSuccess Event returns true for Phase Finalized and failed status");
assertEquals(
"failedAndFirstSuccess Event returns true for Phase Finalized and success status with previous status of failure",
Boolean.TRUE,
isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.SUCCESS, Result.FAILURE),
Boolean.TRUE);
"failedAndFirstSuccess Event returns true for Phase Finalized and success status with previous status of failure");
assertEquals(
"failedAndFirstSuccess Event returns false for Phase Finalized and success status with previous status of success",
Boolean.FALSE,
isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.SUCCESS, Result.SUCCESS),
Boolean.FALSE);
"failedAndFirstSuccess Event returns false for Phase Finalized and success status with previous status of success");
assertEquals(
"failedAndFirstSuccess Event returns false for Phase not Finalized",
Boolean.FALSE,
isRunMethod.invoke(Phase.COMPLETED, endPoint, Result.SUCCESS, Result.FAILURE),
Boolean.FALSE);
"failedAndFirstSuccess Event returns false for Phase not Finalized");
}

@Test
public void testRunNoProperty() {
void testRunNoProperty() {
when(run.getParent()).thenReturn(job);

Phase.STARTED.handle(run, listener, 0L);
Expand All @@ -181,7 +181,7 @@ public void testRunNoProperty() {
}

@Test
public void testRunNoPreviousRunUrlNull() {
void testRunNoPreviousRunUrlNull() {
when(run.getParent()).thenReturn(job);
when(job.getProperty(HudsonNotificationProperty.class)).thenReturn(property);
when(property.getEndpoints()).thenReturn(List.of(endpoint));
Expand All @@ -194,7 +194,7 @@ public void testRunNoPreviousRunUrlNull() {
}

@Test
public void testRunNoPreviousRunUrlTypePublicUnresolvedUrl() throws IOException, InterruptedException {
void testRunNoPreviousRunUrlTypePublicUnresolvedUrl() throws IOException, InterruptedException {
when(run.getParent()).thenReturn(job);
when(job.getProperty(HudsonNotificationProperty.class)).thenReturn(property);
when(property.getEndpoints()).thenReturn(List.of(endpoint));
Expand All @@ -212,7 +212,7 @@ public void testRunNoPreviousRunUrlTypePublicUnresolvedUrl() throws IOException,
}

@Test
public void testRunPreviousRunUrlTypePublic() throws IOException, InterruptedException {
void testRunPreviousRunUrlTypePublic() throws IOException, InterruptedException {
byte[] data = "data".getBytes();
try (MockedStatic<Jenkins> jenkinsMockedStatic = mockStatic(Jenkins.class)) {
jenkinsMockedStatic.when(Jenkins::getInstanceOrNull).thenReturn(jenkins);
Expand Down Expand Up @@ -251,7 +251,7 @@ public void testRunPreviousRunUrlTypePublic() throws IOException, InterruptedExc
}

@Test
public void testRunPreviousRunUrlTypeSecret() throws IOException, InterruptedException {
void testRunPreviousRunUrlTypeSecret() throws IOException, InterruptedException {
byte[] data = "data".getBytes();
try (MockedStatic<Jenkins> jenkinsMockedStatic = mockStatic(Jenkins.class);
MockedStatic<Utils> utilsMockedStatic = mockStatic(Utils.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
*/
package com.tikal.hudson.plugins.notification;

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

import com.google.common.base.MoreObjects;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
Expand All @@ -40,12 +43,14 @@
import java.util.Objects;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import junit.framework.TestCase;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* @author Kohsuke Kawaguchi
*/
public class ProtocolTest extends TestCase {
class ProtocolTest {

static class Request {
private final String url;
Expand Down Expand Up @@ -79,10 +84,9 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Request)) {
if (!(obj instanceof Request other)) {
return false;
}
Request other = (Request) obj;
return Objects.equals(url, other.url)
&& Objects.equals(method, other.method)
&& Objects.equals(body, other.body);
Expand Down Expand Up @@ -191,19 +195,20 @@ public String getUrl(String path) {
};
}

@Override
public void setUp() {
@BeforeEach
void setUp() {
servers = new LinkedList<>();
}

@Override
public void tearDown() {
@AfterEach
void tearDown() {
for (HttpServer server : servers) {
server.stop(1);
}
}

public void testHttpPost() throws Exception {
@Test
void testHttpPost() throws Exception {
BlockingQueue<Request> requests = new LinkedBlockingQueue<>();

UrlFactory urlFactory = startServer(new RecordingServlet(requests), "/realpath");
Expand All @@ -217,7 +222,8 @@ public void testHttpPost() throws Exception {
assertTrue(requests.isEmpty());
}

public void testHttpPostWithBasicAuth() throws Exception {
@Test
void testHttpPostWithBasicAuth() throws Exception {
BlockingQueue<Request> requests = new LinkedBlockingQueue<>();

UrlFactory urlFactory = startSecureServer(new RecordingServlet(requests), "/realpath", "fred:foo");
Expand All @@ -232,7 +238,8 @@ public void testHttpPostWithBasicAuth() throws Exception {
assertEquals(new Request(uri, "POST", "Hello").getUrl(), theRequest.getUrlWithAuthority());
}

public void testHttpPostWithRedirects() throws Exception {
@Test
void testHttpPostWithRedirects() throws Exception {
BlockingQueue<Request> requests = new LinkedBlockingQueue<>();

UrlFactory urlFactory = startServer(new RecordingServlet(requests), "/realpath");
Expand Down
Loading