Search in sources :

Example 36 with ResourceName

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

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

the class DefaultValueComposerTest method defaultValue_wildcardResourceNameWithOnlyDeletedTopic.

@Test
public void defaultValue_wildcardResourceNameWithOnlyDeletedTopic() {
    // Edge case that should never happen in practice.
    // Wildcard, but the resource names map has only other names that contain only the deleted-topic
    // constant.
    FileDescriptor lockerServiceFileDescriptor = LockerProto.getDescriptor();
    Map<String, ResourceName> typeStringsToResourceNames = Parser.parseResourceNames(lockerServiceFileDescriptor);
    ResourceName resourceName = typeStringsToResourceNames.get("cloudresourcemanager.googleapis.com/Anything");
    ResourceName topicResourceName = typeStringsToResourceNames.get("pubsub.googleapis.com/Topic");
    typeStringsToResourceNames.clear();
    typeStringsToResourceNames.put(topicResourceName.resourceTypeString(), topicResourceName);
    Expr expr = DefaultValueComposer.createResourceHelperValue(resourceName, false, typeStringsToResourceNames.values().stream().collect(Collectors.toList()), "ignored");
    expr.accept(writerVisitor);
    assertEquals("TopicName.ofDeletedTopic()", writerVisitor.write());
}
Also used : 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 38 with ResourceName

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

the class DefaultValueComposerTest method defaultValue_resourceNameWithOnePattern.

@Test
public void defaultValue_resourceNameWithOnePattern() {
    FileDescriptor lockerServiceFileDescriptor = LockerProto.getDescriptor();
    Map<String, ResourceName> typeStringsToResourceNames = Parser.parseResourceNames(lockerServiceFileDescriptor);
    ResourceName resourceName = typeStringsToResourceNames.get("cloudbilling.googleapis.com/BillingAccount");
    Expr expr = DefaultValueComposer.createResourceHelperValue(resourceName, false, typeStringsToResourceNames.values().stream().collect(Collectors.toList()), "ignored");
    expr.accept(writerVisitor);
    assertEquals("BillingAccountName.of(\"[BILLING_ACCOUNT]\")", writerVisitor.write());
}
Also used : 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 39 with ResourceName

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

the class DefaultValueComposerTest method defaultValue_resourceNameWithMultiplePatterns.

@Test
public void defaultValue_resourceNameWithMultiplePatterns() {
    FileDescriptor lockerServiceFileDescriptor = LockerProto.getDescriptor();
    Map<String, ResourceName> typeStringsToResourceNames = Parser.parseResourceNames(lockerServiceFileDescriptor);
    ResourceName resourceName = typeStringsToResourceNames.get("cloudresourcemanager.googleapis.com/Folder");
    Expr expr = DefaultValueComposer.createResourceHelperValue(resourceName, false, typeStringsToResourceNames.values().stream().collect(Collectors.toList()), "ignored");
    expr.accept(writerVisitor);
    assertEquals("FolderName.ofProjectFolderName(\"[PROJECT]\", \"[FOLDER]\")", writerVisitor.write());
}
Also used : 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 40 with ResourceName

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

Aggregations

ResourceName (com.google.api.generator.gapic.model.ResourceName)112 Message (com.google.api.generator.gapic.model.Message)82 Test (org.junit.Test)76 TypeNode (com.google.api.generator.engine.ast.TypeNode)58 Method (com.google.api.generator.gapic.model.Method)50 FileDescriptor (com.google.protobuf.Descriptors.FileDescriptor)47 HashSet (java.util.HashSet)35 Descriptors (com.google.protobuf.Descriptors)30 List (java.util.List)29 Expr (com.google.api.generator.engine.ast.Expr)28 Service (com.google.api.generator.gapic.model.Service)28 HashMap (java.util.HashMap)28 ServiceDescriptor (com.google.protobuf.Descriptors.ServiceDescriptor)20 ArrayList (java.util.ArrayList)19 Preconditions (com.google.common.base.Preconditions)18 Path (java.nio.file.Path)18 Map (java.util.Map)18 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)17 Field (com.google.api.generator.gapic.model.Field)17 GapicClass (com.google.api.generator.gapic.model.GapicClass)17