Search in sources :

Example 16 with ConfigNode

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();
}
Also used : MessageGenerator(com.google.api.codegen.configgen.MessageGenerator) ConfigHelper(com.google.api.codegen.configgen.ConfigHelper) URISyntaxException(java.net.URISyntaxException) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) File(java.io.File) URL(java.net.URL) ConfigYamlReader(com.google.api.codegen.configgen.ConfigYamlReader)

Example 17 with ConfigNode

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++));
    }
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) Test(org.junit.Test)

Example 18 with ConfigNode

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++)));
    }
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) Test(org.junit.Test)

Example 19 with ConfigNode

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++));
    }
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) Test(org.junit.Test)

Example 20 with ConfigNode

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++));
    }
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) Test(org.junit.Test)

Aggregations

ConfigNode (com.google.api.codegen.configgen.nodes.ConfigNode)39 FieldConfigNode (com.google.api.codegen.configgen.nodes.FieldConfigNode)35 ListItemConfigNode (com.google.api.codegen.configgen.nodes.ListItemConfigNode)22 ScalarConfigNode (com.google.api.codegen.configgen.nodes.ScalarConfigNode)12 NullConfigNode (com.google.api.codegen.configgen.nodes.NullConfigNode)11 Test (org.junit.Test)5 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)5 DefaultComment (com.google.api.codegen.configgen.nodes.metadata.DefaultComment)4 FixmeComment (com.google.api.codegen.configgen.nodes.metadata.FixmeComment)4 Node (org.yaml.snakeyaml.nodes.Node)4 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)3 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)3 SequenceNode (org.yaml.snakeyaml.nodes.SequenceNode)3 ConfigHelper (com.google.api.codegen.configgen.ConfigHelper)2 ConfigYamlReader (com.google.api.codegen.configgen.ConfigYamlReader)2 MessageGenerator (com.google.api.codegen.configgen.MessageGenerator)2 File (java.io.File)2 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)2 FieldModel (com.google.api.codegen.config.FieldModel)1 ProtoConfigMerger (com.google.api.codegen.configgen.mergers.ProtoConfigMerger)1