use of com.google.api.generator.gapic.model.GapicClass in project gapic-generator-java by googleapis.
the class ComposerTest method gapicClass_addApacheLicense.
@Test
public void gapicClass_addApacheLicense() {
ClassDefinition classDef = ClassDefinition.builder().setPackageString("com.google.showcase.v1beta1.stub").setName("ComposerPostProcOnFooBar").setScope(ScopeNode.PUBLIC).build();
List<GapicClass> gapicClassWithHeaderList = Composer.addApacheLicense(Arrays.asList(GapicClass.create(Kind.TEST, classDef)));
JavaWriterVisitor visitor = new JavaWriterVisitor();
gapicClassWithHeaderList.get(0).classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "ComposerPostProcOnFooBar.golden", visitor.write());
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "ComposerPostProcOnFooBar.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
use of com.google.api.generator.gapic.model.GapicClass in project gapic-generator-java by googleapis.
the class ServiceStubSettingsClassComposerTest method generateServiceClasses.
@Test
public void generateServiceClasses() {
GapicContext context = RestTestProtoLoader.instance().parseCompliance();
Service echoProtoService = context.services().get(0);
GapicClass clazz = ServiceStubSettingsClassComposer.instance().generate(context, echoProtoService);
JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "ComplianceStubSettings.golden", visitor.write());
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "ComplianceStubSettings.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
use of com.google.api.generator.gapic.model.GapicClass in project gapic-generator-java by googleapis.
the class ServiceSettingsClassComposerTest method generateServiceClasses.
@Test
public void generateServiceClasses() {
GapicContext context = GrpcRestTestProtoLoader.instance().parseShowcaseEcho();
Service echoProtoService = context.services().get(0);
GapicClass clazz = ServiceSettingsClassComposer.instance().generate(context, echoProtoService);
JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "EchoSettings.golden", visitor.write());
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "EchoSettings.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
use of com.google.api.generator.gapic.model.GapicClass in project gapic-generator-java by googleapis.
the class ResourceNameHelperClassComposerTest method generateResourceNameClass_loggingOnePatternMultipleVariables.
@Test
public void generateResourceNameClass_loggingOnePatternMultipleVariables() {
FileDescriptor serviceFileDescriptor = LoggingConfigProto.getDescriptor();
ServiceDescriptor serviceDescriptor = serviceFileDescriptor.getServices().get(0);
assertEquals(serviceDescriptor.getName(), "ConfigServiceV2");
List<FileDescriptor> protoFiles = Arrays.asList(serviceFileDescriptor, LoggingProto.getDescriptor(), 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<>();
Parser.parseService(serviceFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
ResourceName billingAccountLocationResname = resourceNames.get("logging.googleapis.com/BillingAccountLocation");
assertThat(outputResourceNames).contains(billingAccountLocationResname);
GapicClass clazz = ResourceNameHelperClassComposer.instance().generate(billingAccountLocationResname, TestProtoLoader.instance().parseLogging());
JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "BillingAccountLocationName.golden", visitor.write());
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "BillingAccountLocationName.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
use of com.google.api.generator.gapic.model.GapicClass in project gapic-generator-java by googleapis.
the class ResourceNameHelperClassComposerTest method generateResourceNameClass_childSingleton.
@Test
public void generateResourceNameClass_childSingleton() {
ResourceName agentResname = ResourceName.builder().setVariableName("agent").setPakkage("com.google.cloud.dialogflow.v2beta1").setResourceTypeString("dialogflow.googleapis.com/Agent").setPatterns(Arrays.asList("projects/{project}/locations/{location}/agent", "projects/{project}/agent")).setParentMessageName("Agent").setDescription("This is a description").build();
GapicContext irrelevantContext = TestProtoLoader.instance().parseShowcaseEcho();
GapicClass clazz = ResourceNameHelperClassComposer.instance().generate(agentResname, irrelevantContext);
JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "AgentName.golden", visitor.write());
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "AgentName.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Aggregations