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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations