Search in sources :

Example 11 with Cursor

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

the class ConfigPayloadTest method createAppConfig.

/**
 * TODO: Test invalid slime trees?
 * TODO: Test sending in wrong class
 */
/**
 ********************************************************************************************
 * Helper methods. consider moving out to another class for reuse by merge tester.            *
 *********************************************************************************************
 */
private AppConfig createAppConfig(String message, String times, String[] names) {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("message", message);
    root.setString("times", times);
    Cursor arr = root.setArray("a");
    for (String name : names) {
        Cursor obj = arr.addObject();
        obj.setString("name", name);
    }
    return new ConfigPayload(slime).toInstance(AppConfig.class, "");
}
Also used : Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 12 with Cursor

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

the class SlimeUtilsTest method test_copying_slime_arrays_into_cursor.

@Test
public void test_copying_slime_arrays_into_cursor() {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("foo", "foobie");
    Cursor subobj = root.setObject("bar");
    Slime slime2 = new Slime();
    Cursor root2 = slime2.setObject();
    Cursor array = root2.setArray("a");
    array.addString("foo");
    array.addLong(4);
    array.addBool(true);
    array.addDouble(3.14);
    array.addNix();
    array.addData(new byte[] { 0x64 });
    Cursor objinner = array.addObject();
    objinner.setString("inner", "binner");
    SlimeUtils.copyObject(slime2.get(), subobj);
    assertThat(root.toString(), is("{\"foo\":\"foobie\",\"bar\":{\"a\":[\"foo\",4,true,3.14,null,\"0x64\",{\"inner\":\"binner\"}]}}"));
}
Also used : Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Test(org.junit.Test)

Example 13 with Cursor

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

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

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

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