Search in sources :

Example 46 with Message

use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.

the class TestProtoLoader method parseShowcaseTesting.

public GapicContext parseShowcaseTesting() {
    FileDescriptor testingFileDescriptor = TestingOuterClass.getDescriptor();
    ServiceDescriptor testingService = testingFileDescriptor.getServices().get(0);
    assertEquals(testingService.getName(), "Testing");
    Map<String, Message> messageTypes = Parser.parseMessages(testingFileDescriptor);
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(testingFileDescriptor);
    Set<ResourceName> outputResourceNames = new HashSet<>();
    List<Service> services = Parser.parseService(testingFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
    return GapicContext.builder().setMessages(messageTypes).setResourceNames(resourceNames).setServices(services).setHelperResourceNames(outputResourceNames).setTransport(transport).build();
}
Also used : Message(com.google.api.generator.gapic.model.Message) ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) ResourceName(com.google.api.generator.gapic.model.ResourceName) Service(com.google.api.generator.gapic.model.Service) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) HashSet(java.util.HashSet)

Example 47 with Message

use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.

the class DefaultValueComposerTest method createSimpleMessage_containsMessagesEnumsAndResourceName.

@Test
public void createSimpleMessage_containsMessagesEnumsAndResourceName() {
    FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    Map<String, ResourceName> typeStringsToResourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Message message = messageTypes.get("com.google.showcase.v1beta1.EchoRequest");
    Expr expr = DefaultValueComposer.createSimpleMessageBuilderValue(message, typeStringsToResourceNames, messageTypes);
    expr.accept(writerVisitor);
    assertEquals("EchoRequest.newBuilder().setName(" + "FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\").toString())" + ".setParent(FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\").toString())" + ".setSeverity(Severity.forNumber(0))" + ".setFoobar(Foobar.newBuilder().build()).build()", writerVisitor.write());
}
Also used : Message(com.google.api.generator.gapic.model.Message) Expr(com.google.api.generator.engine.ast.Expr) ResourceName(com.google.api.generator.gapic.model.ResourceName) ByteString(com.google.protobuf.ByteString) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Test(org.junit.Test)

Example 48 with Message

use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.

the class DefaultValueComposerTest method createSimpleMessage_onlyOneofs.

@Test
public void createSimpleMessage_onlyOneofs() {
    FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    Map<String, ResourceName> typeStringsToResourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Message message = messageTypes.get("com.google.showcase.v1beta1.WaitRequest");
    Expr expr = DefaultValueComposer.createSimpleMessageBuilderValue(message, typeStringsToResourceNames, messageTypes);
    expr.accept(writerVisitor);
    assertEquals("WaitRequest.newBuilder().build()", writerVisitor.write());
}
Also used : Message(com.google.api.generator.gapic.model.Message) Expr(com.google.api.generator.engine.ast.Expr) ResourceName(com.google.api.generator.gapic.model.ResourceName) ByteString(com.google.protobuf.ByteString) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Test(org.junit.Test)

Example 49 with Message

use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.

the class DefaultValueComposerTest method createSimpleMessage_containsRepeatedField.

@Test
public void createSimpleMessage_containsRepeatedField() {
    FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    Map<String, ResourceName> typeStringsToResourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Message message = messageTypes.get("com.google.showcase.v1beta1.PagedExpandResponse");
    Expr expr = DefaultValueComposer.createSimpleMessageBuilderValue(message, typeStringsToResourceNames, messageTypes);
    expr.accept(writerVisitor);
    assertEquals("PagedExpandResponse.newBuilder().addAllResponses(new ArrayList<EchoResponse>())" + ".setNextPageToken(\"nextPageToken-1386094857\").build()", writerVisitor.write());
}
Also used : Message(com.google.api.generator.gapic.model.Message) Expr(com.google.api.generator.engine.ast.Expr) ResourceName(com.google.api.generator.gapic.model.ResourceName) ByteString(com.google.protobuf.ByteString) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Test(org.junit.Test)

Example 50 with Message

use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.

the class BatchingDescriptorComposerTest method batchingDescriptor_hasSubresponseField.

@Test
public void batchingDescriptor_hasSubresponseField() {
    FileDescriptor serviceFileDescriptor = PubsubProto.getDescriptor();
    FileDescriptor commonResourcesFileDescriptor = CommonResources.getDescriptor();
    ServiceDescriptor serviceDescriptor = serviceFileDescriptor.getServices().get(0);
    assertEquals("Publisher", serviceDescriptor.getName());
    Map<String, ResourceName> resourceNames = new HashMap<>();
    resourceNames.putAll(Parser.parseResourceNames(serviceFileDescriptor));
    resourceNames.putAll(Parser.parseResourceNames(commonResourcesFileDescriptor));
    Map<String, Message> messageTypes = Parser.parseMessages(serviceFileDescriptor);
    Set<ResourceName> outputResourceNames = new HashSet<>();
    List<Service> services = Parser.parseService(serviceFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
    String filename = "pubsub_gapic.yaml";
    Path path = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), filename);
    Optional<List<GapicBatchingSettings>> batchingSettingsOpt = BatchingSettingsConfigParser.parse(Optional.of(path.toString()));
    assertTrue(batchingSettingsOpt.isPresent());
    String jsonFilename = "pubsub_grpc_service_config.json";
    Path jsonPath = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), jsonFilename);
    Optional<GapicServiceConfig> configOpt = ServiceConfigParser.parse(jsonPath.toString());
    assertTrue(configOpt.isPresent());
    GapicServiceConfig config = configOpt.get();
    config.setBatchingSettings(batchingSettingsOpt);
    Service service = services.get(0);
    assertEquals("Publisher", service.name());
    Method method = findMethod(service, "Publish");
    GapicBatchingSettings batchingSetting = batchingSettingsOpt.get().get(0);
    assertEquals("Publish", batchingSetting.methodName());
    Expr batchingDescriptorExpr = BatchingDescriptorComposer.createBatchingDescriptorFieldDeclExpr(method, batchingSetting, messageTypes);
    batchingDescriptorExpr.accept(writerVisitor);
    Utils.saveCodegenToFile(this.getClass(), "BatchingDescriptorComposerTestSubresponse.golden", writerVisitor.write());
    Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "BatchingDescriptorComposerTestSubresponse.golden");
    Assert.assertCodeEquals(goldenFilePath, writerVisitor.write());
}
Also used : Path(java.nio.file.Path) Message(com.google.api.generator.gapic.model.Message) HashMap(java.util.HashMap) ResourceName(com.google.api.generator.gapic.model.ResourceName) Service(com.google.api.generator.gapic.model.Service) Method(com.google.api.generator.gapic.model.Method) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Expr(com.google.api.generator.engine.ast.Expr) ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) List(java.util.List) GapicBatchingSettings(com.google.api.generator.gapic.model.GapicBatchingSettings) HashSet(java.util.HashSet) 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