Search in sources :

Example 31 with Field

use of com.google.api.generator.gapic.model.Field in project gapic-generator-java by googleapis.

the class DefaultValueComposerTest method defaultValue_byteStringField.

@Test
public void defaultValue_byteStringField() {
    Field field = Field.builder().setName("foobar").setType(TypeNode.withReference(ConcreteReference.withClazz(ByteString.class))).build();
    Expr expr = DefaultValueComposer.createValue(field);
    expr.accept(writerVisitor);
    assertEquals("ByteString.EMPTY", writerVisitor.write());
}
Also used : Field(com.google.api.generator.gapic.model.Field) Expr(com.google.api.generator.engine.ast.Expr) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 32 with Field

use of com.google.api.generator.gapic.model.Field in project gapic-generator-java by googleapis.

the class DefaultValueComposerTest method defaultValue_listField.

@Test
public void defaultValue_listField() {
    // Incorrect and will never happen in real usage, but proves that list detection is based on
    // isRepeated rather than type().
    Field field = Field.builder().setName("foobar").setType(TypeNode.STRING).setIsRepeated(true).build();
    Expr expr = DefaultValueComposer.createValue(field);
    expr.accept(writerVisitor);
    assertEquals("new ArrayList<>()", 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 33 with Field

use of com.google.api.generator.gapic.model.Field in project gapic-generator-java by googleapis.

the class DefaultValueComposerTest method defaultValue_stringField.

@Test
public void defaultValue_stringField() {
    Field field = Field.builder().setName("foobar").setType(TypeNode.STRING).build();
    Expr expr = DefaultValueComposer.createValue(field);
    expr.accept(writerVisitor);
    assertEquals("\"foobar-1268878963\"", writerVisitor.write());
    writerVisitor.clear();
    // Original name is very clearly in lower_camel_case.
    field = Field.builder().setName("foo_bar_baz").setType(TypeNode.STRING).build();
    expr = DefaultValueComposer.createValue(field);
    expr.accept(writerVisitor);
    assertEquals("\"fooBarBaz-2082080914\"", 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 34 with Field

use of com.google.api.generator.gapic.model.Field in project gapic-generator-java by googleapis.

the class ParserTest method parseMessages_basic.

@Test
public void parseMessages_basic() {
    // TODO(miraleung): Add more tests for oneofs and other message-parsing edge cases.
    Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
    Message echoRequestMessage = messageTypes.get("com.google.showcase.v1beta1.EchoRequest");
    Field echoRequestNameField = echoRequestMessage.fieldMap().get("name");
    assertTrue(echoRequestNameField.hasResourceReference());
    String echoResponseName = "EchoResponse";
    Field echoResponseContentField = Field.builder().setName("content").setType(TypeNode.STRING).build();
    Field echoResponseSeverityField = Field.builder().setName("severity").setType(TypeNode.withReference(VaporReference.builder().setName("Severity").setPakkage(ECHO_PACKAGE).build())).setIsEnum(true).build();
    TypeNode echoResponseType = TypeNode.withReference(VaporReference.builder().setName(echoResponseName).setPakkage(ECHO_PACKAGE).build());
    Message echoResponseMessage = Message.builder().setType(echoResponseType).setName(echoResponseName).setFullProtoName("google.showcase.v1beta1." + echoResponseName).setFields(Arrays.asList(echoResponseContentField, echoResponseSeverityField)).build();
    assertEquals(echoResponseMessage, messageTypes.get("com.google.showcase.v1beta1." + echoResponseName));
}
Also used : Field(com.google.api.generator.gapic.model.Field) Message(com.google.api.generator.gapic.model.Message) TypeNode(com.google.api.generator.engine.ast.TypeNode) 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