Skip to content

Commit

Permalink
bring back the test
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Aug 28, 2024
1 parent fe989a1 commit 847dfbe
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,37 @@ void resolveDefaultDataSourceProperties() {
});
}

@Test
void resolveTenantDataSource() {
DataSource mockDataSource = mock(DataSource.class);
AtomicBoolean dataSourceResolved = new AtomicBoolean(false);
Function<TenantDescriptor, DataSource> 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();
});
}

}

0 comments on commit 847dfbe

Please sign in to comment.