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