Search in sources :

Example 6 with DefParser

use of com.yahoo.config.codegen.DefParser in project vespa by vespa-engine.

the class ConfigFileFormatterTest method require_that_illegal_int_throws_exception.

// TODO: Reenable this when we can reenable typechecking.
@Ignore
@Test(expected = IllegalArgumentException.class)
public void require_that_illegal_int_throws_exception() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("intval", "invalid");
    InnerCNode def = new DefParser("simpletypes", new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
    new ConfigFileFormat(def).encode(new ByteArrayOutputStream(), slime);
}
Also used : InnerCNode(com.yahoo.config.codegen.InnerCNode) StringReader(java.io.StringReader) DefParser(com.yahoo.config.codegen.DefParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with DefParser

use of com.yahoo.config.codegen.DefParser in project vespa by vespa-engine.

the class SuperModelController method getConfigDefinition.

private InnerCNode getConfigDefinition(ConfigKey<?> configKey, DefContent defContent) {
    if (defContent.isEmpty()) {
        ConfigDefinitionKey configDefinitionKey = new ConfigDefinitionKey(configKey.getName(), configKey.getNamespace());
        ConfigDefinition configDefinition = configDefinitionRepo.getConfigDefinitions().get(configDefinitionKey);
        if (configDefinition == null) {
            throw new UnknownConfigDefinitionException("Unable to find config definition for '" + configKey.getNamespace() + "." + configKey.getName());
        }
        return configDefinition.getCNode();
    } else {
        DefParser dParser = new DefParser(configKey.getName(), new StringReader(defContent.asString()));
        return dParser.getTree();
    }
}
Also used : ConfigDefinition(com.yahoo.vespa.config.buildergen.ConfigDefinition) StringReader(java.io.StringReader) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) DefParser(com.yahoo.config.codegen.DefParser)

Example 8 with DefParser

use of com.yahoo.config.codegen.DefParser in project vespa by vespa-engine.

the class ConfigFileFormatterTest method require_that_field_not_found_is_ignored.

@Test
public void require_that_field_not_found_is_ignored() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("nosuchfield", "bar");
    InnerCNode def = new DefParser("simpletypes", new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ConfigFileFormat(def).encode(baos, slime);
    assertThat(baos.toString(), is(""));
}
Also used : InnerCNode(com.yahoo.config.codegen.InnerCNode) StringReader(java.io.StringReader) DefParser(com.yahoo.config.codegen.DefParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Test(org.junit.Test)

Example 9 with DefParser

use of com.yahoo.config.codegen.DefParser in project vespa by vespa-engine.

the class ConfigFileFormatterTest method require_that_illegal_boolean_becomes_false.

@Test
public void require_that_illegal_boolean_becomes_false() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("boolval", "invalid");
    InnerCNode def = new DefParser("simpletypes", new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ConfigFileFormat(def).encode(baos, slime);
    assertThat(baos.toString(), is("boolval false\n"));
}
Also used : InnerCNode(com.yahoo.config.codegen.InnerCNode) StringReader(java.io.StringReader) DefParser(com.yahoo.config.codegen.DefParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Test(org.junit.Test)

Example 10 with DefParser

use of com.yahoo.config.codegen.DefParser in project vespa by vespa-engine.

the class ConfigFileFormatterTest method require_that_types_are_not_checked.

// TODO: Remove this when we can reenable typechecking.
@Test
public void require_that_types_are_not_checked() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("enumval", "null");
    root.setString("intval", "null");
    root.setString("longval", "null");
    root.setString("boolval", "null");
    root.setString("doubleval", "null");
    InnerCNode def = new DefParser("simpletypes", new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ConfigFileFormat(def).encode(baos, slime);
    assertThat(baos.toString("UTF-8"), is("enumval null\nintval null\nlongval null\nboolval false\ndoubleval null\n"));
}
Also used : InnerCNode(com.yahoo.config.codegen.InnerCNode) StringReader(java.io.StringReader) DefParser(com.yahoo.config.codegen.DefParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Test(org.junit.Test)

Aggregations

DefParser (com.yahoo.config.codegen.DefParser)28 StringReader (java.io.StringReader)24 InnerCNode (com.yahoo.config.codegen.InnerCNode)21 Test (org.junit.Test)20 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 Cursor (com.yahoo.slime.Cursor)15 Slime (com.yahoo.slime.Slime)14 Ignore (org.junit.Ignore)5 ConfigDefinition (com.yahoo.vespa.config.ConfigDefinition)3 ConfigDefinitionKey (com.yahoo.vespa.config.ConfigDefinitionKey)3 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)3 SimpletypesConfig (com.yahoo.config.SimpletypesConfig)2 UnparsedConfigDefinition (com.yahoo.config.application.api.UnparsedConfigDefinition)2 SimpletypesConfig (com.yahoo.foo.SimpletypesConfig)2 File (java.io.File)2 ApplicationFile (com.yahoo.config.application.api.ApplicationFile)1 CNode (com.yahoo.config.codegen.CNode)1 JavaClassBuilder (com.yahoo.config.codegen.JavaClassBuilder)1 Utf8Array (com.yahoo.text.Utf8Array)1 ConfigPayloadBuilder (com.yahoo.vespa.config.ConfigPayloadBuilder)1