Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
TestingConfig.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2020 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package org.sleuthkit.autopsy.integrationtesting.config;
20
21import com.fasterxml.jackson.annotation.JsonCreator;
22import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
23import com.fasterxml.jackson.annotation.JsonProperty;
24import java.util.Collections;
25import java.util.HashMap;
26import java.util.HashSet;
27import java.util.List;
28import java.util.Map;
29import java.util.Set;
30import java.util.stream.Collectors;
31import org.apache.commons.collections4.CollectionUtils;
32import org.apache.commons.collections4.MapUtils;
33
37@JsonIgnoreProperties(ignoreUnknown = true)
38public class TestingConfig {
39
40 private final Map<String, ParameterizedResourceConfig> excludeAllExcept;
41 private final Set<String> includeAllExcept;
42
50 @JsonCreator
52 @JsonProperty("excludeAllExcept") List<ParameterizedResourceConfig> excludeAllExcept,
53 @JsonProperty("includeAllExcept") List<String> includeAllExcept) {
54
55 // if exclude all except is null, treat as empty list.
56 List<ParameterizedResourceConfig> safeExcludeAllExcept = ((excludeAllExcept == null) ? Collections.emptyList() : excludeAllExcept);
57
58 // create a map of canonical paths to their parameterized resource config merging configurations if doubled.
59 this.excludeAllExcept = safeExcludeAllExcept
60 .stream()
61 .collect(Collectors.toMap(
62 (res) -> res.getResource() == null ? "" : res.getResource().toUpperCase(),
63 (res) -> res,
64 (res1, res2) -> {
65 Map<String, Object> mergedArgs = new HashMap<>();
66 mergedArgs.putAll(res1.getParameters());
67 mergedArgs.putAll(res2.getParameters());
68 return new ParameterizedResourceConfig(res1.getResource(), mergedArgs);
69 })
70 );
71
72 List<String> safeIncludeAllExcept = ((includeAllExcept == null) ? Collections.emptyList() : includeAllExcept);
73 this.includeAllExcept = safeIncludeAllExcept
74 .stream()
75 .map(String::toUpperCase)
76 .collect(Collectors.toSet());
77 }
78
83 public Set<ParameterizedResourceConfig> getExcludeAllExcept() {
84 return excludeAllExcept == null ? Collections.emptySet() : new HashSet<>(excludeAllExcept.values());
85 }
86
92 public Set<String> getIncludeAllExcept() {
93 return includeAllExcept == null ? Collections.emptySet() : Collections.unmodifiableSet(includeAllExcept);
94 }
95
103 public Map<String, Object> getParameters(String itemType) {
104 ParameterizedResourceConfig resource = (itemType == null) ? null : excludeAllExcept.get(itemType.toUpperCase());
105 return resource == null ? Collections.emptyMap() : new HashMap<>(resource.getParameters());
106 }
107
114 public boolean hasIncludedTest(String itemType) {
115 if (itemType == null) {
116 return false;
117 }
118
119 // if there are items to exclude and this item is excluded
120 if (!CollectionUtils.isEmpty(includeAllExcept) && includeAllExcept.contains(itemType.toUpperCase())) {
121 return false;
122 }
123
124 // otherwise, if there are items that should specifically be included, ensure that this item is in that list.
125 if (!MapUtils.isEmpty(excludeAllExcept)) {
126 return excludeAllExcept.containsKey(itemType.toUpperCase());
127 }
128
129 return true;
130 }
131}
TestingConfig( @JsonProperty("excludeAllExcept") List< ParameterizedResourceConfig > excludeAllExcept, @JsonProperty("includeAllExcept") List< String > includeAllExcept)
final Map< String, ParameterizedResourceConfig > excludeAllExcept

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.