Search in sources :

Example 1 with InnerCNode

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

the class ConfigFileFormatterTest method require_that_strings_are_properly_escaped.

@Test
public void require_that_strings_are_properly_escaped() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("stringval", "some\"quotes\\\"instring");
    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("stringval \"some\\\"quotes\\\\\\\"instring\"\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 2 with InnerCNode

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

the class ConfigFileFormatterTest method require_that_array_formatting_is_correct.

@Test
public void require_that_array_formatting_is_correct() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    Cursor boolarr = root.setArray("boolarr");
    boolarr.addString("true");
    boolarr.addString("false");
    Cursor doublearr = root.setArray("doublearr");
    doublearr.addString("3.14");
    doublearr.addString("1.414");
    Cursor enumarr = root.setArray("enumarr");
    enumarr.addString("VAL1");
    enumarr.addString("VAL2");
    Cursor intarr = root.setArray("intarr");
    intarr.addString("3");
    intarr.addString("5");
    Cursor longarr = root.setArray("longarr");
    longarr.addString("55");
    longarr.addString("66");
    Cursor stringarr = root.setArray("stringarr");
    stringarr.addString("foo");
    stringarr.addString("bar");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InnerCNode def = new DefParser("arraytypes", new StringReader(StringUtilities.implode(ArraytypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
    new ConfigFileFormat(def).encode(baos, slime);
    assertThat(baos.toString(), is("boolarr[0] true\n" + "boolarr[1] false\n" + "doublearr[0] 3.14\n" + "doublearr[1] 1.414\n" + "enumarr[0] VAL1\n" + "enumarr[1] VAL2\n" + "intarr[0] 3\n" + "intarr[1] 5\n" + "longarr[0] 55\n" + "longarr[1] 66\n" + "stringarr[0] \"foo\"\n" + "stringarr[1] \"bar\"\n"));
}
Also used : InnerCNode(com.yahoo.config.codegen.InnerCNode) StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefParser(com.yahoo.config.codegen.DefParser) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Test(org.junit.Test)

Example 3 with InnerCNode

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

the class ConfigFileFormatterTest method require_that_illegal_long_throws_exception.

// TODO: Reenable this when we can reenable typechecking.
@Ignore
@Test(expected = IllegalArgumentException.class)
public void require_that_illegal_long_throws_exception() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("longval", "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 4 with InnerCNode

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

the class ConfigFileFormatterTest method require_that_map_formatting_is_correct.

@Test
public void require_that_map_formatting_is_correct() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    Cursor boolval = root.setObject("boolmap");
    boolval.setString("foo", "true");
    boolval.setString("bar", "false");
    root.setObject("intmap").setString("foo", "1234");
    root.setObject("longmap").setString("foo", "12345");
    root.setObject("doublemap").setString("foo", "3.14");
    root.setObject("stringmap").setString("foo", "bar");
    root.setObject("innermap").setObject("bar").setString("foo", "1234");
    root.setObject("nestedmap").setObject("baz").setObject("inner").setString("foo", "1234");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InnerCNode def = new DefParser("maptypes", new StringReader(StringUtilities.implode(MaptypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
    new ConfigFileFormat(def).encode(baos, slime);
    assertThat(baos.toString(), is("boolmap{\"foo\"} true\n" + "boolmap{\"bar\"} false\n" + "intmap{\"foo\"} 1234\n" + "longmap{\"foo\"} 12345\n" + "doublemap{\"foo\"} 3.14\n" + "stringmap{\"foo\"} \"bar\"\n" + "innermap{\"bar\"}.foo 1234\n" + "nestedmap{\"baz\"}.inner{\"foo\"} 1234\n"));
}
Also used : InnerCNode(com.yahoo.config.codegen.InnerCNode) StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefParser(com.yahoo.config.codegen.DefParser) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Test(org.junit.Test)

Example 5 with InnerCNode

use of com.yahoo.config.codegen.InnerCNode 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)

Aggregations

InnerCNode (com.yahoo.config.codegen.InnerCNode)28 Test (org.junit.Test)23 DefParser (com.yahoo.config.codegen.DefParser)21 StringReader (java.io.StringReader)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 Cursor (com.yahoo.slime.Cursor)15 Slime (com.yahoo.slime.Slime)14 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)10 SimpletypesConfig (com.yahoo.config.SimpletypesConfig)7 HttpResponse (com.yahoo.container.jdisc.HttpResponse)5 Ignore (org.junit.Ignore)5 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)3 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)3 HttpRequest (com.yahoo.container.jdisc.HttpRequest)2 SimpletypesConfig (com.yahoo.foo.SimpletypesConfig)2 ConfigBuilder (com.yahoo.config.ConfigBuilder)1 ApplicationId (com.yahoo.config.provision.ApplicationId)1 Utf8Array (com.yahoo.text.Utf8Array)1 LZ4PayloadCompressor (com.yahoo.vespa.config.LZ4PayloadCompressor)1 ConfigResponse (com.yahoo.vespa.config.protocol.ConfigResponse)1