Search in sources :

Example 16 with InnerCNode

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

the class ConfigFileFormatterTest method require_that_struct_formatting_is_correct.

@Test
public void require_that_struct_formatting_is_correct() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    Cursor simple = root.setObject("simple");
    simple.setString("name", "myname");
    simple.setString("gender", "FEMALE");
    Cursor array = simple.setArray("emails");
    array.addString("foo@bar.com");
    array.addString("bar@baz.net");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InnerCNode def = new DefParser("structtypes", new StringReader(StringUtilities.implode(StructtypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
    new ConfigFileFormat(def).encode(baos, slime);
    assertThat(baos.toString(), is("simple.name \"myname\"\n" + "simple.gender FEMALE\n" + "simple.emails[0] \"foo@bar.com\"\n" + "simple.emails[1] \"bar@baz.net\"\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 17 with InnerCNode

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

the class ConfigFileFormatterTest method require_that_strings_are_encoded.

@Test
public void require_that_strings_are_encoded() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    String value = "\u7d22";
    root.setString("stringval", value);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InnerCNode def = new DefParser("simpletypes", new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
    new ConfigFileFormat(def).encode(baos, slime);
    assertThat(baos.toString("UTF-8"), is("stringval \"" + value + "\"\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 18 with InnerCNode

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

the class ConfigFileFormatterTest method require_that_illegal_double_throws_exception.

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

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

the class ConfigFileFormatterTest method require_that_utf8_works.

@Test
@Ignore
public void require_that_utf8_works() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    final String input = "Hei \u00E6\u00F8\u00E5 \n \uBC14\uB451 \u00C6\u00D8\u00C5 hallo";
    root.setString("stringval", input);
    System.out.println(bytesToHexString(Utf8.toBytes(input)));
    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);
    System.out.println(bytesToHexString(baos.toByteArray()));
    assertThat(Utf8.toString(baos.toByteArray()), is("stringval \"" + input + "\"\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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with InnerCNode

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

the class ConfigPayloadTest method test_applying_extra_default_values.

@Test
public void test_applying_extra_default_values() {
    InnerCNode clientDef = new DefParser(SimpletypesConfig.CONFIG_DEF_NAME, new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n") + "\nnewfield int default=3\n")).getTree();
    ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
    payload = payload.applyDefaultsFromDef(clientDef);
    assertThat(payload.toString(true), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\",\"newfield\":\"3\"}"));
}
Also used : InnerCNode(com.yahoo.config.codegen.InnerCNode) StringReader(java.io.StringReader) DefParser(com.yahoo.config.codegen.DefParser) 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