Search in sources :

Example 11 with Slime

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

the class ConfigPayloadTest method createStructtypesConfigSimple.

private StructtypesConfig createStructtypesConfigSimple(String name, String gender, String[] emails) {
    Slime slime = new Slime();
    addStructFields(slime.setObject().setObject("simple"), name, gender, emails);
    return new ConfigPayload(slime).toInstance(StructtypesConfig.class, "");
}
Also used : Slime(com.yahoo.slime.Slime)

Example 12 with Slime

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

the class ConfigPayloadTest method test_empty_payload.

@Test
public void test_empty_payload() throws Exception {
    Slime slime = new Slime();
    slime.setObject();
    IntConfig config = new ConfigPayload(slime).toInstance(IntConfig.class, "");
    assertThat(config.intVal(), is(1));
}
Also used : Slime(com.yahoo.slime.Slime) Test(org.junit.Test)

Example 13 with Slime

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

the class ConfigPayloadTest method createStructtypesConfigComplexArray.

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

Example 14 with Slime

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

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

the class SlimeUtilsTest method test_json_to_slime.

@Test
public void test_json_to_slime() {
    byte[] json = Utf8.toBytes("{\"foo\":\"foobie\",\"bar\":{}}");
    Slime slime = SlimeUtils.jsonToSlime(json);
    assertThat(slime.get().field("foo").asString(), is("foobie"));
    assertTrue(slime.get().field("bar").valid());
}
Also used : Slime(com.yahoo.slime.Slime) 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