use of org.wildfly.swarm.spi.api.config.SimpleKey in project wildfly-swarm by wildfly-swarm.
the class SimpleKeyTest method testHead.
@Test
public void testHead() {
SimpleKey key = new SimpleKey("hi");
assertThat(key.head()).isEqualTo(key);
}
use of org.wildfly.swarm.spi.api.config.SimpleKey in project wildfly-swarm by wildfly-swarm.
the class InterfaceExtensionTest method testAfterBeanDiscovery.
@Test
public void testAfterBeanDiscovery() throws Exception {
ConfigView configView = mock(ConfigView.class);
List<SimpleKey> interfaces = Arrays.asList(new SimpleKey("test"));
when(configView.simpleSubkeys(any(ConfigKey.class))).thenReturn(interfaces);
when(configView.valueOf(any(ConfigKey.class))).thenReturn("192.168.1.1");
ext = new InterfaceExtension(configView);
BeanManager beanManager = mock(BeanManager.class);
AfterBeanDiscovery abd = mock(AfterBeanDiscovery.class);
@SuppressWarnings("unchecked") ArgumentCaptor<CommonBean<Interface>> captor = ArgumentCaptor.forClass(CommonBean.class);
ext.afterBeanDiscovery(abd, beanManager);
verify(abd, times(1)).addBean(captor.capture());
assertThat(captor.getValue().create(null).getName()).isEqualTo("test");
assertThat(captor.getValue().create(null).getExpression()).isEqualTo("192.168.1.1");
}
use of org.wildfly.swarm.spi.api.config.SimpleKey in project wildfly-swarm by wildfly-swarm.
the class ConfigurableManager method scan.
protected void scan(ConfigKey prefix, Object instance, Class<?> curClass, boolean implicit) throws Exception {
if (curClass == null || curClass == Object.class || isBlacklisted(curClass)) {
return;
}
Field[] fields = curClass.getDeclaredFields();
for (Field field : fields) {
if (!Modifier.isStatic(field.getModifiers())) {
if (isBlacklisted(field)) {
continue;
}
if (implicit || field.getAnnotation(Configurable.class) != null || field.getAnnotation(Configurables.class) != null) {
if (isConfigurableType(field.getType())) {
List<ConfigKey> names = namesFor(prefix, field);
boolean configured = false;
for (ConfigKey name : names) {
if (!seen(name)) {
ConfigurableHandle configurable = new ObjectBackedConfigurableHandle(name, instance, field);
this.configurables.add(configurable);
configured = configure(configurable);
}
if (configured) {
break;
}
}
}
}
}
}
if (!rescanning) {
Method[] methods = curClass.getDeclaredMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(Configurable.class)) {
ConfigKey subPrefix = prefix.append(nameFor(method));
if (method.getParameterCount() == 1) {
// configuration keys that imply we want it.
if (this.configView.hasKeyOrSubkeys(subPrefix)) {
Object lambda = createLambda(subPrefix, method);
if (lambda != null) {
method.invoke(instance, lambda);
}
}
} else if (method.getParameterCount() == 2) {
List<SimpleKey> keysWithConfiguration = this.configView.simpleSubkeys(subPrefix);
if (!keysWithConfiguration.isEmpty()) {
for (SimpleKey key : keysWithConfiguration) {
ConfigKey itemPrefix = subPrefix.append(key);
Object lambda = createLambda(itemPrefix, method);
if (lambda != null) {
method.invoke(instance, key.name(), lambda);
}
}
}
}
}
}
}
scan(prefix, instance, curClass.getSuperclass(), implicit);
}
use of org.wildfly.swarm.spi.api.config.SimpleKey in project wildfly-swarm by wildfly-swarm.
the class ConfigurableManager method nameFor.
protected ConfigKey nameFor(Fraction fraction) throws Exception {
Configurable anno = fraction.getClass().getAnnotation(Configurable.class);
if (anno != null) {
return ConfigKey.parse(anno.value());
}
SimpleKey key = getKey(fraction);
if (key == null) {
key = new SimpleKey(fraction.getClass().getSimpleName().replace("Fraction", "").toLowerCase());
}
return ConfigKey.of("swarm").append(key);
}
use of org.wildfly.swarm.spi.api.config.SimpleKey in project wildfly-swarm by wildfly-swarm.
the class NetworkConfigurer method fixSocketBindings.
protected void fixSocketBindings(SocketBindingGroup group) {
ConfigKey key = ROOT.append(group.name()).append("socket-bindings");
List<SimpleKey> names = this.configView.simpleSubkeys(key);
names.stream().map(e -> e.name()).map(name -> group.socketBindings().stream().filter(e -> e.name().equals(name)).findFirst().orElseGet(() -> {
SocketBinding binding = new SocketBinding(name);
group.socketBinding(binding);
return binding;
})).forEach(e -> {
applyConfiguration(key, e);
});
}
Aggregations