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,14 +34,20 @@ public class DatabasePropertiesIntegrationTest extends BaseDBTestCase {
*/ */
@Test @Test
public void testIsEmpty() throws Exception { public void testIsEmpty() throws Exception {
CveDB cveDB = new CveDB(); CveDB cveDB = null;
cveDB.open(); try {
DatabaseProperties instance = cveDB.getDatabaseProperties(); cveDB = new CveDB();
boolean expResult = false; cveDB.open();
boolean result = instance.isEmpty(); DatabaseProperties instance = cveDB.getDatabaseProperties();
//no exception means the call worked... whether or not it is empty depends on if the db is new boolean expResult = false;
//assertEquals(expResult, result); boolean result = instance.isEmpty();
cveDB.close(); //no exception means the call worked... whether or not it is empty depends on if the db is new
//assertEquals(expResult, result);
} finally {
if (cveDB != null) {
cveDB.close();
}
}
} }
/** /**
@@ -54,18 +60,24 @@ 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;
cveDB.open(); try {
DatabaseProperties instance = cveDB.getDatabaseProperties(); cveDB = new CveDB();
instance.save(updatedValue); cveDB.open();
//reload the properties DatabaseProperties instance = cveDB.getDatabaseProperties();
cveDB.close(); instance.save(updatedValue);
cveDB = new CveDB(); //reload the properties
cveDB.open(); cveDB.close();
instance = cveDB.getDatabaseProperties(); cveDB = new CveDB();
cveDB.close(); cveDB.open();
long results = Long.parseLong(instance.getProperty("NVD CVE " + key)); instance = cveDB.getDatabaseProperties();
assertEquals(expected, results); long results = Long.parseLong(instance.getProperty("NVD CVE " + key));
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;
cveDB.open(); try {
DatabaseProperties instance = cveDB.getDatabaseProperties(); cveDB = new CveDB();
cveDB.close(); cveDB.open();
String expResult = "default"; DatabaseProperties instance = cveDB.getDatabaseProperties();
String result = instance.getProperty(key, defaultValue); String expResult = "default";
assertEquals(expResult, result); String result = instance.getProperty(key, defaultValue);
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;
cveDB.open(); try {
DatabaseProperties instance = cveDB.getDatabaseProperties(); cveDB = new CveDB();
cveDB.close(); cveDB.open();
String result = instance.getProperty(key); DatabaseProperties instance = cveDB.getDatabaseProperties();
double version = Double.parseDouble(result); String result = instance.getProperty(key);
assertTrue(version >= 2.8); double version = Double.parseDouble(result);
assertTrue(version <= 10); assertTrue(version >= 2.8);
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;
cveDB.open(); try {
DatabaseProperties instance = cveDB.getDatabaseProperties(); cveDB = new CveDB();
cveDB.close(); cveDB.open();
Properties result = instance.getProperties(); DatabaseProperties instance = cveDB.getDatabaseProperties();
assertTrue(result.size() > 0); Properties result = instance.getProperties();
assertTrue(result.size() > 0);
} finally {
if (cveDB != null) {
cveDB.close();
}
}
} }
} }