added try/catch to tests to correctly close the db

Former-commit-id: 8f71f57a7724340a8526a35bd0e42748f02530c5
This commit is contained in:
Jeremy Long
2015-07-17 08:45:33 -04:00
parent 6a2ed23822
commit 0ae228d6f8

View File

@@ -34,15 +34,21 @@ public class DatabasePropertiesIntegrationTest extends BaseDBTestCase {
*/ */
@Test @Test
public void testIsEmpty() throws Exception { public void testIsEmpty() throws Exception {
CveDB cveDB = new CveDB(); CveDB cveDB = null;
try {
cveDB = new CveDB();
cveDB.open(); cveDB.open();
DatabaseProperties instance = cveDB.getDatabaseProperties(); DatabaseProperties instance = cveDB.getDatabaseProperties();
boolean expResult = false; boolean expResult = false;
boolean result = instance.isEmpty(); boolean result = instance.isEmpty();
//no exception means the call worked... whether or not it is empty depends on if the db is new //no exception means the call worked... whether or not it is empty depends on if the db is new
//assertEquals(expResult, result); //assertEquals(expResult, result);
} finally {
if (cveDB != null) {
cveDB.close(); cveDB.close();
} }
}
}
/** /**
* Test of save method, of class DatabaseProperties. * Test of save method, of class DatabaseProperties.
@@ -54,7 +60,9 @@ public class DatabasePropertiesIntegrationTest extends BaseDBTestCase {
long expected = 1337; long expected = 1337;
updatedValue.setId(key); updatedValue.setId(key);
updatedValue.setTimestamp(expected); updatedValue.setTimestamp(expected);
CveDB cveDB = new CveDB(); CveDB cveDB = null;
try {
cveDB = new CveDB();
cveDB.open(); cveDB.open();
DatabaseProperties instance = cveDB.getDatabaseProperties(); DatabaseProperties instance = cveDB.getDatabaseProperties();
instance.save(updatedValue); instance.save(updatedValue);
@@ -63,9 +71,13 @@ public class DatabasePropertiesIntegrationTest extends BaseDBTestCase {
cveDB = new CveDB(); cveDB = new CveDB();
cveDB.open(); cveDB.open();
instance = cveDB.getDatabaseProperties(); instance = cveDB.getDatabaseProperties();
cveDB.close();
long results = Long.parseLong(instance.getProperty("NVD CVE " + key)); long results = Long.parseLong(instance.getProperty("NVD CVE " + key));
assertEquals(expected, results); assertEquals(expected, results);
} finally {
if (cveDB != null) {
cveDB.close();
}
}
} }
/** /**
@@ -75,13 +87,19 @@ public class DatabasePropertiesIntegrationTest extends BaseDBTestCase {
public void testGetProperty_String_String() throws Exception { public void testGetProperty_String_String() throws Exception {
String key = "doesn't exist"; String key = "doesn't exist";
String defaultValue = "default"; String defaultValue = "default";
CveDB cveDB = new CveDB(); CveDB cveDB = null;
try {
cveDB = new CveDB();
cveDB.open(); cveDB.open();
DatabaseProperties instance = cveDB.getDatabaseProperties(); DatabaseProperties instance = cveDB.getDatabaseProperties();
cveDB.close();
String expResult = "default"; String expResult = "default";
String result = instance.getProperty(key, defaultValue); String result = instance.getProperty(key, defaultValue);
assertEquals(expResult, result); assertEquals(expResult, result);
} finally {
if (cveDB != null) {
cveDB.close();
}
}
} }
/** /**
@@ -90,14 +108,20 @@ public class DatabasePropertiesIntegrationTest extends BaseDBTestCase {
@Test @Test
public void testGetProperty_String() throws DatabaseException { public void testGetProperty_String() throws DatabaseException {
String key = "version"; String key = "version";
CveDB cveDB = new CveDB(); CveDB cveDB = null;
try {
cveDB = new CveDB();
cveDB.open(); cveDB.open();
DatabaseProperties instance = cveDB.getDatabaseProperties(); DatabaseProperties instance = cveDB.getDatabaseProperties();
cveDB.close();
String result = instance.getProperty(key); String result = instance.getProperty(key);
double version = Double.parseDouble(result); double version = Double.parseDouble(result);
assertTrue(version >= 2.8); assertTrue(version >= 2.8);
assertTrue(version <= 10); assertTrue(version <= 10);
} finally {
if (cveDB != null) {
cveDB.close();
}
}
} }
/** /**
@@ -105,11 +129,17 @@ public class DatabasePropertiesIntegrationTest extends BaseDBTestCase {
*/ */
@Test @Test
public void testGetProperties() throws DatabaseException { public void testGetProperties() throws DatabaseException {
CveDB cveDB = new CveDB(); CveDB cveDB = null;
try {
cveDB = new CveDB();
cveDB.open(); cveDB.open();
DatabaseProperties instance = cveDB.getDatabaseProperties(); DatabaseProperties instance = cveDB.getDatabaseProperties();
cveDB.close();
Properties result = instance.getProperties(); Properties result = instance.getProperties();
assertTrue(result.size() > 0); assertTrue(result.size() > 0);
} finally {
if (cveDB != null) {
cveDB.close();
}
}
} }
} }