use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class ConfigFileFormatterTest method require_that_complex_struct_formatting_is_correct.
@Test
public void require_that_complex_struct_formatting_is_correct() throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
Cursor nested = root.setObject("nested");
Cursor nested_inner = nested.setObject("inner");
nested_inner.setString("name", "baz");
nested_inner.setString("gender", "FEMALE");
Cursor nested_inner_arr = nested_inner.setArray("emails");
nested_inner_arr.addString("foo");
nested_inner_arr.addString("bar");
Cursor nestedarr = root.setArray("nestedarr");
Cursor nestedarr1 = nestedarr.addObject();
Cursor inner1 = nestedarr1.setObject("inner");
inner1.setString("name", "foo");
inner1.setString("gender", "FEMALE");
Cursor inner1arr = inner1.setArray("emails");
inner1arr.addString("foo@bar");
inner1arr.addString("bar@foo");
Cursor complexarr = root.setArray("complexarr");
Cursor complexarr1 = complexarr.addObject();
Cursor innerarr1 = complexarr1.setArray("innerarr");
Cursor innerarr11 = innerarr1.addObject();
innerarr11.setString("name", "bar");
innerarr11.setString("gender", "MALE");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InnerCNode def = new DefParser("structtypes", new StringReader(StringUtilities.implode(StructtypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
new ConfigFileFormat(def).encode(baos, slime);
assertThat(baos.toString(), is("nested.inner.name \"baz\"\n" + "nested.inner.gender FEMALE\n" + "nested.inner.emails[0] \"foo\"\n" + "nested.inner.emails[1] \"bar\"\n" + "nestedarr[0].inner.name \"foo\"\n" + "nestedarr[0].inner.gender FEMALE\n" + "nestedarr[0].inner.emails[0] \"foo@bar\"\n" + "nestedarr[0].inner.emails[1] \"bar@foo\"\n" + "complexarr[0].innerarr[0].name \"bar\"\n" + "complexarr[0].innerarr[0].gender MALE\n"));
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class ConfigFileFormatterTest method require_that_basic_formatting_is_correct.
@Test
public void require_that_basic_formatting_is_correct() throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
root.setString("stringval", "foo");
root.setString("intval", "324234");
root.setString("longval", "324");
root.setString("doubleval", "3.455");
root.setString("enumval", "VAL2");
root.setString("boolval", "true");
assertConfigFormat(slime, expected_simpletypes);
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class ConfigFileFormatterTest method require_that_illegal_enum_throws_exception.
// TODO: Reenable this when we can reenable typechecking.
@Ignore
@Test(expected = IllegalArgumentException.class)
public void require_that_illegal_enum_throws_exception() throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
root.setString("enumval", "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.Slime in project vespa by vespa-engine.
the class ConfigFileFormatterTest method require_that_struct_formatting_is_correct.
@Test
public void require_that_struct_formatting_is_correct() throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
Cursor simple = root.setObject("simple");
simple.setString("name", "myname");
simple.setString("gender", "FEMALE");
Cursor array = simple.setArray("emails");
array.addString("foo@bar.com");
array.addString("bar@baz.net");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InnerCNode def = new DefParser("structtypes", new StringReader(StringUtilities.implode(StructtypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
new ConfigFileFormat(def).encode(baos, slime);
assertThat(baos.toString(), is("simple.name \"myname\"\n" + "simple.gender FEMALE\n" + "simple.emails[0] \"foo@bar.com\"\n" + "simple.emails[1] \"bar@baz.net\"\n"));
}
use of com.yahoo.slime.Slime in project vespa by vespa-engine.
the class ConfigFileFormatterTest method require_that_strings_are_encoded.
@Test
public void require_that_strings_are_encoded() throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
String value = "\u7d22";
root.setString("stringval", value);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InnerCNode def = new DefParser("simpletypes", new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
new ConfigFileFormat(def).encode(baos, slime);
assertThat(baos.toString("UTF-8"), is("stringval \"" + value + "\"\n"));
}
Aggregations