Skip to content

Commit

Permalink
chore: Add showcase test for endpoint context
Browse files Browse the repository at this point in the history
  • Loading branch information
lqiu96 committed Jan 9, 2024
1 parent 2e68026 commit 0b6d2bc
Showing 1 changed file with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>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);
}
}

0 comments on commit 0b6d2bc

Please sign in to comment.