Skip to content

Commit fd89c6c

Browse files
HeikoKlareakurtakov
authored andcommitted
Allow to set INI values in session tests
The JUnit 3 ConfigurationSessionTestSuite allows to set/change INI values for the configuration of an execution session. This capability is currently missing in the JUnit 5 SessionTestExection and the respective CustomSessionConfiguration. This change adds it.
1 parent 72cce17 commit fd89c6c

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/CustomSessionConfiguration.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,15 @@ public interface CustomSessionConfiguration extends SessionCustomization {
7272
*/
7373
public CustomSessionConfiguration setReadOnly();
7474

75+
/**
76+
* Sets the given config value for the application configuration via the ini. If
77+
* the value is null, the key will be removed from the ini.
78+
*
79+
* @param key the key to define
80+
* @param value the value to set to the key or {@code null} to remove the key
81+
*
82+
* @return this
83+
*/
84+
public CustomSessionConfiguration setConfigIniValue(String key, String value);
85+
7586
}

runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/RemoteTestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void executeRemotely(String testClass, String testMethod, boolean shouldFail) th
6666
throw new CoreException(status);
6767
}
6868
if (!collector.didTestFinish()) {
69-
throw new Exception("session test did not run: " + descriptor);
69+
throw new Exception("session test did not run: " + descriptor + "\n" + collector.stackTrace);
7070
}
7171
if (!collector.wasTestSuccessful()) {
7272
throw collector.getError();

runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/customization/CustomSessionConfigurationDummy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ public CustomSessionConfiguration addBundle(Bundle bundle) {
6363
return this;
6464
}
6565

66+
@Override
67+
public CustomSessionConfiguration setConfigIniValue(String key, String value) {
68+
return this;
69+
}
70+
6671
}

runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/customization/CustomSessionConfigurationImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import java.nio.file.Files;
2121
import java.nio.file.Path;
2222
import java.util.Collection;
23+
import java.util.HashMap;
2324
import java.util.LinkedHashSet;
25+
import java.util.Map;
2426
import java.util.Objects;
2527
import java.util.Optional;
2628
import java.util.Properties;
@@ -50,6 +52,7 @@ public class CustomSessionConfigurationImpl implements CustomSessionConfiguratio
5052

5153
private final Collection<BundleReference> bundleReferences = new LinkedHashSet<>();
5254
private Path configurationDirectory;
55+
private final Map<String, String> configIniValues = new HashMap<>();
5356
private boolean readOnly = false;
5457
private boolean cascaded = false;
5558
private boolean firstExecutedSession = true;
@@ -141,6 +144,16 @@ public CustomSessionConfiguration setReadOnly() {
141144
return this;
142145
}
143146

147+
@Override
148+
public CustomSessionConfiguration setConfigIniValue(String key, String value) {
149+
if (value == null) {
150+
configIniValues.remove(key);
151+
} else {
152+
configIniValues.put(key, value);
153+
}
154+
return this;
155+
}
156+
144157
@Override
145158
public CustomSessionConfiguration setConfigurationDirectory(Path configurationDirectory) {
146159
Objects.requireNonNull(configurationDirectory);
@@ -212,6 +225,9 @@ private void createOrRefreshConfigIni() throws IOException {
212225
contents.put(PROP_SHARED_CONFIG_AREA, Platform.getConfigurationLocation().getURL().toExternalForm());
213226
}
214227
contents.put(PROP_CONFIG_AREA_READ_ONLY, Boolean.valueOf(readOnly).toString());
228+
for (Map.Entry<String, String> entry : configIniValues.entrySet()) {
229+
contents.put(entry.getKey(), entry.getValue());
230+
}
215231
// save the properties
216232
Path configINI = getConfigurationDirectory().resolve("config.ini");
217233
try (OutputStream out = Files.newOutputStream(configINI)) {

0 commit comments

Comments
 (0)