Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2691d8c

Browse files
committed
fix: ensure paged tests use the right repeated resp. type
1 parent 297f64a commit 2691d8c

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

src/main/java/com/google/api/generator/engine/ast/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ java_library(
2020
"@com_google_auto_value_auto_value_annotations//jar",
2121
"@com_google_code_findbugs_jsr305//jar",
2222
"@com_google_guava_guava//jar",
23+
"@com_google_protobuf//:protobuf_java",
2324
"@javax_validation_javax_validation_api//jar",
2425
],
2526
)

src/main/java/com/google/api/generator/engine/ast/TypeNode.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.google.auto.value.AutoValue;
1818
import com.google.common.annotations.VisibleForTesting;
1919
import com.google.common.base.Preconditions;
20+
import com.google.protobuf.ByteString;
2021
import java.util.HashMap;
2122
import java.util.Map;
2223
import java.util.Objects;
@@ -64,6 +65,9 @@ public enum TypeKind {
6465
public static final TypeNode SHORT_OBJECT =
6566
withReference(ConcreteReference.withClazz(Short.class));
6667

68+
public static final TypeNode BYTESTRING =
69+
TypeNode.withReference(ConcreteReference.withClazz(ByteString.class));
70+
6771
private static final Map<TypeNode, TypeNode> BOXED_TYPE_MAP = createBoxedTypeMap();
6872

6973
public static final TypeNode VOID = builder().setTypeKind(TypeKind.VOID).build();
@@ -187,7 +191,7 @@ public boolean isPrimitiveType() {
187191
}
188192

189193
public boolean isProtoPrimitiveType() {
190-
return isPrimitiveType() || this.equals(TypeNode.STRING);
194+
return isPrimitiveType() || this.equals(TypeNode.STRING) || this.equals(TypeNode.BYTESTRING);
191195
}
192196

193197
public boolean isSupertypeOrEquals(TypeNode other) {

src/main/java/com/google/api/generator/gapic/composer/DefaultValueComposer.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import com.google.common.base.Preconditions;
3434
import com.google.longrunning.Operation;
3535
import com.google.protobuf.Any;
36-
import com.google.protobuf.ByteString;
3736
import java.util.ArrayList;
3837
import java.util.Arrays;
3938
import java.util.HashMap;
@@ -46,8 +45,6 @@ public class DefaultValueComposer {
4645
private static TypeNode OPERATION_TYPE =
4746
TypeNode.withReference(ConcreteReference.withClazz(Operation.class));
4847
private static TypeNode ANY_TYPE = TypeNode.withReference(ConcreteReference.withClazz(Any.class));
49-
private static TypeNode BYTESTRING_TYPE =
50-
TypeNode.withReference(ConcreteReference.withClazz(ByteString.class));
5148

5249
static Expr createDefaultValue(
5350
MethodArgument methodArg, Map<String, ResourceName> resourceNames) {
@@ -126,10 +123,10 @@ static Expr createDefaultValue(Field f) {
126123
PrimitiveValue.builder().setType(f.type()).setValue("true").build());
127124
}
128125

129-
if (f.type().equals(BYTESTRING_TYPE)) {
126+
if (f.type().equals(TypeNode.BYTESTRING)) {
130127
return VariableExpr.builder()
131-
.setStaticReferenceType(BYTESTRING_TYPE)
132-
.setVariable(Variable.builder().setName("EMPTY").setType(BYTESTRING_TYPE).build())
128+
.setStaticReferenceType(TypeNode.BYTESTRING)
129+
.setVariable(Variable.builder().setName("EMPTY").setType(TypeNode.BYTESTRING).build())
133130
.build();
134131
}
135132

src/main/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ private static MethodDefinition createRpcTestMethod(
494494
"No repeated field found for paged method %s with output message type %s",
495495
method.name(), methodOutputMessage.name()));
496496

497+
// Must be a non-repeated type.
497498
repeatedResponseType = repeatedPagedResultsField.type();
498499
responsesElementVarExpr =
499500
VariableExpr.withVariable(
@@ -506,7 +507,7 @@ private static MethodDefinition createRpcTestMethod(
506507
Field.builder()
507508
.setType(repeatedResponseType)
508509
.setName("responsesElement")
509-
.setIsMessage(true)
510+
.setIsMessage(!repeatedResponseType.isProtoPrimitiveType())
510511
.build()))
511512
.build());
512513
}

src/test/java/com/google/api/generator/gapic/composer/goldens/LoggingClientTest.golden

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public class LoggingServiceV2ClientTest {
343343

344344
@Test
345345
public void listLogsTest() throws Exception {
346-
String responsesElement = String.newBuilder().build();
346+
String responsesElement = "responsesElement-318365110";
347347
ListLogsResponse expectedResponse =
348348
ListLogsResponse.newBuilder()
349349
.setNextPageToken("")
@@ -387,7 +387,7 @@ public class LoggingServiceV2ClientTest {
387387

388388
@Test
389389
public void listLogsTest2() throws Exception {
390-
String responsesElement = String.newBuilder().build();
390+
String responsesElement = "responsesElement-318365110";
391391
ListLogsResponse expectedResponse =
392392
ListLogsResponse.newBuilder()
393393
.setNextPageToken("")
@@ -431,7 +431,7 @@ public class LoggingServiceV2ClientTest {
431431

432432
@Test
433433
public void listLogsTest3() throws Exception {
434-
String responsesElement = String.newBuilder().build();
434+
String responsesElement = "responsesElement-318365110";
435435
ListLogsResponse expectedResponse =
436436
ListLogsResponse.newBuilder()
437437
.setNextPageToken("")
@@ -475,7 +475,7 @@ public class LoggingServiceV2ClientTest {
475475

476476
@Test
477477
public void listLogsTest4() throws Exception {
478-
String responsesElement = String.newBuilder().build();
478+
String responsesElement = "responsesElement-318365110";
479479
ListLogsResponse expectedResponse =
480480
ListLogsResponse.newBuilder()
481481
.setNextPageToken("")
@@ -519,7 +519,7 @@ public class LoggingServiceV2ClientTest {
519519

520520
@Test
521521
public void listLogsTest5() throws Exception {
522-
String responsesElement = String.newBuilder().build();
522+
String responsesElement = "responsesElement-318365110";
523523
ListLogsResponse expectedResponse =
524524
ListLogsResponse.newBuilder()
525525
.setNextPageToken("")

0 commit comments

Comments
 (0)