Skip to content

Commit 0967e2c

Browse files
committed
test: retore missing test
1 parent 821cec4 commit 0967e2c

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/HttpRuleParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ private static Set<HttpBinding> validateAndConstructHttpBindings(
151151
for (int i = 0; i < subFields.length; i++) {
152152
String subFieldName = subFields[i];
153153
Field field = nestedMessage.fieldMap().get(subFieldName);
154+
Preconditions.checkState(
155+
field != null,
156+
"Expected message %s to contain field %s but none found",
157+
nestedMessage.name(),
158+
subFieldName);
154159

155160
// Each component of the JSON name uses the json_name annotation of the field,
156161
// or default to the field name

sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/HttpRuleParserTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ void parseHttpAnnotation_multipleBindings() {
7979
.containsExactly("answer", "foo", "name", "test_to_verify.name", "type");
8080
}
8181

82+
@Test
83+
void parseHttpAnnotation_missingFieldFromMessage() {
84+
FileDescriptor testingFileDescriptor = TestingOuterClass.getDescriptor();
85+
ServiceDescriptor testingService = testingFileDescriptor.getServices().get(0);
86+
assertEquals("Testing", testingService.getName());
87+
88+
Map<String, Message> messages = Parser.parseMessages(testingFileDescriptor);
89+
90+
// VerityTest method.
91+
MethodDescriptor rpcMethod =
92+
testingService.getMethods().get(testingService.getMethods().size() - 1);
93+
Message inputMessage = messages.get("com.google.showcase.v1beta1.CreateSessionRequest");
94+
assertThrows(
95+
IllegalStateException.class, () -> HttpRuleParser.parse(rpcMethod, inputMessage, messages));
96+
}
97+
8298
@Test
8399
void parseHttpAnnotation_shouldPutAllFieldsIntoQueryParamsIfPathParamAndBodyAreNotConfigured() {
84100
FileDescriptor fileDescriptor = HttpRuleParserTestingOuterClass.getDescriptor();

0 commit comments

Comments
 (0)