use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.
the class CodegenTestUtil method readConfig.
public static ConfigProto readConfig(DiagCollector diagCollector, TestDataLocator testDataLocator, String[] gapicConfigFileNames) {
ConfigYamlReader yamlReader = new ConfigYamlReader();
MessageGenerator messageGenerator = new MessageGenerator(ConfigProto.newBuilder());
for (String gapicConfigFileName : gapicConfigFileNames) {
URL gapicConfigUrl = testDataLocator.findTestData(gapicConfigFileName);
File gapicConfigFile = null;
try {
gapicConfigFile = new File(gapicConfigUrl.toURI());
} catch (URISyntaxException e) {
continue;
}
ConfigHelper helper = new ConfigHelper(diagCollector, gapicConfigFile.getName());
ConfigNode configNode = yamlReader.generateConfigNode(gapicConfigFile, helper);
if (configNode == null) {
continue;
}
messageGenerator.visit(configNode.getChild());
}
if (diagCollector.getErrorCount() > 0) {
System.err.println(diagCollector.toString());
return null;
}
return (ConfigProto) messageGenerator.getValue();
}
use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.
the class ListTransformerTest method testGenerateStringList.
@Test
public void testGenerateStringList() throws Exception {
List<String> elements = Arrays.asList("1", "2");
ConfigNode parent = new FieldConfigNode(0, "parent");
ConfigNode listNode = ListTransformer.generateStringList(elements, parent);
int index = 0;
for (ConfigNode node : NodeFinder.getChildren(parent)) {
Truth.assertThat(node.getChild().getText()).isEqualTo(elements.get(index++));
}
}
use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.
the class ListTransformerTest method testGenerateList.
@Test
public void testGenerateList() throws Exception {
List<Integer> elements = Arrays.asList(1, 2);
ConfigNode parent = new FieldConfigNode(0, "parent");
ConfigNode listNode = ListTransformer.generateList(elements, parent, (startLine, element) -> new ListItemConfigNode(startLine).setChild(new ScalarConfigNode(startLine, String.valueOf(element))));
int index = 0;
for (ConfigNode node : NodeFinder.getChildren(parent)) {
Truth.assertThat(node.getChild().getText()).isEqualTo(String.valueOf(elements.get(index++)));
}
}
use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.
the class MissingFieldTransformerTest method testPrepend.
@Test
public void testPrepend() throws Exception {
ConfigNode parent = new FieldConfigNode(0, "parent");
Map<String, String> fields = ImmutableMap.of("B", "2", "C", "3");
ListTransformer.generateList(fields.entrySet(), parent, (startLine, entry) -> FieldConfigNode.createStringPair(startLine, entry.getKey(), entry.getValue()));
MissingFieldTransformer.prepend("A", parent).generate();
List<String> fieldNames = Arrays.asList("A", "B", "C");
int index = 0;
for (ConfigNode node : NodeFinder.getChildren(parent)) {
Truth.assertThat(node.getText()).isEqualTo(fieldNames.get(index++));
}
}
use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.
the class MissingFieldTransformerTest method testAppend.
@Test
public void testAppend() throws Exception {
ConfigNode parent = new FieldConfigNode(0, "parent");
Map<String, String> fields = ImmutableMap.of("A", "1", "B", "2");
ListTransformer.generateList(fields.entrySet(), parent, (startLine, entry) -> FieldConfigNode.createStringPair(startLine, entry.getKey(), entry.getValue()));
MissingFieldTransformer.append("C", parent).generate();
List<String> fieldNames = Arrays.asList("A", "B", "C");
int index = 0;
for (ConfigNode node : NodeFinder.getChildren(parent)) {
Truth.assertThat(node.getText()).isEqualTo(fieldNames.get(index++));
}
}
Aggregations