use of com.google.api.generator.gapic.model.Field in project gapic-generator-java by googleapis.
the class ServiceClientCallableMethodSampleComposerTest method invalid_composeRegularCallableMethod_noRepeatedResponsePagedRpc.
@Test
public void invalid_composeRegularCallableMethod_noRepeatedResponsePagedRpc() {
Descriptors.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("NoRepeatedResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
Method method = Method.builder().setName("PagedExpand").setInputType(inputType).setOutputType(outputType).setPageSizeFieldName(PAGINATED_FIELD_NAME).build();
Field responseField = Field.builder().setName("response").setType(TypeNode.STRING).build();
Message noRepeatedResponseMessage = Message.builder().setName("NoRepeatedResponse").setFullProtoName("google.showcase.v1beta1.NoRepeatedResponse").setType(TypeNode.withReference(VaporReference.builder().setName("NoRepeatedResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build())).setFields(Arrays.asList(responseField)).build();
messageTypes.put("NoRepeatedResponse", noRepeatedResponseMessage);
Assert.assertThrows(NullPointerException.class, () -> ServiceClientCallableMethodSampleComposer.composeRegularCallableMethod(method, clientType, resourceNames, messageTypes));
}
use of com.google.api.generator.gapic.model.Field in project gapic-generator-java by googleapis.
the class ServiceClientHeaderSampleComposerTest method invalid_composeShowcaseMethodSample_noRepeatedResponseTypeInPagedMethod.
@Test
public void invalid_composeShowcaseMethodSample_noRepeatedResponseTypeInPagedMethod() {
Descriptors.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("PagedResponse").setPakkage(SHOWCASE_PACKAGE_NAME).build());
List<MethodArgument> methodArguments = Collections.emptyList();
Method method = Method.builder().setName("simplePagedMethod").setMethodSignatures(Arrays.asList(methodArguments)).setInputType(inputType).setOutputType(outputType).setPageSizeFieldName(PAGINATED_FIELD_NAME).build();
Field responseField = Field.builder().setName("response").setType(TypeNode.withReference(ConcreteReference.builder().setClazz(List.class).setGenerics(ConcreteReference.withClazz(String.class)).build())).setIsMessage(true).setIsRepeated(false).build();
Field nextPageToken = Field.builder().setName("next_page_token").setType(TypeNode.STRING).build();
Message noRepeatedFieldMessage = Message.builder().setName("PagedResponse").setFullProtoName("google.showcase.v1beta1.PagedResponse").setType(outputType).setFields(Arrays.asList(responseField, nextPageToken)).build();
messageTypes.put("PagedResponse", noRepeatedFieldMessage);
Assert.assertThrows(NullPointerException.class, () -> ServiceClientHeaderSampleComposer.composeShowcaseMethodSample(method, clientType, methodArguments, resourceNames, messageTypes));
}
use of com.google.api.generator.gapic.model.Field in project gapic-generator-java by googleapis.
the class DefaultValueComposerTest method defaultValue_enumField.
@Test
public void defaultValue_enumField() {
// Incorrect and will never happen in real usage, but proves that enum detection is based on
// isEnum() rather than type().
Field field = Field.builder().setName("foobar").setType(TypeNode.STRING).setIsEnum(true).build();
Expr expr = DefaultValueComposer.createValue(field);
expr.accept(writerVisitor);
assertEquals("String.forNumber(0)", writerVisitor.write());
}
use of com.google.api.generator.gapic.model.Field in project gapic-generator-java by googleapis.
the class DefaultValueComposerTest method defaultValue_messageField.
@Test
public void defaultValue_messageField() {
// Incorrect and will never happen in real usage, but proves that message detection is based on
// isMessage() rather than type().
Field field = Field.builder().setName("foobar").setType(TypeNode.STRING).setIsMessage(true).build();
Expr expr = DefaultValueComposer.createValue(field);
expr.accept(writerVisitor);
assertEquals("String.newBuilder().build()", writerVisitor.write());
}
use of com.google.api.generator.gapic.model.Field in project gapic-generator-java by googleapis.
the class DefaultValueComposerTest method defaultValue_numericField.
@Test
public void defaultValue_numericField() {
Field field = Field.builder().setName("foobar").setType(TypeNode.INT).build();
Expr expr = DefaultValueComposer.createValue(field);
expr.accept(writerVisitor);
assertEquals("-1268878963", writerVisitor.write());
writerVisitor.clear();
field = Field.builder().setName("foobar").setType(TypeNode.DOUBLE).build();
expr = DefaultValueComposer.createValue(field);
expr.accept(writerVisitor);
assertEquals("-1268878963", writerVisitor.write());
}
Aggregations