@Test public void updateUserRaisesEvent() { ApplicationEventPublisher applicationEventPublisher = mock(ApplicationEventPublisher.class); UserController userController = mock(UserController.class); doAnswer((invocationOnMock -> new User((String)invocationOnMock.getArguments()[0], (String)invocationOnMock.getArguments()[1]) )).when(userController).updateUser(any(), any(), any()); UserControllerFacade facade = testSubject.userControllerFacade(userController, applicationEventPublisher); facade.updateUser("User", "Password", Collections.emptySet()); verify(applicationEventPublisher).publishEvent(argThat(new ArgumentMatcher<Object>() { @Override public boolean matches(Object o) { return o instanceof UserEvents.UserUpdated&& ((UserEvents.UserUpdated) o).getUser().getUserName().equals("User"); } })); }
@Bean @ConditionalOnMissingBean(UserControllerFacade.class) public UserControllerFacade userControllerFacade(UserController userController, ApplicationEventPublisher eventPublisher) { return new UserControllerFacade() { @Override public void updateUser(String userName, String password, Set<UserRole> roles) { validateContexts(roles); User updatedUser = userController.updateUser(userName, password, roles); eventPublisher.publishEvent(new UserEvents.UserUpdated(updatedUser, false)); } private void validateContexts(Set<UserRole> roles) { if (roles == null) { return; } if (roles.stream().anyMatch(userRole -> !validContext(userRole.getContext()))) { throw new MessagingPlatformException(ErrorCode.CONTEXT_NOT_FOUND, "Only specify context default for standard edition"); } } private boolean validContext(String context) { return context == null || context.equals(Topology.DEFAULT_CONTEXT) || context.equals("*"); } @Override public List<User> getUsers() { return userController.getUsers(); } @Override public void deleteUser(String name) { userController.deleteUser(name); eventPublisher.publishEvent(new UserEvents.UserDeleted(name, false)); } }; }
AxonServerStandardConfiguration { @Bean @ConditionalOnMissingBean(UserControllerFacade.class) public UserControllerFacade userControllerFacade(UserController userController, ApplicationEventPublisher eventPublisher) { return new UserControllerFacade() { @Override public void updateUser(String userName, String password, Set<UserRole> roles) { validateContexts(roles); User updatedUser = userController.updateUser(userName, password, roles); eventPublisher.publishEvent(new UserEvents.UserUpdated(updatedUser, false)); } private void validateContexts(Set<UserRole> roles) { if (roles == null) { return; } if (roles.stream().anyMatch(userRole -> !validContext(userRole.getContext()))) { throw new MessagingPlatformException(ErrorCode.CONTEXT_NOT_FOUND, "Only specify context default for standard edition"); } } private boolean validContext(String context) { return context == null || context.equals(Topology.DEFAULT_CONTEXT) || context.equals("*"); } @Override public List<User> getUsers() { return userController.getUsers(); } @Override public void deleteUser(String name) { userController.deleteUser(name); eventPublisher.publishEvent(new UserEvents.UserDeleted(name, false)); } }; } }
AxonServerStandardConfiguration { @Bean @ConditionalOnMissingBean(UserControllerFacade.class) public UserControllerFacade userControllerFacade(UserController userController, ApplicationEventPublisher eventPublisher) { return new UserControllerFacade() { @Override public void updateUser(String userName, String password, Set<UserRole> roles) { validateContexts(roles); User updatedUser = userController.updateUser(userName, password, roles); eventPublisher.publishEvent(new UserEvents.UserUpdated(updatedUser, false)); } private void validateContexts(Set<UserRole> roles) { if (roles == null) { return; } if (roles.stream().anyMatch(userRole -> !validContext(userRole.getContext()))) { throw new MessagingPlatformException(ErrorCode.CONTEXT_NOT_FOUND, "Only specify context default for standard edition"); } } private boolean validContext(String context) { return context == null || context.equals(Topology.DEFAULT_CONTEXT) || context.equals("*"); } @Override public List<User> getUsers() { return userController.getUsers(); } @Override public void deleteUser(String name) { userController.deleteUser(name); eventPublisher.publishEvent(new UserEvents.UserDeleted(name, false)); } }; }  }
AxonServerStandardConfiguration { @Bean @ConditionalOnMissingBean(UserControllerFacade.class) public UserControllerFacade userControllerFacade(UserController userController, ApplicationEventPublisher eventPublisher) { return new UserControllerFacade() { @Override public void updateUser(String userName, String password, Set<UserRole> roles) { validateContexts(roles); User updatedUser = userController.updateUser(userName, password, roles); eventPublisher.publishEvent(new UserEvents.UserUpdated(updatedUser, false)); } private void validateContexts(Set<UserRole> roles) { if (roles == null) { return; } if (roles.stream().anyMatch(userRole -> !validContext(userRole.getContext()))) { throw new MessagingPlatformException(ErrorCode.CONTEXT_NOT_FOUND, "Only specify context default for standard edition"); } } private boolean validContext(String context) { return context == null || context.equals(Topology.DEFAULT_CONTEXT) || context.equals("*"); } @Override public List<User> getUsers() { return userController.getUsers(); } @Override public void deleteUser(String name) { userController.deleteUser(name); eventPublisher.publishEvent(new UserEvents.UserDeleted(name, false)); } }; }  @Bean @ConditionalOnMissingBean(StorageTransactionManagerFactory.class) StorageTransactionManagerFactory storageTransactionManagerFactory(); @Bean @ConditionalOnMissingBean(EventTransformerFactory.class) EventTransformerFactory eventTransformerFactory(); @Bean @ConditionalOnMissingBean(EventStoreFactory.class) EventStoreFactory eventStoreFactory(EmbeddedDBProperties embeddedDBProperties,
                                               EventTransformerFactory eventTransformerFactory,
                                               StorageTransactionManagerFactory storageTransactionManagerFactory,
                                               MeterFactory meterFactory); @Bean @ConditionalOnMissingBean(QueryHandlerSelector.class) QueryHandlerSelector queryHandlerSelector(); @Bean @ConditionalOnMissingBean(Topology.class) Topology topology(MessagingPlatformConfiguration configuration); @Bean @ConditionalOnMissingBean(MetricCollector.class) MetricCollector metricCollector(); @Bean @ConditionalOnMissingBean(EventStoreLocator.class) EventStoreLocator eventStoreLocator(LocalEventStore localEventStore); @Bean @ConditionalOnMissingBean(FeatureChecker.class) FeatureChecker featureChecker(); @Bean @ConditionalOnMissingBean(EventSchedulerGrpc.EventSchedulerImplBase.class) AxonServerClientService eventSchedulerService(StandaloneTaskManager localTaskManager,
                                                         TaskPayloadSerializer taskPayloadSerializer); @Bean @ConditionalOnMissingBean(EventDecorator.class) EventDecorator eventDecorator(); @Bean PasswordEncoder passwordEncoder(); @Bean @Qualifier("taskScheduler") ScheduledExecutorService scheduler(); @Bean @ConditionalOnMissingBean(UserControllerFacade.class) UserControllerFacade userControllerFacade(UserController userController,
                                                     ApplicationEventPublisher eventPublisher); @Bean Clock clock(); @Bean @Qualifier("platformInstructionAckSource") InstructionAckSource<PlatformOutboundInstruction> platformInstructionAckSource(); @Bean @Qualifier("commandInstructionAckSource") InstructionAckSource<SerializedCommandProviderInbound> commandInstructionAckSource(); @Bean @Qualifier("queryInstructionAckSource") InstructionAckSource<QueryProviderInbound> queryInstructionAckSource(); @Bean @ConditionalOnMissingBean(VersionInfoProvider.class) VersionInfoProvider versionInfoProvider(); @Bean @ConditionalOnMissingBean(StandaloneTaskManager.class) StandaloneTaskManager localTaskManager(ScheduledTaskExecutor taskExecutor,
                                                  TaskRepository taskRepository,
                                                  TaskPayloadSerializer taskPayloadSerializer,
                                                  PlatformTransactionManager platformTransactionManager,
                                                  @Qualifier("taskScheduler") ScheduledExecutorService scheduler,
                                                  Clock clock); @Bean ApplicationEventMulticaster applicationEventMulticaster(); }
