chore: add unary-unary showcase test for gRPC support (#1501)
* chore: add simple unary callable showcase test for gRPC support
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index fa9625d..a53a3b2 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -181,7 +181,10 @@
- name: Install maven modules
run: |
mvn install -B -ntp -DskipTests -Dclirr.skip -Dcheckstyle.skip
-
+ - name: Java Linter
+ working-directory: showcase
+ run: |
+ mvn -B -ntp fmt:check
- name: Showcase golden tests
working-directory: showcase
run: |
diff --git a/showcase/gapic-showcase/pom.xml b/showcase/gapic-showcase/pom.xml
index c9ced7d..3ff935c 100644
--- a/showcase/gapic-showcase/pom.xml
+++ b/showcase/gapic-showcase/pom.xml
@@ -18,10 +18,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
- <properties>
- <fmt.skip>true</fmt.skip>
- </properties>
-
<profiles>
<profile>
<id>enable-golden-tests</id>
@@ -102,6 +98,14 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>com.coveo</groupId>
+ <artifactId>fmt-maven-plugin</artifactId>
+ <version>2.9</version>
+ <configuration>
+ <filesNamePattern>(IT.*\.java)|(.*Test.java)</filesNamePattern>
+ </configuration>
+ </plugin>
</plugins>
</build>
@@ -163,6 +167,13 @@
</dependency>
<dependency>
+ <groupId>com.google.truth</groupId>
+ <artifactId>truth</artifactId>
+ <version>1.1.3</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-gapic-showcase-v1beta1</artifactId>
<scope>test</scope>
diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITFirstHttp.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITFirstHttp.java
deleted file mode 100644
index e1a66d6..0000000
--- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITFirstHttp.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2022 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.showcase.v1beta1.it;
-
-import static org.junit.Assert.assertEquals;
-
-import com.google.api.client.http.javanet.NetHttpTransport;
-import com.google.api.gax.core.NoCredentialsProvider;
-import com.google.showcase.v1beta1.EchoClient;
-import com.google.showcase.v1beta1.EchoRequest;
-import com.google.showcase.v1beta1.EchoResponse;
-import com.google.showcase.v1beta1.EchoSettings;
-import java.io.IOException;
-import java.security.GeneralSecurityException;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class ITFirstHttp {
-
- private static EchoClient client;
-
- @BeforeClass
- public static void createClient() throws IOException, GeneralSecurityException {
- EchoSettings echoSettings =
- EchoSettings.newHttpJsonBuilder()
- .setCredentialsProvider(NoCredentialsProvider.create())
- .setTransportChannelProvider(
- EchoSettings.defaultHttpJsonTransportProviderBuilder()
- .setHttpTransport(
- new NetHttpTransport.Builder().doNotValidateCertificate().build())
- .setEndpoint("http://localhost:7469")
- .build())
- .build();
-
- client = EchoClient.create(echoSettings);
- }
-
- @AfterClass
- public static void destroyClient() {
- client.close();
- }
-
- @Test
- public void testEcho() {
- assertEquals("http-echo?", echo("http-echo?"));
- assertEquals("http-echo!", echo("http-echo!"));
- }
-
- private String echo(String value) {
- EchoResponse response = client.echo(EchoRequest.newBuilder().setContent(value).build());
- return response.getContent();
- }
-}
\ No newline at end of file
diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITFirstRpc.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITFirstRpc.java
deleted file mode 100644
index 46e681b..0000000
--- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITFirstRpc.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2022 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.showcase.v1beta1.it;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import com.google.api.gax.core.NoCredentialsProvider;
-import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
-import com.google.showcase.v1beta1.EchoClient;
-import com.google.showcase.v1beta1.EchoRequest;
-import com.google.showcase.v1beta1.EchoResponse;
-import com.google.showcase.v1beta1.EchoSettings;
-import io.grpc.ManagedChannelBuilder;
-import java.io.IOException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ITFirstRpc {
-
- private static EchoClient client;
-
- @Before
- public void createClient() throws IOException {
- EchoSettings echoSettings =
- EchoSettings.newBuilder()
- .setCredentialsProvider(NoCredentialsProvider.create())
- .setTransportChannelProvider(
- InstantiatingGrpcChannelProvider.newBuilder()
- .setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
- .build())
- .build();
-
- client = EchoClient.create(echoSettings);
- }
-
- @After
- public void destroyClient() {
- client.close();
- }
-
- @Test
- public void testEcho() {
- assertEquals("grpc-echo?", echo("grpc-echo?"));
- assertEquals("grpc-echo!", echo("grpc-echo!"));
- }
-
- @Test
- public void testShutdown() {
- assertFalse(client.isShutdown());
- client.shutdown();
- assertTrue(client.isShutdown());
- }
-
- private String echo(String value) {
- EchoResponse response = client.echo(EchoRequest.newBuilder().setContent(value).build());
- return response.getContent();
- }
-}
\ No newline at end of file
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 7d87b37..232c339 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
@@ -23,10 +23,9 @@
import com.google.showcase.v1beta1.ComplianceClient;
import com.google.showcase.v1beta1.ComplianceSettings;
import com.google.showcase.v1beta1.EnumRequest;
+import com.google.showcase.v1beta1.EnumResponse;
import java.io.IOException;
import java.security.GeneralSecurityException;
-
-import com.google.showcase.v1beta1.EnumResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -61,4 +60,4 @@
EnumResponse initialResponse = client.getEnum(request);
assertEquals(initialResponse, client.verifyEnum(initialResponse));
}
-}
\ No newline at end of file
+}
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
new file mode 100644
index 0000000..82fb80b
--- /dev/null
+++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITUnaryCallable.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2023 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.showcase.v1beta1.it;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertThrows;
+
+import com.google.api.client.http.javanet.NetHttpTransport;
+import com.google.api.gax.core.NoCredentialsProvider;
+import com.google.api.gax.grpc.GrpcStatusCode;
+import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
+import com.google.api.gax.rpc.CancelledException;
+import com.google.api.gax.rpc.StatusCode;
+import com.google.rpc.Status;
+import com.google.showcase.v1beta1.EchoClient;
+import com.google.showcase.v1beta1.EchoRequest;
+import com.google.showcase.v1beta1.EchoResponse;
+import com.google.showcase.v1beta1.EchoSettings;
+import io.grpc.ManagedChannelBuilder;
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ITUnaryCallable {
+
+ private EchoClient grpcClient;
+
+ private EchoClient httpJsonClient;
+
+ @Before
+ public void createClients() throws IOException, GeneralSecurityException {
+ // Create gRPC Echo Client
+ EchoSettings grpcEchoSettings =
+ EchoSettings.newBuilder()
+ .setCredentialsProvider(NoCredentialsProvider.create())
+ .setTransportChannelProvider(
+ InstantiatingGrpcChannelProvider.newBuilder()
+ .setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
+ .build())
+ .build();
+ grpcClient = EchoClient.create(grpcEchoSettings);
+
+ // Create Http JSON Echo Client
+ EchoSettings httpJsonEchoSettings =
+ EchoSettings.newHttpJsonBuilder()
+ .setCredentialsProvider(NoCredentialsProvider.create())
+ .setTransportChannelProvider(
+ EchoSettings.defaultHttpJsonTransportProviderBuilder()
+ .setHttpTransport(
+ new NetHttpTransport.Builder().doNotValidateCertificate().build())
+ .setEndpoint("http://localhost:7469")
+ .build())
+ .build();
+ httpJsonClient = EchoClient.create(httpJsonEchoSettings);
+ }
+
+ @After
+ public void destroyClient() {
+ grpcClient.close();
+ httpJsonClient.close();
+ }
+
+ @Test
+ public void testGrpc_receiveContent() {
+ assertThat(echoGrpc("grpc-echo?")).isEqualTo("grpc-echo?");
+ assertThat(echoGrpc("grpc-echo!")).isEqualTo("grpc-echo!");
+ }
+
+ @Test
+ public void testGrpc_serverResponseError_throwsException() {
+ Status cancelledStatus =
+ Status.newBuilder().setCode(StatusCode.Code.CANCELLED.ordinal()).build();
+ EchoRequest requestWithServerError = EchoRequest.newBuilder().setError(cancelledStatus).build();
+ CancelledException exception =
+ assertThrows(CancelledException.class, () -> grpcClient.echo(requestWithServerError));
+ assertThat(exception.getStatusCode().getCode()).isEqualTo(GrpcStatusCode.Code.CANCELLED);
+ }
+
+ @Test
+ public void testGrpc_shutdown() {
+ assertThat(grpcClient.isShutdown()).isFalse();
+ grpcClient.shutdown();
+ assertThat(grpcClient.isShutdown()).isTrue();
+ }
+
+ @Test
+ public void testHttpJson() {
+ assertThat(echoHttpJson("http-echo?")).isEqualTo("http-echo?");
+ assertThat(echoHttpJson("http-echo!")).isEqualTo("http-echo!");
+ }
+
+ private String echoGrpc(String value) {
+ EchoResponse response = grpcClient.echo(EchoRequest.newBuilder().setContent(value).build());
+ return response.getContent();
+ }
+
+ private String echoHttpJson(String value) {
+ EchoResponse response = httpJsonClient.echo(EchoRequest.newBuilder().setContent(value).build());
+ return response.getContent();
+ }
+}