Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CaseUtils.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018 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  */
19 package org.sleuthkit.autopsy.testutils;
20 
21 import java.nio.file.Path;
22 import java.nio.file.Paths;
28 
33 public final class CaseUtils {
34 
44  public static Case createAsCurrentCase(String caseName) throws TestUtilsException {
45  String uniqueCaseName = caseName + "_" + TimeStampUtils.createTimeStamp();
46  Path caseDirectoryPath = Paths.get(System.getProperty("java.io.tmpdir"), uniqueCaseName);
47  Case currentCase = null;
48  try {
49  Case.createAsCurrentCase(Case.CaseType.SINGLE_USER_CASE, caseDirectoryPath.toString(), new CaseDetails(uniqueCaseName));
50  currentCase = Case.getCurrentCaseThrows();
52  throw new TestUtilsException(String.format("Failed to create case %s at %s", uniqueCaseName, caseDirectoryPath), ex);
53  }
54  return currentCase;
55  }
56 
61  public static void closeCurrentCase() throws TestUtilsException {
62  Case currentCase;
63 
64  try {
65  currentCase = Case.getCurrentCaseThrows();
66  } catch (NoCurrentCaseException ex) {
67  throw new TestUtilsException("Failed to get current case.", ex);
68  }
69 
70  String caseName = currentCase.getName();
71  String caseDirectory = currentCase.getCaseDirectory();
72  try {
74  } catch (CaseActionException ex) {
75  throw new TestUtilsException(String.format("Failed to close case %s at %s", caseName, caseDirectory), ex);
76  }
77  }
78 
82  private CaseUtils() {
83  }
84 
85 }
static void createAsCurrentCase(String caseDir, String caseDisplayName, String caseNumber, String examiner, CaseType caseType)
Definition: Case.java:801
static Case createAsCurrentCase(String caseName)
Definition: CaseUtils.java:44

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.