Skip to content

Commit

Permalink
test: add test for config changes ref: #26391
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Oct 24, 2023
1 parent b5b470d commit 01ecc6c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions dotCMS/src/test/java/com/dotmarketing/util/ConfigTest.java
Expand Up @@ -17,6 +17,7 @@
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.tuckey.web.filters.urlrewrite.Conf;

public class ConfigTest {

Expand Down Expand Up @@ -316,6 +317,48 @@ public void test_isKeyEnvBased() {
assertTrue(Config.isKeyEnvBased(MY_ENV_VAR_PROPERTY));
}

/**
* Method to test {@link Config#envKey(String)}
* Checks if the method is converting the key to env key successfully.
*/
@Test
public void test_envKey_keyWithoutPrefix_returnsEnvKey() {
final String MY_ENV_VAR_PROPERTY = "my.env.var.property";
final String convertedProperty = Config.envKey(MY_ENV_VAR_PROPERTY);

assertTrue(convertedProperty.contains("DOT_"));
assertFalse(convertedProperty.contains("."));
}

/**
* Method to test {@link Config#envKey(String)}
* If the key is already an Env Key it doesn't need to be converted.
*/
@Test
public void test_envKey_keyWithPrefix_returnsEnvKey() {
final String DOT_MY_ENV_VAR_PROPERTY = "DOT_MY_ENV_VAR_PROPERTY";
final String convertedProperty = Config.envKey(DOT_MY_ENV_VAR_PROPERTY);

assertTrue(convertedProperty.contains("DOT_"));
assertFalse(convertedProperty.contains("."));
assertFalse(convertedProperty.contains("DOT_DOT_"));
}

/**
* Method to test {@link Config#subsetContainsAsList(String)}
* Pull out all the properties that contains the given string, in this case testSubset.
*/
@Test
public void test_subsetContainsAsList(){
Config.props.addProperty("DOT_testSubset_anyKey","anyValue");
Config.props.addProperty("testSubset.anyKey","anyValue");

final List<String> properties = Config.subsetContainsAsList("testSubset");
assertTrue(properties.size()>=2);
assertTrue(properties.contains("DOT_testSubset_anyKey"));
assertTrue(properties.contains("testSubset.anyKey"));
}

/*
*
* Restore default variables for each test
Expand Down

0 comments on commit 01ecc6c

Please sign in to comment.