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());
}
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());
}
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());
}
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));
}
Aggregations