From 5799827a864be627bac03969cc178efc9d6170aa Mon Sep 17 00:00:00 2001 From: Min Zhu Date: Mon, 20 May 2024 22:17:46 +0800 Subject: [PATCH] chore: Migrate Junit 4 to Junit 5 for showcase (#2757) fixes #2728, attempt to remove Junit 4 support after migration. Other than POM dependency migrate, changes include: - package name changes - Junit 5 syntax upgrades, e.g. `@Before` --> `@BeforeEach`, Replace assertion methods - remove public modifier on tests and test classes. - Refactor JUnit 4 TemporaryFolder `@Rule` in [ITGdch.java](https://github.com/googleapis/sdk-platform-java/pull/2757/files#diff-6ae7755a0b038e1a2febae2d27e36c762f6751b8c7db577421667069399884b4) to JUnit 5 `@TempDir` - Replace `@Test(timeout = 15000L)` in [ITClientShutdown.java](https://github.com/googleapis/sdk-platform-java/pull/2757/files#diff-70d1df57471178a7a63302f82e4a4855ffbbd642ea67d92d501bd1f7008957ca) with `@Timeout(15)` - Update `@RunWith(Parameterized.class)` test in [ITHttpAnnotation.java](https://github.com/googleapis/sdk-platform-java/pull/2757/files#diff-03d420650ecc9fe78ad4887761043c4fdceaa978f464ce30cfc4ed5f8be9b64d) to `@ParameterizedTest` with `@MethodSource("data")` ~~Note: #2737 creates a new test class with JUnit4 syntax. Depending on merging order, I will either update in this pr, or #2737.~~ Updated. Due to truth library depending on junit 4 ([see issue](https://github.com/google/truth/issues/333)), junit 4 cannot be completely removed, or will encounter `java.lang.ClassNotFoundException: org.junit.runner.notification.RunListener` running tests with maven surefire. To keep things cleaner, excluding the implicitly junit brought in from truth and `junit-vintage-engine`. We could also do the reverse, and make a comment if that's prefered. --------- Co-authored-by: Burke Davison <40617934+burkedavison@users.noreply.github.com> Co-authored-by: Lawrence Qiu --- showcase/gapic-showcase/pom.xml | 20 ++++- .../v1beta1/it/ITApiVersionHeaders.java | 64 ++++++++-------- .../v1beta1/it/ITAutoPopulatedFields.java | 42 ++++++----- .../showcase/v1beta1/it/ITBidiStreaming.java | 18 ++--- .../showcase/v1beta1/it/ITClientShutdown.java | 37 ++++++---- .../v1beta1/it/ITClientSideStreaming.java | 22 +++--- .../v1beta1/it/ITCommonServiceMixins.java | 24 +++--- .../google/showcase/v1beta1/it/ITCrud.java | 26 +++---- .../v1beta1/it/ITDynamicRoutingHeaders.java | 73 +++++++++++-------- .../v1beta1/it/ITEndpointContext.java | 39 +++++----- .../google/showcase/v1beta1/it/ITGdch.java | 46 ++++++------ .../showcase/v1beta1/it/ITHttpAnnotation.java | 44 +++++------ .../com/google/showcase/v1beta1/it/ITIam.java | 38 +++++----- .../v1beta1/it/ITLongRunningOperation.java | 17 ++--- .../showcase/v1beta1/it/ITNumericEnums.java | 20 ++--- .../showcase/v1beta1/it/ITOtelMetrics.java | 60 +++++++-------- .../showcase/v1beta1/it/ITPagination.java | 20 ++--- .../v1beta1/it/ITServerSideStreaming.java | 57 +++++++-------- .../showcase/v1beta1/it/ITUnaryCallable.java | 26 +++---- .../showcase/v1beta1/it/ITUnaryDeadline.java | 26 +++---- showcase/pom.xml | 18 ++++- 21 files changed, 386 insertions(+), 351 deletions(-) diff --git a/showcase/gapic-showcase/pom.xml b/showcase/gapic-showcase/pom.xml index 9e1b331ceb..e8022b5328 100644 --- a/showcase/gapic-showcase/pom.xml +++ b/showcase/gapic-showcase/pom.xml @@ -132,14 +132,30 @@ - junit - junit + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.vintage + junit-vintage-engine + test + + + org.junit.jupiter + junit-jupiter-params test com.google.truth truth 1.4.2 + + + junit + junit + + test diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITApiVersionHeaders.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITApiVersionHeaders.java index 7ef4019975..5f892c5886 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITApiVersionHeaders.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITApiVersionHeaders.java @@ -16,7 +16,7 @@ package com.google.showcase.v1beta1.it; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.api.gax.httpjson.*; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -31,15 +31,15 @@ import java.io.IOException; import java.util.ArrayList; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; // TODO: add testing on error responses once feat is implemented in showcase. // https://github.com/googleapis/gapic-showcase/pull/1456 // TODO: watch for showcase gRPC trailer changes suggested in // https://github.com/googleapis/gapic-showcase/pull/1509#issuecomment-2089147103 -public class ITApiVersionHeaders { +class ITApiVersionHeaders { private static final String HTTP_RESPONSE_HEADER_STRING = "x-showcase-request-" + ApiClientHeaderProvider.API_VERSION_HEADER_KEY; private static final Metadata.Key API_VERSION_HEADER_KEY = @@ -51,7 +51,6 @@ public class ITApiVersionHeaders { private static final String EXPECTED_EXCEPTION_MESSAGE = "Header provider can't override the header: " + ApiClientHeaderProvider.API_VERSION_HEADER_KEY; - private static final int DEFAULT_AWAIT_TERMINATION_SEC = 10; // Implement a client interceptor to retrieve the trailing metadata from response. private static class GrpcCapturingClientInterceptor implements ClientInterceptor { @@ -149,17 +148,17 @@ public void onClose(int statusCode, HttpJsonMetadata trailers) { } } - private HttpJsonCapturingClientInterceptor httpJsonInterceptor; - private GrpcCapturingClientInterceptor grpcInterceptor; - private HttpJsonCapturingClientInterceptor httpJsonComplianceInterceptor; - private GrpcCapturingClientInterceptor grpcComplianceInterceptor; - private EchoClient grpcClient; - private EchoClient httpJsonClient; - private ComplianceClient grpcComplianceClient; - private ComplianceClient httpJsonComplianceClient; - - @Before - public void createClients() throws Exception { + private static HttpJsonCapturingClientInterceptor httpJsonInterceptor; + private static GrpcCapturingClientInterceptor grpcInterceptor; + private static HttpJsonCapturingClientInterceptor httpJsonComplianceInterceptor; + private static GrpcCapturingClientInterceptor grpcComplianceInterceptor; + private static EchoClient grpcClient; + private static EchoClient httpJsonClient; + private static ComplianceClient grpcComplianceClient; + private static ComplianceClient httpJsonComplianceClient; + + @BeforeAll + static void createClients() throws Exception { // Create gRPC Interceptor and Client grpcInterceptor = new GrpcCapturingClientInterceptor(); grpcClient = TestClientInitializer.createGrpcEchoClient(ImmutableList.of(grpcInterceptor)); @@ -183,28 +182,31 @@ public void createClients() throws Exception { ImmutableList.of(httpJsonComplianceInterceptor)); } - @After - public void destroyClient() throws InterruptedException { + @AfterAll + static void destroyClient() throws InterruptedException { grpcClient.close(); httpJsonClient.close(); grpcComplianceClient.close(); httpJsonComplianceClient.close(); - grpcClient.awaitTermination(DEFAULT_AWAIT_TERMINATION_SEC, TimeUnit.SECONDS); - httpJsonClient.awaitTermination(DEFAULT_AWAIT_TERMINATION_SEC, TimeUnit.SECONDS); - grpcComplianceClient.awaitTermination(DEFAULT_AWAIT_TERMINATION_SEC, TimeUnit.SECONDS); - httpJsonComplianceClient.awaitTermination(DEFAULT_AWAIT_TERMINATION_SEC, TimeUnit.SECONDS); + grpcClient.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + httpJsonClient.awaitTermination( + TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + grpcComplianceClient.awaitTermination( + TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + httpJsonComplianceClient.awaitTermination( + TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); } @Test - public void testGrpc_matchesApiVersion() { + void testGrpc_matchesApiVersion() { grpcClient.echo(EchoRequest.newBuilder().build()); String headerValue = grpcInterceptor.metadata.get(API_VERSION_HEADER_KEY); assertThat(headerValue).isEqualTo(EXPECTED_ECHO_API_VERSION); } @Test - public void testHttpJson_matchesHeaderName() { + void testHttpJson_matchesHeaderName() { httpJsonClient.echo(EchoRequest.newBuilder().build()); ArrayList headerValues = (ArrayList) httpJsonInterceptor.metadata.getHeaders().get(HTTP_RESPONSE_HEADER_STRING); @@ -213,7 +215,7 @@ public void testHttpJson_matchesHeaderName() { } @Test - public void testGrpc_noApiVersion() { + void testGrpc_noApiVersion() { RepeatRequest request = RepeatRequest.newBuilder().setInfo(ComplianceData.newBuilder().setFString("test")).build(); grpcComplianceClient.repeatDataSimplePath(request); @@ -221,7 +223,7 @@ public void testGrpc_noApiVersion() { } @Test - public void testHttpJson_noApiVersion() { + void testHttpJson_noApiVersion() { RepeatRequest request = RepeatRequest.newBuilder().setInfo(ComplianceData.newBuilder().setFString("test")).build(); httpJsonComplianceClient.repeatDataSimplePath(request); @@ -230,7 +232,7 @@ public void testHttpJson_noApiVersion() { } @Test - public void testGrpcEcho_userApiVersionThrowsException() throws IOException { + void testGrpcEcho_userApiVersionThrowsException() throws IOException { StubSettings stubSettings = grpcClient .getSettings() @@ -249,7 +251,7 @@ public void testGrpcEcho_userApiVersionThrowsException() throws IOException { } @Test - public void testHttpJsonEcho_userApiVersionThrowsException() throws IOException { + void testHttpJsonEcho_userApiVersionThrowsException() throws IOException { StubSettings stubSettings = httpJsonClient .getSettings() @@ -268,7 +270,7 @@ public void testHttpJsonEcho_userApiVersionThrowsException() throws IOException } @Test - public void testGrpcCompliance_userApiVersionSetSuccess() throws IOException { + void testGrpcCompliance_userApiVersionSetSuccess() throws IOException { StubSettings stubSettingsWithApiVersionHeader = grpcComplianceClient .getSettings() @@ -293,7 +295,7 @@ public void testGrpcCompliance_userApiVersionSetSuccess() throws IOException { } @Test - public void testHttpJsonCompliance_userApiVersionSetSuccess() throws IOException { + void testHttpJsonCompliance_userApiVersionSetSuccess() throws IOException { StubSettings httpJsonStubSettingsWithApiVersionHeader = httpJsonComplianceClient .getSettings() diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITAutoPopulatedFields.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITAutoPopulatedFields.java index d448a2af8b..f73b6b3c7d 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITAutoPopulatedFields.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITAutoPopulatedFields.java @@ -15,7 +15,7 @@ */ package com.google.showcase.v1beta1.it; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.api.gax.httpjson.ApiMethodDescriptor; import com.google.api.gax.httpjson.ForwardingHttpJsonClientCall; @@ -47,12 +47,12 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.threeten.bp.Duration; -public class ITAutoPopulatedFields { +class ITAutoPopulatedFields { private static class HttpJsonInterceptor implements HttpJsonClientInterceptor { private Consumer onRequestIntercepted; @@ -120,8 +120,8 @@ public void sendMessage(ReqT message) { private EchoClient httpJsonClient; private EchoClient httpJsonClientWithRetries; - @Before - public void createClients() throws Exception { + @BeforeEach + void createClients() throws Exception { RetrySettings defaultRetrySettings = RetrySettings.newBuilder() .setInitialRpcTimeout(Duration.ofMillis(5000L)) @@ -156,15 +156,22 @@ public void createClients() throws Exception { defaultRetrySettings, retryableCodes, ImmutableList.of(httpJsonInterceptor)); } - @After - public void destroyClient() { + @AfterEach + void destroyClient() throws InterruptedException { grpcClientWithoutRetries.close(); grpcClientWithRetries.close(); httpJsonClient.close(); + + grpcClientWithoutRetries.awaitTermination( + TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + grpcClientWithRetries.awaitTermination( + TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + httpJsonClient.awaitTermination( + TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); } @Test - public void testGrpc_autoPopulateRequestIdWhenAttemptedOnceSuccessfully() { + void testGrpc_autoPopulateRequestIdWhenAttemptedOnceSuccessfully() { List capturedRequestIds = new ArrayList<>(); grpcRequestInterceptor.setOnRequestIntercepted( request -> { @@ -181,7 +188,7 @@ public void testGrpc_autoPopulateRequestIdWhenAttemptedOnceSuccessfully() { } @Test - public void testGrpc_shouldNotAutoPopulateRequestIdIfSetInRequest() { + void testGrpc_shouldNotAutoPopulateRequestIdIfSetInRequest() { List capturedRequestIds = new ArrayList<>(); grpcRequestInterceptor.setOnRequestIntercepted( request -> { @@ -197,7 +204,7 @@ public void testGrpc_shouldNotAutoPopulateRequestIdIfSetInRequest() { } @Test - public void testHttpJson_autoPopulateRequestIdWhenAttemptedOnceSuccessfully() { + void testHttpJson_autoPopulateRequestIdWhenAttemptedOnceSuccessfully() { List capturedRequestIds = new ArrayList<>(); httpJsonInterceptor.setOnRequestIntercepted( request -> { @@ -214,7 +221,7 @@ public void testHttpJson_autoPopulateRequestIdWhenAttemptedOnceSuccessfully() { } @Test - public void testHttpJson_shouldNotAutoPopulateRequestIdIfSetInRequest() { + void testHttpJson_shouldNotAutoPopulateRequestIdIfSetInRequest() { String UUIDsent = UUID.randomUUID().toString(); List capturedRequestIds = new ArrayList<>(); httpJsonInterceptor.setOnRequestIntercepted( @@ -230,7 +237,7 @@ public void testHttpJson_shouldNotAutoPopulateRequestIdIfSetInRequest() { } @Test - public void testGRPC_setsSameRequestIdIfSetInRequestWhenRequestsAreRetried() throws Exception { + void testGRPC_setsSameRequestIdIfSetInRequestWhenRequestsAreRetried() throws Exception { List capturedRequestIds = new ArrayList<>(); grpcRequestInterceptor.setOnRequestIntercepted( request -> { @@ -264,7 +271,7 @@ public void testGRPC_setsSameRequestIdIfSetInRequestWhenRequestsAreRetried() thr } @Test - public void testGRPC_setsSameAutoPopulatedRequestIdWhenRequestsAreRetried() throws Exception { + void testGRPC_setsSameAutoPopulatedRequestIdWhenRequestsAreRetried() throws Exception { List capturedRequestIds = new ArrayList<>(); grpcRequestInterceptor.setOnRequestIntercepted( request -> { @@ -302,8 +309,7 @@ public void testGRPC_setsSameAutoPopulatedRequestIdWhenRequestsAreRetried() thro } @Test - public void testHttpJson_setsSameRequestIdIfSetInRequestWhenRequestsAreRetried() - throws Exception { + void testHttpJson_setsSameRequestIdIfSetInRequestWhenRequestsAreRetried() throws Exception { List capturedRequestIds = new ArrayList<>(); httpJsonInterceptor.setOnRequestIntercepted( request -> { @@ -336,7 +342,7 @@ public void testHttpJson_setsSameRequestIdIfSetInRequestWhenRequestsAreRetried() } @Test - public void testHttpJson_setsSameAutoPopulatedRequestIdWhenRequestsAreRetried() throws Exception { + void testHttpJson_setsSameAutoPopulatedRequestIdWhenRequestsAreRetried() throws Exception { List capturedRequestIds = new ArrayList<>(); httpJsonInterceptor.setOnRequestIntercepted( request -> { diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITBidiStreaming.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITBidiStreaming.java index 4a2717b6f3..72b8f1b0de 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITBidiStreaming.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITBidiStreaming.java @@ -30,22 +30,22 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -public class ITBidiStreaming { +class ITBidiStreaming { private static EchoClient grpcClient; - @BeforeClass - public static void createClients() throws Exception { + @BeforeAll + static void createClients() throws Exception { // Create gRPC Echo Client grpcClient = TestClientInitializer.createGrpcEchoClient(); } - @AfterClass - public static void destroyClients() throws Exception { + @AfterAll + static void destroyClients() throws Exception { grpcClient.close(); grpcClient.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); } @@ -57,7 +57,7 @@ public static void destroyClients() throws Exception { // three requests, respond twice for every request etc. If that happens, the response content may // not be exactly the same as request content. @Test - public void testGrpc_splitCall_shouldListensToResponse() throws Exception { + void testGrpc_splitCall_shouldListensToResponse() throws Exception { // given List expected = Arrays.asList("The rain in Spain stays mainly on the plain".split(" ")); TestResponseObserver responseObserver = new TestResponseObserver(); diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITClientShutdown.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITClientShutdown.java index 5915c8e065..e55ee8d1ed 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITClientShutdown.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITClientShutdown.java @@ -24,31 +24,35 @@ import com.google.showcase.v1beta1.EchoClient; import com.google.showcase.v1beta1.EchoRequest; import com.google.showcase.v1beta1.it.util.TestClientInitializer; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.threeten.bp.Duration; -public class ITClientShutdown { +class ITClientShutdown { private static final long DEFAULT_RPC_TIMEOUT_MS = 15000L; private static final long DEFAULT_CLIENT_TERMINATION_MS = 5000L; // Test to ensure the client can close + terminate properly - @Test(timeout = 15000L) - public void testGrpc_closeClient() throws Exception { + @Test + @Timeout(15) + void testGrpc_closeClient() throws Exception { EchoClient grpcClient = TestClientInitializer.createGrpcEchoClient(); assertClientTerminated(grpcClient); } // Test to ensure the client can close + terminate properly - @Test(timeout = 15000L) - public void testHttpJson_closeClient() throws Exception { + @Test + @Timeout(15) + void testHttpJson_closeClient() throws Exception { EchoClient httpjsonClient = TestClientInitializer.createHttpJsonEchoClient(); assertClientTerminated(httpjsonClient); } // Test to ensure the client can close + terminate after a quick RPC invocation - @Test(timeout = 15000L) - public void testGrpc_rpcInvoked_closeClient() throws Exception { + @Test + @Timeout(15) + void testGrpc_rpcInvoked_closeClient() throws Exception { EchoClient grpcClient = TestClientInitializer.createGrpcEchoClient(); // Response is ignored for this test grpcClient.echo(EchoRequest.newBuilder().setContent("Test").build()); @@ -56,8 +60,9 @@ public void testGrpc_rpcInvoked_closeClient() throws Exception { } // Test to ensure the client can close + terminate after a quick RPC invocation - @Test(timeout = 15000L) - public void testHttpJson_rpcInvoked_closeClient() throws Exception { + @Test + @Timeout(15) + void testHttpJson_rpcInvoked_closeClient() throws Exception { EchoClient httpjsonClient = TestClientInitializer.createHttpJsonEchoClient(); // Response is ignored for this test httpjsonClient.echo(EchoRequest.newBuilder().setContent("Test").build()); @@ -67,9 +72,9 @@ public void testHttpJson_rpcInvoked_closeClient() throws Exception { // This test is to ensure that the client is able to close + terminate any resources // once a response has been received. Set a max test duration of 15s to ensure that // the test does not continue on forever. - @Test(timeout = 15000L) - public void testGrpc_rpcInvokedWithLargeTimeout_closeClientOnceResponseReceived() - throws Exception { + @Test + @Timeout(15) + void testGrpc_rpcInvokedWithLargeTimeout_closeClientOnceResponseReceived() throws Exception { // Set the maxAttempts to 1 to ensure there are no retries scheduled. The single RPC // invocation should time out in 15s, but the client will receive a response in 2s. // Any outstanding tasks (timeout tasks) should be cancelled once a response has been @@ -100,9 +105,9 @@ public void testGrpc_rpcInvokedWithLargeTimeout_closeClientOnceResponseReceived( // This test is to ensure that the client is able to close + terminate any resources // once a response has been received. Set a max test duration of 15s to ensure that // the test does not continue on forever. - @Test(timeout = 15000L) - public void testHttpJson_rpcInvokedWithLargeTimeout_closeClientOnceResponseReceived() - throws Exception { + @Test + @Timeout(15) + void testHttpJson_rpcInvokedWithLargeTimeout_closeClientOnceResponseReceived() throws Exception { // Set the maxAttempts to 1 to ensure there are no retries scheduled. The single RPC // invocation should time out in 15s, but the client will receive a response in 2s. // Any outstanding tasks (timeout tasks) should be cancelled once a response has been diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITClientSideStreaming.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITClientSideStreaming.java index d6a25654e4..61b507f49a 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITClientSideStreaming.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITClientSideStreaming.java @@ -17,7 +17,7 @@ package com.google.showcase.v1beta1.it; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.api.core.SettableApiFuture; import com.google.api.gax.rpc.ApiStreamObserver; @@ -32,28 +32,28 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -public class ITClientSideStreaming { +class ITClientSideStreaming { private static EchoClient grpcClient; - @BeforeClass - public static void createClients() throws Exception { + @BeforeAll + static void createClients() throws Exception { // Create gRPC Echo Client grpcClient = TestClientInitializer.createGrpcEchoClient(); } - @AfterClass - public static void destroyClients() throws InterruptedException { + @AfterAll + static void destroyClients() throws InterruptedException { grpcClient.close(); grpcClient.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); } @Test - public void testGrpc_sendStreamedContent_receiveConcatenatedResponse() + void testGrpc_sendStreamedContent_receiveConcatenatedResponse() throws ExecutionException, InterruptedException { CollectStreamObserver responseObserver = new CollectStreamObserver<>(); ApiStreamObserver requestObserver = @@ -71,7 +71,7 @@ public void testGrpc_sendStreamedContent_receiveConcatenatedResponse() } @Test - public void testGrpc_sendStreamedContent_handleServerError() { + void testGrpc_sendStreamedContent_handleServerError() { CollectStreamObserver responseObserver = new CollectStreamObserver<>(); ApiStreamObserver requestObserver = grpcClient.collectCallable().clientStreamingCall(responseObserver); diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITCommonServiceMixins.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITCommonServiceMixins.java index a00809914a..a64f95a258 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITCommonServiceMixins.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITCommonServiceMixins.java @@ -27,11 +27,11 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -public class ITCommonServiceMixins { +class ITCommonServiceMixins { // The showcase server always returns a fixed list of locations. See // https://github.com/googleapis/gapic-showcase/blob/main/server/services/locations_service.go @@ -56,8 +56,8 @@ public class ITCommonServiceMixins { private static EchoClient grpcClient; private static EchoClient httpjsonClient; - @BeforeClass - public static void createClients() throws Exception { + @BeforeAll + static void createClients() throws Exception { // Create gRPC Echo Client grpcClient = TestClientInitializer.createGrpcEchoClient(); @@ -65,8 +65,8 @@ public static void createClients() throws Exception { httpjsonClient = TestClientInitializer.createHttpJsonEchoClient(); } - @AfterClass - public static void destroyClients() throws InterruptedException { + @AfterAll + static void destroyClients() throws InterruptedException { grpcClient.close(); httpjsonClient.close(); @@ -76,7 +76,7 @@ public static void destroyClients() throws InterruptedException { } @Test - public void testGrpc_getLocation() { + void testGrpc_getLocation() { GetLocationRequest request = GetLocationRequest.newBuilder().setName("projects/showcase/location/us-central1").build(); Location location = grpcClient.getLocation(request); @@ -89,7 +89,7 @@ public void testGrpc_getLocation() { } @Test - public void testGrpc_listLocations() { + void testGrpc_listLocations() { ListLocationsRequest request = ListLocationsRequest.newBuilder().setName("projects/showcase").build(); EchoClient.ListLocationsPagedResponse locationsPagedResponse = @@ -104,7 +104,7 @@ public void testGrpc_listLocations() { } @Test - public void testHttpJson_getLocation() { + void testHttpJson_getLocation() { GetLocationRequest request = GetLocationRequest.newBuilder().setName("projects/showcase/locations/us-central1").build(); Location location = httpjsonClient.getLocation(request); @@ -117,7 +117,7 @@ public void testHttpJson_getLocation() { } @Test - public void testHttpJson_listLocations() { + void testHttpJson_listLocations() { ListLocationsRequest request = ListLocationsRequest.newBuilder().setName("projects/showcase").build(); EchoClient.ListLocationsPagedResponse locationsPagedResponse = diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITCrud.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITCrud.java index 3cf4b77d2f..2bd0f770ed 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITCrud.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITCrud.java @@ -30,12 +30,12 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class ITCrud { +class ITCrud { private static final User DEFAULT_USER = User.newBuilder() @@ -49,7 +49,7 @@ public class ITCrud { private static IdentityClient grpcClient; private static IdentityClient httpjsonClient; - @BeforeClass + @BeforeAll public static void createClients() throws Exception { // Create gRPC IdentityClient grpcClient = TestClientInitializer.createGrpcIdentityClient(); @@ -57,7 +57,7 @@ public static void createClients() throws Exception { httpjsonClient = TestClientInitializer.createHttpJsonIdentityClient(); } - @AfterClass + @AfterAll public static void destroyClients() throws InterruptedException { grpcClient.close(); httpjsonClient.close(); @@ -67,8 +67,8 @@ public static void destroyClients() throws InterruptedException { TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); } - @Before - public void cleanupData() { + @BeforeEach + void cleanupData() { IdentityClient.ListUsersPagedResponse pagedResponse = grpcClient.listUsers(ListUsersRequest.newBuilder().setPageSize(5).build()); for (IdentityClient.ListUsersPage listUsersPage : pagedResponse.iteratePages()) { @@ -81,7 +81,7 @@ public void cleanupData() { } @Test - public void testHttpJson_Create() { + void testHttpJson_Create() { User userResponse = createDefaultUser(); // These properties should be the same @@ -99,7 +99,7 @@ public void testHttpJson_Create() { } @Test - public void testHttpJson_Read() { + void testHttpJson_Read() { List expectedUsersList = ImmutableList.of( createDefaultUser(), @@ -126,7 +126,7 @@ public void testHttpJson_Read() { } @Test - public void testHttpJson_Update() { + void testHttpJson_Update() { User userResponse = createDefaultUser(); // Update multiple fields in the User. Age + Nickname are not included in the FieldMask // userResponse's enableNotifications field is populated from the server @@ -161,7 +161,7 @@ public void testHttpJson_Update() { } @Test - public void testHttpJson_Delete() { + void testHttpJson_Delete() { User userResponse = createDefaultUser(); httpjsonClient.deleteUser( diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITDynamicRoutingHeaders.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITDynamicRoutingHeaders.java index bafe8730d0..7828da8b53 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITDynamicRoutingHeaders.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITDynamicRoutingHeaders.java @@ -45,11 +45,12 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class ITDynamicRoutingHeaders { +class ITDynamicRoutingHeaders { private static final String SPLIT_TOKEN = "&"; private static final Metadata.Key REQUEST_PARAMS_HEADER_KEY = Metadata.Key.of(DYNAMIC_ROUTING_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER); @@ -117,18 +118,18 @@ public void onClose(int statusCode, HttpJsonMetadata trailers) { } } - private HttpJsonCapturingClientInterceptor httpJsonInterceptor; - private HttpJsonCapturingClientInterceptor httpJsonComplianceInterceptor; - private GrpcCapturingClientInterceptor grpcInterceptor; - private GrpcCapturingClientInterceptor grpcComplianceInterceptor; + private static HttpJsonCapturingClientInterceptor httpJsonInterceptor; + private static HttpJsonCapturingClientInterceptor httpJsonComplianceInterceptor; + private static GrpcCapturingClientInterceptor grpcInterceptor; + private static GrpcCapturingClientInterceptor grpcComplianceInterceptor; - private EchoClient grpcClient; - private EchoClient httpJsonClient; - private ComplianceClient grpcComplianceClient; - private ComplianceClient httpJsonComplianceClient; + private static EchoClient grpcClient; + private static EchoClient httpJsonClient; + private static ComplianceClient grpcComplianceClient; + private static ComplianceClient httpJsonComplianceClient; - @Before - public void createClients() throws Exception { + @BeforeAll + static void createClients() throws Exception { // Create gRPC Interceptor and Client grpcInterceptor = new GrpcCapturingClientInterceptor(); grpcClient = TestClientInitializer.createGrpcEchoClient(ImmutableList.of(grpcInterceptor)); @@ -153,8 +154,16 @@ public void createClients() throws Exception { TestClientInitializer.createHttpJsonEchoClient(ImmutableList.of(httpJsonInterceptor)); } - @After - public void destroyClient() throws InterruptedException { + @BeforeEach + void cleanUpParams() { + grpcInterceptor.metadata = null; + grpcComplianceInterceptor.metadata = null; + httpJsonInterceptor.requestParam = null; + httpJsonComplianceInterceptor.requestParam = null; + } + + @AfterAll + static void destroyClient() throws InterruptedException { grpcClient.close(); grpcComplianceClient.close(); @@ -172,35 +181,35 @@ public void destroyClient() throws InterruptedException { } @Test - public void testGrpc_noRoutingHeaderUsed() { + void testGrpc_noRoutingHeaderUsed() { grpcClient.echo(EchoRequest.newBuilder().build()); String headerValue = grpcInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); assertThat(headerValue).isNull(); } @Test - public void testHttpJson_noRoutingHeaderUsed() { + void testHttpJson_noRoutingHeaderUsed() { httpJsonClient.echo(EchoRequest.newBuilder().build()); String headerValue = httpJsonInterceptor.requestParam; assertThat(headerValue).isNull(); } @Test - public void testGrpc_emptyHeader() { + void testGrpc_emptyHeader() { grpcClient.echo(EchoRequest.newBuilder().setHeader("").build()); String headerValue = grpcInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); assertThat(headerValue).isNull(); } @Test - public void testHttpJson_emptyHeader() { + void testHttpJson_emptyHeader() { httpJsonClient.echo(EchoRequest.newBuilder().setHeader("").build()); String headerValue = httpJsonInterceptor.requestParam; assertThat(headerValue).isNull(); } @Test - public void testGrpc_matchesHeaderName() { + void testGrpc_matchesHeaderName() { grpcClient.echo(EchoRequest.newBuilder().setHeader("potato").build()); String headerValue = grpcInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); assertThat(headerValue).isNotNull(); @@ -211,7 +220,7 @@ public void testGrpc_matchesHeaderName() { } @Test - public void testGrpc_implicitHeaders_enumsEncodedasInt() { + void testGrpc_implicitHeaders_enumsEncodedasInt() { RepeatRequest request = RepeatRequest.newBuilder().setInfo(ComplianceData.newBuilder().setFKingdomValue(5)).build(); RepeatResponse actualResponse = grpcComplianceClient.repeatDataSimplePath(request); @@ -228,7 +237,7 @@ public void testGrpc_implicitHeaders_enumsEncodedasInt() { } @Test - public void testHttpJson_implicitHeaders_enumsEncodedasInt() { + void testHttpJson_implicitHeaders_enumsEncodedasInt() { RepeatRequest request = RepeatRequest.newBuilder() .setInfo( @@ -256,7 +265,7 @@ public void testHttpJson_implicitHeaders_enumsEncodedasInt() { } @Test - public void testHttpJson_matchesHeaderName() { + void testHttpJson_matchesHeaderName() { httpJsonClient.echo(EchoRequest.newBuilder().setHeader("potato").build()); String headerValue = httpJsonInterceptor.requestParam; assertThat(headerValue).isNotNull(); @@ -267,7 +276,7 @@ public void testHttpJson_matchesHeaderName() { } @Test - public void testGrpc_matchesOtherHeaderName() { + void testGrpc_matchesOtherHeaderName() { grpcClient.echo(EchoRequest.newBuilder().setOtherHeader("instances/456").build()); String headerValue = grpcInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); assertThat(headerValue).isNotNull(); @@ -278,7 +287,7 @@ public void testGrpc_matchesOtherHeaderName() { } @Test - public void testHttpJson_matchesOtherHeaderName() { + void testHttpJson_matchesOtherHeaderName() { httpJsonClient.echo(EchoRequest.newBuilder().setOtherHeader("instances/456").build()); String headerValue = httpJsonInterceptor.requestParam; assertThat(headerValue).isNotNull(); @@ -289,7 +298,7 @@ public void testHttpJson_matchesOtherHeaderName() { } @Test - public void testGrpc_matchesMultipleOfSameRoutingHeader_usesHeader() { + void testGrpc_matchesMultipleOfSameRoutingHeader_usesHeader() { grpcClient.echo(EchoRequest.newBuilder().setHeader("projects/123/instances/456").build()); String headerValue = grpcInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); assertThat(headerValue).isNotNull(); @@ -306,7 +315,7 @@ public void testGrpc_matchesMultipleOfSameRoutingHeader_usesHeader() { } @Test - public void testHttpJson_matchesMultipleOfSameRoutingHeader_usesHeader() { + void testHttpJson_matchesMultipleOfSameRoutingHeader_usesHeader() { httpJsonClient.echo(EchoRequest.newBuilder().setHeader("projects/123/instances/456").build()); String headerValue = httpJsonInterceptor.requestParam; assertThat(headerValue).isNotNull(); @@ -323,7 +332,7 @@ public void testHttpJson_matchesMultipleOfSameRoutingHeader_usesHeader() { } @Test - public void testGrpc_matchesMultipleOfSameRoutingHeader_usesOtherHeader() { + void testGrpc_matchesMultipleOfSameRoutingHeader_usesOtherHeader() { grpcClient.echo(EchoRequest.newBuilder().setOtherHeader("projects/123/instances/456").build()); String headerValue = grpcInterceptor.metadata.get(REQUEST_PARAMS_HEADER_KEY); assertThat(headerValue).isNotNull(); @@ -335,7 +344,7 @@ public void testGrpc_matchesMultipleOfSameRoutingHeader_usesOtherHeader() { } @Test - public void testHttpJson_matchesMultipleOfSameRoutingHeader_usesOtherHeader() { + void testHttpJson_matchesMultipleOfSameRoutingHeader_usesOtherHeader() { httpJsonClient.echo( EchoRequest.newBuilder().setOtherHeader("projects/123/instances/456").build()); String headerValue = httpJsonInterceptor.requestParam; @@ -348,7 +357,7 @@ public void testHttpJson_matchesMultipleOfSameRoutingHeader_usesOtherHeader() { } @Test - public void testGrpc_matchesMultipleRoutingHeaders() { + void testGrpc_matchesMultipleRoutingHeaders() { grpcClient.echo( EchoRequest.newBuilder() .setHeader("regions/123/zones/456") @@ -369,7 +378,7 @@ public void testGrpc_matchesMultipleRoutingHeaders() { } @Test - public void testHttpJson_matchesMultipleRoutingHeaders() { + void testHttpJson_matchesMultipleRoutingHeaders() { httpJsonClient.echo( EchoRequest.newBuilder() .setHeader("regions/123/zones/456") diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITEndpointContext.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITEndpointContext.java index 812a52696b..abf3844a6f 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITEndpointContext.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITEndpointContext.java @@ -1,6 +1,6 @@ package com.google.showcase.v1beta1.it; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.NoCredentialsProvider; @@ -22,8 +22,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; /** * This IT tests the different user configurations allowed and their effects on endpoint and @@ -38,7 +38,7 @@ * only use the gRPC transport for testing. HttpJson functionality exists inside the wrapper * classes, but is not being used. */ -public class ITEndpointContext { +class ITEndpointContext { /** * Inside the test cases below, we must explicitly configure serviceName. Normally this should not * be configured at all, but showcase clients do not have a serviceName. The ExtendStubSettings @@ -221,8 +221,8 @@ public Credentials getCredentials() { private EchoClient echoClient; - @After - public void cleanup() throws InterruptedException { + @AfterEach + void cleanup() throws InterruptedException { if (echoClient != null) { echoClient.close(); echoClient.awaitTermination( @@ -232,7 +232,7 @@ public void cleanup() throws InterruptedException { // Default (no configuration) @Test - public void endpointResolution_default() throws IOException { + void endpointResolution_default() throws IOException { EchoSettings echoSettings = ExtendedEchoSettings.newBuilder() .setCredentialsProvider(UniverseDomainCredentialsProvider.create()) @@ -245,7 +245,7 @@ public void endpointResolution_default() throws IOException { // User configuration @Test - public void endpointResolution_userSetEndpoint() throws IOException { + void endpointResolution_userSetEndpoint() throws IOException { String customEndpoint = "test.com:123"; EchoSettings echoSettings = ExtendedEchoSettings.newBuilder() @@ -259,7 +259,7 @@ public void endpointResolution_userSetEndpoint() throws IOException { } @Test - public void endpointResolution_userSetUniverseDomainAndNoUserSetEndpoint() throws IOException { + void endpointResolution_userSetUniverseDomainAndNoUserSetEndpoint() throws IOException { String customUniverseDomain = "random.com"; EchoSettings echoSettings = ExtendedEchoSettings.newBuilder() @@ -273,7 +273,7 @@ public void endpointResolution_userSetUniverseDomainAndNoUserSetEndpoint() throw } @Test - public void endpointResolution_userSetEndpointAndUniverseDomain() throws IOException { + void endpointResolution_userSetEndpointAndUniverseDomain() throws IOException { String customEndpoint = "custom.endpoint.com:443"; String customUniverseDomain = "random.com"; EchoSettings echoSettings = @@ -291,7 +291,7 @@ public void endpointResolution_userSetEndpointAndUniverseDomain() throws IOExcep } @Test - public void universeDomainValidation_credentialsGDU_noUserConfiguration() throws IOException { + void universeDomainValidation_credentialsGDU_noUserConfiguration() throws IOException { EchoSettings echoSettings = ExtendedEchoSettings.newBuilder() .setCredentialsProvider(UniverseDomainCredentialsProvider.create()) @@ -308,7 +308,7 @@ public void universeDomainValidation_credentialsGDU_noUserConfiguration() throws } @Test - public void universeDomainValidation_credentialsNonGDU_noUserConfiguration() throws IOException { + void universeDomainValidation_credentialsNonGDU_noUserConfiguration() throws IOException { EchoSettings echoSettings = ExtendedEchoSettings.newBuilder() .setCredentialsProvider(UniverseDomainCredentialsProvider.create("random.com")) @@ -328,8 +328,7 @@ public void universeDomainValidation_credentialsNonGDU_noUserConfiguration() thr } @Test - public void universeDomainValidation_credentialsNonGDUMatchesUserConfiguration() - throws IOException { + void universeDomainValidation_credentialsNonGDUMatchesUserConfiguration() throws IOException { String universeDomain = "random.com"; EchoSettings echoSettings = ExtendedEchoSettings.newBuilder() @@ -348,7 +347,7 @@ public void universeDomainValidation_credentialsNonGDUMatchesUserConfiguration() } @Test - public void universeDomainValidation_credentialsNonGDUDoesNotMatchUserConfiguration() + void universeDomainValidation_credentialsNonGDUDoesNotMatchUserConfiguration() throws IOException { String universeDomain = "random.com"; String userConfigurationUniverseDomain = "test.com"; @@ -373,7 +372,7 @@ public void universeDomainValidation_credentialsNonGDUDoesNotMatchUserConfigurat // This test uses NoCredentialsProvider (will default to GDU) @Test - public void universeDomainValidation_noCredentials_noUserSetUniverseDomain() throws IOException { + void universeDomainValidation_noCredentials_noUserSetUniverseDomain() throws IOException { EchoSettings echoSettings = ExtendedEchoSettings.newBuilder() .setCredentialsProvider(NoCredentialsProvider.create()) @@ -391,7 +390,7 @@ public void universeDomainValidation_noCredentials_noUserSetUniverseDomain() thr // This test uses NoCredentialsProvider (will default to GDU) @Test - public void universeDomainValidation_noCredentials_userSetUniverseDomain() throws IOException { + void universeDomainValidation_noCredentials_userSetUniverseDomain() throws IOException { String universeDomain = "random.com"; EchoSettings echoSettings = ExtendedEchoSettings.newBuilder() @@ -414,7 +413,7 @@ public void universeDomainValidation_noCredentials_userSetUniverseDomain() throw // Default in Builder (no configuration) @Test - public void endpointResolution_defaultViaBuilder() { + void endpointResolution_defaultViaBuilder() { EchoSettings.Builder echoSettingsBuilder = EchoSettings.newBuilder(); // `StubSettings.newBuilder()` will return the clientSettingsEndpoint Truth.assertThat(echoSettingsBuilder.getEndpoint()).isEqualTo(null); @@ -422,7 +421,7 @@ public void endpointResolution_defaultViaBuilder() { // User configuration in Builder @Test - public void endpointResolution_userConfigurationViaBuilder() { + void endpointResolution_userConfigurationViaBuilder() { EchoSettings.Builder echoSettingsBuilder = EchoSettings.newBuilder().setEndpoint("test.com:123"); // `StubSettings.newBuilder()` will return the clientSettingsEndpoint @@ -430,7 +429,7 @@ public void endpointResolution_userConfigurationViaBuilder() { } @Test - public void endpointResolution_builderBuilderBackToBuilder() throws IOException { + void endpointResolution_builderBuilderBackToBuilder() throws IOException { String customEndpoint = "test.com:123"; EchoStubSettings.Builder echoStubSettingsBuilder = EchoStubSettings.newBuilder().setEndpoint(customEndpoint); diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java index ed5ff03100..f043d45cfc 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java @@ -18,10 +18,10 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.api.client.json.GenericJson; import com.google.api.client.json.JsonFactory; @@ -41,21 +41,20 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.net.URISyntaxException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; /** * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made since * it is not feasible to test against real GDCH servers (or replicate an environment) */ -public class ITGdch { +class ITGdch { private static final String CA_CERT_FILENAME = "fake_cert.pem"; private static final String CA_CERT_RESOURCE_PATH = "/" + CA_CERT_FILENAME; @@ -65,8 +64,6 @@ public class ITGdch { private static final String GDCH_TOKEN_STRING = "1/MkSJoj1xsli0AccessToken_NKPY2"; private static final String SID_NAME = "service-identity-name"; - @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); - private EchoClient client; private EchoSettings settings; private EchoStubSettings stubSettings; @@ -76,27 +73,27 @@ public class ITGdch { private String projectId; private URI tokenUri; - @Before - public void setup() throws IOException, URISyntaxException { + @BeforeEach + void setup(@TempDir Path tempDir) throws IOException { transportFactory = new InterceptingMockTokenServerTransportFactory(); - prepareCredentials(); + prepareCredentials(tempDir); settings = EchoSettings.newBuilder() .setCredentialsProvider(FixedCredentialsProvider.create(initialCredentials)) .build(); } - @After - public void tearDown() throws InterruptedException { + @AfterEach + void tearDown() throws InterruptedException { if (client != null) { client.close(); client.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); } } - private void prepareCredentials() throws IOException { + private void prepareCredentials(Path tempDir) throws IOException { // Copy file so it can be referenced by Path even in native-image builds - File caCertFile = tempFolder.newFile(CA_CERT_FILENAME); + File caCertFile = new File(tempDir.toFile(), CA_CERT_FILENAME); try (InputStream inputStream = getClass().getResourceAsStream(CA_CERT_RESOURCE_PATH)) { assertThat(inputStream).isNotNull(); Files.copy(inputStream, caCertFile.toPath(), StandardCopyOption.REPLACE_EXISTING); @@ -115,7 +112,7 @@ private void prepareCredentials() throws IOException { projectId = converted.get("project").toString(); tokenUri = URI.create(converted.get("token_uri").toString()); - File tempGdchCredentialFile = tempFolder.newFile(GDCH_CREDENTIAL_FILENAME); + File tempGdchCredentialFile = new File(tempDir.toFile(), GDCH_CREDENTIAL_FILENAME); try (FileWriter fileWriter = new FileWriter(tempGdchCredentialFile)) { String preparedJson = converted.toPrettyString(); fileWriter.write(preparedJson); @@ -133,7 +130,7 @@ private void prepareCredentials() throws IOException { * @throws IOException */ @Test - public void testCreateClient_withGdchCredentialAndNoAudience_defaultsToEndpointBasedAudience() + void testCreateClient_withGdchCredentialAndNoAudience_defaultsToEndpointBasedAudience() throws IOException { // we create the client as usual - no audience passed @@ -178,9 +175,8 @@ public void testCreateClient_withGdchCredentialAndNoAudience_defaultsToEndpointB * @throws IOException */ @Test - public void - testCreateClient_withGdchCredentialWithValidAudience_usesCredentialWithPassedAudience() - throws IOException { + void testCreateClient_withGdchCredentialWithValidAudience_usesCredentialWithPassedAudience() + throws IOException { // Similar to the previous test, create a client as usual but this time we pass a explicit // audience. It should diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITHttpAnnotation.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITHttpAnnotation.java index d81b142918..3b73d7e5b6 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITHttpAnnotation.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITHttpAnnotation.java @@ -39,38 +39,33 @@ import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.stream.Collectors; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import java.util.stream.Stream; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; // This test runs from the parameters in the compliance_suite.json file // The file is downloaded from the gapic-showcase repo. Each compliance // group is a set of HttpJson behaviors we want to test for. Each group // tests the product of the rpc list and requests list. -@RunWith(Parameterized.class) -public class ITHttpAnnotation { +class ITHttpAnnotation { - @Parameterized.Parameters(name = "Compliance Group Name: {0}") - public static String[] data() { - return new String[] { - "Fully working conversions, resources", - "Binding selection testing", - "Cases that apply to non-path requests", - "Fully working conversions, no resources" - }; + static Stream data() { + return Stream.of( + Arguments.of("Fully working conversions, resources"), + Arguments.of("Binding selection testing"), + Arguments.of("Cases that apply to non-path requests"), + Arguments.of("Fully working conversions, no resources")); } - @Parameterized.Parameter(0) - public String groupName; - private static ComplianceClient httpjsonClient; private static ComplianceSuite complianceSuite; private static Map> validComplianceRpcMap; - @BeforeClass - public static void createClients() throws IOException, GeneralSecurityException { + @BeforeAll + static void createClients() throws IOException, GeneralSecurityException { ComplianceSuite.Builder builder = ComplianceSuite.newBuilder(); JsonFormat.parser() .merge( @@ -113,8 +108,8 @@ public static void createClients() throws IOException, GeneralSecurityException httpjsonClient::repeatDataPathResource); } - @AfterClass - public static void destroyClients() throws InterruptedException { + @AfterAll + static void destroyClients() throws InterruptedException { httpjsonClient.close(); httpjsonClient.awaitTermination( TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); @@ -123,8 +118,9 @@ public static void destroyClients() throws InterruptedException { // Verify that the input's info is the same as the response's info // This ensures that the entire group's behavior over HttpJson // works as intended - @Test - public void testComplianceGroup() { + @ParameterizedTest + @MethodSource("data") + void testComplianceGroup(String groupName) { Optional complianceGroupOptional = complianceSuite.getGroupList().stream() .filter(x -> x.getName().equals(groupName)) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index 181608571a..893eeb2679 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -16,7 +16,7 @@ package com.google.showcase.v1beta1.it; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.api.gax.rpc.InvalidArgumentException; import com.google.common.collect.ImmutableList; @@ -31,12 +31,12 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class ITIam { +class ITIam { private static final Policy DEFAULT_POLICY = Policy.newBuilder() .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) @@ -45,18 +45,18 @@ public class ITIam { private static IdentityClient httpjsonClient; private String resourceName; - @BeforeClass - public static void createClients() throws Exception { + @BeforeAll + static void createClients() throws Exception { grpcClient = TestClientInitializer.createGrpcIdentityClient(); httpjsonClient = TestClientInitializer.createHttpJsonIdentityClient(); } - @Before - public void setupTests() { + @BeforeEach + void setupTests() { resourceName = "users/" + UUID.randomUUID().toString().substring(0, 8); } - @AfterClass + @AfterAll public static void destroyClients() throws InterruptedException { grpcClient.close(); httpjsonClient.close(); @@ -67,7 +67,7 @@ public static void destroyClients() throws InterruptedException { } @Test - public void testGrpc_setIamPolicy() { + void testGrpc_setIamPolicy() { SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) @@ -78,7 +78,7 @@ public void testGrpc_setIamPolicy() { } @Test - public void testHttpJson_setIamPolicy() { + void testHttpJson_setIamPolicy() { SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) @@ -89,7 +89,7 @@ public void testHttpJson_setIamPolicy() { } @Test - public void testGrpc_getIamPolicy() { + void testGrpc_getIamPolicy() { SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) @@ -104,7 +104,7 @@ public void testGrpc_getIamPolicy() { } @Test - public void testHttpJson_getIamPolicy() { + void testHttpJson_getIamPolicy() { SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) @@ -119,7 +119,7 @@ public void testHttpJson_getIamPolicy() { } @Test - public void testGrpc_testIamPermissions() { + void testGrpc_testIamPermissions() { SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) @@ -140,7 +140,7 @@ public void testGrpc_testIamPermissions() { } @Test - public void testHttpJson_testIamPermissions() { + void testHttpJson_testIamPermissions() { SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) @@ -165,14 +165,14 @@ public void testHttpJson_testIamPermissions() { // cases, and we simply assert that an exception has been thrown for a single case with a single // RPC (No resource in the request for SetIamPolicy's RPC). @Test - public void testGrpc_iamThrowsException() { + void testGrpc_iamThrowsException() { SetIamPolicyRequest setIamPolicyRequest = SetIamPolicyRequest.newBuilder().build(); assertThrows( InvalidArgumentException.class, () -> grpcClient.setIamPolicy(setIamPolicyRequest)); } @Test - public void testHttpJson_iamThrowsException() { + void testHttpJson_iamThrowsException() { SetIamPolicyRequest setIamPolicyRequest = SetIamPolicyRequest.newBuilder().build(); assertThrows( InvalidArgumentException.class, () -> httpjsonClient.setIamPolicy(setIamPolicyRequest)); diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITLongRunningOperation.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITLongRunningOperation.java index 5f1e29963d..bab3d04cd5 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITLongRunningOperation.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITLongRunningOperation.java @@ -16,7 +16,7 @@ package com.google.showcase.v1beta1.it; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.retrying.RetrySettings; @@ -28,7 +28,7 @@ import com.google.showcase.v1beta1.it.util.TestClientInitializer; import java.util.concurrent.CancellationException; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.threeten.bp.Duration; import org.threeten.bp.Instant; import org.threeten.bp.temporal.ChronoUnit; @@ -37,10 +37,10 @@ * For this test, we test a combination of various LRO RetrySettings and try to ensure that the * calls are polling correctly. Each test attempts to test the number of attempts done in each call. */ -public class ITLongRunningOperation { +class ITLongRunningOperation { @Test - public void testGRPC_LROSuccessfulResponse_doesNotExceedTotalTimeout() throws Exception { + void testGRPC_LROSuccessfulResponse_doesNotExceedTotalTimeout() throws Exception { RetrySettings initialUnaryRetrySettings = RetrySettings.newBuilder() .setInitialRpcTimeout(Duration.ofMillis(3000L)) @@ -79,7 +79,7 @@ public void testGRPC_LROSuccessfulResponse_doesNotExceedTotalTimeout() throws Ex } @Test - public void testHttpJson_LROSuccessfulResponse_doesNotExceedTotalTimeout() throws Exception { + void testHttpJson_LROSuccessfulResponse_doesNotExceedTotalTimeout() throws Exception { RetrySettings initialUnaryRetrySettings = RetrySettings.newBuilder() .setInitialRpcTimeout(Duration.ofMillis(3000L)) @@ -119,7 +119,7 @@ public void testHttpJson_LROSuccessfulResponse_doesNotExceedTotalTimeout() throw } @Test - public void testGRPC_LROUnsuccessfulResponse_exceedsTotalTimeout_throwsDeadlineExceededException() + void testGRPC_LROUnsuccessfulResponse_exceedsTotalTimeout_throwsDeadlineExceededException() throws Exception { RetrySettings initialUnaryRetrySettings = RetrySettings.newBuilder() @@ -157,9 +157,8 @@ public void testGRPC_LROUnsuccessfulResponse_exceedsTotalTimeout_throwsDeadlineE } @Test - public void - testHttpJson_LROUnsuccessfulResponse_exceedsTotalTimeout_throwsDeadlineExceededException() - throws Exception { + void testHttpJson_LROUnsuccessfulResponse_exceedsTotalTimeout_throwsDeadlineExceededException() + throws Exception { RetrySettings initialUnaryRetrySettings = RetrySettings.newBuilder() .setInitialRpcTimeout(Duration.ofMillis(5000L)) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITNumericEnums.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITNumericEnums.java index 2b921b421b..76c54a803c 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITNumericEnums.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITNumericEnums.java @@ -16,7 +16,7 @@ package com.google.showcase.v1beta1.it; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.gax.core.NoCredentialsProvider; @@ -28,16 +28,16 @@ import java.io.IOException; import java.security.GeneralSecurityException; import java.util.concurrent.TimeUnit; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -public class ITNumericEnums { +class ITNumericEnums { private static ComplianceClient httpjsonClient; - @BeforeClass - public static void createClients() throws GeneralSecurityException, IOException { + @BeforeAll + static void createClients() throws GeneralSecurityException, IOException { ComplianceSettings complianceSettings = ComplianceSettings.newHttpJsonBuilder() .setCredentialsProvider(NoCredentialsProvider.create()) @@ -51,15 +51,15 @@ public static void createClients() throws GeneralSecurityException, IOException httpjsonClient = ComplianceClient.create(complianceSettings); } - @AfterClass - public static void destroyClients() throws InterruptedException { + @AfterAll + static void destroyClients() throws InterruptedException { httpjsonClient.close(); httpjsonClient.awaitTermination( TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); } @Test - public void verifyEnums() { + void verifyEnums() { EnumRequest request = EnumRequest.newBuilder().setUnknownEnum(true).build(); EnumResponse initialResponse = httpjsonClient.getEnum(request); assertEquals(initialResponse, httpjsonClient.verifyEnum(initialResponse)); diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelMetrics.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelMetrics.java index 317897710b..c2ecff034d 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelMetrics.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelMetrics.java @@ -30,7 +30,7 @@ package com.google.showcase.v1beta1.it; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.core.ApiFuture; @@ -76,11 +76,11 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * Showcase Test to confirm that metrics are being collected and that the correct metrics are being @@ -93,7 +93,7 @@ * via {@link #verifyStatusAttribute(List, List)}. Finally, check that the status for each attempt * is correct. */ -public class ITOtelMetrics { +class ITOtelMetrics { private static final int DEFAULT_OPERATION_COUNT = 1; private static final String SERVICE_NAME = "ShowcaseTest"; private static final String ATTEMPT_COUNT = SERVICE_NAME + "/attempt_count"; @@ -141,8 +141,8 @@ private OpenTelemetryMetricsRecorder createOtelMetricsRecorder( return new OpenTelemetryMetricsRecorder(openTelemetry, SERVICE_NAME); } - @Before - public void setup() throws Exception { + @BeforeEach + void setup() throws Exception { inMemoryMetricReader = InMemoryMetricReader.create(); OpenTelemetryMetricsRecorder otelMetricsRecorder = createOtelMetricsRecorder(inMemoryMetricReader); @@ -154,8 +154,8 @@ public void setup() throws Exception { new MetricsTracerFactory(otelMetricsRecorder)); } - @After - public void cleanup() throws InterruptedException { + @AfterEach + void cleanup() throws InterruptedException { inMemoryMetricReader.shutdown(); grpcClient.close(); @@ -285,12 +285,12 @@ private List getMetricDataList() throws InterruptedException { return metricData; } } - Assert.fail("Unable to collect all the metrics required for the test"); + Assertions.fail("Unable to collect all the metrics required for the test"); return new ArrayList<>(); } @Test - public void testGrpc_operationSucceeded_recordsMetrics() throws InterruptedException { + void testGrpc_operationSucceeded_recordsMetrics() throws InterruptedException { int attemptCount = 1; EchoRequest echoRequest = EchoRequest.newBuilder().setContent("test_grpc_operation_succeeded").build(); @@ -311,9 +311,9 @@ public void testGrpc_operationSucceeded_recordsMetrics() throws InterruptedExcep verifyStatusAttribute(metricDataList, statusCountList); } - @Ignore("https://github.com/googleapis/sdk-platform-java/issues/2503") + @Disabled("https://github.com/googleapis/sdk-platform-java/issues/2503") @Test - public void testHttpJson_operationSucceeded_recordsMetrics() throws InterruptedException { + void testHttpJson_operationSucceeded_recordsMetrics() throws InterruptedException { int attemptCount = 1; EchoRequest echoRequest = EchoRequest.newBuilder().setContent("test_http_operation_succeeded").build(); @@ -335,7 +335,7 @@ public void testHttpJson_operationSucceeded_recordsMetrics() throws InterruptedE } @Test - public void testGrpc_operationCancelled_recordsMetrics() throws Exception { + void testGrpc_operationCancelled_recordsMetrics() throws Exception { int attemptCount = 1; BlockRequest blockRequest = BlockRequest.newBuilder() @@ -364,9 +364,9 @@ public void testGrpc_operationCancelled_recordsMetrics() throws Exception { verifyStatusAttribute(metricDataList, statusCountList); } - @Ignore("https://github.com/googleapis/sdk-platform-java/issues/2503") + @Disabled("https://github.com/googleapis/sdk-platform-java/issues/2503") @Test - public void testHttpJson_operationCancelled_recordsMetrics() throws Exception { + void testHttpJson_operationCancelled_recordsMetrics() throws Exception { int attemptCount = 1; BlockRequest blockRequest = BlockRequest.newBuilder().setResponseDelay(Duration.newBuilder().setSeconds(5)).build(); @@ -393,7 +393,7 @@ public void testHttpJson_operationCancelled_recordsMetrics() throws Exception { } @Test - public void testGrpc_operationFailed_recordsMetrics() throws InterruptedException { + void testGrpc_operationFailed_recordsMetrics() throws InterruptedException { int attemptCount = 1; Code statusCode = Code.INVALID_ARGUMENT; BlockRequest blockRequest = @@ -421,9 +421,9 @@ public void testGrpc_operationFailed_recordsMetrics() throws InterruptedExceptio verifyStatusAttribute(metricDataList, statusCountList); } - @Ignore("https://github.com/googleapis/sdk-platform-java/issues/2503") + @Disabled("https://github.com/googleapis/sdk-platform-java/issues/2503") @Test - public void testHttpJson_operationFailed_recordsMetrics() throws InterruptedException { + void testHttpJson_operationFailed_recordsMetrics() throws InterruptedException { int attemptCount = 1; Code statusCode = Code.INVALID_ARGUMENT; BlockRequest blockRequest = @@ -452,7 +452,7 @@ public void testHttpJson_operationFailed_recordsMetrics() throws InterruptedExce } @Test - public void testGrpc_attemptFailedRetriesExhausted_recordsMetrics() throws Exception { + void testGrpc_attemptFailedRetriesExhausted_recordsMetrics() throws Exception { int attemptCount = 3; Code statusCode = Code.UNAVAILABLE; // A custom EchoClient is used in this test because retries have jitter, and we cannot @@ -517,9 +517,9 @@ public void testGrpc_attemptFailedRetriesExhausted_recordsMetrics() throws Excep grpcClient.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); } - @Ignore("https://github.com/googleapis/sdk-platform-java/issues/2503") + @Disabled("https://github.com/googleapis/sdk-platform-java/issues/2503") @Test - public void testHttpJson_attemptFailedRetriesExhausted_recordsMetrics() throws Exception { + void testHttpJson_attemptFailedRetriesExhausted_recordsMetrics() throws Exception { int attemptCount = 3; Code statusCode = Code.UNAVAILABLE; // A custom EchoClient is used in this test because retries have jitter, and we cannot @@ -586,7 +586,7 @@ public void testHttpJson_attemptFailedRetriesExhausted_recordsMetrics() throws E } @Test - public void testGrpc_attemptPermanentFailure_recordsMetrics() throws InterruptedException { + void testGrpc_attemptPermanentFailure_recordsMetrics() throws InterruptedException { int attemptCount = 1; Code statusCode = Code.INVALID_ARGUMENT; BlockRequest blockRequest = @@ -612,9 +612,9 @@ public void testGrpc_attemptPermanentFailure_recordsMetrics() throws Interrupted verifyStatusAttribute(metricDataList, statusCountList); } - @Ignore("https://github.com/googleapis/sdk-platform-java/issues/2503") + @Disabled("https://github.com/googleapis/sdk-platform-java/issues/2503") @Test - public void testHttpJson_attemptPermanentFailure_recordsMetrics() throws InterruptedException { + void testHttpJson_attemptPermanentFailure_recordsMetrics() throws InterruptedException { int attemptCount = 1; Code statusCode = Code.INVALID_ARGUMENT; BlockRequest blockRequest = @@ -641,7 +641,7 @@ public void testHttpJson_attemptPermanentFailure_recordsMetrics() throws Interru } @Test - public void testGrpc_multipleFailedAttempts_successfulOperation() throws Exception { + void testGrpc_multipleFailedAttempts_successfulOperation() throws Exception { int attemptCount = 3; // Disable Jitter on this test to try and ensure that the there are 3 attempts made // for test. The first two calls should result in a DEADLINE_EXCEEDED exception as @@ -713,9 +713,9 @@ public void testGrpc_multipleFailedAttempts_successfulOperation() throws Excepti grpcClient.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); } - @Ignore("https://github.com/googleapis/sdk-platform-java/issues/2503") + @Disabled("https://github.com/googleapis/sdk-platform-java/issues/2503") @Test - public void testHttpJson_multipleFailedAttempts_successfulOperation() throws Exception { + void testHttpJson_multipleFailedAttempts_successfulOperation() throws Exception { int attemptCount = 3; RetrySettings retrySettings = RetrySettings.newBuilder() diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITPagination.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITPagination.java index 4d4aaf3002..ebcabeab9e 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITPagination.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITPagination.java @@ -23,25 +23,25 @@ import com.google.showcase.v1beta1.PagedExpandRequest; import com.google.showcase.v1beta1.it.util.TestClientInitializer; import java.util.concurrent.TimeUnit; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -public class ITPagination { +class ITPagination { private static EchoClient grpcClient; private static EchoClient httpjsonClient; - @BeforeClass - public static void createClients() throws Exception { + @BeforeAll + static void createClients() throws Exception { // Create gRPC Echo Client grpcClient = TestClientInitializer.createGrpcEchoClient(); // Create Http JSON Echo Client httpjsonClient = TestClientInitializer.createHttpJsonEchoClient(); } - @AfterClass - public static void destroyClients() throws InterruptedException { + @AfterAll + static void destroyClients() throws InterruptedException { grpcClient.close(); httpjsonClient.close(); @@ -60,7 +60,7 @@ public static void destroyClients() throws InterruptedException { // Page # | - | - | - | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 | 5 // Token # | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 @Test - public void testPagedExpandWithTokenGrpc() { + void testPagedExpandWithTokenGrpc() { int pageSize = 2; int pageToken = 3; String content = "A series of words that will be sent back one by one"; @@ -97,7 +97,7 @@ public void testPagedExpandWithTokenGrpc() { // Page # | - | - | - | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 | 5 // Token # | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 @Test - public void testPagedExpandWithTokenHttpJson() { + void testPagedExpandWithTokenHttpJson() { int pageSize = 2; int pageToken = 3; String content = "A series of words that will be sent back one by one"; diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITServerSideStreaming.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITServerSideStreaming.java index 9558be2e9d..9d9ccba39e 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITServerSideStreaming.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITServerSideStreaming.java @@ -17,7 +17,7 @@ package com.google.showcase.v1beta1.it; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.api.gax.core.NoCredentialsProvider; import com.google.api.gax.rpc.CancelledException; @@ -34,30 +34,30 @@ import io.grpc.ManagedChannelBuilder; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.threeten.bp.Duration; -public class ITServerSideStreaming { +class ITServerSideStreaming { private static EchoClient grpcClient; private static EchoClient httpjsonClient; - @BeforeClass - public static void createClients() throws Exception { + @BeforeAll + static void createClients() throws Exception { // Create gRPC Echo Client grpcClient = TestClientInitializer.createGrpcEchoClient(); // Create Http JSON Echo Client httpjsonClient = TestClientInitializer.createHttpJsonEchoClient(); } - @AfterClass - public static void destroyClients() throws InterruptedException { + @AfterAll + static void destroyClients() throws InterruptedException { grpcClient.close(); httpjsonClient.close(); @@ -67,7 +67,7 @@ public static void destroyClients() throws InterruptedException { } @Test - public void testGrpc_receiveStreamedContent() { + void testGrpc_receiveStreamedContent() { String content = "The rain in Spain stays mainly on the plain!"; ServerStream responseStream = grpcClient.expandCallable().call(ExpandRequest.newBuilder().setContent(content).build()); @@ -84,7 +84,7 @@ public void testGrpc_receiveStreamedContent() { } @Test - public void testGrpc_receiveStreamedContentStreamAPI() { + void testGrpc_receiveStreamedContentStreamAPI() { String content = "The rain in Spain stays mainly on the plain!"; ServerStream responseStream = grpcClient.expandCallable().call(ExpandRequest.newBuilder().setContent(content).build()); @@ -96,7 +96,7 @@ public void testGrpc_receiveStreamedContentStreamAPI() { } @Test - public void testGrpc_serverError_receiveErrorAfterLastWordInStream() { + void testGrpc_serverError_receiveErrorAfterLastWordInStream() { String content = "The rain in Spain"; Status cancelledStatus = Status.newBuilder().setCode(StatusCode.Code.CANCELLED.ordinal()).build(); @@ -116,7 +116,7 @@ public void testGrpc_serverError_receiveErrorAfterLastWordInStream() { } @Test - public void testGrpc_serverWaitTimeout_watchdogCancelsStream() throws Exception { + void testGrpc_serverWaitTimeout_watchdogCancelsStream() throws Exception { EchoSettings.Builder settings = EchoSettings.newBuilder() .setCredentialsProvider(NoCredentialsProvider.create()) @@ -146,21 +146,20 @@ public void testGrpc_serverWaitTimeout_watchdogCancelsStream() throws Exception .setStreamWaitTime( com.google.protobuf.Duration.newBuilder().setSeconds(1).build()) .build()); - ArrayList responses = new ArrayList<>(); - try { - for (EchoResponse response : responseStream) { - responses.add(response.getContent()); - } - Assert.fail("No exception was thrown"); - } catch (WatchdogTimeoutException e) { - assertThat(e).hasMessageThat().contains("Canceled due to timeout waiting for next response"); - } finally { - echoClient.close(); - } + List responses = new ArrayList<>(); + WatchdogTimeoutException exception = + assertThrows( + WatchdogTimeoutException.class, + () -> responseStream.forEach(x -> responses.add(x.getContent()))); + assertThat(exception) + .hasMessageThat() + .contains("Canceled due to timeout waiting for next response"); + echoClient.close(); + echoClient.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); } @Test - public void testHttpJson_receiveStreamedContent() { + void testHttpJson_receiveStreamedContent() { String content = "The rain in Spain stays mainly on the plain!"; ServerStream responseStream = httpjsonClient @@ -178,10 +177,10 @@ public void testHttpJson_receiveStreamedContent() { .inOrder(); } - @Ignore( + @Disabled( value = "Ignore until https://github.com/googleapis/gapic-showcase/issues/1286 is resolved") @Test - public void testHttpJson_serverError_receiveErrorAfterLastWordInStream() { + void testHttpJson_serverError_receiveErrorAfterLastWordInStream() { String content = "The rain in Spain"; Status cancelledStatus = Status.newBuilder().setCode(StatusCode.Code.CANCELLED.ordinal()).build(); diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITUnaryCallable.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITUnaryCallable.java index 6c0e860fee..4d6018f6fc 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITUnaryCallable.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITUnaryCallable.java @@ -17,7 +17,7 @@ package com.google.showcase.v1beta1.it; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.api.gax.grpc.GrpcStatusCode; import com.google.api.gax.rpc.CancelledException; @@ -28,26 +28,26 @@ import com.google.showcase.v1beta1.EchoResponse; import com.google.showcase.v1beta1.it.util.TestClientInitializer; import java.util.concurrent.TimeUnit; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -public class ITUnaryCallable { +class ITUnaryCallable { private static EchoClient grpcClient; private static EchoClient httpjsonClient; - @BeforeClass - public static void createClients() throws Exception { + @BeforeAll + static void createClients() throws Exception { // Create gRPC Echo Client grpcClient = TestClientInitializer.createGrpcEchoClient(); // Create Http JSON Echo Client httpjsonClient = TestClientInitializer.createHttpJsonEchoClient(); } - @AfterClass - public static void destroyClients() throws InterruptedException { + @AfterAll + static void destroyClients() throws InterruptedException { grpcClient.close(); httpjsonClient.close(); @@ -57,13 +57,13 @@ public static void destroyClients() throws InterruptedException { } @Test - public void testGrpc_receiveContent() { + void testGrpc_receiveContent() { assertThat(echoGrpc("grpc-echo?")).isEqualTo("grpc-echo?"); assertThat(echoGrpc("grpc-echo!")).isEqualTo("grpc-echo!"); } @Test - public void testGrpc_serverResponseError_throwsException() { + void testGrpc_serverResponseError_throwsException() { Status cancelledStatus = Status.newBuilder().setCode(StatusCode.Code.CANCELLED.ordinal()).build(); EchoRequest requestWithServerError = EchoRequest.newBuilder().setError(cancelledStatus).build(); @@ -73,13 +73,13 @@ public void testGrpc_serverResponseError_throwsException() { } @Test - public void testHttpJson_receiveContent() { + void testHttpJson_receiveContent() { assertThat(echoHttpJson("http-echo?")).isEqualTo("http-echo?"); assertThat(echoHttpJson("http-echo!")).isEqualTo("http-echo!"); } @Test - public void testHttpJson_serverResponseError_throwsException() { + void testHttpJson_serverResponseError_throwsException() { EchoRequest requestWithServerError = EchoRequest.newBuilder() .setError(Status.newBuilder().setCode(StatusCode.Code.CANCELLED.ordinal()).build()) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITUnaryDeadline.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITUnaryDeadline.java index d7d12a4ad5..984598bc9e 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITUnaryDeadline.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITUnaryDeadline.java @@ -16,7 +16,7 @@ package com.google.showcase.v1beta1.it; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.retrying.RetryingFuture; @@ -29,7 +29,7 @@ import com.google.showcase.v1beta1.it.util.TestClientInitializer; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.threeten.bp.Duration; /** @@ -39,10 +39,10 @@ *

Each test attempts to get the number of attempts done in each call. The attemptCount is * incremented by 1 as the first attempt is zero indexed. */ -public class ITUnaryDeadline { +class ITUnaryDeadline { @Test - public void testGRPC_unarySuccessfulResponse_doesNotExceedTotalTimeout() throws Exception { + void testGRPC_unarySuccessfulResponse_doesNotExceedTotalTimeout() throws Exception { RetrySettings defaultNoRetrySettings = RetrySettings.newBuilder() .setInitialRpcTimeout(Duration.ofMillis(5000L)) @@ -76,7 +76,7 @@ public void testGRPC_unarySuccessfulResponse_doesNotExceedTotalTimeout() throws } @Test - public void testHttpJson_unarySuccessfulResponse_doesNotExceedTotalTimeout() throws Exception { + void testHttpJson_unarySuccessfulResponse_doesNotExceedTotalTimeout() throws Exception { RetrySettings defaultNoRetrySettings = RetrySettings.newBuilder() .setInitialRpcTimeout(Duration.ofMillis(5000L)) @@ -113,8 +113,7 @@ public void testHttpJson_unarySuccessfulResponse_doesNotExceedTotalTimeout() thr // Retry is configured by setting the initial RPC timeout (1.5s) to be less than // the RPC delay (2s). The next RPC timeout (3s) will wait long enough for the delay. @Test - public void testGRPC_unarySuccessfulResponse_exceedsRPCDeadlineButWithinTotalTimeout() - throws Exception { + void testGRPC_unarySuccessfulResponse_exceedsRPCDeadlineButWithinTotalTimeout() throws Exception { RetrySettings defaultRetrySettings = RetrySettings.newBuilder() .setInitialRpcTimeout(Duration.ofMillis(1500L)) @@ -148,7 +147,7 @@ public void testGRPC_unarySuccessfulResponse_exceedsRPCDeadlineButWithinTotalTim // Retry is configured by setting the initial RPC timeout (1.5s) to be less than // the RPC delay (2s). The next RPC timeout (3s) will wait long enough for the delay. @Test - public void testHttpJson_unarySuccessfulResponse_exceedsRPCDeadlineButWithinTotalTimeout() + void testHttpJson_unarySuccessfulResponse_exceedsRPCDeadlineButWithinTotalTimeout() throws Exception { RetrySettings defaultRetrySettings = RetrySettings.newBuilder() @@ -184,7 +183,7 @@ public void testHttpJson_unarySuccessfulResponse_exceedsRPCDeadlineButWithinTota // Request is set to block for 6 seconds to allow the RPC to timeout. If retries are // disabled, the RPC timeout is set to be the totalTimeout (5s). @Test - public void + void testGRPC_unaryUnsuccessfulResponse_exceedsRPCTimeoutAndTotalTimeout_throwsDeadlineExceededException() throws Exception { RetrySettings defaultNoRetrySettings = @@ -227,7 +226,7 @@ public void testHttpJson_unarySuccessfulResponse_exceedsRPCDeadlineButWithinTota // Request is set to block for 6 seconds to allow the RPC to timeout. If retries are // disabled, the RPC timeout is set to be the totalTimeout (5s). @Test - public void + void testHttpJson_unaryUnsuccessfulResponse_exceedsRPCTimeoutAndTotalTimeout_throwsDeadlineExceededException() throws Exception { RetrySettings defaultNoRetrySettings = @@ -274,9 +273,8 @@ public void testHttpJson_unarySuccessfulResponse_exceedsRPCDeadlineButWithinTota // receive a response from the server (200ms) regardless of it was cancelled, then // we would expect at most 50 responses. @Test - public void - testGRPC_unaryCallableRetry_deadlineExecutorTimesOutRequest_throwsDeadlineExceededException() - throws Exception { + void testGRPC_unaryCallableRetry_deadlineExecutorTimesOutRequest_throwsDeadlineExceededException() + throws Exception { RetrySettings defaultRetrySettings = RetrySettings.newBuilder() .setInitialRpcTimeout(Duration.ofMillis(100L)) @@ -324,7 +322,7 @@ public void testHttpJson_unarySuccessfulResponse_exceedsRPCDeadlineButWithinTota // receive a response from the server (200ms) regardless of it was cancelled, then // we would expect at most 50 responses. @Test - public void + void testHttpJson_unaryCallableRetry_deadlineExecutorTimesOutRequest_throwsDeadlineExceededException() throws Exception { RetrySettings defaultRetrySettings = diff --git a/showcase/pom.xml b/showcase/pom.xml index cc884b6ca9..cb17baaa68 100644 --- a/showcase/pom.xml +++ b/showcase/pom.xml @@ -54,10 +54,11 @@ 0.0.1-SNAPSHOT - junit - junit - 4.13.2 - test + org.junit + junit-bom + 5.10.2 + pom + import @@ -116,6 +117,15 @@ org.apache.maven.plugins maven-failsafe-plugin + + + + + org.apache.maven.surefire + surefire-junit-platform + ${surefire.version} + + org.codehaus.mojo