Search in sources :

Example 26 with Field

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));
}
Also used : Field(com.google.api.generator.gapic.model.Field) Message(com.google.api.generator.gapic.model.Message) ResourceName(com.google.api.generator.gapic.model.ResourceName) Descriptors(com.google.protobuf.Descriptors) TypeNode(com.google.api.generator.engine.ast.TypeNode) Method(com.google.api.generator.gapic.model.Method) Test(org.junit.Test)

Example 27 with Field

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));
}
Also used : Message(com.google.api.generator.gapic.model.Message) MethodArgument(com.google.api.generator.gapic.model.MethodArgument) ResourceName(com.google.api.generator.gapic.model.ResourceName) Method(com.google.api.generator.gapic.model.Method) Field(com.google.api.generator.gapic.model.Field) List(java.util.List) Descriptors(com.google.protobuf.Descriptors) TypeNode(com.google.api.generator.engine.ast.TypeNode) Test(org.junit.Test)

Example 28 with Field

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());
}
Also used : Field(com.google.api.generator.gapic.model.Field) Expr(com.google.api.generator.engine.ast.Expr) Test(org.junit.Test)

Example 29 with Field

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());
}
Also used : Field(com.google.api.generator.gapic.model.Field) Expr(com.google.api.generator.engine.ast.Expr) Test(org.junit.Test)

Example 30 with Field

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());
}
Also used : Field(com.google.api.generator.gapic.model.Field) Expr(com.google.api.generator.engine.ast.Expr) Test(org.junit.Test)

Aggregations

Field (com.google.api.generator.gapic.model.Field)34 Message (com.google.api.generator.gapic.model.Message)23 TypeNode (com.google.api.generator.engine.ast.TypeNode)21 Expr (com.google.api.generator.engine.ast.Expr)17 Test (org.junit.Test)16 Method (com.google.api.generator.gapic.model.Method)14 ResourceName (com.google.api.generator.gapic.model.ResourceName)14 ArrayList (java.util.ArrayList)13 List (java.util.List)12 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)9 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)9 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)9 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)8 Preconditions (com.google.common.base.Preconditions)8 Map (java.util.Map)8 Collectors (java.util.stream.Collectors)8 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)7 Statement (com.google.api.generator.engine.ast.Statement)7 MethodArgument (com.google.api.generator.gapic.model.MethodArgument)7 Strings (com.google.common.base.Strings)7