From 0b6d2bc6db6f3faf8e222a90a672fd5d09b84390 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Tue, 9 Jan 2024 12:55:31 -0500 Subject: [PATCH] chore: Add showcase test for endpoint context --- .../v1beta1/it/ITEndpointContext.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITEndpointContext.java 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 new file mode 100644 index 0000000000..ac5f160fa4 --- /dev/null +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITEndpointContext.java @@ -0,0 +1,67 @@ +package com.google.showcase.v1beta1.it; + +import com.google.common.truth.Truth; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoSettings; +import com.google.showcase.v1beta1.it.util.TestClientInitializer; +import org.junit.Test; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +/** This IT tests the different user configurations allowed and their effects on + * endpoint and universe domain resolution. + * + *

This test will be enhanced in the future when the settings are able to return + * the resolved endpoint and universe domain values. + */ +public class ITEndpointContext { + public static final String SHOWCASE_DEFAULT_ENDPOINT = "localhost:7469"; + + // Default (no configuration) + @Test + public void endpointResolution_default() throws InterruptedException, IOException { + EchoClient echoClient = null; + try { + echoClient = EchoClient.create(); + Truth.assertThat(echoClient.getSettings().getEndpoint()).isEqualTo(SHOWCASE_DEFAULT_ENDPOINT); + } finally { + if (echoClient != null) { + echoClient.close(); + echoClient.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + } + } + } + + // User configuration + @Test + public void endpointResolution_userConfiguration() throws InterruptedException, IOException { + String customEndpoint = "test.com:123"; + EchoClient echoClient = null; + try { + EchoSettings echoSettings = EchoSettings.newBuilder().setEndpoint(customEndpoint).build(); + echoClient = EchoClient.create(echoSettings); + Truth.assertThat(echoClient.getSettings().getEndpoint()).isEqualTo(customEndpoint); + } finally { + if (echoClient != null) { + echoClient.close(); + echoClient.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + } + } + } + + // Default in Builder (no configuration) + @Test + public void endpointResolution_defaultBuilder() { + EchoSettings.Builder echoSettingsBuilder = EchoSettings.newBuilder(); + Truth.assertThat(echoSettingsBuilder.getEndpoint()).isEqualTo(SHOWCASE_DEFAULT_ENDPOINT); + } + + // User configuration in Builder + @Test + public void endpointResolution_userConfigurationBuilder() { + String customEndpoint = "test.com:123"; + EchoSettings.Builder echoSettingsBuilder = EchoSettings.newBuilder().setEndpoint(customEndpoint); + Truth.assertThat(echoSettingsBuilder.getEndpoint()).isEqualTo(customEndpoint); + } +}