use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class TestProtoLoader method parseShowcaseTesting.
public GapicContext parseShowcaseTesting() {
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<>();
List<Service> services = Parser.parseService(testingFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
return GapicContext.builder().setMessages(messageTypes).setResourceNames(resourceNames).setServices(services).setHelperResourceNames(outputResourceNames).setTransport(transport).build();
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class DefaultValueComposerTest method createSimpleMessage_containsMessagesEnumsAndResourceName.
@Test
public void createSimpleMessage_containsMessagesEnumsAndResourceName() {
FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
Map<String, ResourceName> typeStringsToResourceNames = Parser.parseResourceNames(echoFileDescriptor);
Message message = messageTypes.get("com.google.showcase.v1beta1.EchoRequest");
Expr expr = DefaultValueComposer.createSimpleMessageBuilderValue(message, typeStringsToResourceNames, messageTypes);
expr.accept(writerVisitor);
assertEquals("EchoRequest.newBuilder().setName(" + "FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\").toString())" + ".setParent(FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\").toString())" + ".setSeverity(Severity.forNumber(0))" + ".setFoobar(Foobar.newBuilder().build()).build()", writerVisitor.write());
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class DefaultValueComposerTest method createSimpleMessage_onlyOneofs.
@Test
public void createSimpleMessage_onlyOneofs() {
FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
Map<String, ResourceName> typeStringsToResourceNames = Parser.parseResourceNames(echoFileDescriptor);
Message message = messageTypes.get("com.google.showcase.v1beta1.WaitRequest");
Expr expr = DefaultValueComposer.createSimpleMessageBuilderValue(message, typeStringsToResourceNames, messageTypes);
expr.accept(writerVisitor);
assertEquals("WaitRequest.newBuilder().build()", writerVisitor.write());
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class DefaultValueComposerTest method createSimpleMessage_containsRepeatedField.
@Test
public void createSimpleMessage_containsRepeatedField() {
FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor();
Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
Map<String, ResourceName> typeStringsToResourceNames = Parser.parseResourceNames(echoFileDescriptor);
Message message = messageTypes.get("com.google.showcase.v1beta1.PagedExpandResponse");
Expr expr = DefaultValueComposer.createSimpleMessageBuilderValue(message, typeStringsToResourceNames, messageTypes);
expr.accept(writerVisitor);
assertEquals("PagedExpandResponse.newBuilder().addAllResponses(new ArrayList<EchoResponse>())" + ".setNextPageToken(\"nextPageToken-1386094857\").build()", writerVisitor.write());
}
use of com.google.api.generator.gapic.model.Message in project gapic-generator-java by googleapis.
the class BatchingDescriptorComposerTest method batchingDescriptor_hasSubresponseField.
@Test
public void batchingDescriptor_hasSubresponseField() {
FileDescriptor serviceFileDescriptor = PubsubProto.getDescriptor();
FileDescriptor commonResourcesFileDescriptor = CommonResources.getDescriptor();
ServiceDescriptor serviceDescriptor = serviceFileDescriptor.getServices().get(0);
assertEquals("Publisher", serviceDescriptor.getName());
Map<String, ResourceName> resourceNames = new HashMap<>();
resourceNames.putAll(Parser.parseResourceNames(serviceFileDescriptor));
resourceNames.putAll(Parser.parseResourceNames(commonResourcesFileDescriptor));
Map<String, Message> messageTypes = Parser.parseMessages(serviceFileDescriptor);
Set<ResourceName> outputResourceNames = new HashSet<>();
List<Service> services = Parser.parseService(serviceFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
String filename = "pubsub_gapic.yaml";
Path path = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), filename);
Optional<List<GapicBatchingSettings>> batchingSettingsOpt = BatchingSettingsConfigParser.parse(Optional.of(path.toString()));
assertTrue(batchingSettingsOpt.isPresent());
String jsonFilename = "pubsub_grpc_service_config.json";
Path jsonPath = Paths.get(TestProtoLoader.instance().getTestFilesDirectory(), jsonFilename);
Optional<GapicServiceConfig> configOpt = ServiceConfigParser.parse(jsonPath.toString());
assertTrue(configOpt.isPresent());
GapicServiceConfig config = configOpt.get();
config.setBatchingSettings(batchingSettingsOpt);
Service service = services.get(0);
assertEquals("Publisher", service.name());
Method method = findMethod(service, "Publish");
GapicBatchingSettings batchingSetting = batchingSettingsOpt.get().get(0);
assertEquals("Publish", batchingSetting.methodName());
Expr batchingDescriptorExpr = BatchingDescriptorComposer.createBatchingDescriptorFieldDeclExpr(method, batchingSetting, messageTypes);
batchingDescriptorExpr.accept(writerVisitor);
Utils.saveCodegenToFile(this.getClass(), "BatchingDescriptorComposerTestSubresponse.golden", writerVisitor.write());
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "BatchingDescriptorComposerTestSubresponse.golden");
Assert.assertCodeEquals(goldenFilePath, writerVisitor.write());
}
Aggregations