Search in sources :

Example 56 with Cursor

use of com.yahoo.slime.Cursor in project vespa by vespa-engine.

the class ConfigFileFormatterTest method require_that_complex_struct_formatting_is_correct.

@Test
public void require_that_complex_struct_formatting_is_correct() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    Cursor nested = root.setObject("nested");
    Cursor nested_inner = nested.setObject("inner");
    nested_inner.setString("name", "baz");
    nested_inner.setString("gender", "FEMALE");
    Cursor nested_inner_arr = nested_inner.setArray("emails");
    nested_inner_arr.addString("foo");
    nested_inner_arr.addString("bar");
    Cursor nestedarr = root.setArray("nestedarr");
    Cursor nestedarr1 = nestedarr.addObject();
    Cursor inner1 = nestedarr1.setObject("inner");
    inner1.setString("name", "foo");
    inner1.setString("gender", "FEMALE");
    Cursor inner1arr = inner1.setArray("emails");
    inner1arr.addString("foo@bar");
    inner1arr.addString("bar@foo");
    Cursor complexarr = root.setArray("complexarr");
    Cursor complexarr1 = complexarr.addObject();
    Cursor innerarr1 = complexarr1.setArray("innerarr");
    Cursor innerarr11 = innerarr1.addObject();
    innerarr11.setString("name", "bar");
    innerarr11.setString("gender", "MALE");
    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("nested.inner.name \"baz\"\n" + "nested.inner.gender FEMALE\n" + "nested.inner.emails[0] \"foo\"\n" + "nested.inner.emails[1] \"bar\"\n" + "nestedarr[0].inner.name \"foo\"\n" + "nestedarr[0].inner.gender FEMALE\n" + "nestedarr[0].inner.emails[0] \"foo@bar\"\n" + "nestedarr[0].inner.emails[1] \"bar@foo\"\n" + "complexarr[0].innerarr[0].name \"bar\"\n" + "complexarr[0].innerarr[0].gender MALE\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 57 with Cursor

use of com.yahoo.slime.Cursor in project vespa by vespa-engine.

the class ConfigFileFormatterTest method require_that_basic_formatting_is_correct.

@Test
public void require_that_basic_formatting_is_correct() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("stringval", "foo");
    root.setString("intval", "324234");
    root.setString("longval", "324");
    root.setString("doubleval", "3.455");
    root.setString("enumval", "VAL2");
    root.setString("boolval", "true");
    assertConfigFormat(slime, expected_simpletypes);
}
Also used : Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Test(org.junit.Test)

Example 58 with Cursor

use of com.yahoo.slime.Cursor in project vespa by vespa-engine.

the class ConfigFileFormatterTest method require_that_illegal_enum_throws_exception.

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

use of com.yahoo.slime.Cursor 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 60 with Cursor

use of com.yahoo.slime.Cursor 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)

Aggregations

Cursor (com.yahoo.slime.Cursor)112 Slime (com.yahoo.slime.Slime)79 Test (org.junit.Test)33 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 DefParser (com.yahoo.config.codegen.DefParser)15 InnerCNode (com.yahoo.config.codegen.InnerCNode)15 StringReader (java.io.StringReader)15 IOException (java.io.IOException)9 ApplicationId (com.yahoo.config.provision.ApplicationId)8 JsonFormat (com.yahoo.slime.JsonFormat)8 Application (com.yahoo.vespa.hosted.controller.Application)6 List (java.util.List)6 Map (java.util.Map)6 Inspector (com.yahoo.slime.Inspector)5 SlimeUtils (com.yahoo.vespa.config.SlimeUtils)5 Ignore (org.junit.Ignore)5 Version (com.yahoo.component.Version)4 RegionName (com.yahoo.config.provision.RegionName)4 TenantName (com.yahoo.config.provision.TenantName)4