cleaned up test cases to properly close the DB

Former-commit-id: 7333e882aebfe54b94a4d70cdb55ca2fbd3f3c51
This commit is contained in:
Jeremy Long
2015-07-17 15:31:00 -04:00
parent 7ac71a7b2a
commit dacb91b9a8

View File

@@ -39,28 +39,37 @@ public class CveDBIntegrationTest extends BaseDBTestCase {
*/
@Test
public void testOpen() throws Exception {
CveDB instance = new CveDB();
CveDB instance = null;
try {
instance = new CveDB();
instance.open();
instance.commit();
} finally {
if (instance != null) {
instance.close();
}
}
}
/**
* Test of getCPEs method, of class CveDB.
*/
@Test
public void testGetCPEs() throws Exception {
CveDB instance = new CveDB();
CveDB instance = null;
try {
instance = new CveDB();
String vendor = "apache";
String product = "struts";
instance.open();
Set<VulnerableSoftware> result = instance.getCPEs(vendor, product);
assertTrue(result.size() > 5);
} finally {
if (instance != null) {
instance.close();
}
}
}
/**
* Test of getVulnerabilities method, of class CveDB.
@@ -68,9 +77,10 @@ public class CveDBIntegrationTest extends BaseDBTestCase {
@Test
public void testGetVulnerabilities() throws Exception {
String cpeStr = "cpe:/a:apache:struts:2.1.2";
CveDB instance = new CveDB();
CveDB instance = null;
List<Vulnerability> results;
try {
instance = new CveDB();
instance.open();
results = instance.getVulnerabilities(cpeStr);
assertTrue(results.size() > 5);
@@ -99,20 +109,23 @@ public class CveDBIntegrationTest extends BaseDBTestCase {
assertTrue("Expected " + expected + ", but was not identified", found);
} finally {
if (instance != null) {
instance.close();
}
}
}
/**
* Test of getMatchingSoftware method, of class CveDB.
*/
@Test
public void testGetMatchingSoftware() throws Exception {
CveDB instance = null;
HashMap<String, Boolean> versions = new HashMap<String, Boolean>();
DependencyVersion identifiedVersion = new DependencyVersion("1.0.1o");
versions.put("cpe:/a:openssl:openssl:1.0.1e", Boolean.FALSE);
CveDB instance = new CveDB();
try {
instance = new CveDB();
Entry<String, Boolean> results = instance.getMatchingSoftware(versions, "openssl", "openssl", identifiedVersion);
Assert.assertNull(results);
versions.put("cpe:/a:openssl:openssl:1.0.1p", Boolean.FALSE);
@@ -157,7 +170,11 @@ public class CveDBIntegrationTest extends BaseDBTestCase {
identifiedVersion = new DependencyVersion("1.6.3");
results = instance.getMatchingSoftware(versions, "springsource", "spring_framework", identifiedVersion);
Assert.assertNotNull(results);
} finally {
if (instance != null) {
instance.close();
}
}
}
}