Search in sources :

Example 71 with Slime

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

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

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

the class ConfigPayloadTest method createStructtypesConfigNested.

private StructtypesConfig createStructtypesConfigNested(String name, String gender) {
    Slime slime = new Slime();
    addStructFields(slime.setObject().setObject("nested").setObject("inner"), name, gender, null);
    return new ConfigPayload(slime).toInstance(StructtypesConfig.class, "");
}
Also used : Slime(com.yahoo.slime.Slime)

Example 74 with Slime

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

the class ConfigPayloadTest method createStructtypesConfigArray.

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

Example 75 with Slime

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

the class SlimeUtilsTest method test_slime_to_json.

@Test
public void test_slime_to_json() throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("foo", "foobie");
    root.setObject("bar");
    String json = Utf8.toString(SlimeUtils.toJsonBytes(slime));
    assertThat(json, is("{\"foo\":\"foobie\",\"bar\":{}}"));
}
Also used : 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