19 package org.sleuthkit.autopsy.integrationtesting;
21 import java.lang.reflect.Method;
22 import java.lang.reflect.ParameterizedType;
23 import java.lang.reflect.Type;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
28 import java.util.logging.Level;
30 import java.util.stream.Collectors;
31 import java.util.stream.Stream;
32 import org.apache.commons.collections.CollectionUtils;
33 import org.openide.util.Pair;
58 List<ConfigurationModule<?>> reversed =
new ArrayList<>(configModules);
59 Collections.reverse(reversed);
62 configModule.revert();
63 }
catch (Exception ex) {
65 logger.log(Level.SEVERE,
"An error occurred while reverting configuration module: " + configModule.getClass().getCanonicalName(), ex);
77 static String getProfileName(String caseName) {
78 return String.format(
"integrationTestProfile-%s", caseName);
91 getProfileName(caseName),
94 .filter((f) -> !DEFAULT_EXCLUDED_MODULES.contains(f.getModuleDisplayName()))
96 .collect(Collectors.toList())
110 Pair<IngestJobSettings, List<ConfigurationModule<?>>> runConfigurationModules(String caseName, List<ParameterizedResourceConfig> configModules) {
112 if (CollectionUtils.isEmpty(configModules)) {
117 IngestJobSettings curConfig =
new IngestJobSettings(
118 getProfileName(caseName),
120 Collections.emptyList());
122 List<ConfigurationModule<?>> configurationModuleCache =
new ArrayList<>();
125 for (ParameterizedResourceConfig configModule : configModules) {
126 Pair<IngestJobSettings, ConfigurationModule<?>> ingestResult =
runConfigurationModule(curConfig, configModule);
128 if (ingestResult != null) {
129 curConfig = ingestResult.first() == null ? curConfig : ingestResult.first();
130 if (ingestResult.second() != null) {
131 configurationModuleCache.add(ingestResult.second());
135 return Pair.of(curConfig, configurationModuleCache);
151 Class<?> clazz = null;
154 }
catch (ClassNotFoundException ex) {
155 logger.log(Level.WARNING,
"Unable to find module: " + configModule.
getResource(), ex);
161 logger.log(Level.WARNING, String.format(
"%s does not seem to be an instance of a configuration module.", configModule.
getResource()));
166 Type configurationModuleType = Stream.of(clazz.getGenericInterfaces())
167 .filter(type -> type instanceof ParameterizedType && ((ParameterizedType) type).getRawType().equals(
ConfigurationModule.class))
168 .map(type -> ((ParameterizedType) type).getActualTypeArguments()[0])
172 if (configurationModuleType == null) {
173 logger.log(Level.SEVERE, String.format(
"Could not determine generic type of config module: %s", configModule.
getResource()));
179 Object result = null;
182 Method m = clazz.getMethod(
"configure",
IngestJobSettings.class, (Class<?>) configurationModuleType);
183 result = m.invoke(configModuleObj, curConfig, configDeserializer.convertToObj(configModule.
getParameters(), configurationModuleType));
184 }
catch (Exception ex) {
186 logger.log(Level.SEVERE, String.format(
"There was an error calling configure method on Configuration Module %s", configModule.
getResource()), ex);
192 return Pair.of((IngestJobSettings) result, configModuleObj);
194 logger.log(Level.SEVERE, String.format(
"Could not retrieve IngestJobSettings or null was returned from %s", configModule.
getResource()));
Map< String, Object > getParameters()
static final ConfigDeserializer configDeserializer
IngestJobSettings getDefaultIngestConfig(String caseName)
static final Logger logger
List< IngestModuleFactory > getFactories()
static final Set< String > DEFAULT_EXCLUDED_MODULES
synchronized static Logger getLogger(String name)
static final IngestJobSettings.IngestType DEFAULT_INGEST_FILTER_TYPE
static final IngestModuleFactoryService ingestModuleFactories
Pair< IngestJobSettings, ConfigurationModule<?> > runConfigurationModule(IngestJobSettings curConfig, ParameterizedResourceConfig configModule)