mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-16 16:46:55 +01:00
general updates
Former-commit-id: edac8a6df87e1793f94ebdad615ed424acb27d90
This commit is contained in:
@@ -9,6 +9,8 @@ import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import junit.framework.TestCase;
|
||||
@@ -30,8 +32,22 @@ public abstract class BaseIndexTestCase extends TestCase {
|
||||
ensureIndexExists();
|
||||
}
|
||||
|
||||
protected static File getDataDirectory() throws IOException {
|
||||
String fileName = Settings.getString(Settings.KEYS.CPE_INDEX);
|
||||
String filePath = BaseIndexTestCase.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||
String decodedPath = URLDecoder.decode(filePath, "UTF-8");
|
||||
File exePath = new File(decodedPath);
|
||||
if (!exePath.isDirectory()) {
|
||||
exePath = exePath.getParentFile();
|
||||
}
|
||||
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
||||
path = new File(path.getCanonicalPath());
|
||||
return path;
|
||||
}
|
||||
|
||||
public static void ensureIndexExists() throws Exception {
|
||||
String indexPath = Settings.getString(Settings.KEYS.CPE_INDEX);
|
||||
//String indexPath = Settings.getString(Settings.KEYS.CPE_INDEX);
|
||||
String indexPath = getDataDirectory().getCanonicalPath();
|
||||
java.io.File f = new File(indexPath);
|
||||
if (!f.exists()) {
|
||||
f.mkdirs();
|
||||
|
||||
@@ -10,6 +10,8 @@ import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import junit.framework.TestCase;
|
||||
@@ -31,8 +33,23 @@ public abstract class BaseIndexTestCase extends TestCase {
|
||||
ensureIndexExists();
|
||||
}
|
||||
|
||||
|
||||
protected static File getDataDirectory() throws IOException {
|
||||
String fileName = Settings.getString(Settings.KEYS.CVE_INDEX);
|
||||
String filePath = BaseIndexTestCase.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||
String decodedPath = URLDecoder.decode(filePath, "UTF-8");
|
||||
File exePath = new File(decodedPath);
|
||||
if (!exePath.isDirectory()) {
|
||||
exePath = exePath.getParentFile();
|
||||
}
|
||||
File path = new File(exePath.getCanonicalFile() + File.separator + fileName);
|
||||
path = new File(path.getCanonicalPath());
|
||||
return path;
|
||||
}
|
||||
|
||||
public static void ensureIndexExists() throws Exception {
|
||||
String indexPath = Settings.getString(Settings.KEYS.CVE_INDEX);
|
||||
//String indexPath = Settings.getString(Settings.KEYS.CVE_INDEX);
|
||||
String indexPath = getDataDirectory().getCanonicalPath();
|
||||
java.io.File f = new File(indexPath);
|
||||
if (!f.exists()) {
|
||||
f.mkdirs();
|
||||
|
||||
@@ -45,6 +45,8 @@ public class IndexTest extends BaseIndexTestCase {
|
||||
Index instance = new Index();
|
||||
String exp = File.separatorChar + "target" + File.separatorChar + "data" + File.separatorChar + "cve";
|
||||
Directory result = instance.getDirectory();
|
||||
assertTrue(result.toString().contains(exp));
|
||||
|
||||
assertTrue("Recieved '" + result.toString() + "' and excpected '" + exp + "'.",
|
||||
result.toString().contains(exp));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class SettingsTest extends TestCase {
|
||||
public void testGetString() {
|
||||
System.out.println("getString");
|
||||
String key = Settings.KEYS.CPE_INDEX;
|
||||
String expResult = "target/data/cpe";
|
||||
String expResult = "../data/cpe";
|
||||
String result = Settings.getString(key);
|
||||
assertTrue(result.endsWith(expResult));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user