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

Use JUnit Jupiter for JerseyTest tests #2852

Closed
wants to merge 1 commit into from
Closed
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: 1 addition & 3 deletions config/checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<suppress files="implementations[\\/].+" id="SLF4JIllegalImportCheck" />
<suppress files="samples[\\/].+" checks="IllegalImport" />
<suppress files="test[\\/]java[\\/]io[\\/]micrometer[\\/]jersey.+" checks="IllegalImport" />
<suppress files="test[\\/]java[\\/]io[\\/]micrometer[\\/]core[\\/]instrument[\\/]binder[\\/]jersey[\\/]server.+" checks="(IllegalImport|SpringJUnit5)" />
<suppress files="test[\\/]java[\\/]io[\\/]micrometer[\\/]core[\\/]instrument[\\/]binder[\\/]jersey[\\/]server.+" checks="(IllegalImport)" />
<suppress files="LogbackMetricsAutoConfiguration" checks="IllegalImport" />
<suppress files="io[\\/]micrometer[\\/]jersey2[\\/]server[\\/].+" checks="SpringJUnit5" />
<suppress files="io[\\/]micrometer[\\/]samples[\\/]jersey3[\\/].+" checks="SpringJUnit5" />
</suppressions>
2 changes: 0 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def VERSIONS = [
'javax.cache:cache-api:latest.release',
'javax.inject:javax.inject:1',
'javax.xml.bind:jaxb-api:2.3.+',
'junit:junit:4.12',
'net.sf.ehcache:ehcache:latest.release',
'org.apache.httpcomponents:httpasyncclient:latest.release',
'org.apache.httpcomponents:httpclient:latest.release',
Expand All @@ -65,7 +64,6 @@ def VERSIONS = [
'org.jsr107.ri:cache-ri-impl:1.0.0',
'org.junit.jupiter:junit-jupiter:5.8.+',
'org.junit.platform:junit-platform-launcher:1.8.+',
'org.junit.vintage:junit-vintage-engine:5.8.+',
'org.latencyutils:LatencyUtils:latest.release',
'org.mockito:mockito-core:latest.release',
'org.mockito:mockito-inline:latest.release',
Expand Down
3 changes: 0 additions & 3 deletions micrometer-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ dependencies {

// JUnit 5
testImplementation 'org.junit.jupiter:junit-jupiter'
// See https://github.com/eclipse-ee4j/jersey/issues/3662
testImplementation 'junit:junit'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
testImplementation 'com.tngtech.archunit:archunit-junit5'

// Eclipse still needs this (as of 4.7.1a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.glassfish.jersey.server.monitoring.RequestEvent;
import org.glassfish.jersey.server.monitoring.RequestEvent.Type;
import org.glassfish.jersey.uri.UriTemplate;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import javax.ws.rs.NotAcceptableException;
import java.net.URI;
Expand All @@ -44,36 +44,36 @@
* @author Michael Weirauch
* @author Johnny Lim
*/
public class DefaultJerseyTagsProviderTest {
class DefaultJerseyTagsProviderTest {

private final DefaultJerseyTagsProvider tagsProvider = new DefaultJerseyTagsProvider();

@Test
public void testRootPath() {
void testRootPath() {
assertThat(tagsProvider.httpRequestTags(event(200, null, "/", (String[]) null)))
.containsExactlyInAnyOrder(tagsFrom("root", 200, null, "SUCCESS"));
}

@Test
public void templatedPathsAreReturned() {
void templatedPathsAreReturned() {
assertThat(tagsProvider.httpRequestTags(event(200, null, "/", "/", "/hello/{name}")))
.containsExactlyInAnyOrder(tagsFrom("/hello/{name}", 200, null, "SUCCESS"));
}

@Test
public void applicationPathIsPresent() {
void applicationPathIsPresent() {
assertThat(tagsProvider.httpRequestTags(event(200, null, "/app", "/", "/hello")))
.containsExactlyInAnyOrder(tagsFrom("/app/hello", 200, null, "SUCCESS"));
}

@Test
public void notFoundsAreShunted() {
void notFoundsAreShunted() {
assertThat(tagsProvider.httpRequestTags(event(404, null, "/app", "/", "/not-found")))
.containsExactlyInAnyOrder(tagsFrom("NOT_FOUND", 404, null, "CLIENT_ERROR"));
}

@Test
public void redirectsAreShunted() {
void redirectsAreShunted() {
assertThat(tagsProvider.httpRequestTags(event(301, null, "/app", "/", "/redirect301")))
.containsExactlyInAnyOrder(tagsFrom("REDIRECTION", 301, null, "REDIRECTION"));
assertThat(tagsProvider.httpRequestTags(event(302, null, "/app", "/", "/redirect302")))
Expand All @@ -84,7 +84,7 @@ public void redirectsAreShunted() {

@Test
@SuppressWarnings("serial")
public void exceptionsAreMappedCorrectly() {
void exceptionsAreMappedCorrectly() {
assertThat(tagsProvider.httpRequestTags(
event(500, new IllegalArgumentException(), "/app", (String[]) null)))
.containsExactlyInAnyOrder(tagsFrom("/app", 500, "IllegalArgumentException", "SERVER_ERROR"));
Expand All @@ -100,7 +100,7 @@ public void exceptionsAreMappedCorrectly() {
}

@Test
public void longRequestTags() {
void longRequestTags() {
assertThat(tagsProvider.httpLongRequestTags(event(0, null, "/app", (String[]) null)))
.containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/app"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Application;
Expand All @@ -38,7 +38,7 @@
* @author Michael Weirauch
* @author Johnny Lim
*/
public class MetricsRequestEventListenerTest extends JerseyTest {
class MetricsRequestEventListenerTest extends JerseyTest {

static {
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
Expand All @@ -64,7 +64,7 @@ protected Application configure() {
}

@Test
public void resourcesAreTimed() {
void resourcesAreTimed() {
target("/").request().get();
target("hello").request().get();
target("hello/").request().get();
Expand Down Expand Up @@ -92,7 +92,7 @@ public void resourcesAreTimed() {
}

@Test
public void notFoundIsAccumulatedUnderSameUri() {
void notFoundIsAccumulatedUnderSameUri() {
try {
target("not-found").request().get();
} catch (NotFoundException ignored) {
Expand All @@ -104,7 +104,7 @@ public void notFoundIsAccumulatedUnderSameUri() {
}

@Test
public void notFoundIsReportedWithUriOfMatchedResource() {
void notFoundIsReportedWithUriOfMatchedResource() {
try {
target("throws-not-found-exception").request().get();
} catch (NotFoundException ignored) {
Expand All @@ -116,7 +116,7 @@ public void notFoundIsReportedWithUriOfMatchedResource() {
}

@Test
public void redirectsAreAccumulatedUnderSameUri() {
void redirectsAreAccumulatedUnderSameUri() {
target("redirect/302").request().get();
target("redirect/307").request().get();

Expand All @@ -130,7 +130,7 @@ public void redirectsAreAccumulatedUnderSameUri() {
}

@Test
public void exceptionsAreMappedCorrectly() {
void exceptionsAreMappedCorrectly() {
try {
target("throws-exception").request().get();
} catch (Exception ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import javax.ws.rs.ProcessingException;
import javax.ws.rs.core.Application;
Expand All @@ -40,7 +40,7 @@
/**
* @author Michael Weirauch
*/
public class MetricsRequestEventListenerTimedTest extends JerseyTest {
class MetricsRequestEventListenerTimedTest extends JerseyTest {

static {
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
Expand Down Expand Up @@ -73,7 +73,7 @@ protected Application configure() {
}

@Test
public void resourcesAndNotFoundsAreNotAutoTimed() {
void resourcesAndNotFoundsAreNotAutoTimed() {
target("not-timed").request().get();
target("not-found").request().get();

Expand All @@ -85,7 +85,7 @@ public void resourcesAndNotFoundsAreNotAutoTimed() {
}

@Test
public void resourcesWithAnnotationAreTimed() {
void resourcesWithAnnotationAreTimed() {
target("timed").request().get();
target("multi-timed").request().get();

Expand All @@ -103,7 +103,7 @@ public void resourcesWithAnnotationAreTimed() {
}

@Test
public void longTaskTimerSupported() throws InterruptedException, ExecutionException {
void longTaskTimerSupported() throws InterruptedException, ExecutionException {
final Future<Response> future = target("long-timed").request().async().get();

/*
Expand Down Expand Up @@ -136,14 +136,14 @@ public void longTaskTimerSupported() throws InterruptedException, ExecutionExcep
}

@Test
public void unnamedLongTaskTimerIsNotSupported() {
void unnamedLongTaskTimerIsNotSupported() {
assertThatExceptionOfType(ProcessingException.class)
.isThrownBy(() -> target("long-timed-unnamed").request().get())
.withCauseInstanceOf(IllegalArgumentException.class);
}

@Test
public void classLevelAnnotationIsInherited() {
void classLevelAnnotationIsInherited() {
target("/class/inherited").request().get();

assertThat(registry.get(METRIC_NAME)
Expand All @@ -154,7 +154,7 @@ public void classLevelAnnotationIsInherited() {
}

@Test
public void methodLevelAnnotationOverridesClassLevel() {
void methodLevelAnnotationOverridesClassLevel() {
target("/class/on-method").request().get();

assertThat(registry.get(METRIC_NAME)
Expand Down
8 changes: 1 addition & 7 deletions micrometer-jersey2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ dependencies {
api 'org.glassfish.jersey.core:jersey-server'
testRuntimeOnly 'org.glassfish.jersey.inject:jersey-hk2'

testImplementation project(':micrometer-test')
testImplementation 'org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-inmemory'

// required by jdk 9
testRuntimeOnly 'javax.xml.bind:jaxb-api'

testImplementation 'org.assertj:assertj-core'

// See https://github.com/eclipse-ee4j/jersey/issues/3662
testImplementation 'junit:junit'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
testImplementation 'org.mockito:mockito-core'
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.glassfish.jersey.server.monitoring.RequestEvent;
import org.glassfish.jersey.server.monitoring.RequestEvent.Type;
import org.glassfish.jersey.uri.UriTemplate;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import javax.ws.rs.NotAcceptableException;
import java.net.URI;
Expand All @@ -45,36 +45,36 @@
* @author Michael Weirauch
* @author Johnny Lim
*/
public class DefaultJerseyTagsProviderTest {
class DefaultJerseyTagsProviderTest {

private final DefaultJerseyTagsProvider tagsProvider = new DefaultJerseyTagsProvider();

@Test
public void testRootPath() {
void testRootPath() {
assertThat(tagsProvider.httpRequestTags(event(200, null, "/", (String[]) null)))
.containsExactlyInAnyOrder(tagsFrom("root", 200, null, "SUCCESS"));
}

@Test
public void templatedPathsAreReturned() {
void templatedPathsAreReturned() {
assertThat(tagsProvider.httpRequestTags(event(200, null, "/", "/", "/hello/{name}")))
.containsExactlyInAnyOrder(tagsFrom("/hello/{name}", 200, null, "SUCCESS"));
}

@Test
public void applicationPathIsPresent() {
void applicationPathIsPresent() {
assertThat(tagsProvider.httpRequestTags(event(200, null, "/app", "/", "/hello")))
.containsExactlyInAnyOrder(tagsFrom("/app/hello", 200, null, "SUCCESS"));
}

@Test
public void notFoundsAreShunted() {
void notFoundsAreShunted() {
assertThat(tagsProvider.httpRequestTags(event(404, null, "/app", "/", "/not-found")))
.containsExactlyInAnyOrder(tagsFrom("NOT_FOUND", 404, null, "CLIENT_ERROR"));
}

@Test
public void redirectsAreShunted() {
void redirectsAreShunted() {
assertThat(tagsProvider.httpRequestTags(event(301, null, "/app", "/", "/redirect301")))
.containsExactlyInAnyOrder(tagsFrom("REDIRECTION", 301, null, "REDIRECTION"));
assertThat(tagsProvider.httpRequestTags(event(302, null, "/app", "/", "/redirect302")))
Expand All @@ -85,7 +85,7 @@ public void redirectsAreShunted() {

@Test
@SuppressWarnings("serial")
public void exceptionsAreMappedCorrectly() {
void exceptionsAreMappedCorrectly() {
assertThat(tagsProvider.httpRequestTags(
event(500, new IllegalArgumentException(), "/app", (String[]) null)))
.containsExactlyInAnyOrder(tagsFrom("/app", 500, "IllegalArgumentException", "SERVER_ERROR"));
Expand All @@ -101,7 +101,7 @@ public void exceptionsAreMappedCorrectly() {
}

@Test
public void longRequestTags() {
void longRequestTags() {
assertThat(tagsProvider.httpLongRequestTags(event(0, null, "/app", (String[]) null)))
.containsExactlyInAnyOrder(Tag.of("method", "GET"), Tag.of("uri", "/app"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.micrometer.jersey2.server.resources.TestResource;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Application;
Expand All @@ -38,7 +38,7 @@
* @author Michael Weirauch
* @author Johnny Lim
*/
public class MetricsRequestEventListenerTest extends JerseyTest {
class MetricsRequestEventListenerTest extends JerseyTest {

static {
Logger.getLogger("org.glassfish.jersey").setLevel(Level.OFF);
Expand All @@ -64,7 +64,7 @@ protected Application configure() {
}

@Test
public void resourcesAreTimed() {
void resourcesAreTimed() {
target("/").request().get();
target("hello").request().get();
target("hello/").request().get();
Expand Down Expand Up @@ -92,7 +92,7 @@ public void resourcesAreTimed() {
}

@Test
public void notFoundIsAccumulatedUnderSameUriIfFromUnmatchedResource() {
void notFoundIsAccumulatedUnderSameUriIfFromUnmatchedResource() {
try {
target("not-found").request().get();
} catch (NotFoundException ignored) {
Expand All @@ -104,7 +104,7 @@ public void notFoundIsAccumulatedUnderSameUriIfFromUnmatchedResource() {
}

@Test
public void notFoundIsReportedWithUriOfMatchedResource() {
void notFoundIsReportedWithUriOfMatchedResource() {
try {
target("throws-not-found-exception").request().get();
} catch (NotFoundException ignored) {
Expand All @@ -116,7 +116,7 @@ public void notFoundIsReportedWithUriOfMatchedResource() {
}

@Test
public void redirectsAreAccumulatedUnderSameUri() {
void redirectsAreAccumulatedUnderSameUri() {
target("redirect/302").request().get();
target("redirect/307").request().get();

Expand All @@ -130,7 +130,7 @@ public void redirectsAreAccumulatedUnderSameUri() {
}

@Test
public void exceptionsAreMappedCorrectly() {
void exceptionsAreMappedCorrectly() {
try {
target("throws-exception").request().get();
} catch (Exception ignored) {
Expand Down
Loading