InterfaceExtension extends AbstractNetworkExtension<Interface> { @SuppressWarnings("unused") void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception { List<SimpleKey> configuredInterfaces = this.configView.simpleSubkeys(ROOT); for (SimpleKey interfaceName : configuredInterfaces) { Set<Bean<?>> ifaces = beanManager.getBeans(Interface.class, Any.Literal.INSTANCE); if (ifaces .stream() .noneMatch(e -> e.getQualifiers() .stream() .anyMatch(anno -> anno instanceof Named && ((Named) anno).value().equals(interfaceName + "-interface")))) { Interface iface = new Interface(interfaceName.name(), "0.0.0.0"); applyConfiguration(iface); CommonBean<Interface> interfaceBean = CommonBeanBuilder.newBuilder(Interface.class) .beanClass(InterfaceExtension.class) .scope(ApplicationScoped.class) .addQualifier(Any.Literal.INSTANCE) .addQualifier(NamedLiteral.of(interfaceName.name() + "-interface")) .createSupplier(() -> iface) .addType(Interface.class) .addType(Object.class) .build(); abd.addBean(interfaceBean); } } } InterfaceExtension(ConfigView configView);   }
@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"); }