-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RHCLOUD-35924 | feature: tests for the configuration override (#3113)
* feature: tests for the configuration override The tests will solidify the implementation. RHCLOUD-35924 * fix: the Kessel gRPC port is 9000 for both Inventory and Relations RHCLOUD-35924
- Loading branch information
1 parent
646b458
commit 503b0f7
Showing
2 changed files
with
81 additions
and
13 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
77 changes: 77 additions & 0 deletions
77
backend/src/test/java/com/redhat/cloud/notifications/config/KesselConfigInterceptorTest.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,77 @@ | ||
package com.redhat.cloud.notifications.config; | ||
|
||
import io.smallrye.config.ConfigSourceInterceptorContext; | ||
import io.smallrye.config.ConfigValue; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.stream.Stream; | ||
|
||
public class KesselConfigInterceptorTest { | ||
private final KesselConfigInterceptor kesselConfigInterceptor = new KesselConfigInterceptor(); | ||
|
||
/** | ||
* Test cases which make sure that the configuration interceptor only | ||
* overrides the configuration properties when they're Kessel properties | ||
* and their values are URLs. | ||
* @return the stream of arguments to try. | ||
*/ | ||
private static Stream<Arguments> testCases() { | ||
return Stream.of( | ||
Arguments.of("another-property-which-should-not-be-overwritten", "value", "value"), | ||
Arguments.of("another-property-which-should-not-be-overwritten", "http://kessel-url:8000", "http://kessel-url:8000"), | ||
Arguments.of("another-property-which-should-not-be-overwritten", "https://kessel-url:8000", "https://kessel-url:8000"), | ||
Arguments.of("inventory-api.target-url", "invalidUrl", "invalidUrl"), | ||
Arguments.of("inventory-api.target-url", "localhost:8000", "localhost:8000"), | ||
Arguments.of("inventory-api.target-url", "http://kessel-inventory-api.url.test:8000", "kessel-inventory-api.url.test:9000"), | ||
Arguments.of("inventory-api.target-url", "https://kessel-inventory-api-secure.url.test:8000", "kessel-inventory-api-secure.url.test:9000"), | ||
Arguments.of("relations-api.target-url", "invalidUrl", "invalidUrl"), | ||
Arguments.of("relations-api.target-url", "localhost:8000", "localhost:8000"), | ||
Arguments.of("relations-api.target-url", "http://kessel-relations-api.url.test:8000", "kessel-relations-api.url.test:9000"), | ||
Arguments.of("relations-api.target-url", "https://kessel-relations-api-secure.url.test:8000", "kessel-relations-api-secure.url.test:9000") | ||
); | ||
} | ||
|
||
/** | ||
* Tests that the Kessel properties are overriden when the property values | ||
* are URLs. | ||
* @param configurationPropertyName the configuration property name that | ||
* might get overriden. | ||
* @param configurationPropertyValue the original configuration property | ||
* value as it would be read from the | ||
* properties files or the environment | ||
* variables. | ||
* @param expectedFinalValue the expected final value of the configuration | ||
* property after it has been overriden or not. | ||
*/ | ||
@MethodSource("testCases") | ||
@ParameterizedTest | ||
void testConfigurationOverrides(final String configurationPropertyName, final String configurationPropertyValue, final String expectedFinalValue) { | ||
Assertions.assertEquals( | ||
expectedFinalValue, | ||
this.kesselConfigInterceptor.getValue(this.mockConfigSourceInterceptorContext(configurationPropertyName, configurationPropertyValue), configurationPropertyName).getValue(), | ||
"unexpected configuration property value received" | ||
); | ||
} | ||
|
||
/** | ||
* Mocks the configuration source context. | ||
* @param configurationPropertyName the property name that is simulated to | ||
* be processed. | ||
* @param configurationPropertyValue the original property value that is | ||
* simulated to be read from properties | ||
* or environment values. | ||
* @return the built configuration source interceptor context. | ||
*/ | ||
private ConfigSourceInterceptorContext mockConfigSourceInterceptorContext(final String configurationPropertyName, final String configurationPropertyValue) { | ||
final ConfigSourceInterceptorContext configSourceInterceptorContext = Mockito.mock(ConfigSourceInterceptorContext.class); | ||
|
||
final ConfigValue configValue = ConfigValue.builder().withValue(configurationPropertyValue).build(); | ||
Mockito.when(configSourceInterceptorContext.proceed(configurationPropertyName)).thenReturn(configValue); | ||
|
||
return configSourceInterceptorContext; | ||
} | ||
} |