-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0044ecf
commit 58b8c27
Showing
8 changed files
with
39 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package ch.puzzle.okr.multitenancy; | ||
|
||
import ch.puzzle.okr.test.SpringIntegrationTest; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -24,8 +25,10 @@ public class TenantConfigProviderTestIT { | |
private static final String FRONTEND_CLIENT_ISSUER_URL = "frontendClientIssuerUrl"; | ||
private static final String FRONTEND_CLIENT_ID = "frontendClientId"; | ||
private static final String DATASOURCE_URL = "datasourceUrl"; | ||
private static final String DATASOURCE_NAME = "datasourceName"; | ||
private static final String DATASOURCE_PASSWORD = "datasourcePassword"; | ||
private static final String DATASOURCE_NAME_FLY = "datasourceNameFly"; | ||
private static final String DATASOURCE_PASSWORD_FLY = "datasourcePasswordFly"; | ||
private static final String DATASOURCE_NAME_APP = "datasourceNameApp"; | ||
private static final String DATASOURCE_PASSWORD_APP = "datasourcePasswordApp"; | ||
private static final String DATASOURCE_SCHEMA = "datasourceSchema"; | ||
private static final String DRIVER_CLASS_NAME = "driverClassName"; | ||
private static final String CHAMPION_EMAILS_1 = "[email protected]"; | ||
|
@@ -37,20 +40,30 @@ public class TenantConfigProviderTestIT { | |
@Mock | ||
private Environment env; | ||
|
||
private TenantConfigProvider configProvider; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
for (String tenantId : tenantIds) { | ||
setupPropertiesForTenantWithId(tenantId); | ||
} | ||
configProvider = new TenantConfigProvider(tenantIds, env); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
TenantConfigProvider.clearTenantConfigsCache(); | ||
} | ||
|
||
private void setupPropertiesForTenantWithId(String id) { | ||
mockProperty("okr.tenants.{0}.security.oauth2.resourceserver.jwt.jwk-set-uri", JWK_SET_URI, id); | ||
mockProperty("okr.tenants.{0}.security.oauth2.frontend.issuer-url", FRONTEND_CLIENT_ISSUER_URL, id); | ||
mockProperty("okr.tenants.{0}.security.oauth2.frontend.client-id", FRONTEND_CLIENT_ID, id); | ||
mockProperty("okr.tenants.{0}.datasource.url", DATASOURCE_URL, id); | ||
mockProperty("okr.tenants.{0}.datasource.username", DATASOURCE_NAME, id); | ||
mockProperty("okr.tenants.{0}.datasource.password", DATASOURCE_PASSWORD, id); | ||
mockProperty("okr.tenants.{0}.datasource.username.fly", DATASOURCE_NAME_FLY, id); | ||
mockProperty("okr.tenants.{0}.datasource.password.fly", DATASOURCE_PASSWORD_FLY, id); | ||
mockProperty("okr.tenants.{0}.datasource.username.app", DATASOURCE_NAME_APP, id); | ||
mockProperty("okr.tenants.{0}.datasource.password.app", DATASOURCE_PASSWORD_APP, id); | ||
mockProperty("okr.tenants.{0}.datasource.schema", DATASOURCE_SCHEMA, id); | ||
|
||
mockProperty("okr.datasource.driver-class-name", DRIVER_CLASS_NAME); | ||
|
@@ -78,7 +91,6 @@ private String prefix(String tenantId) { | |
@DisplayName("getTenantConfigs returns all TenantConfigs as List") | ||
@Test | ||
public void testGetTenantConfigs() { | ||
TenantConfigProvider configProvider = new TenantConfigProvider(tenantIds, env); | ||
List<TenantConfigProvider.TenantConfig> tenantConfigs = configProvider.getTenantConfigs(); | ||
for (TenantConfigProvider.TenantConfig config : tenantConfigs) { | ||
assertTenantConfigProvider(config); | ||
|
@@ -89,7 +101,6 @@ public void testGetTenantConfigs() { | |
@ParameterizedTest | ||
@CsvSource({ "pitc, acme" }) | ||
void testGetTenantConfigByIdForExistingTenantId(String tenantId) { | ||
TenantConfigProvider configProvider = new TenantConfigProvider(tenantIds, env); | ||
Optional<TenantConfigProvider.TenantConfig> config = configProvider.getTenantConfigById(tenantId); | ||
assertTrue(config.isPresent()); | ||
assertTenantConfigProvider(config.get()); | ||
|
@@ -99,7 +110,6 @@ void testGetTenantConfigByIdForExistingTenantId(String tenantId) { | |
@ParameterizedTest | ||
@CsvSource({ "PITC-London" }) | ||
void testGetTenantConfigByIdForNonExistingTenantId(String nonExistingTenantId) { | ||
TenantConfigProvider configProvider = new TenantConfigProvider(tenantIds, env); | ||
Optional<TenantConfigProvider.TenantConfig> config = configProvider.getTenantConfigById(nonExistingTenantId); | ||
assertTrue(config.isEmpty()); | ||
} | ||
|
@@ -108,9 +118,6 @@ void testGetTenantConfigByIdForNonExistingTenantId(String nonExistingTenantId) { | |
@ParameterizedTest | ||
@CsvSource({ "pitc", "acme" }) | ||
void testGetJwkSetUriForExistingTenantId(String tenantId) { | ||
// arrange | ||
TenantConfigProvider configProvider = new TenantConfigProvider(tenantIds, env); | ||
|
||
// act | ||
Optional<String> jwkSetUri = configProvider.getJwkSetUri(tenantId); | ||
|
||
|
@@ -123,7 +130,6 @@ void testGetJwkSetUriForExistingTenantId(String tenantId) { | |
@ParameterizedTest | ||
@CsvSource({ "PITC-London" }) | ||
void testGetJwkSetUriForNonExistingTenantId(String nonExistingTenantId) { | ||
TenantConfigProvider configProvider = new TenantConfigProvider(tenantIds, env); | ||
Optional<String> jwkSetUri = configProvider.getJwkSetUri(nonExistingTenantId); | ||
assertTrue(jwkSetUri.isEmpty()); | ||
} | ||
|
@@ -134,13 +140,15 @@ private void assertTenantConfigProvider(TenantConfigProvider.TenantConfig tenant | |
assertEquals(prefix(tenantId) + JWK_SET_URI, tenantConfig.jwkSetUri()); | ||
assertEquals(prefix(tenantId) + FRONTEND_CLIENT_ISSUER_URL, tenantConfig.issuerUrl()); | ||
assertEquals(prefix(tenantId) + FRONTEND_CLIENT_ID, tenantConfig.clientId()); | ||
assertEquals(prefix(tenantId) + DATASOURCE_URL, tenantConfig.dataSourceConfig().url()); | ||
assertEquals(prefix(tenantId) + DATASOURCE_NAME, tenantConfig.dataSourceConfig().name()); | ||
assertEquals(prefix(tenantId) + DATASOURCE_PASSWORD, tenantConfig.dataSourceConfig().password()); | ||
assertEquals(prefix(tenantId) + DATASOURCE_SCHEMA, tenantConfig.dataSourceConfig().schema()); | ||
assertEquals(prefix(tenantId) + DATASOURCE_URL, tenantConfig.dataSourceConfigFlyway().url()); | ||
assertEquals(prefix(tenantId) + DATASOURCE_NAME_FLY, tenantConfig.dataSourceConfigFlyway().name()); | ||
assertEquals(prefix(tenantId) + DATASOURCE_PASSWORD_FLY, tenantConfig.dataSourceConfigFlyway().password()); | ||
assertEquals(prefix(tenantId) + DATASOURCE_NAME_APP, tenantConfig.dataSourceConfigApp().name()); | ||
assertEquals(prefix(tenantId) + DATASOURCE_PASSWORD_APP, tenantConfig.dataSourceConfigApp().password()); | ||
assertEquals(prefix(tenantId) + DATASOURCE_SCHEMA, tenantConfig.dataSourceConfigApp().schema()); | ||
|
||
assertArrayEquals(new String[] { CHAMPION_EMAILS_1, CHAMPION_EMAILS_2 }, tenantConfig.okrChampionEmails()); | ||
assertEquals(DRIVER_CLASS_NAME, tenantConfig.dataSourceConfig().driverClassName()); | ||
assertEquals(DRIVER_CLASS_NAME, tenantConfig.dataSourceConfigFlyway().driverClassName()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ void updateUserAsNoChampion() { | |
// arrange | ||
User noChampionUser = User.Builder.builder().withEmail("[email protected]").build(); | ||
TenantConfigProvider.TenantConfig tenantConfig = new TenantConfigProvider.TenantConfig(null, // | ||
new String[] { "[email protected]" }, null, null, null, null); | ||
new String[] { "[email protected]" }, null, null, null, null, null); | ||
|
||
// act | ||
User updatedUser = helper.setOkrChampionFromProperties(noChampionUser, tenantConfig); | ||
|
@@ -61,7 +61,7 @@ void updateUserAsChampion() { | |
// arrange | ||
User championUser = User.Builder.builder().withEmail("[email protected]").build(); | ||
TenantConfigProvider.TenantConfig tenantConfig = new TenantConfigProvider.TenantConfig(null, // | ||
new String[] { "[email protected]" }, null, null, null, null); | ||
new String[] { "[email protected]" }, null, null, null, null, null); | ||
|
||
// act | ||
User updatedUser = helper.setOkrChampionFromProperties(championUser, tenantConfig); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters