From ca08887dcafbf0f74bc58854aaac92a995d869fe Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Fri, 3 Jan 2014 14:04:11 -0500 Subject: [PATCH] fixed tests to work with the new method for accessing the DB properties Former-commit-id: 1cbd6305d8aa758618f80a4c46d6bb20d03fc57f --- .../data/nvdcve/DatabasePropertiesTest.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 dependency-check-core/src/test/java/org/owasp/dependencycheck/data/nvdcve/DatabasePropertiesTest.java diff --git a/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/nvdcve/DatabasePropertiesTest.java b/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/nvdcve/DatabasePropertiesTest.java new file mode 100644 index 000000000..dd719bdf7 --- /dev/null +++ b/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/nvdcve/DatabasePropertiesTest.java @@ -0,0 +1,111 @@ +/* + * This file is part of dependency-check-core. + * + * Dependency-check-core is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Dependency-check-core is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * dependency-check-core. If not, see http://www.gnu.org/licenses/. + * + * Copyright (c) 2013 Jeremy Long. All Rights Reserved. + */ +package org.owasp.dependencycheck.data.nvdcve; + +import org.owasp.dependencycheck.data.nvdcve.DatabaseProperties; +import java.io.File; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import org.owasp.dependencycheck.data.nvdcve.CveDB; +import org.owasp.dependencycheck.data.update.NvdCveInfo; + +/** + * + * @author Jeremy Long (jeremy.long@owasp.org) + */ +public class DatabasePropertiesTest { + + public DatabasePropertiesTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of isEmpty method, of class DatabaseProperties. + */ + @Test + public void testIsEmpty() throws Exception { + CveDB cveDB = new CveDB(); + cveDB.open(); + DatabaseProperties instance = cveDB.getDatabaseProperties(); + boolean expResult = false; + boolean result = instance.isEmpty(); + //no exception means the call worked... whether or not it is empty depends on if the db is new + //assertEquals(expResult, result); + cveDB.close(); + } + + /** + * Test of save method, of class DatabaseProperties. + */ + @Test + public void testSave() throws Exception { + NvdCveInfo updatedValue = new NvdCveInfo(); + String key = "test"; + long expected = 1337; + updatedValue.setId(key); + updatedValue.setTimestamp(expected); + CveDB cveDB = new CveDB(); + cveDB.open(); + DatabaseProperties instance = cveDB.getDatabaseProperties(); + instance.save(updatedValue); + //reload the properties + cveDB.close(); + cveDB = new CveDB(); + cveDB.open(); + instance = cveDB.getDatabaseProperties(); + cveDB.close(); + long results = Long.parseLong(instance.getProperty("lastupdated." + key)); + assertEquals(expected, results); + } + + /** + * Test of getProperty method, of class DatabaseProperties. + */ + @Test + public void testGetProperty_String_String() throws Exception { + String key = "doesn't exist"; + String defaultValue = "default"; + CveDB cveDB = new CveDB(); + cveDB.open(); + DatabaseProperties instance = cveDB.getDatabaseProperties(); + cveDB.close(); + String expResult = "default"; + String result = instance.getProperty(key, defaultValue); + assertEquals(expResult, result); + } +}