-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support contextprovider as a method parameter
- Loading branch information
1 parent
5d47c2f
commit 4c224a8
Showing
5 changed files
with
153 additions
and
2 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
27 changes: 27 additions & 0 deletions
27
src/test/java/org/zalando/baigan/e2e/filerepo/CustomContextProvider.java
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.zalando.baigan.e2e.filerepo; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.zalando.baigan.context.ContextProvider; | ||
|
||
import java.util.Set; | ||
|
||
public class CustomContextProvider implements ContextProvider { | ||
|
||
private final Set<String> PARAMS = Set.of("appdomain"); | ||
|
||
private final String appDomain; | ||
|
||
public CustomContextProvider(String appDomain) { | ||
this.appDomain = appDomain; | ||
} | ||
|
||
@Override | ||
public String getContextParam(@NotNull final String name) { | ||
return appDomain; | ||
} | ||
|
||
@Override | ||
public Set<String> getProvidedContexts() { | ||
return PARAMS; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...va/org/zalando/baigan/e2e/filerepo/FileSystemConfigurationContextProviderEnd2EndTest.java
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.zalando.baigan.e2e.filerepo; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.zalando.baigan.BaiganSpringContext; | ||
import org.zalando.baigan.annotation.ConfigurationServiceScan; | ||
import org.zalando.baigan.e2e.configs.SomeConfiguration; | ||
import org.zalando.baigan.repository.FileSystemConfigurationRepository; | ||
import org.zalando.baigan.repository.RepositoryFactory; | ||
|
||
import java.time.Duration; | ||
|
||
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@ContextConfiguration(classes = {FileSystemConfigurationContextProviderEnd2EndTest.RepoConfig.class}) | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
public class FileSystemConfigurationContextProviderEnd2EndTest { | ||
|
||
@Autowired | ||
private SomeConfiguration someConfiguration; | ||
|
||
private static final Duration CONFIG_REFRESH_INTERVAL = Duration.ofMillis(100); | ||
|
||
@Test | ||
public void testConfigurationsWithContext() { | ||
assertThat(someConfiguration.toggleFlag(new CustomContextProvider("1")), equalTo(true)); | ||
assertThat(someConfiguration.toggleFlag(new CustomContextProvider("2")), equalTo(false)); | ||
assertThat(someConfiguration.toggleFlag(null), equalTo(false)); | ||
} | ||
|
||
@ConfigurationServiceScan(basePackageClasses = SomeConfiguration.class) | ||
@Testcontainers | ||
@ComponentScan(basePackageClasses = {BaiganSpringContext.class}) | ||
static class RepoConfig { | ||
|
||
@Bean | ||
FileSystemConfigurationRepository configurationRepository(RepositoryFactory repositoryFactory) { | ||
return repositoryFactory.fileSystemConfigurationRepository() | ||
.fileName(FileSystemConfigurationContextProviderEnd2EndTest.class.getClassLoader().getResource("test-config.json").getPath()) | ||
.refreshInterval(CONFIG_REFRESH_INTERVAL) | ||
.objectMapper(new ObjectMapper().configure(FAIL_ON_UNKNOWN_PROPERTIES, false)) | ||
.build(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[ | ||
{ | ||
"alias": "some.non.existing.config", | ||
"defaultValue": "an irrelevant value" | ||
}, | ||
{ | ||
"alias": "some.configuration.is.this.true", | ||
"defaultValue": false, | ||
"conditions": [ | ||
{ | ||
"value": true, | ||
"conditionType": { | ||
"onValue": "1", | ||
"type": "Equals" | ||
}, | ||
"paramName": "appdomain" | ||
} | ||
] | ||
}, | ||
{ | ||
"alias": "some.configuration.some.value", | ||
"defaultValue": "some value" | ||
}, | ||
{ | ||
"alias": "some.configuration.some.config", | ||
"defaultValue": { | ||
"config_key": "a value", | ||
"extra_field": "objectMapper configured to not fail for unknown properties" | ||
} | ||
}, | ||
{ | ||
"alias": "some.configuration.toggle.flag", | ||
"defaultValue": false, | ||
"conditions": [ | ||
{ | ||
"value": true, | ||
"conditionType": { | ||
"onValue": "1", | ||
"type": "Equals" | ||
}, | ||
"paramName": "appdomain" | ||
} | ||
] | ||
}, | ||
{ | ||
"alias": "some.configuration.config.list", | ||
"defaultValue": [ | ||
"A", | ||
"B" | ||
] | ||
} | ||
] |