Search in sources :

Example 21 with ResourceName

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

the class ResourceNameParserTest method parseResourceNamesFromMessage_noResourceDefinition.

@Test
public void parseResourceNamesFromMessage_noResourceDefinition() {
    String pakkage = TypeParser.getPackage(lockerServiceFileDescriptor);
    List<Descriptor> messageDescriptors = lockerServiceFileDescriptor.getMessageTypes();
    Descriptor folderMessageDescriptor = messageDescriptors.get(1);
    assertEquals("Folder", folderMessageDescriptor.getName());
    Optional<ResourceName> resourceNameOpt = ResourceNameParser.parseResourceNameFromMessageType(folderMessageDescriptor, pakkage);
    assertFalse(resourceNameOpt.isPresent());
}
Also used : ResourceName(com.google.api.generator.gapic.model.ResourceName) Descriptor(com.google.protobuf.Descriptors.Descriptor) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Test(org.junit.Test)

Example 22 with ResourceName

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

the class ResourceNameParserTest method parseResourceNameFromMessage_basicResourceDefinition.

@Test
public void parseResourceNameFromMessage_basicResourceDefinition() {
    String pakkage = TypeParser.getPackage(lockerServiceFileDescriptor);
    List<Descriptor> messageDescriptors = lockerServiceFileDescriptor.getMessageTypes();
    Descriptor documentMessageDescriptor = messageDescriptors.get(0);
    assertEquals("Document", documentMessageDescriptor.getName());
    Optional<ResourceName> resourceNameOpt = ResourceNameParser.parseResourceNameFromMessageType(documentMessageDescriptor, pakkage);
    assertTrue(resourceNameOpt.isPresent());
    assertEquals("testgapic.googleapis.com/Document", resourceNameOpt.get().resourceTypeString());
}
Also used : ResourceName(com.google.api.generator.gapic.model.ResourceName) Descriptor(com.google.protobuf.Descriptors.Descriptor) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Test(org.junit.Test)

Example 23 with ResourceName

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

the class ResourceNameParserTest method parseResourceNameFromMessage_nonNameResourceReferenceField.

@Test
public void parseResourceNameFromMessage_nonNameResourceReferenceField() {
    String pakkage = TypeParser.getPackage(lockerServiceFileDescriptor);
    List<Descriptor> messageDescriptors = lockerServiceFileDescriptor.getMessageTypes();
    Descriptor binderMessageDescriptor = messageDescriptors.get(2);
    assertEquals("Binder", binderMessageDescriptor.getName());
    Optional<ResourceName> resourceNameOpt = ResourceNameParser.parseResourceNameFromMessageType(binderMessageDescriptor, pakkage);
    assertTrue(resourceNameOpt.isPresent());
    assertEquals("testgapic.googleapis.com/Binder", resourceNameOpt.get().resourceTypeString());
}
Also used : ResourceName(com.google.api.generator.gapic.model.ResourceName) Descriptor(com.google.protobuf.Descriptors.Descriptor) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Test(org.junit.Test)

Example 24 with ResourceName

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

the class ResourceNameParserTest method parseResourceNames_basicTwoPatterns.

@Test
public void parseResourceNames_basicTwoPatterns() {
    Map<String, ResourceName> typeStringsToResourceNames = ResourceNameParser.parseResourceNamesFromFile(lockerServiceFileDescriptor);
    assertEquals(4, typeStringsToResourceNames.size());
    ResourceName resourceName = typeStringsToResourceNames.get("cloudresourcemanager.googleapis.com/Folder");
    assertEquals(2, resourceName.patterns().size());
    assertThat(resourceName.patterns()).contains("projects/{project}/folders/{folder}");
    assertThat(resourceName.patterns()).contains("folders/{folder}");
    assertEquals("folder", resourceName.variableName());
    assertEquals("cloudresourcemanager.googleapis.com/Folder", resourceName.resourceTypeString());
    assertEquals(MAIN_PACKAGE, resourceName.pakkage());
    assertFalse(resourceName.hasParentMessageName());
    assertFalse(resourceName.isOnlyWildcard());
}
Also used : ResourceName(com.google.api.generator.gapic.model.ResourceName) Test(org.junit.Test)

Example 25 with ResourceName

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

the class ResourceReferenceParserTest method parseParentResourceName_createFromPattern.

@Test
public void parseParentResourceName_createFromPattern() {
    String resourceNamePackage = String.format("%s.common", MAIN_PACKAGE);
    String domainName = "cloudbilling.googleapis.com";
    String description = "This is the resource name description";
    String resourceTypeString = String.format("%s/BillingAccount", domainName);
    String parentResourceTypeString = String.format("%s/Project", domainName);
    Map<String, ResourceName> patternsToResourceNames = new HashMap<>();
    String parentPattern = "projects/{project}";
    Optional<ResourceName> parentResourceNameOpt = ResourceReferenceParser.parseParentResourceName(String.format("%s/billingAccounts/{billing_account}", parentPattern), MAIN_PACKAGE, resourceNamePackage, resourceTypeString, description, patternsToResourceNames);
    assertTrue(parentResourceNameOpt.isPresent());
    ResourceName parentResourceName = parentResourceNameOpt.get();
    assertEquals("project", parentResourceName.variableName());
    assertEquals(Arrays.asList(parentPattern), parentResourceName.patterns());
    assertEquals(parentResourceTypeString, parentResourceName.resourceTypeString());
    assertEquals(resourceNamePackage, parentResourceName.pakkage());
    assertEquals(description, parentResourceName.description());
    assertEquals(TypeNode.withReference(VaporReference.builder().setName("ProjectName").setPakkage(resourceNamePackage).build()), parentResourceName.type());
    assertEquals(patternsToResourceNames.get(parentPattern), parentResourceName);
}
Also used : HashMap(java.util.HashMap) ResourceName(com.google.api.generator.gapic.model.ResourceName) 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