Search in sources :

Example 31 with Message

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());
}
Also used : Field(com.google.api.generator.gapic.model.Field) Message(com.google.api.generator.gapic.model.Message) ResourceReference(com.google.api.generator.gapic.model.ResourceReference) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Test(org.junit.Test)

Example 32 with Message

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());
}
Also used : Field(com.google.api.generator.gapic.model.Field) Message(com.google.api.generator.gapic.model.Message) ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Test(org.junit.Test)

Example 33 with Message

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);
}
Also used : Message(com.google.api.generator.gapic.model.Message) MethodDescriptor(com.google.protobuf.Descriptors.MethodDescriptor)

Example 34 with Message

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");
}
Also used : Message(com.google.api.generator.gapic.model.Message) HttpBindings(com.google.api.generator.gapic.model.HttpBindings) ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) MethodDescriptor(com.google.protobuf.Descriptors.MethodDescriptor) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Test(org.junit.Test)

Example 35 with Message

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));
}
Also used : Message(com.google.api.generator.gapic.model.Message) ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) MethodDescriptor(com.google.protobuf.Descriptors.MethodDescriptor) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Test(org.junit.Test)

Aggregations

Message (com.google.api.generator.gapic.model.Message)123 ResourceName (com.google.api.generator.gapic.model.ResourceName)85 TypeNode (com.google.api.generator.engine.ast.TypeNode)74 Test (org.junit.Test)68 Method (com.google.api.generator.gapic.model.Method)60 FileDescriptor (com.google.protobuf.Descriptors.FileDescriptor)44 HashSet (java.util.HashSet)39 ArrayList (java.util.ArrayList)36 Service (com.google.api.generator.gapic.model.Service)35 List (java.util.List)34 Expr (com.google.api.generator.engine.ast.Expr)32 Field (com.google.api.generator.gapic.model.Field)31 Descriptors (com.google.protobuf.Descriptors)30 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)29 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)26 ServiceDescriptor (com.google.protobuf.Descriptors.ServiceDescriptor)26 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)25 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)25 Statement (com.google.api.generator.engine.ast.Statement)24 HashMap (java.util.HashMap)23