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