Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
public class ServiceClientSampleCodeComposer {

public static String composeClassHeaderCredentialsSampleCode(
// TODO(summerji): Add unit tests for composeClassHeaderCredentialsSampleCode.
TypeNode clientType, TypeNode settingsType) {
// Initialize clientSettings with builder() method.
// e.g. EchoSettings echoSettings =
Expand Down Expand Up @@ -130,7 +129,6 @@ public static String composeClassHeaderCredentialsSampleCode(
}

public static String composeClassHeaderEndpointSampleCode(
// TODO(summerji): Add unit tests for composeClassHeaderEndpointSampleCode.
TypeNode clientType, TypeNode settingsType) {
// Initialize client settings with builder() method.
// e.g. EchoSettings echoSettings = EchoSettings.newBuilder().setEndpoint("myEndpoint").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,56 @@ public class ServiceClientSampleCodeComposerTest {
private static final String LRO_PACKAGE_NAME = "com.google.longrunning";
private static final String PROTO_PACKAGE_NAME = "com.google.protobuf";

// =============================== Class Header Sample Code ===============================//
@Test
public void composeClassHeaderCredentialsSampleCode() {
TypeNode clientType =
TypeNode.withReference(
VaporReference.builder()
.setName("EchoClient")
.setPakkage(SHOWCASE_PACKAGE_NAME)
.build());
TypeNode settingsType =
TypeNode.withReference(
VaporReference.builder()
.setName("EchoSettings")
.setPakkage(SHOWCASE_PACKAGE_NAME)
.build());
String results =
ServiceClientSampleCodeComposer.composeClassHeaderCredentialsSampleCode(clientType, settingsType);
String expected =
LineFormatter.lines(
"EchoSettings echoSettings =\n",
" EchoSettings.newBuilder()\n",
" .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))\n",
" .build();\n",
"EchoClient echoClient = EchoClient.create(echoSettings);");
assertEquals(expected, results);
}

@Test
public void composeClassHeaderEndpointSampleCode() {
TypeNode clientType =
TypeNode.withReference(
VaporReference.builder()
.setName("EchoClient")
.setPakkage(SHOWCASE_PACKAGE_NAME)
.build());
TypeNode settingsType =
TypeNode.withReference(
VaporReference.builder()
.setName("EchoSettings")
.setPakkage(SHOWCASE_PACKAGE_NAME)
.build());
String results =
ServiceClientSampleCodeComposer.composeClassHeaderEndpointSampleCode(clientType, settingsType);
String expected =
LineFormatter.lines(
"EchoSettings echoSettings = EchoSettings.newBuilder().setEndpoint(myEndpoint).build();\n",
"EchoClient echoClient = EchoClient.create(echoSettings);");
assertEquals(expected, results);
}

// =======================================Unary RPC Method Sample Code=======================//
@Test
public void validComposeRpcMethodHeaderSampleCode_pureUnaryRpc() {
Expand Down