Search in sources :

Example 36 with Service

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

the class ServiceClientHeaderSampleComposerTest method composeClassHeaderSample_unaryRpc.

/*Testing composeClassHeaderSample*/
@Test
public void composeClassHeaderSample_unaryRpc() {
    Descriptors.FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    Set<ResourceName> outputResourceNames = new HashSet<>();
    List<Service> services = Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
    Service echoProtoService = services.get(0);
    TypeNode clientType = TypeNode.withReference(VaporReference.builder().setName("EchoClient").setPakkage(SHOWCASE_PACKAGE_NAME).build());
    Sample sample = ServiceClientHeaderSampleComposer.composeClassHeaderSample(echoProtoService, clientType, resourceNames, messageTypes);
    String results = writeStatements(sample);
    String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", "  EchoResponse response = echoClient.echo();\n", "}");
    Assert.assertEquals(expected, results);
}
Also used : Message(com.google.api.generator.gapic.model.Message) ResourceName(com.google.api.generator.gapic.model.ResourceName) Sample(com.google.api.generator.gapic.model.Sample) Service(com.google.api.generator.gapic.model.Service) Descriptors(com.google.protobuf.Descriptors) TypeNode(com.google.api.generator.engine.ast.TypeNode) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 37 with Service

use of com.google.api.generator.gapic.model.Service 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());
}
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 38 with Service

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

the class ServiceSettingsClassComposerTest method generateServiceSettingsClasses.

@Test
public void generateServiceSettingsClasses() {
    Service service = context.services().get(0);
    GapicClass clazz = ServiceSettingsClassComposer.instance().generate(context, service);
    Assert.assertGoldenClass(this.getClass(), clazz, name + ".golden");
    Assert.assertGoldenSamples(this.getClass(), "servicesettings", clazz.classDefinition().packageString(), clazz.samples());
}
Also used : GapicClass(com.google.api.generator.gapic.model.GapicClass) Service(com.google.api.generator.gapic.model.Service) Test(org.junit.Test)

Example 39 with Service

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

the class ServiceStubSettingsClassComposerTest method generateServiceStubSettingsClasses.

@Test
public void generateServiceStubSettingsClasses() {
    Service service = context.services().get(0);
    GapicClass clazz = ServiceStubSettingsClassComposer.instance().generate(context, service);
    Assert.assertGoldenClass(this.getClass(), clazz, name + ".golden");
    Assert.assertGoldenSamples(this.getClass(), "servicesettings/stub", clazz.classDefinition().packageString(), clazz.samples());
}
Also used : GapicClass(com.google.api.generator.gapic.model.GapicClass) Service(com.google.api.generator.gapic.model.Service) Test(org.junit.Test)

Example 40 with Service

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

the class GrpcRestTestProtoLoader method parseShowcaseEcho.

@Override
public GapicContext parseShowcaseEcho() {
    FileDescriptor echoFileDescriptor = EchoGrpcrest.getDescriptor();
    ServiceDescriptor echoServiceDescriptor = echoFileDescriptor.getServices().get(0);
    assertEquals("Echo", echoServiceDescriptor.getName());
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    Map<String, Message> operationMessageTypes = Parser.parseMessages(OperationsProto.getDescriptor());
    messageTypes.putAll(operationMessageTypes);
    Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
    Set<ResourceName> outputResourceNames = new HashSet<>();
    List<Service> services = Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
    String jsonFilename = "showcase_grpc_service_config.json";
    Path jsonPath = Paths.get(getTestFilesDirectory(), jsonFilename);
    Optional<GapicServiceConfig> configOpt = ServiceConfigParser.parse(jsonPath.toString());
    assertTrue(configOpt.isPresent());
    GapicServiceConfig config = configOpt.get();
    return GapicContext.builder().setMessages(messageTypes).setResourceNames(resourceNames).setServices(services).setServiceConfig(config).setHelperResourceNames(outputResourceNames).setTransport(getTransport()).build();
}
Also used : Path(java.nio.file.Path) Message(com.google.api.generator.gapic.model.Message) ResourceName(com.google.api.generator.gapic.model.ResourceName) Service(com.google.api.generator.gapic.model.Service) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) HashSet(java.util.HashSet)

Aggregations

Service (com.google.api.generator.gapic.model.Service)87 GapicContext (com.google.api.generator.gapic.model.GapicContext)54 GapicClass (com.google.api.generator.gapic.model.GapicClass)48 Message (com.google.api.generator.gapic.model.Message)45 Test (org.junit.Test)45 Method (com.google.api.generator.gapic.model.Method)39 List (java.util.List)39 TypeNode (com.google.api.generator.engine.ast.TypeNode)37 ResourceName (com.google.api.generator.gapic.model.ResourceName)35 Expr (com.google.api.generator.engine.ast.Expr)34 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)32 GapicServiceConfig (com.google.api.generator.gapic.model.GapicServiceConfig)32 ArrayList (java.util.ArrayList)32 Arrays (java.util.Arrays)32 Collectors (java.util.stream.Collectors)32 Path (java.nio.file.Path)31 HashSet (java.util.HashSet)31 Function (java.util.function.Function)31 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)30 Preconditions (com.google.common.base.Preconditions)30