Skip to content

Commit cbb7ce5

Browse files
committed
Add unit tests for stub, stub settings,service settings
1 parent a87d3b0 commit cbb7ce5

File tree

8 files changed

+852
-15
lines changed

8 files changed

+852
-15
lines changed

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposerTest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@ static Stream<Arguments> data() {
3232
"EchoSettings",
3333
TestProtoLoader.instance().parseShowcaseEcho(),
3434
"localhost:7469",
35-
"v1beta1"),
35+
"v1beta1",
36+
0),
3637
Arguments.of(
3738
"DeprecatedServiceSettings",
3839
TestProtoLoader.instance().parseDeprecatedService(),
3940
"localhost:7469",
40-
"v1"));
41+
"v1",
42+
0),
43+
Arguments.of(
44+
"EchoServiceSelectiveGapicServiceSettings",
45+
TestProtoLoader.instance().parseSelectiveGenerationTesting(),
46+
"localhost:7469",
47+
"v1beta1",
48+
1));
4149
}
4250

4351
@ParameterizedTest
@@ -46,8 +54,9 @@ void generateServiceSettingsClasses(
4654
String name,
4755
GapicContext context,
4856
String apiShortNameExpected,
49-
String packageVersionExpected) {
50-
Service service = context.services().get(0);
57+
String packageVersionExpected,
58+
int serviceIndex) {
59+
Service service = context.services().get(serviceIndex);
5160
GapicClass clazz = ServiceSettingsClassComposer.instance().generate(context, service);
5261

5362
Assert.assertGoldenClass(this.getClass(), clazz, name + ".golden");

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubClassComposerTest.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@
2727
class ServiceStubClassComposerTest {
2828
static Stream<Arguments> data() {
2929
return Stream.of(
30-
Arguments.of("EchoStub", TestProtoLoader.instance().parseShowcaseEcho(), "", ""),
30+
Arguments.of("EchoStub", TestProtoLoader.instance().parseShowcaseEcho(), "", "", 0),
3131
Arguments.of(
32-
"DeprecatedServiceStub", TestProtoLoader.instance().parseDeprecatedService(), "", ""));
32+
"DeprecatedServiceStub",
33+
TestProtoLoader.instance().parseDeprecatedService(),
34+
"",
35+
"",
36+
0),
37+
Arguments.of(
38+
"EchoServiceSelectiveGapicClientStub",
39+
TestProtoLoader.instance().parseSelectiveGenerationTesting(),
40+
"",
41+
"",
42+
1));
3343
}
3444

3545
@ParameterizedTest
@@ -38,8 +48,9 @@ void generateServiceStubClasses(
3848
String name,
3949
GapicContext context,
4050
String apiShortNameExpected,
41-
String packageVersionExpected) {
42-
Service service = context.services().get(0);
51+
String packageVersionExpected,
52+
int serviceIndex) {
53+
Service service = context.services().get(serviceIndex);
4354
GapicClass clazz = ServiceStubClassComposer.instance().generate(context, service);
4455

4556
Assert.assertGoldenClass(this.getClass(), clazz, name + ".golden");

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,38 @@ static Stream<Arguments> data() {
3131
"LoggingServiceV2StubSettings",
3232
GrpcTestProtoLoader.instance().parseLogging(),
3333
"logging",
34-
"v2"),
34+
"v2",
35+
0),
3536
Arguments.of(
3637
"PublisherStubSettings",
3738
GrpcTestProtoLoader.instance().parsePubSubPublisher(),
3839
"pubsub",
39-
"v1"),
40+
"v1",
41+
0),
4042
Arguments.of(
4143
"EchoStubSettings",
4244
GrpcTestProtoLoader.instance().parseShowcaseEcho(),
4345
"localhost:7469",
44-
"v1beta1"),
46+
"v1beta1",
47+
0),
4548
Arguments.of(
4649
"DeprecatedServiceStubSettings",
4750
GrpcTestProtoLoader.instance().parseDeprecatedService(),
4851
"localhost:7469",
49-
"v1"),
52+
"v1",
53+
0),
5054
Arguments.of(
5155
"ApiVersionTestingStubSettings",
5256
GrpcTestProtoLoader.instance().parseApiVersionTesting(),
5357
"localhost:7469",
54-
"v1"));
58+
"v1",
59+
0),
60+
Arguments.of(
61+
"EchoServiceSelectiveGapicStubSettings",
62+
GrpcTestProtoLoader.instance().parseSelectiveGenerationTesting(),
63+
"localhost:7469",
64+
"v1beta1",
65+
1));
5566
}
5667

5768
@ParameterizedTest
@@ -60,8 +71,9 @@ void generateServiceStubSettingsClasses(
6071
String name,
6172
GapicContext context,
6273
String apiShortNameExpected,
63-
String packageVersionExpected) {
64-
Service service = context.services().get(0);
74+
String packageVersionExpected,
75+
int serviceIndex) {
76+
Service service = context.services().get(serviceIndex);
6577
GapicClass clazz = ServiceStubSettingsClassComposer.instance().generate(context, service);
6678

6779
Assert.assertGoldenClass(this.getClass(), clazz, name + ".golden");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.google.selective.generate.v1beta1.stub;
2+
3+
import com.google.api.core.BetaApi;
4+
import com.google.api.core.InternalApi;
5+
import com.google.api.gax.core.BackgroundResource;
6+
import com.google.api.gax.rpc.BidiStreamingCallable;
7+
import com.google.api.gax.rpc.UnaryCallable;
8+
import com.google.selective.generate.v1beta1.EchoRequest;
9+
import com.google.selective.generate.v1beta1.EchoResponse;
10+
import javax.annotation.Generated;
11+
12+
// AUTO-GENERATED DOCUMENTATION AND CLASS.
13+
/**
14+
* Base stub class for the EchoServiceShouldGeneratePartialUsual service API.
15+
*
16+
* <p>This class is for advanced usage and reflects the underlying API directly.
17+
*/
18+
@BetaApi
19+
@Generated("by gapic-generator-java")
20+
public abstract class EchoServiceShouldGeneratePartialUsualStub implements BackgroundResource {
21+
22+
public UnaryCallable<EchoRequest, EchoResponse> echoShouldGenerateAsUsualCallable() {
23+
throw new UnsupportedOperationException("Not implemented: echoShouldGenerateAsUsualCallable()");
24+
}
25+
26+
public BidiStreamingCallable<EchoRequest, EchoResponse> chatShouldGenerateAsUsualCallable() {
27+
throw new UnsupportedOperationException("Not implemented: chatShouldGenerateAsUsualCallable()");
28+
}
29+
30+
public BidiStreamingCallable<EchoRequest, EchoResponse> chatAgainShouldGenerateAsUsualCallable() {
31+
throw new UnsupportedOperationException(
32+
"Not implemented: chatAgainShouldGenerateAsUsualCallable()");
33+
}
34+
35+
@InternalApi("Internal API. This API is not intended for public consumption.")
36+
public UnaryCallable<EchoRequest, EchoResponse> chatShouldGenerateAsInternalCallable() {
37+
throw new UnsupportedOperationException(
38+
"Not implemented: chatShouldGenerateAsInternalCallable()");
39+
}
40+
41+
@InternalApi("Internal API. This API is not intended for public consumption.")
42+
public BidiStreamingCallable<EchoRequest, EchoResponse> echoShouldGenerateAsInternalCallable() {
43+
throw new UnsupportedOperationException(
44+
"Not implemented: echoShouldGenerateAsInternalCallable()");
45+
}
46+
47+
@Override
48+
public abstract void close();
49+
}

0 commit comments

Comments
 (0)