ServiceComponentScanner implements Extension { @SuppressWarnings("unused") void afterDeploymentValidation(@Observes final AfterDeploymentValidation event, final BeanManager beanManager) { final Set<Bean<?>> directAdapters = beanManager.getBeans(SynchronousDirectAdapter.class); allBeansFrom(beanManager) .filter(this::isServiceComponent) .filter(bean -> isNotDirectComponentWithoutAdapter(bean, directAdapters)) .forEach(this::processServiceComponentsForEvents); fireAllCollectedEvents(beanManager); }    }
@SuppressWarnings("unchecked") @Test public void shouldNotFireAnyEventWithNoHandler() throws Exception { mockBeanManagerGetBeansWith(TestBean.of(Object.class)); serviceComponentScanner.afterDeploymentValidation(NOT_USED_AFTER_DEPLOYMENT_VALIDATION, beanManager); verify(beanManager, never()).fireEvent(any()); }
@Test public void shouldFireEventForDirectHandlerIfCorrespondingDirectAdapterExists() throws Exception { final ArgumentCaptor<ServiceComponentFoundEvent> captor = ArgumentCaptor.forClass(ServiceComponentFoundEvent.class); doReturn(new HashSet<Bean<Object>>(asList(TestBean.of(TestDirectQueryViewAdapter.class), TestBean.of(TestDirectQueryApiHandler.class)))).when(beanManager).getBeans(any(), any()); doReturn(new HashSet<Bean<Object>>(asList(TestBean.of(TestDirectQueryViewAdapter.class)))).when(beanManager).getBeans(SynchronousDirectAdapter.class); serviceComponentScanner.afterDeploymentValidation(NOT_USED_AFTER_DEPLOYMENT_VALIDATION, beanManager); verify(beanManager).fireEvent(captor.capture()); assertThat(captor.getValue(), instanceOf(ServiceComponentFoundEvent.class)); assertThat(captor.getValue().getHandlerBean().getBeanClass(), equalTo(TestDirectQueryApiHandler.class)); assertThat(captor.getValue().getLocation(), equalTo(ServiceComponentLocation.REMOTE)); }
@Test public void shouldNotFireEventForDirectComponentIfCorrespondingDirectAdapterDoesNotExist() throws Exception { doReturn(new HashSet<Bean<Object>>(asList( TestBean.of(OtherTestDirectAdapter.class), TestBean.of(TestDirectQueryApiHandler.class)))) .when(beanManager).getBeans(any(), any()); doReturn(new HashSet<Bean<Object>>(asList(TestBean.of(OtherTestDirectAdapter.class)))) .when(beanManager).getBeans(SynchronousDirectAdapter.class); serviceComponentScanner.afterDeploymentValidation(NOT_USED_AFTER_DEPLOYMENT_VALIDATION, beanManager); verify(beanManager, never()).fireEvent(any()); }