use of com.yahoo.config.codegen.InnerCNode in project vespa by vespa-engine.
the class HttpGetConfigHandlerTest method require_that_handler_can_be_created.
@Test
public void require_that_handler_can_be_created() throws IOException {
// Define config response for mock handler
final long generation = 1L;
ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
InnerCNode targetDef = getInnerCNode();
mockRequestHandler.responses.put(new ApplicationId.Builder().tenant(tenant).applicationName("myapplication").build(), SlimeConfigResponse.fromConfigPayload(payload, targetDef, generation, "mymd5"));
HttpResponse response = handler.handle(HttpRequest.createTestRequest(configUri, GET));
assertThat(SessionHandlerTest.getRenderedString(response), is(EXPECTED_RENDERED_STRING));
}
use of com.yahoo.config.codegen.InnerCNode in project vespa by vespa-engine.
the class HttpGetConfigHandlerTest method require_that_handler_can_be_created.
@Test
public void require_that_handler_can_be_created() throws IOException {
// Define config response for mock handler
final long generation = 1L;
ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
InnerCNode targetDef = getInnerCNode();
mockRequestHandler.responses.put(ApplicationId.defaultId(), SlimeConfigResponse.fromConfigPayload(payload, targetDef, generation, "mymd5"));
HttpResponse response = handler.handle(HttpRequest.createTestRequest(configUri, GET));
assertThat(SessionHandlerTest.getRenderedString(response), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}"));
}
use of com.yahoo.config.codegen.InnerCNode in project vespa by vespa-engine.
the class HttpGetConfigHandlerTest method require_that_nocache_property_works.
@Test
public void require_that_nocache_property_works() throws IOException {
long generation = 1L;
ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
InnerCNode targetDef = getInnerCNode();
mockRequestHandler.responses.put(ApplicationId.defaultId(), SlimeConfigResponse.fromConfigPayload(payload, targetDef, generation, "mymd5"));
final HttpRequest request = HttpRequest.createTestRequest(configUri, GET, null, Collections.singletonMap("nocache", "true"));
HttpResponse response = handler.handle(request);
assertThat(SessionHandlerTest.getRenderedString(response), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}"));
}
use of com.yahoo.config.codegen.InnerCNode 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.config.codegen.InnerCNode 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);
}
Aggregations