Search in sources :

Example 11 with InnerCNode

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));
}
Also used : SimpletypesConfig(com.yahoo.config.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) HttpResponse(com.yahoo.container.jdisc.HttpResponse) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) Test(org.junit.Test) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest)

Example 12 with InnerCNode

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\"}"));
}
Also used : SimpletypesConfig(com.yahoo.config.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 13 with InnerCNode

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\"}"));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) SimpletypesConfig(com.yahoo.config.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 14 with InnerCNode

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"));
}
Also used : InnerCNode(com.yahoo.config.codegen.InnerCNode) StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefParser(com.yahoo.config.codegen.DefParser) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Test(org.junit.Test)

Example 15 with InnerCNode

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);
}
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)

Aggregations

InnerCNode (com.yahoo.config.codegen.InnerCNode)28 Test (org.junit.Test)23 DefParser (com.yahoo.config.codegen.DefParser)21 StringReader (java.io.StringReader)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 Cursor (com.yahoo.slime.Cursor)15 Slime (com.yahoo.slime.Slime)14 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)10 SimpletypesConfig (com.yahoo.config.SimpletypesConfig)7 HttpResponse (com.yahoo.container.jdisc.HttpResponse)5 Ignore (org.junit.Ignore)5 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)3 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)3 HttpRequest (com.yahoo.container.jdisc.HttpRequest)2 SimpletypesConfig (com.yahoo.foo.SimpletypesConfig)2 ConfigBuilder (com.yahoo.config.ConfigBuilder)1 ApplicationId (com.yahoo.config.provision.ApplicationId)1 Utf8Array (com.yahoo.text.Utf8Array)1 LZ4PayloadCompressor (com.yahoo.vespa.config.LZ4PayloadCompressor)1 ConfigResponse (com.yahoo.vespa.config.protocol.ConfigResponse)1