Search in sources :

Example 16 with JavaWriterVisitor

use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.

the class ResourceNameHelperClassComposerTest method generateResourceNameClass_testingBlueprintPatternWithNonSlashSeparator.

@Test
public void generateResourceNameClass_testingBlueprintPatternWithNonSlashSeparator() {
    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<>();
    Parser.parseService(testingFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
    ResourceName testResname = resourceNames.get("showcase.googleapis.com/Test");
    assertThat(outputResourceNames).contains(testResname);
    GapicClass clazz = ResourceNameHelperClassComposer.instance().generate(testResname, TestProtoLoader.instance().parseShowcaseTesting());
    JavaWriterVisitor visitor = new JavaWriterVisitor();
    clazz.classDefinition().accept(visitor);
    Utils.saveCodegenToFile(this.getClass(), "TestName.golden", visitor.write());
    Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "TestName.golden");
    Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Also used : Path(java.nio.file.Path) Message(com.google.api.generator.gapic.model.Message) ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) ResourceName(com.google.api.generator.gapic.model.ResourceName) GapicClass(com.google.api.generator.gapic.model.GapicClass) JavaWriterVisitor(com.google.api.generator.engine.writer.JavaWriterVisitor) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with JavaWriterVisitor

use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.

the class HttpJsonServiceCallableFactoryClassComposerTest method generateServiceClasses.

@Test
public void generateServiceClasses() {
    GapicContext context = RestTestProtoLoader.instance().parseCompliance();
    Service echoProtoService = context.services().get(0);
    GapicClass clazz = HttpJsonServiceCallableFactoryClassComposer.instance().generate(context, echoProtoService);
    JavaWriterVisitor visitor = new JavaWriterVisitor();
    clazz.classDefinition().accept(visitor);
    Utils.saveCodegenToFile(this.getClass(), "HttpJsonComplianceCallableFactory.golden", visitor.write());
    Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "HttpJsonComplianceCallableFactory.golden");
    Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Also used : Path(java.nio.file.Path) GapicClass(com.google.api.generator.gapic.model.GapicClass) Service(com.google.api.generator.gapic.model.Service) JavaWriterVisitor(com.google.api.generator.engine.writer.JavaWriterVisitor) GapicContext(com.google.api.generator.gapic.model.GapicContext) Test(org.junit.Test)

Example 18 with JavaWriterVisitor

use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.

the class HttpJsonServiceStubClassComposerTest method generateServiceClasses.

@Test
public void generateServiceClasses() {
    GapicContext context = RestTestProtoLoader.instance().parseCompliance();
    Service echoProtoService = context.services().get(0);
    GapicClass clazz = HttpJsonServiceStubClassComposer.instance().generate(context, echoProtoService);
    JavaWriterVisitor visitor = new JavaWriterVisitor();
    clazz.classDefinition().accept(visitor);
    Utils.saveCodegenToFile(this.getClass(), "HttpJsonComplianceStub.golden", visitor.write());
    Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "HttpJsonComplianceStub.golden");
    Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Also used : Path(java.nio.file.Path) GapicClass(com.google.api.generator.gapic.model.GapicClass) Service(com.google.api.generator.gapic.model.Service) JavaWriterVisitor(com.google.api.generator.engine.writer.JavaWriterVisitor) GapicContext(com.google.api.generator.gapic.model.GapicContext) Test(org.junit.Test)

Example 19 with JavaWriterVisitor

use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.

the class ServiceClientTestClassComposerTest method generateServiceClasses.

@Test
public void generateServiceClasses() {
    GapicContext context = RestTestProtoLoader.instance().parseCompliance();
    Service echoProtoService = context.services().get(0);
    GapicClass clazz = ServiceClientTestClassComposer.instance().generate(context, echoProtoService);
    JavaWriterVisitor visitor = new JavaWriterVisitor();
    clazz.classDefinition().accept(visitor);
    Utils.saveCodegenToFile(this.getClass(), "ComplianceClientTest.golden", visitor.write());
    Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "ComplianceClientTest.golden");
    assertCodeEquals(goldenFilePath, visitor.write());
}
Also used : Path(java.nio.file.Path) GapicClass(com.google.api.generator.gapic.model.GapicClass) Service(com.google.api.generator.gapic.model.Service) JavaWriterVisitor(com.google.api.generator.engine.writer.JavaWriterVisitor) GapicContext(com.google.api.generator.gapic.model.GapicContext) Test(org.junit.Test)

Example 20 with JavaWriterVisitor

use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.

the class GrpcServiceStubClassComposerTest method generateServiceClasses.

@Test
public void generateServiceClasses() {
    GapicContext context = GrpcRestTestProtoLoader.instance().parseShowcaseEcho();
    Service echoProtoService = context.services().get(0);
    GapicClass clazz = GrpcServiceStubClassComposer.instance().generate(context, echoProtoService);
    JavaWriterVisitor visitor = new JavaWriterVisitor();
    clazz.classDefinition().accept(visitor);
    Utils.saveCodegenToFile(this.getClass(), "GrpcEchoStub.golden", visitor.write());
    Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "GrpcEchoStub.golden");
    Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Also used : Path(java.nio.file.Path) GapicClass(com.google.api.generator.gapic.model.GapicClass) Service(com.google.api.generator.gapic.model.Service) JavaWriterVisitor(com.google.api.generator.engine.writer.JavaWriterVisitor) GapicContext(com.google.api.generator.gapic.model.GapicContext) Test(org.junit.Test)

Aggregations

JavaWriterVisitor (com.google.api.generator.engine.writer.JavaWriterVisitor)25 Path (java.nio.file.Path)22 GapicClass (com.google.api.generator.gapic.model.GapicClass)21 Test (org.junit.Test)21 GapicContext (com.google.api.generator.gapic.model.GapicContext)15 Service (com.google.api.generator.gapic.model.Service)14 ResourceName (com.google.api.generator.gapic.model.ResourceName)5 Message (com.google.api.generator.gapic.model.Message)4 HashSet (java.util.HashSet)4 FileDescriptor (com.google.protobuf.Descriptors.FileDescriptor)3 ServiceDescriptor (com.google.protobuf.Descriptors.ServiceDescriptor)3 ClassDefinition (com.google.api.generator.engine.ast.ClassDefinition)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)1 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)1 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)1 Statement (com.google.api.generator.engine.ast.Statement)1 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)1 ByteString (com.google.protobuf.ByteString)1 CodeGeneratorResponse (com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse)1