Search in sources :

Example 1 with ConfigPayloadApplier

use of com.yahoo.vespa.config.ConfigPayloadApplier in project vespa by vespa-engine.

the class ConfigBuilderGeneratorTest method require_that_custom_classes_can_be_generated.

@Test
public void require_that_custom_classes_can_be_generated() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
    String[] schema = new String[] { "namespace=foo.bar", "intval int", "stringval string" };
    File tempDir = Files.createTempDir();
    ConfigDefinitionKey key = new ConfigDefinitionKey("quux", "foo.bar");
    ConfigCompiler compiler = new LazyConfigCompiler(tempDir);
    ConfigInstance.Builder builder = compiler.compile(new ConfigDefinition(key.getName(), schema).generateClass()).newInstance();
    assertNotNull(builder);
    ConfigPayloadApplier<?> payloadApplier = new ConfigPayloadApplier<>(builder);
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    root.setString("intval", "3");
    root.setString("stringval", "Hello, world");
    payloadApplier.applyPayload(new ConfigPayload(slime));
    String className = createClassName(key.getName());
    ConfigInstance instance = (ConfigInstance) builder.getClass().getClassLoader().loadClass("com.yahoo." + key.getNamespace() + "." + className).getConstructor(new Class<?>[] { builder.getClass() }).newInstance(builder);
    assertNotNull(instance);
    assertEquals("intval 3\nstringval \"Hello, world\"", instance.toString());
}
Also used : ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) ConfigPayloadApplier(com.yahoo.vespa.config.ConfigPayloadApplier) File(java.io.File) ConfigInstance(com.yahoo.config.ConfigInstance) Test(org.junit.Test)

Aggregations

ConfigInstance (com.yahoo.config.ConfigInstance)1 Cursor (com.yahoo.slime.Cursor)1 Slime (com.yahoo.slime.Slime)1 ConfigDefinitionKey (com.yahoo.vespa.config.ConfigDefinitionKey)1 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)1 ConfigPayloadApplier (com.yahoo.vespa.config.ConfigPayloadApplier)1 File (java.io.File)1 Test (org.junit.Test)1