19 package org.sleuthkit.autopsy.integrationtesting;
22 import java.lang.reflect.Method;
23 import java.lang.reflect.ParameterizedType;
24 import java.lang.reflect.Type;
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.List;
29 import java.util.logging.Level;
31 import java.util.stream.Collectors;
32 import java.util.stream.Stream;
33 import org.apache.commons.collections.CollectionUtils;
34 import org.openide.util.Pair;
53 ).collect(Collectors.toSet());
62 List<ConfigurationModule<?>> reversed =
new ArrayList<>(configModules);
63 Collections.reverse(reversed);
66 configModule.revert();
67 }
catch (Exception ex) {
69 logger.log(Level.SEVERE,
"An error occurred while reverting configuration module: " + configModule.getClass().getCanonicalName(), ex);
81 static String getProfileName(String caseName) {
82 return String.format(
"integrationTestProfile-%s", caseName);
95 getProfileName(caseName),
98 .filter((f) -> !DEFAULT_EXCLUDED_MODULES.contains(f.getModuleDisplayName()))
100 .collect(Collectors.toList())
114 Pair<IngestJobSettings, List<ConfigurationModule<?>>> runConfigurationModules(String caseName, List<ParameterizedResourceConfig> configModules) {
116 if (CollectionUtils.isEmpty(configModules)) {
121 IngestJobSettings curConfig =
new IngestJobSettings(
122 getProfileName(caseName),
124 Collections.emptyList());
126 List<ConfigurationModule<?>> configurationModuleCache =
new ArrayList<>();
129 for (ParameterizedResourceConfig configModule : configModules) {
130 Pair<IngestJobSettings, ConfigurationModule<?>> ingestResult =
runConfigurationModule(curConfig, configModule);
132 if (ingestResult != null) {
133 curConfig = ingestResult.first() == null ? curConfig : ingestResult.first();
134 if (ingestResult.second() != null) {
135 configurationModuleCache.add(ingestResult.second());
139 return Pair.of(curConfig, configurationModuleCache);
155 Class<?> clazz = null;
158 }
catch (ClassNotFoundException ex) {
159 logger.log(Level.WARNING,
"Unable to find module: " + configModule.
getResource(), ex);
165 logger.log(Level.WARNING, String.format(
"%s does not seem to be an instance of a configuration module.", configModule.
getResource()));
170 Type configurationModuleType = Stream.of(clazz.getGenericInterfaces())
171 .filter(type -> type instanceof ParameterizedType && ((ParameterizedType) type).getRawType().equals(
ConfigurationModule.class))
172 .map(type -> ((ParameterizedType) type).getActualTypeArguments()[0])
176 if (configurationModuleType == null) {
177 logger.log(Level.SEVERE, String.format(
"Could not determine generic type of config module: %s", configModule.
getResource()));
183 Object result = null;
186 Method m = clazz.getMethod(
"configure",
IngestJobSettings.class, (Class<?>) configurationModuleType);
187 result = m.invoke(configModuleObj, curConfig, configDeserializer.convertToObj(configModule.
getParameters(), configurationModuleType));
188 }
catch (Exception ex) {
190 logger.log(Level.SEVERE, String.format(
"There was an error calling configure method on Configuration Module %s", configModule.
getResource()), ex);
196 return Pair.of((IngestJobSettings) result, configModuleObj);
198 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 String getDisplayName()
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)