diff --git a/multitenancy-spring-boot-autoconfigure/src/test/java/org/axonframework/extensions/multitenancy/autoconfig/MultiTenantDataSourceManagerTest.java b/multitenancy-spring-boot-autoconfigure/src/test/java/org/axonframework/extensions/multitenancy/autoconfig/MultiTenantDataSourceManagerTest.java index ea88619..c89ea72 100644 --- a/multitenancy-spring-boot-autoconfigure/src/test/java/org/axonframework/extensions/multitenancy/autoconfig/MultiTenantDataSourceManagerTest.java +++ b/multitenancy-spring-boot-autoconfigure/src/test/java/org/axonframework/extensions/multitenancy/autoconfig/MultiTenantDataSourceManagerTest.java @@ -95,4 +95,37 @@ void resolveDefaultDataSourceProperties() { }); } + @Test + void resolveTenantDataSource() { + DataSource mockDataSource = mock(DataSource.class); + AtomicBoolean dataSourceResolved = new AtomicBoolean(false); + Function tenantDataSourceResolver = + (tenant) -> { + dataSourceResolved.set(true); + return mockDataSource; + + }; + + DataSourceProperties defaultDataSourceProperties = mock(DataSourceProperties.class); + DataSourceBuilder mockBuilder = mock(DataSourceBuilder.class); + when(mockBuilder.build()).thenReturn(mockDataSource); + when(defaultDataSourceProperties.initializeDataSourceBuilder()).thenReturn(mockBuilder); + + TenantProvider tenantProvider = mock(TenantProvider.class); + when(tenantProvider.subscribe(any())).thenReturn(() -> true); + + this.contextRunner.withPropertyValues("axon.axonserver.contexts=default") + .withAllowBeanDefinitionOverriding(true) + .withBean(TenantProvider.class, () -> tenantProvider) + .withBean("tenantDataSourceResolver", Function.class, () -> tenantDataSourceResolver) + .withBean("properties", DataSourceProperties.class, () -> defaultDataSourceProperties) + .run(context -> { + assertThat(context).hasSingleBean(MultiTenantDataSourceManager.class); + MultiTenantDataSourceManager multiTenantDataSourceManager = context.getBean(MultiTenantDataSourceManager.class); + verify(tenantProvider).subscribe(multiTenantDataSourceManager); + multiTenantDataSourceManager.registerTenant(TenantDescriptor.tenantWithId("test")); + assertThat(dataSourceResolved.get()).isTrue(); + }); + } + } \ No newline at end of file