use of com.google.api.generator.gapic.model.Service in project gapic-generator-java by googleapis.
the class RetrySettingsComposerTest method codesDefinitionsBlock_basic.
@Test
public void codesDefinitionsBlock_basic() {
FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
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);
assertEquals(1, services.size());
Service service = services.get(0);
String jsonFilename = "showcase_grpc_service_config.json";
Path jsonPath = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), jsonFilename);
Optional<GapicServiceConfig> serviceConfigOpt = ServiceConfigParser.parse(jsonPath.toString());
assertTrue(serviceConfigOpt.isPresent());
GapicServiceConfig serviceConfig = serviceConfigOpt.get();
BlockStatement paramDefinitionsBlock = RetrySettingsComposer.createRetryCodesDefinitionsBlock(service, serviceConfig, RETRY_CODES_DEFINITIONS_VAR_EXPR);
paramDefinitionsBlock.accept(writerVisitor);
String expected = LineFormatter.lines("static {\n", "ImmutableMap.Builder<String, ImmutableSet<StatusCode.Code>> definitions =" + " ImmutableMap.builder();\n", "definitions.put(\"retry_policy_1_codes\"," + " ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList(StatusCode.Code.UNAVAILABLE," + " StatusCode.Code.UNKNOWN)));\n", "definitions.put(\"no_retry_0_codes\"," + " ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList()));\n", "RETRYABLE_CODE_DEFINITIONS = definitions.build();\n", "}\n");
assertEquals(expected, writerVisitor.write());
}
use of com.google.api.generator.gapic.model.Service in project gapic-generator-java by googleapis.
the class RetrySettingsComposerTest method paramDefinitionsBlock_noConfigsFound.
@Test
public void paramDefinitionsBlock_noConfigsFound() {
GapicContext context = TestProtoLoader.instance().parseShowcaseEcho();
Service service = context.services().get(0);
String jsonFilename = "retrying_grpc_service_config.json";
Path jsonPath = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), jsonFilename);
Optional<GapicServiceConfig> serviceConfigOpt = ServiceConfigParser.parse(jsonPath.toString());
assertTrue(serviceConfigOpt.isPresent());
GapicServiceConfig serviceConfig = serviceConfigOpt.get();
BlockStatement paramDefinitionsBlock = RetrySettingsComposer.createRetryParamDefinitionsBlock(service, serviceConfig, RETRY_PARAM_DEFINITIONS_VAR_EXPR);
paramDefinitionsBlock.accept(writerVisitor);
String expected = LineFormatter.lines("static {\n", "ImmutableMap.Builder<String, RetrySettings> definitions = ImmutableMap.builder();\n", "RetrySettings settings = null;\n", "settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build();\n", "definitions.put(\"no_retry_params\", settings);\n", "RETRY_PARAM_DEFINITIONS = definitions.build();\n", "}\n");
assertEquals(expected, writerVisitor.write());
}
use of com.google.api.generator.gapic.model.Service in project gapic-generator-java by googleapis.
the class RetrySettingsComposerTest method codesDefinitionsBlock_noConfigsFound.
@Test
public void codesDefinitionsBlock_noConfigsFound() {
FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
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);
assertEquals(1, services.size());
Service service = services.get(0);
String jsonFilename = "retrying_grpc_service_config.json";
Path jsonPath = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), jsonFilename);
Optional<GapicServiceConfig> serviceConfigOpt = ServiceConfigParser.parse(jsonPath.toString());
assertTrue(serviceConfigOpt.isPresent());
GapicServiceConfig serviceConfig = serviceConfigOpt.get();
BlockStatement paramDefinitionsBlock = RetrySettingsComposer.createRetryCodesDefinitionsBlock(service, serviceConfig, RETRY_CODES_DEFINITIONS_VAR_EXPR);
paramDefinitionsBlock.accept(writerVisitor);
String expected = LineFormatter.lines("static {\n", "ImmutableMap.Builder<String, ImmutableSet<StatusCode.Code>> definitions =" + " ImmutableMap.builder();\n", "definitions.put(\"no_retry_codes\"," + " ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList()));\n", "RETRYABLE_CODE_DEFINITIONS = definitions.build();\n", "}\n");
assertEquals(expected, writerVisitor.write());
}
use of com.google.api.generator.gapic.model.Service 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.Service in project gapic-generator-java by googleapis.
the class ServiceClientHeaderSampleComposerTest method composeClassHeaderSample_firstMethodIsStream.
@Test
public void composeClassHeaderSample_firstMethodIsStream() {
Descriptors.FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
TypeNode inputType = TypeNode.withReference(VaporReference.builder().setName("ExpandRequest").setPakkage(SHOWCASE_PACKAGE_NAME).build());
TypeNode outputType = TypeNode.withReference(VaporReference.builder().setName("EchoResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
Method method = Method.builder().setName("Expand").setInputType(inputType).setOutputType(outputType).setStream(Method.Stream.SERVER).build();
Service service = Service.builder().setName("Echo").setDefaultHost("localhost:7469").setOauthScopes(Arrays.asList("https://www.googleapis.com/auth/cloud-platform")).setPakkage(SHOWCASE_PACKAGE_NAME).setProtoPakkage(SHOWCASE_PACKAGE_NAME).setOriginalJavaPackage(SHOWCASE_PACKAGE_NAME).setOverriddenName("Echo").setMethods(Arrays.asList(method)).build();
TypeNode clientType = TypeNode.withReference(VaporReference.builder().setName("EchoClient").setPakkage(SHOWCASE_PACKAGE_NAME).build());
String results = writeStatements(ServiceClientHeaderSampleComposer.composeClassHeaderSample(service, clientType, resourceNames, messageTypes));
String expected = LineFormatter.lines("try (EchoClient echoClient = EchoClient.create()) {\n", " ExpandRequest request =\n", " ExpandRequest.newBuilder().setContent(\"content951530617\").setInfo(\"info3237038\").build();\n", " ServerStream<EchoResponse> stream = echoClient.expandCallable().call(request);\n", " for (EchoResponse response : stream) {\n", " // Do something when a response is received.\n", " }\n", "}");
Assert.assertEquals(results, expected);
}
Aggregations