-
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.
Merge pull request #101 from rameshmalla/main
Support contextprovider as a method parameter
- Loading branch information
Showing
6 changed files
with
164 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
1 change: 1 addition & 0 deletions
1
src/test/java/org/zalando/baigan/e2e/configs/SomeConfiguration.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
15 changes: 15 additions & 0 deletions
15
src/test/java/org/zalando/baigan/e2e/configs/TestContextConfiguration.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,15 @@ | ||
package org.zalando.baigan.e2e.configs; | ||
|
||
import org.zalando.baigan.annotation.BaiganConfig; | ||
import org.zalando.baigan.e2e.filerepo.CustomContextProvider; | ||
|
||
@BaiganConfig | ||
public interface TestContextConfiguration { | ||
|
||
String someValue(); | ||
|
||
Boolean isThisTrue(CustomContextProvider customContextProvider); | ||
|
||
Boolean toggleFlag(CustomContextProvider customContextProvider, CustomContextProvider secondProvider); | ||
|
||
} |
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; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...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,61 @@ | ||
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.TestContextConfiguration; | ||
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; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@ContextConfiguration(classes = {FileSystemConfigurationContextProviderEnd2EndTest.RepoConfig.class}) | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
public class FileSystemConfigurationContextProviderEnd2EndTest { | ||
|
||
@Autowired | ||
private TestContextConfiguration testContextConfiguration; | ||
|
||
private static final Duration CONFIG_REFRESH_INTERVAL = Duration.ofMillis(100); | ||
|
||
@Test | ||
public void testConfigurationsWithMultipleContextsHavingTheSameKeyShouldFail() { | ||
assertThrows(RuntimeException.class, () -> testContextConfiguration.toggleFlag(new CustomContextProvider("1"), new CustomContextProvider("3"))); | ||
} | ||
|
||
@Test | ||
public void testConfigurationsWithMultipleContexts() { | ||
assertThat(testContextConfiguration.isThisTrue(new CustomContextProvider("1")), equalTo(true)); | ||
assertThat(testContextConfiguration.someValue(), equalTo("some value")); | ||
} | ||
|
||
@ConfigurationServiceScan(basePackageClasses = TestContextConfiguration.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,34 @@ | ||
[ | ||
{ | ||
"alias": "test.context.configuration.is.this.true", | ||
"defaultValue": false, | ||
"conditions": [ | ||
{ | ||
"value": true, | ||
"conditionType": { | ||
"onValue": "1", | ||
"type": "Equals" | ||
}, | ||
"paramName": "appdomain" | ||
} | ||
] | ||
}, | ||
{ | ||
"alias": "test.context.configuration.some.value", | ||
"defaultValue": "some value" | ||
}, | ||
{ | ||
"alias": "test.context.configuration.toggle.flag", | ||
"defaultValue": false, | ||
"conditions": [ | ||
{ | ||
"value": true, | ||
"conditionType": { | ||
"onValue": "1", | ||
"type": "Equals" | ||
}, | ||
"paramName": "appdomain" | ||
} | ||
] | ||
} | ||
] |