working through some changes

This commit is contained in:
Greg DiCristofaro 2020-11-03 20:40:56 -05:00
parent 7cbeeb7e54
commit 11ce927a4a
2 changed files with 17 additions and 11 deletions

View File

@ -235,7 +235,7 @@
<for list="${integration-test-sys-props}" param="integration-test-sys-prop"> <for list="${integration-test-sys-props}" param="integration-test-sys-prop">
<sequential> <sequential>
<property <property
name="test-qa-functional-sys-prop.@{integration-test-sys-prop}" name="test-qa-functional-sys-prop.integration-test.@{integration-test-sys-prop}"
value="${integration-test.@{integration-test-sys-prop}}" value="${integration-test.@{integration-test-sys-prop}}"
/> />
</sequential> </sequential>

View File

@ -33,7 +33,6 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level; import java.util.logging.Level;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -56,6 +55,8 @@ public class ConfigDeserializer {
// A config file key must be specifed or at least the test suites path, and output path. // A config file key must be specifed or at least the test suites path, and output path.
// If a config specifying the EnvConfig json exists, specify this path to load it // If a config specifying the EnvConfig json exists, specify this path to load it
private static final String CONFIG_FILE_KEY = "configFile"; private static final String CONFIG_FILE_KEY = "configFile";
// expecting properties are marked as "integration-test.propVal"
private static final String INTEGRATION_TEST_NAMESPACE = "integration-test";
/** /**
* Deserializes the specified json file into an EnvConfig object using * Deserializes the specified json file into an EnvConfig object using
@ -69,9 +70,10 @@ public class ConfigDeserializer {
* validated. * validated.
*/ */
public EnvConfig getEnvConfigFromSysProps() throws IOException, IllegalStateException { public EnvConfig getEnvConfigFromSysProps() throws IOException, IllegalStateException {
if (System.getProperty(CONFIG_FILE_KEY) != null) { String configFileKey = String.join(".", INTEGRATION_TEST_NAMESPACE, CONFIG_FILE_KEY);
if (System.getProperty(configFileKey) != null) {
// try to load from file if value is present // try to load from file if value is present
String fileLoc = System.getProperty(CONFIG_FILE_KEY); String fileLoc = System.getProperty(configFileKey);
File envConfigFile = new File(fileLoc); File envConfigFile = new File(fileLoc);
if (envConfigFile.exists()) { if (envConfigFile.exists()) {
return getEnvConfig(envConfigFile); return getEnvConfig(envConfigFile);
@ -81,7 +83,8 @@ public class ConfigDeserializer {
} else { } else {
// otherwise, try to load from properties // otherwise, try to load from properties
try { try {
return validate(null, convertToObj(getSysPropsMap(), EnvConfig.class)); Map<String, Object> integrationProperties = getOrCreate(getSysPropsMap(), INTEGRATION_TEST_NAMESPACE);
return validate(null, convertToObj(integrationProperties, EnvConfig.class));
} catch (IllegalStateException ex) { } catch (IllegalStateException ex) {
throw new IllegalStateException("EnvConfig could not be determined from system property values", ex); throw new IllegalStateException("EnvConfig could not be determined from system property values", ex);
} }
@ -99,9 +102,8 @@ public class ConfigDeserializer {
private Map<String, Object> getSysPropsMap() { private Map<String, Object> getSysPropsMap() {
Map<String, Object> mapToRet = new HashMap<>(); Map<String, Object> mapToRet = new HashMap<>();
for (Entry<Object, Object> property : System.getProperties().entrySet()) { for (String key : System.getProperties().stringPropertyNames()) {
String key = property.getKey().toString(); String value = System.getProperty(key);
Object value = property.getValue().toString();
String[] keyPieces = key.split("\\."); String[] keyPieces = key.split("\\.");
Map<String, Object> mapToAddTo = mapToRet; Map<String, Object> mapToAddTo = mapToRet;
@ -117,7 +119,8 @@ public class ConfigDeserializer {
/** /**
* Extends HashMap<String, Object> to guarantee a type of * Extends HashMap<String, Object> to guarantee a type of
* Map<String, Object> with type erasure. * Map<String, Object>
* with type erasure.
*/ */
private static class StringObjMap extends HashMap<String, Object> { private static class StringObjMap extends HashMap<String, Object> {
@ -237,7 +240,9 @@ public class ConfigDeserializer {
JsonNode root = mapper.readTree(configFile); JsonNode root = mapper.readTree(configFile);
if (root.isArray()) { if (root.isArray()) {
// Define a collection type of List<TestSuiteConfig> for the purposes of json deserialization. // Define a collection type of List<TestSuiteConfig> for the purposes of json deserialization.
CollectionType listClass = mapper.getTypeFactory().constructCollectionType(List.class, TestSuiteConfig.class); CollectionType listClass = mapper.getTypeFactory().constructCollectionType(List.class,
TestSuiteConfig.class
);
// This suppresses compiler warning for this cast. // This suppresses compiler warning for this cast.
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -245,7 +250,8 @@ public class ConfigDeserializer {
return validate(rootDirectory, configFile, testSuites); return validate(rootDirectory, configFile, testSuites);
} else { } else {
return validate(rootDirectory, configFile, Arrays.asList(mapper.treeToValue(root, TestSuiteConfig.class))); return validate(rootDirectory, configFile, Arrays.asList(mapper.treeToValue(root, TestSuiteConfig.class
)));
} }
} catch (IOException ex) { } catch (IOException ex) {
logger.log(Level.WARNING, "Unable to read test suite config at " + configFile.getPath(), ex); logger.log(Level.WARNING, "Unable to read test suite config at " + configFile.getPath(), ex);