diff --git a/jberet-se/pom.xml b/jberet-se/pom.xml
index abf2abf44..7f274400d 100644
--- a/jberet-se/pom.xml
+++ b/jberet-se/pom.xml
@@ -71,6 +71,11 @@ SPDX-License-Identifier: EPL-2.0
org.junit.jupiter
junit-jupiter-api
+
+ org.junit.jupiter
+ junit-jupiter-params
+ test
+
diff --git a/jberet-se/src/main/java/org/jberet/se/BatchSEEnvironment.java b/jberet-se/src/main/java/org/jberet/se/BatchSEEnvironment.java
index 7a31e2edf..afaf2ae6f 100644
--- a/jberet-se/src/main/java/org/jberet/se/BatchSEEnvironment.java
+++ b/jberet-se/src/main/java/org/jberet/se/BatchSEEnvironment.java
@@ -12,6 +12,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.List;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.concurrent.BlockingQueue;
@@ -62,7 +63,7 @@ public final class BatchSEEnvironment implements BatchEnvironment {
private final JobXmlResolver jobXmlResolver;
private final JobExecutor executor;
- private static final String PROP_PATTERN_STR = "\\$\\{([0-9a-zA-Z_\\-]+)(:([0-9a-zA-Z_\\-]*))?\\}";
+ private static final String PROP_PATTERN_STR = "\\$\\{([0-9a-zA-Z_\\-]+)(:([0-9a-zA-Z_\\-;:=/.]*))?\\}";
private static final Pattern PROP_PATTERN = Pattern.compile(PROP_PATTERN_STR);
@@ -80,8 +81,13 @@ public final class BatchSEEnvironment implements BatchEnvironment {
static final String THREAD_POOL_REJECTION_POLICY = "thread-pool-rejection-policy";
static final String THREAD_FACTORY = "thread-factory";
+ static final String DB_URL_KEY = "db-url";
static final String DB_USER_KEY = "db-user";
static final String DB_PASSWORD_KEY = "db-password";
+ static final String DB_TABLE_PREFIX_KEY = "db-table-prefix";
+ static final String DB_TABLE_SUFFIX_KEY = "db-table-suffix";
+
+ static final List PROP_NAMES_THAT_COULD_HAVE_A_DEFAULT_VALUE = List.of(DB_URL_KEY, DB_USER_KEY, DB_PASSWORD_KEY, DB_TABLE_PREFIX_KEY, DB_TABLE_SUFFIX_KEY);
public BatchSEEnvironment() {
configProperties = new Properties();
@@ -91,16 +97,11 @@ public BatchSEEnvironment() {
configProperties.load(configStream);
if (configProperties.getProperty(JOB_REPOSITORY_TYPE_KEY).equals(REPOSITORY_TYPE_JDBC) ||
configProperties.getProperty(JOB_REPOSITORY_TYPE_KEY).equals(REPOSITORY_TYPE_MONGODB)) {
-
- String dbUser = configProperties.getProperty(DB_USER_KEY);
- String dbPassword = configProperties.getProperty(DB_PASSWORD_KEY);
-
- if (dbUser != null) {
- configProperties.setProperty(DB_USER_KEY, parseProp(dbUser));
- }
-
- if (dbPassword != null) {
- configProperties.setProperty(DB_PASSWORD_KEY, parseProp(dbPassword));
+ for (String propName : PROP_NAMES_THAT_COULD_HAVE_A_DEFAULT_VALUE) {
+ final String propVal = configProperties.getProperty(propName);
+ if (propVal != null) {
+ configProperties.setProperty(propName, parseProp(propVal));
+ }
}
}
} catch (final IOException e) {
diff --git a/jberet-se/src/test/java/org/jberet/se/BatchSEEnvironmentTest.java b/jberet-se/src/test/java/org/jberet/se/BatchSEEnvironmentTest.java
index 767b2110e..9c04ebe8e 100644
--- a/jberet-se/src/test/java/org/jberet/se/BatchSEEnvironmentTest.java
+++ b/jberet-se/src/test/java/org/jberet/se/BatchSEEnvironmentTest.java
@@ -16,11 +16,16 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
import jakarta.batch.operations.BatchRuntimeException;
import org.jberet.repository.JdbcRepository;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import static org.jberet.se.BatchSEEnvironment.THREAD_FACTORY;
import static org.jberet.se.BatchSEEnvironment.THREAD_POOL_ALLOW_CORE_THREAD_TIMEOUT;
@@ -156,30 +161,29 @@ public void testResolveDbProps() {
.getProperty(JdbcRepository.DB_USER_KEY));
}
+ @ParameterizedTest
+ @MethodSource("provideValuesForTestingPropParsing")
+ public void testPropParsings(String propValue, String expectedAfterParsing) {
+ Assertions.assertEquals(expectedAfterParsing, BatchSEEnvironment.parseProp(propValue));
+ }
+
@Test
- public void testPropParsings() {
- String p1 = "${FOO:bar}";
- String p2 = "${FOO}";
- String p3 = "${BAR:defaultVal}";
- String p4 = "${INVALID";
- String p5 = "$INVALID}";
- String p6 = "${{INVALID}";
- String p7 = "${INVALID}}";
- String p8 = "${BAR:}";
- String p9 = "${}";
- String p10 = "${BAR}";
-
-
- Assertions.assertEquals("foo", BatchSEEnvironment.parseProp(p1));
- Assertions.assertEquals("foo", BatchSEEnvironment.parseProp(p2));
- Assertions.assertEquals("defaultVal", BatchSEEnvironment.parseProp(p3));
- Assertions.assertEquals("${INVALID", BatchSEEnvironment.parseProp(p4));
- Assertions.assertEquals("$INVALID}", BatchSEEnvironment.parseProp(p5));
- Assertions.assertEquals("${{INVALID}", BatchSEEnvironment.parseProp(p6));
- Assertions.assertEquals("${INVALID}}", BatchSEEnvironment.parseProp(p7));
- Assertions.assertEquals("", BatchSEEnvironment.parseProp(p8));
- Assertions.assertEquals("${}", BatchSEEnvironment.parseProp(p9));
- Assertions.assertNull(BatchSEEnvironment.parseProp(p10));
+ public void testPropParsingWhenEnvVarIsNull() {
+ Assertions.assertNull(BatchSEEnvironment.parseProp("${BAR}"));
+ }
+
+ private static Stream provideValuesForTestingPropParsing() {
+ return Stream.of(Arguments.of("${FOO:bar}", "foo"),
+ Arguments.of("${FOO}", "foo"),
+ Arguments.of("${BAR:defaultVal}", "defaultVal"),
+ Arguments.of("${INVALID", "${INVALID"),
+ Arguments.of("$INVALID}", "$INVALID}"),
+ Arguments.of("${{INVALID}", "${{INVALID}"),
+ Arguments.of("${INVALID}}", "${INVALID}}"),
+ Arguments.of("${BAR:}", ""),
+ Arguments.of("${}", "${}"),
+ Arguments.of("${DB_URL:jdbc:h2:./target/jberet-repo}", "jdbc:h2:./target/jberet-repo"),
+ Arguments.of("${DB_URL:jdbc:h2:mem:jberet;DB_CLOSE_DELAY=-1}", "jdbc:h2:mem:jberet;DB_CLOSE_DELAY=-1"));
}
private ThreadPoolExecutor verifyThreadPool(final int coreSize,
diff --git a/pom.xml b/pom.xml
index fdebb6429..b97c41dd4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -833,6 +833,12 @@
${junit-jupiter.version}
test
+
+ org.junit.jupiter
+ junit-jupiter-params
+ ${junit-jupiter.version}
+ test
+
io.rest-assured
rest-assured