use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class ParserTest method parseMessages_fieldsHaveResourceReferences.
@Test
public void parseMessages_fieldsHaveResourceReferences() {
FileDescriptor lockerServiceFileDescriptor = LockerProto.getDescriptor();
Map<String, Message> messageTypes = Parser.parseMessages(lockerServiceFileDescriptor);
// Child type.
Message message = messageTypes.get("com.google.testgapic.v1beta1.CreateFolderRequest");
Field field = message.fieldMap().get("parent");
assertTrue(field.hasResourceReference());
ResourceReference resourceReference = field.resourceReference();
assertEquals("cloudresourcemanager.googleapis.com/Folder", resourceReference.resourceTypeString());
assertTrue(resourceReference.isChildType());
// Type.
message = messageTypes.get("com.google.testgapic.v1beta1.GetFolderRequest");
field = message.fieldMap().get("name");
assertTrue(field.hasResourceReference());
resourceReference = field.resourceReference();
assertEquals("cloudresourcemanager.googleapis.com/Folder", resourceReference.resourceTypeString());
assertFalse(resourceReference.isChildType());
// Non-RPC-specific message.
message = messageTypes.get("com.google.testgapic.v1beta1.Folder");
field = message.fieldMap().get("name");
assertTrue(field.hasResourceReference());
resourceReference = field.resourceReference();
assertEquals("cloudresourcemanager.googleapis.com/Folder", resourceReference.resourceTypeString());
assertFalse(resourceReference.isChildType());
// No explicit resource_reference annotation on the field, and the resource annotation is in the
// message.
message = messageTypes.get("com.google.testgapic.v1beta1.Document");
field = message.fieldMap().get("name");
assertTrue(field.hasResourceReference());
resourceReference = field.resourceReference();
assertEquals("testgapic.googleapis.com/Document", resourceReference.resourceTypeString());
assertFalse(resourceReference.isChildType());
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class ParserTest method parseFields_mapType.
@Test
public void parseFields_mapType() {
FileDescriptor testingFileDescriptor = TestingOuterClass.getDescriptor();
ServiceDescriptor testingService = testingFileDescriptor.getServices().get(0);
assertEquals(testingService.getName(), "Testing");
Map<String, Message> messageTypes = Parser.parseMessages(testingFileDescriptor);
Message message = messageTypes.get("com.google.showcase.v1beta1.Session");
Field field = message.fieldMap().get("session_ids_to_descriptor");
assertEquals(TypeNode.withReference(ConcreteReference.builder().setClazz(Map.class).setGenerics(Arrays.asList(TypeNode.INT_OBJECT.reference(), TypeNode.STRING.reference())).build()), field.type());
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class RoutingRuleParserTest method getRoutingHeaders.
private RoutingHeaderRule getRoutingHeaders(int testingIndex) {
MethodDescriptor rpcMethod = TESTING_SERVICE.getMethods().get(testingIndex);
Map<String, Message> messages = Parser.parseMessages(TESTING_FILE_DESCRIPTOR);
Message inputMessage = messages.get("com." + rpcMethod.getInputType().getFullName());
return RoutingRuleParser.parse(rpcMethod, inputMessage, messages);
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class HttpRuleParserTest method parseHttpAnnotation_multipleBindings.
@Test
public void parseHttpAnnotation_multipleBindings() {
FileDescriptor testingFileDescriptor = TestingOuterClass.getDescriptor();
ServiceDescriptor testingService = testingFileDescriptor.getServices().get(0);
assertEquals("Testing", testingService.getName());
Map<String, Message> messages = Parser.parseMessages(testingFileDescriptor);
// VerityTest method.
MethodDescriptor rpcMethod = testingService.getMethods().get(testingService.getMethods().size() - 1);
Message inputMessage = messages.get("com.google.showcase.v1beta1.VerifyTestRequest");
HttpBindings httpBindings = HttpRuleParser.parse(rpcMethod, inputMessage, messages);
assertThat(httpBindings.pathParameters().stream().map(HttpBinding::name).collect(Collectors.toList())).containsExactly("answer", "foo", "name", "test_to_verify.name", "type");
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class HttpRuleParserTest method parseHttpAnnotation_missingFieldFromMessage.
@Test
public void parseHttpAnnotation_missingFieldFromMessage() {
FileDescriptor testingFileDescriptor = TestingOuterClass.getDescriptor();
ServiceDescriptor testingService = testingFileDescriptor.getServices().get(0);
assertEquals("Testing", testingService.getName());
Map<String, Message> messages = Parser.parseMessages(testingFileDescriptor);
// VerityTest method.
MethodDescriptor rpcMethod = testingService.getMethods().get(testingService.getMethods().size() - 1);
Message inputMessage = messages.get("com.google.showcase.v1beta1.CreateSessionRequest");
assertThrows(IllegalStateException.class, () -> HttpRuleParser.parse(rpcMethod, inputMessage, messages));
}
Aggregations