Search in sources :

Example 6 with GapicServiceConfig

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

the class TestProtoLoader method parseLogging.

public GapicContext parseLogging() {
    FileDescriptor serviceFileDescriptor = LoggingProto.getDescriptor();
    ServiceDescriptor serviceDescriptor = serviceFileDescriptor.getServices().get(0);
    assertEquals(serviceDescriptor.getName(), "LoggingServiceV2");
    List<FileDescriptor> protoFiles = Arrays.asList(serviceFileDescriptor, LogEntryProto.getDescriptor(), LoggingConfigProto.getDescriptor(), LoggingMetricsProto.getDescriptor());
    Map<String, ResourceName> resourceNames = new HashMap<>();
    Map<String, Message> messageTypes = new HashMap<>();
    for (FileDescriptor fileDescriptor : protoFiles) {
        resourceNames.putAll(Parser.parseResourceNames(fileDescriptor));
        messageTypes.putAll(Parser.parseMessages(fileDescriptor));
    }
    // Additional resource names.
    FileDescriptor commonResourcesFileDescriptor = CommonResources.getDescriptor();
    resourceNames.putAll(Parser.parseResourceNames(commonResourcesFileDescriptor));
    Set<ResourceName> outputResourceNames = new HashSet<>();
    List<Service> services = Parser.parseService(serviceFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
    String filename = "logging_gapic.yaml";
    Path path = Paths.get(getTestFilesDirectory(), filename);
    Optional<List<GapicBatchingSettings>> batchingSettingsOpt = BatchingSettingsConfigParser.parse(Optional.of(path.toString()));
    assertTrue(batchingSettingsOpt.isPresent());
    String jsonFilename = "logging_grpc_service_config.json";
    Path jsonPath = Paths.get(getTestFilesDirectory(), jsonFilename);
    Optional<GapicServiceConfig> configOpt = ServiceConfigParser.parse(jsonPath.toString());
    assertTrue(configOpt.isPresent());
    GapicServiceConfig config = configOpt.get();
    config.setBatchingSettings(batchingSettingsOpt);
    return GapicContext.builder().setMessages(messageTypes).setResourceNames(resourceNames).setServices(services).setServiceConfig(config).setHelperResourceNames(outputResourceNames).setTransport(transport).build();
}
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) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) List(java.util.List) HashSet(java.util.HashSet)

Example 7 with GapicServiceConfig

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

the class TestProtoLoader method parseShowcaseEcho.

public GapicContext parseShowcaseEcho() {
    FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
    ServiceDescriptor echoServiceDescriptor = echoFileDescriptor.getServices().get(0);
    assertEquals(echoServiceDescriptor.getName(), "Echo");
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Set<ResourceName> outputResourceNames = new HashSet<>();
    List<Service> services = Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
    String jsonFilename = "showcase_grpc_service_config.json";
    Path jsonPath = Paths.get(testFilesDirectory, jsonFilename);
    Optional<GapicServiceConfig> configOpt = ServiceConfigParser.parse(jsonPath.toString());
    assertTrue(configOpt.isPresent());
    GapicServiceConfig config = configOpt.get();
    return GapicContext.builder().setMessages(messageTypes).setResourceNames(resourceNames).setServices(services).setServiceConfig(config).setHelperResourceNames(outputResourceNames).setTransport(transport).build();
}
Also used : Path(java.nio.file.Path) Message(com.google.api.generator.gapic.model.Message) ResourceName(com.google.api.generator.gapic.model.ResourceName) Service(com.google.api.generator.gapic.model.Service) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) HashSet(java.util.HashSet)

Example 8 with GapicServiceConfig

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

the class TestProtoLoader method parsePubSubPublisher.

public GapicContext parsePubSubPublisher() {
    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(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(getTestFilesDirectory(), jsonFilename);
    Optional<GapicServiceConfig> configOpt = ServiceConfigParser.parse(jsonPath.toString());
    assertTrue(configOpt.isPresent());
    GapicServiceConfig config = configOpt.get();
    config.setBatchingSettings(batchingSettingsOpt);
    return GapicContext.builder().setMessages(messageTypes).setResourceNames(resourceNames).setServices(services).setServiceConfig(config).setHelperResourceNames(outputResourceNames).setTransport(transport).build();
}
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) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) List(java.util.List) HashSet(java.util.HashSet)

Example 9 with GapicServiceConfig

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

the class TestProtoLoader method parseBookshopService.

public GapicContext parseBookshopService() {
    FileDescriptor fileDescriptor = BookshopProto.getDescriptor();
    ServiceDescriptor serviceDescriptor = fileDescriptor.getServices().get(0);
    assertEquals(serviceDescriptor.getName(), "Bookshop");
    Map<String, Message> messageTypes = Parser.parseMessages(fileDescriptor);
    Map<String, ResourceName> resourceNames = new HashMap<>();
    Set<ResourceName> outputResourceNames = new HashSet<>();
    List<Service> services = Parser.parseService(fileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
    String jsonFilename = "bookshop_grpc_service_config.json";
    Path jsonPath = Paths.get(testFilesDirectory, jsonFilename);
    Optional<GapicServiceConfig> configOpt = ServiceConfigParser.parse(jsonPath.toString());
    assertTrue(configOpt.isPresent());
    GapicServiceConfig config = configOpt.get();
    return GapicContext.builder().setMessages(messageTypes).setResourceNames(resourceNames).setServices(services).setServiceConfig(config).setHelperResourceNames(outputResourceNames).setTransport(transport).build();
}
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) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) HashSet(java.util.HashSet)

Example 10 with GapicServiceConfig

use of com.google.api.generator.gapic.model.GapicServiceConfig 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

GapicServiceConfig (com.google.api.generator.gapic.model.GapicServiceConfig)28 Service (com.google.api.generator.gapic.model.Service)26 Message (com.google.api.generator.gapic.model.Message)19 HashSet (java.util.HashSet)19 Path (java.nio.file.Path)17 ResourceName (com.google.api.generator.gapic.model.ResourceName)16 FileDescriptor (com.google.protobuf.Descriptors.FileDescriptor)16 List (java.util.List)15 GapicBatchingSettings (com.google.api.generator.gapic.model.GapicBatchingSettings)13 Method (com.google.api.generator.gapic.model.Method)13 Expr (com.google.api.generator.engine.ast.Expr)12 ServiceDescriptor (com.google.protobuf.Descriptors.ServiceDescriptor)12 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)11 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 TypeNode (com.google.api.generator.engine.ast.TypeNode)9 GapicContext (com.google.api.generator.gapic.model.GapicContext)9 Preconditions (com.google.common.base.Preconditions)9 ImmutableSet (com.google.common.collect.ImmutableSet)9 Arrays (java.util.Arrays)9