Search in sources :

Example 6 with Slime

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

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

Example 8 with Slime

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

the class ConfigPayloadTest method createSimpletypesConfig.

private SimpletypesConfig createSimpletypesConfig(String field, String value) {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString(field, value);
    return new ConfigPayload(slime).toInstance(SimpletypesConfig.class, "");
}
Also used : Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 9 with Slime

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

the class ConfigPayloadTest method createArraytypesConfig.

private ArraytypesConfig createArraytypesConfig(String field, String[] values) {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    Cursor array = root.setArray(field);
    for (String value : values) {
        array.addString(value);
    }
    return new ConfigPayload(slime).toInstance(ArraytypesConfig.class, "");
}
Also used : Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 10 with Slime

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

the class ConfigPayloadTest method createStructtypesConfigNestedArray.

private StructtypesConfig createStructtypesConfigNestedArray(String[] names, String[] genders, String[][] emails) {
    Slime slime = new Slime();
    Cursor array = slime.setObject().setArray("nestedarr");
    assertEquals(names.length, genders.length);
    for (int i = 0; i < names.length; i++) {
        addStructFields(array.addObject().setObject("inner"), names[i], genders[i], emails[i]);
    }
    return new ConfigPayload(slime).toInstance(StructtypesConfig.class, "");
}
Also used : Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

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