Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ggj][codegen] fix: use generic types in field instantiation in ServiceClientTest #431

Merged
merged 16 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
90c4f38
fix: support non-name fields with res-refs in resname def parsing
miraleung Oct 27, 2020
1d15125
Merge branch 'master' of github.com:googleapis/gapic-generator-java i…
miraleung Oct 30, 2020
7db263e
fix: add workaround for missing default_host and oauth_scopes annotation
miraleung Oct 27, 2020
abebd63
[ggj][infra][3/5]feat: add goldens update bazel rules for Redis API (…
xiaozhenliu-gg5 Oct 26, 2020
f2a1674
[ggj][infra][4/5]feat: add goldens update bazel rules for Asset API (…
xiaozhenliu-gg5 Oct 28, 2020
8f906fa
[ggj][infra][3/5]feat: add goldens update bazel rules for Redis API (…
xiaozhenliu-gg5 Oct 26, 2020
58271c3
[ggj][infra][4/5]feat: add goldens update bazel rules for Asset API (…
xiaozhenliu-gg5 Oct 28, 2020
9cd2c89
[ggj][infra][3/5]feat: add goldens update bazel rules for Redis API (…
xiaozhenliu-gg5 Oct 26, 2020
bb9e50c
[ggj][infra][4/5]feat: add goldens update bazel rules for Asset API (…
xiaozhenliu-gg5 Oct 28, 2020
9792aab
fix: clarify LRO parsing error messages
miraleung Oct 27, 2020
e337c6a
feat: support deeply-nested types in AST and proto message parsing
miraleung Oct 28, 2020
d53ea8a
fix: prevent resname tokens from matching subcomponents
miraleung Oct 28, 2020
b274fdc
fix: use TypeParser for proto message parsing
miraleung Oct 28, 2020
930edb2
fix: merge master
miraleung Oct 30, 2020
74dbafb
fix: use generic types in field instantiation in ServiceClientTest
miraleung Oct 28, 2020
a0801b6
Merge branch 'master' into alpha/g6
miraleung Oct 30, 2020
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 @@ -77,10 +77,18 @@ static Expr createDefaultValue(
}

static Expr createDefaultValue(Field f) {
return createDefaultValue(f, false);
}

static Expr createDefaultValue(Field f, boolean useExplicitInitTypeInGenerics) {
if (f.isRepeated()) {
TypeNode newType =
TypeNode.withReference(
ConcreteReference.withClazz(f.isMap() ? HashMap.class : ArrayList.class));
ConcreteReference.Builder refBuilder =
ConcreteReference.builder().setClazz(f.isMap() ? HashMap.class : ArrayList.class);
if (useExplicitInitTypeInGenerics) {
refBuilder = refBuilder.setGenerics(f.type().reference().generics().get(0));
}

TypeNode newType = TypeNode.withReference(refBuilder.build());
return NewObjectExpr.builder().setType(newType).setIsGeneric(true).build();
}

Expand Down Expand Up @@ -238,7 +246,7 @@ static Expr createSimpleMessageBuilderExpr(
.setReturnType(TypeNode.STRING)
.build();
} else {
defaultExpr = createDefaultValue(field);
defaultExpr = createDefaultValue(field, true);
}
builderExpr =
MethodInvocationExpr.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ public void createSimpleMessage_containsRepeatedField() {
message, typeStringsToResourceNames, messageTypes);
expr.accept(writerVisitor);
assertEquals(
"PagedExpandResponse.newBuilder().addAllResponses(new"
+ " ArrayList<>()).setNextPageToken(\"next_page_token-1530815211\").build()",
"PagedExpandResponse.newBuilder().addAllResponses(new ArrayList<EchoResponse>())"
+ ".setNextPageToken(\"next_page_token-1530815211\").build()",
writerVisitor.write());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class SubscriberClientTest {
.setPushConfig(PushConfig.newBuilder().build())
.setAckDeadlineSeconds(2135351438)
.setRetainAckedMessages(true)
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.setEnableMessageOrdering(true)
.setExpirationPolicy(ExpirationPolicy.newBuilder().build())
.setFilter("filter-1274492040")
Expand Down Expand Up @@ -140,7 +140,7 @@ public class SubscriberClientTest {
.setPushConfig(PushConfig.newBuilder().build())
.setAckDeadlineSeconds(2135351438)
.setRetainAckedMessages(true)
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.setEnableMessageOrdering(true)
.setExpirationPolicy(ExpirationPolicy.newBuilder().build())
.setFilter("filter-1274492040")
Expand Down Expand Up @@ -199,7 +199,7 @@ public class SubscriberClientTest {
.setPushConfig(PushConfig.newBuilder().build())
.setAckDeadlineSeconds(2135351438)
.setRetainAckedMessages(true)
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.setEnableMessageOrdering(true)
.setExpirationPolicy(ExpirationPolicy.newBuilder().build())
.setFilter("filter-1274492040")
Expand Down Expand Up @@ -258,7 +258,7 @@ public class SubscriberClientTest {
.setPushConfig(PushConfig.newBuilder().build())
.setAckDeadlineSeconds(2135351438)
.setRetainAckedMessages(true)
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.setEnableMessageOrdering(true)
.setExpirationPolicy(ExpirationPolicy.newBuilder().build())
.setFilter("filter-1274492040")
Expand Down Expand Up @@ -317,7 +317,7 @@ public class SubscriberClientTest {
.setPushConfig(PushConfig.newBuilder().build())
.setAckDeadlineSeconds(2135351438)
.setRetainAckedMessages(true)
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.setEnableMessageOrdering(true)
.setExpirationPolicy(ExpirationPolicy.newBuilder().build())
.setFilter("filter-1274492040")
Expand Down Expand Up @@ -366,7 +366,7 @@ public class SubscriberClientTest {
.setPushConfig(PushConfig.newBuilder().build())
.setAckDeadlineSeconds(2135351438)
.setRetainAckedMessages(true)
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.setEnableMessageOrdering(true)
.setExpirationPolicy(ExpirationPolicy.newBuilder().build())
.setFilter("filter-1274492040")
Expand Down Expand Up @@ -415,7 +415,7 @@ public class SubscriberClientTest {
.setPushConfig(PushConfig.newBuilder().build())
.setAckDeadlineSeconds(2135351438)
.setRetainAckedMessages(true)
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.setEnableMessageOrdering(true)
.setExpirationPolicy(ExpirationPolicy.newBuilder().build())
.setFilter("filter-1274492040")
Expand Down Expand Up @@ -781,7 +781,7 @@ public class SubscriberClientTest {
@Test
public void pullTest() throws Exception {
PullResponse expectedResponse =
PullResponse.newBuilder().addAllReceivedMessages(new ArrayList<>()).build();
PullResponse.newBuilder().addAllReceivedMessages(new ArrayList<ReceivedMessage>()).build();
mockSubscriber.addResponse(expectedResponse);

SubscriptionName subscription = SubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
Expand Down Expand Up @@ -823,7 +823,7 @@ public class SubscriberClientTest {
@Test
public void pullTest2() throws Exception {
PullResponse expectedResponse =
PullResponse.newBuilder().addAllReceivedMessages(new ArrayList<>()).build();
PullResponse.newBuilder().addAllReceivedMessages(new ArrayList<ReceivedMessage>()).build();
mockSubscriber.addResponse(expectedResponse);

String subscription = "subscription341203229";
Expand Down Expand Up @@ -865,14 +865,16 @@ public class SubscriberClientTest {
@Test
public void streamingPullTest() throws Exception {
StreamingPullResponse expectedResponse =
StreamingPullResponse.newBuilder().addAllReceivedMessages(new ArrayList<>()).build();
StreamingPullResponse.newBuilder()
.addAllReceivedMessages(new ArrayList<ReceivedMessage>())
.build();
mockSubscriber.addResponse(expectedResponse);
StreamingPullRequest request =
StreamingPullRequest.newBuilder()
.setSubscription(SubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]").toString())
.addAllAckIds(new ArrayList<>())
.addAllModifyDeadlineSeconds(new ArrayList<>())
.addAllModifyDeadlineAckIds(new ArrayList<>())
.addAllAckIds(new ArrayList<String>())
.addAllModifyDeadlineSeconds(new ArrayList<Integer>())
.addAllModifyDeadlineAckIds(new ArrayList<String>())
.setStreamAckDeadlineSeconds(1875467245)
.setClientId("client_id-1904089585")
.setMaxOutstandingMessages(-1315266996)
Expand Down Expand Up @@ -901,9 +903,9 @@ public class SubscriberClientTest {
StreamingPullRequest request =
StreamingPullRequest.newBuilder()
.setSubscription(SubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]").toString())
.addAllAckIds(new ArrayList<>())
.addAllModifyDeadlineSeconds(new ArrayList<>())
.addAllModifyDeadlineAckIds(new ArrayList<>())
.addAllAckIds(new ArrayList<String>())
.addAllModifyDeadlineSeconds(new ArrayList<Integer>())
.addAllModifyDeadlineAckIds(new ArrayList<String>())
.setStreamAckDeadlineSeconds(1875467245)
.setClientId("client_id-1904089585")
.setMaxOutstandingMessages(-1315266996)
Expand Down Expand Up @@ -1011,7 +1013,7 @@ public class SubscriberClientTest {
Snapshot.newBuilder()
.setName(SnapshotName.of("[PROJECT]", "[SNAPSHOT]").toString())
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.build();
mockSubscriber.addResponse(expectedResponse);

Expand Down Expand Up @@ -1051,7 +1053,7 @@ public class SubscriberClientTest {
Snapshot.newBuilder()
.setName(SnapshotName.of("[PROJECT]", "[SNAPSHOT]").toString())
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.build();
mockSubscriber.addResponse(expectedResponse);

Expand Down Expand Up @@ -1179,7 +1181,7 @@ public class SubscriberClientTest {
Snapshot.newBuilder()
.setName(SnapshotName.of("[PROJECT]", "[SNAPSHOT]").toString())
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.build();
mockSubscriber.addResponse(expectedResponse);

Expand Down Expand Up @@ -1222,7 +1224,7 @@ public class SubscriberClientTest {
Snapshot.newBuilder()
.setName(SnapshotName.of("[PROJECT]", "[SNAPSHOT]").toString())
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.build();
mockSubscriber.addResponse(expectedResponse);

Expand Down Expand Up @@ -1265,7 +1267,7 @@ public class SubscriberClientTest {
Snapshot.newBuilder()
.setName(SnapshotName.of("[PROJECT]", "[SNAPSHOT]").toString())
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.build();
mockSubscriber.addResponse(expectedResponse);

Expand Down Expand Up @@ -1308,7 +1310,7 @@ public class SubscriberClientTest {
Snapshot.newBuilder()
.setName(SnapshotName.of("[PROJECT]", "[SNAPSHOT]").toString())
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.build();
mockSubscriber.addResponse(expectedResponse);

Expand Down Expand Up @@ -1351,7 +1353,7 @@ public class SubscriberClientTest {
Snapshot.newBuilder()
.setName(SnapshotName.of("[PROJECT]", "[SNAPSHOT]").toString())
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.putAllLabels(new HashMap<>())
.putAllLabels(new HashMap<String>())
.build();
mockSubscriber.addResponse(expectedResponse);

Expand Down