use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class ServiceClientMethodSampleComposerTest method valid_composeDefaultSample_pureUnaryReturnResponse.
@Test
public void valid_composeDefaultSample_pureUnaryReturnResponse() {
FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
TypeNode clientType = TypeNode.withReference(VaporReference.builder().setName("EchoClient").setPakkage(SHOWCASE_PACKAGE_NAME).build());
TypeNode inputType = TypeNode.withReference(VaporReference.builder().setName("EchoRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("EchoResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
Method method = Method.builder().setName("Echo").setInputType(inputType).setOutputType(outputType).setMethodSignatures(Collections.emptyList()).build();
String results = writeStatements(ServiceClientMethodSampleComposer.composeCanonicalSample(method, clientType, resourceNames, messageTypes));
String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", " EchoRequest request =\n", " EchoRequest.newBuilder()\n", " .setName(FoobarName.ofProjectFoobarName(\"[PROJECT]\"," + " \"[FOOBAR]\").toString())\n", " .setParent(FoobarName.ofProjectFoobarName(\"[PROJECT]\"," + " \"[FOOBAR]\").toString())\n", " .setSeverity(Severity.forNumber(0))\n", " .setFoobar(Foobar.newBuilder().build())\n", " .build();\n", " EchoResponse response = echoClient.echo(request);\n", "}");
Assert.assertEquals(results, expected);
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class ServiceClientMethodSampleComposerTest method invalid_composeDefaultSample_isPagedMethod.
@Test
public void invalid_composeDefaultSample_isPagedMethod() {
FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
TypeNode clientType = TypeNode.withReference(VaporReference.builder().setName("EchoClient").setPakkage(SHOWCASE_PACKAGE_NAME).build());
TypeNode inputType = TypeNode.withReference(VaporReference.builder().setName("NotExistRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("PagedExpandResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
Method method = Method.builder().setName("PagedExpand").setInputType(inputType).setOutputType(outputType).setMethodSignatures(Collections.emptyList()).setPageSizeFieldName(PAGINATED_FIELD_NAME).build();
Assert.assertThrows(NullPointerException.class, () -> ServiceClientMethodSampleComposer.composeCanonicalSample(method, clientType, resourceNames, messageTypes));
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class ServiceClientMethodSampleComposerTest method valid_composeDefaultSample_pureUnaryReturnVoid.
@Test
public void valid_composeDefaultSample_pureUnaryReturnVoid() {
FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
TypeNode clientType = TypeNode.withReference(VaporReference.builder().setName("EchoClient").setPakkage(SHOWCASE_PACKAGE_NAME).build());
TypeNode inputType = TypeNode.withReference(VaporReference.builder().setName("EchoRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("Empty").setPakkage(PROTO_PACKAGE_NAME).build());
Method method = Method.builder().setName("Echo").setInputType(inputType).setOutputType(outputType).setMethodSignatures(Collections.emptyList()).build();
String results = writeStatements(ServiceClientMethodSampleComposer.composeCanonicalSample(method, clientType, resourceNames, messageTypes));
String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", " EchoRequest request =\n", " EchoRequest.newBuilder()\n", " .setName(FoobarName.ofProjectFoobarName(\"[PROJECT]\"," + " \"[FOOBAR]\").toString())\n", " .setParent(FoobarName.ofProjectFoobarName(\"[PROJECT]\"," + " \"[FOOBAR]\").toString())\n", " .setSeverity(Severity.forNumber(0))\n", " .setFoobar(Foobar.newBuilder().build())\n", " .build();\n", " echoClient.echo(request);\n", "}");
Assert.assertEquals(results, expected);
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class TestProtoLoader method parseLogging.
public GapicContext parseLogging() {
FileDescriptor serviceFileDescriptor = LoggingProto.getDescriptor();
ServiceDescriptor serviceDescriptor = serviceFileDescriptor.getServices().get(0);
assertEquals(serviceDescriptor.getName(), "LoggingServiceV2");
List<FileDescriptor> protoFiles = Arrays.asList(serviceFileDescriptor, 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<>();
List<Service> services = Parser.parseService(serviceFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
String filename = "logging_gapic.yaml";
Path path = Paths.get(getTestFilesDirectory(), filename);
Optional<List<GapicBatchingSettings>> batchingSettingsOpt = BatchingSettingsConfigParser.parse(Optional.of(path.toString()));
assertTrue(batchingSettingsOpt.isPresent());
String jsonFilename = "logging_grpc_service_config.json";
Path jsonPath = Paths.get(getTestFilesDirectory(), jsonFilename);
Optional<GapicServiceConfig> configOpt = ServiceConfigParser.parse(jsonPath.toString());
assertTrue(configOpt.isPresent());
GapicServiceConfig config = configOpt.get();
config.setBatchingSettings(batchingSettingsOpt);
return GapicContext.builder().setMessages(messageTypes).setResourceNames(resourceNames).setServices(services).setServiceConfig(config).setHelperResourceNames(outputResourceNames).setTransport(transport).build();
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class TestProtoLoader method parseShowcaseEcho.
public GapicContext parseShowcaseEcho() {
FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
ServiceDescriptor echoServiceDescriptor = echoFileDescriptor.getServices().get(0);
assertEquals(echoServiceDescriptor.getName(), "Echo");
Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
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(testFilesDirectory, 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(transport).build();
}
Aggregations