AxonServerStandardConfiguration { @Bean @ConditionalOnMissingBean(UserControllerFacade.class) public UserControllerFacade userControllerFacade(UserController userController, ApplicationEventPublisher eventPublisher) { return new UserControllerFacade() { @Override public void updateUser(String userName, String password, Set<UserRole> roles) { validateContexts(roles); User updatedUser = userController.updateUser(userName, password, roles); eventPublisher.publishEvent(new UserEvents.UserUpdated(updatedUser, false)); } private void validateContexts(Set<UserRole> roles) { if (roles == null) { return; } if (roles.stream().anyMatch(userRole -> !validContext(userRole.getContext()))) { throw new MessagingPlatformException(ErrorCode.CONTEXT_NOT_FOUND, "Only specify context default for standard edition"); } } private boolean validContext(String context) { return context == null || context.equals(Topology.DEFAULT_CONTEXT) || context.equals("*"); } @Override public List<User> getUsers() { return userController.getUsers(); } @Override public void deleteUser(String name) { userController.deleteUser(name); eventPublisher.publishEvent(new UserEvents.UserDeleted(name, false)); } }; }  @Bean @ConditionalOnMissingBean(StorageTransactionManagerFactory.class) StorageTransactionManagerFactory storageTransactionManagerFactory(); @Bean @ConditionalOnMissingBean(EventTransformerFactory.class) EventTransformerFactory eventTransformerFactory(); @Bean @ConditionalOnMissingBean(EventStoreFactory.class) EventStoreFactory eventStoreFactory(EmbeddedDBProperties embeddedDBProperties,
                                               EventTransformerFactory eventTransformerFactory,
                                               StorageTransactionManagerFactory storageTransactionManagerFactory,
                                               MeterFactory meterFactory); @Bean @ConditionalOnMissingBean(QueryHandlerSelector.class) QueryHandlerSelector queryHandlerSelector(); @Bean @ConditionalOnMissingBean(Topology.class) Topology topology(MessagingPlatformConfiguration configuration); @Bean @ConditionalOnMissingBean(MetricCollector.class) MetricCollector metricCollector(); @Bean @ConditionalOnMissingBean(EventStoreLocator.class) EventStoreLocator eventStoreLocator(LocalEventStore localEventStore); @Bean @ConditionalOnMissingBean(FeatureChecker.class) FeatureChecker featureChecker(); @Bean @ConditionalOnMissingBean(EventSchedulerGrpc.EventSchedulerImplBase.class) AxonServerClientService eventSchedulerService(StandaloneTaskManager localTaskManager,
                                                         TaskPayloadSerializer taskPayloadSerializer); @Bean @ConditionalOnMissingBean(EventDecorator.class) EventDecorator eventDecorator(); @Bean PasswordEncoder passwordEncoder(); @Bean @Qualifier("taskScheduler") ScheduledExecutorService scheduler(); @Bean @ConditionalOnMissingBean(UserControllerFacade.class) UserControllerFacade userControllerFacade(UserController userController,
                                                     ApplicationEventPublisher eventPublisher); @Bean Clock clock(); @Bean @Qualifier("platformInstructionAckSource") InstructionAckSource<PlatformOutboundInstruction> platformInstructionAckSource(); @Bean @Qualifier("commandInstructionAckSource") InstructionAckSource<SerializedCommandProviderInbound> commandInstructionAckSource(); @Bean @Qualifier("queryInstructionAckSource") InstructionAckSource<QueryProviderInbound> queryInstructionAckSource(); @Bean @ConditionalOnMissingBean(VersionInfoProvider.class) VersionInfoProvider versionInfoProvider(); @Bean @ConditionalOnMissingBean(StandaloneTaskManager.class) StandaloneTaskManager localTaskManager(ScheduledTaskExecutor taskExecutor,
                                                  TaskRepository taskRepository,
                                                  TaskPayloadSerializer taskPayloadSerializer,
                                                  PlatformTransactionManager platformTransactionManager,
                                                  @Qualifier("taskScheduler") ScheduledExecutorService scheduler,
                                                  Clock clock); @Bean ApplicationEventMulticaster applicationEventMulticaster();  }