general updates

Former-commit-id: edac8a6df87e1793f94ebdad615ed424acb27d90
This commit is contained in:
Jeremy Long
2012-11-12 13:36:44 -05:00
parent 99c056e7f5
commit 9f21ea6a9d
9 changed files with 186 additions and 37 deletions

View File

@@ -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();

View File

@@ -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();

View File

@@ -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));
}
}

View File

@@ -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));
}