use of com.yahoo.slime.Cursor 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);
}
use of com.yahoo.slime.Cursor 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"));
}
use of com.yahoo.slime.Cursor 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, "");
}
use of com.yahoo.slime.Cursor 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\":{}}"));
}
use of com.yahoo.slime.Cursor in project vespa by vespa-engine.
the class SlimeUtilsTest method test_copying_slime_types_into_cursor.
@Test
public void test_copying_slime_types_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();
root2.setString("a", "a");
root2.setLong("b", 2);
root2.setBool("c", true);
root2.setDouble("d", 3.14);
root2.setData("e", new byte[] { 0x64 });
root2.setNix("f");
SlimeUtils.copyObject(slime2.get(), subobj);
assertThat(root.toString(), is("{\"foo\":\"foobie\",\"bar\":{\"a\":\"a\",\"b\":2,\"c\":true,\"d\":3.14,\"e\":\"0x64\",\"f\":null}}"));
}
Aggregations