Search in sources :

Example 66 with Slime

use of com.yahoo.slime.Slime 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 67 with Slime

use of com.yahoo.slime.Slime 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 68 with Slime

use of com.yahoo.slime.Slime 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 69 with Slime

use of com.yahoo.slime.Slime 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 70 with Slime

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

Slime (com.yahoo.slime.Slime)131 Cursor (com.yahoo.slime.Cursor)76 Test (org.junit.Test)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)23 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)22 DefParser (com.yahoo.config.codegen.DefParser)14 InnerCNode (com.yahoo.config.codegen.InnerCNode)14 StringReader (java.io.StringReader)14 JsonFormat (com.yahoo.slime.JsonFormat)10 ApplicationId (com.yahoo.config.provision.ApplicationId)9 Inspector (com.yahoo.slime.Inspector)9 Application (com.yahoo.vespa.hosted.controller.Application)9 SlimeAdapter (com.yahoo.data.access.slime.SlimeAdapter)8 IOException (java.io.IOException)8 Version (com.yahoo.component.Version)7 JsonDecoder (com.yahoo.slime.JsonDecoder)6 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)6 HttpResponse (com.yahoo.container.jdisc.HttpResponse)5 DeployLogger (com.yahoo.config.application.api.DeployLogger)4 TenantName (com.yahoo.config.provision.TenantName)4