Ensure that DBMS brand is detected before using the knowledge. Begin adding unit tests.

This commit is contained in:
Mark H. Wood
2014-09-05 19:55:35 -04:00
parent 69291af2d8
commit dfcf5a2491
3 changed files with 777 additions and 87 deletions

View File

@@ -94,6 +94,13 @@ public class DatabaseManager
public static boolean isOracle()
{
try
{
initialize();
} catch (SQLException ex)
{
log.error("Failed to initialize the database: ", ex);
}
return isOracle;
}
@@ -1519,6 +1526,11 @@ public class DatabaseManager
*/
public static String getDbName()
{
try {
initialize();
} catch (SQLException ex) {
log.error("Failed to initialize the database: ", ex);
}
return dbms;
}

View File

@@ -0,0 +1,681 @@
/*
* Copyright 2014 Mark H. Wood.
*/
package org.dspace.storage.rdbms;
import org.dspace.AbstractUnitTest;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
/**
*
* @author mhwood
*/
public class DatabaseManagerTest
extends AbstractUnitTest
{
public DatabaseManagerTest()
{
}
@BeforeClass
public static void setUpClass()
{
}
@AfterClass
public static void tearDownClass()
{
}
@Before
public void setUp()
{
}
@After
public void tearDown()
{
}
/**
* Test of isOracle method, of class DatabaseManager.
*/
@Test
public void testIsOracle()
{
System.out.println("isOracle");
boolean expResult = true;
boolean result = DatabaseManager.isOracle();
assertEquals(expResult, result);
}
/**
* Test of setConstraintDeferred method, of class DatabaseManager.
*/
/*
@Test
public void testSetConstraintDeferred() throws Exception
{
System.out.println("setConstraintDeferred");
Context context = null;
String constraintName = "";
DatabaseManager.setConstraintDeferred(context, constraintName);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of setConstraintImmediate method, of class DatabaseManager.
*/
/*
@Test
public void testSetConstraintImmediate() throws Exception
{
System.out.println("setConstraintImmediate");
Context context = null;
String constraintName = "";
DatabaseManager.setConstraintImmediate(context, constraintName);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of queryTable method, of class DatabaseManager.
*/
/*
@Test
public void testQueryTable() throws Exception
{
System.out.println("queryTable");
Context context = null;
String table = "";
String query = "";
Object[] parameters = null;
TableRowIterator expResult = null;
TableRowIterator result = DatabaseManager.queryTable(context, table,
query, parameters);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of query method, of class DatabaseManager.
*/
/*
@Test
public void testQuery() throws Exception
{
System.out.println("query");
Context context = null;
String query = "";
Object[] parameters = null;
TableRowIterator expResult = null;
TableRowIterator result = DatabaseManager.query(context, query,
parameters);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of querySingle method, of class DatabaseManager.
*/
/*
@Test
public void testQuerySingle() throws Exception
{
System.out.println("querySingle");
Context context = null;
String query = "";
Object[] parameters = null;
TableRow expResult = null;
TableRow result = DatabaseManager.querySingle(context, query, parameters);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of querySingleTable method, of class DatabaseManager.
*/
/*
@Test
public void testQuerySingleTable() throws Exception
{
System.out.println("querySingleTable");
Context context = null;
String table = "";
String query = "";
Object[] parameters = null;
TableRow expResult = null;
TableRow result = DatabaseManager.querySingleTable(context, table, query,
parameters);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of updateQuery method, of class DatabaseManager.
*/
/*
@Test
public void testUpdateQuery() throws Exception
{
System.out.println("updateQuery");
Context context = null;
String query = "";
Object[] parameters = null;
int expResult = 0;
int result = DatabaseManager.updateQuery(context, query, parameters);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of create method, of class DatabaseManager.
*/
/*
@Test
public void testCreate() throws Exception
{
System.out.println("create");
Context context = null;
String table = "";
TableRow expResult = null;
TableRow result = DatabaseManager.create(context, table);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of find method, of class DatabaseManager.
*/
/*
@Test
public void testFind() throws Exception
{
System.out.println("find");
Context context = null;
String table = "";
int id = 0;
TableRow expResult = null;
TableRow result = DatabaseManager.find(context, table, id);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of findByUnique method, of class DatabaseManager.
*/
/*
@Test
public void testFindByUnique() throws Exception
{
System.out.println("findByUnique");
Context context = null;
String table = "";
String column = "";
Object value = null;
TableRow expResult = null;
TableRow result = DatabaseManager.findByUnique(context, table, column,
value);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of delete method, of class DatabaseManager.
*/
/*
@Test
public void testDelete_3args() throws Exception
{
System.out.println("delete");
Context context = null;
String table = "";
int id = 0;
int expResult = 0;
int result = DatabaseManager.delete(context, table, id);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of deleteByValue method, of class DatabaseManager.
*/
/*
@Test
public void testDeleteByValue() throws Exception
{
System.out.println("deleteByValue");
Context context = null;
String table = "";
String column = "";
Object value = null;
int expResult = 0;
int result = DatabaseManager.deleteByValue(context, table, column, value);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of getConnection method, of class DatabaseManager.
*/
/*
@Test
public void testGetConnection() throws Exception
{
System.out.println("getConnection");
Connection expResult = null;
Connection result = DatabaseManager.getConnection();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of getDataSource method, of class DatabaseManager.
*/
/*
@Test
public void testGetDataSource()
{
System.out.println("getDataSource");
DataSource expResult = null;
DataSource result = DatabaseManager.getDataSource();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of freeConnection method, of class DatabaseManager.
*/
/*
@Test
public void testFreeConnection()
{
System.out.println("freeConnection");
Connection c = null;
DatabaseManager.freeConnection(c);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of row method, of class DatabaseManager.
*/
/*
@Test
public void testRow() throws Exception
{
System.out.println("row");
String table = "";
TableRow expResult = null;
TableRow result = DatabaseManager.row(table);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of insert method, of class DatabaseManager.
*/
/*
@Test
public void testInsert() throws Exception
{
System.out.println("insert");
Context context = null;
TableRow row = null;
DatabaseManager.insert(context, row);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of update method, of class DatabaseManager.
*/
/*
@Test
public void testUpdate() throws Exception
{
System.out.println("update");
Context context = null;
TableRow row = null;
int expResult = 0;
int result = DatabaseManager.update(context, row);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of delete method, of class DatabaseManager.
*/
/*
@Test
public void testDelete_Context_TableRow() throws Exception
{
System.out.println("delete");
Context context = null;
TableRow row = null;
int expResult = 0;
int result = DatabaseManager.delete(context, row);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of getColumnInfo method, of class DatabaseManager.
*/
/*
@Test
public void testGetColumnInfo_String() throws Exception
{
System.out.println("getColumnInfo");
String table = "";
Collection<ColumnInfo> expResult = null;
Collection<ColumnInfo> result = DatabaseManager.getColumnInfo(table);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of getColumnInfo method, of class DatabaseManager.
*/
/*
@Test
public void testGetColumnInfo_String_String() throws Exception
{
System.out.println("getColumnInfo");
String table = "";
String column = "";
ColumnInfo expResult = null;
ColumnInfo result = DatabaseManager.getColumnInfo(table, column);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of getColumnNames method, of class DatabaseManager.
*/
/*
@Test
public void testGetColumnNames_String() throws Exception
{
System.out.println("getColumnNames");
String table = "";
List<String> expResult = null;
List<String> result = DatabaseManager.getColumnNames(table);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of getColumnNames method, of class DatabaseManager.
*/
/*
@Test
public void testGetColumnNames_ResultSetMetaData() throws Exception
{
System.out.println("getColumnNames");
ResultSetMetaData meta = null;
List<String> expResult = null;
List<String> result = DatabaseManager.getColumnNames(meta);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of canonicalize method, of class DatabaseManager.
*/
/*
@Test
public void testCanonicalize()
{
System.out.println("canonicalize");
String table = "";
String expResult = "";
String result = DatabaseManager.canonicalize(table);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of loadSql method, of class DatabaseManager.
*/
/*
@Test
public void testLoadSql_String() throws Exception
{
System.out.println("loadSql");
String sql = "";
DatabaseManager.loadSql(sql);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of loadSql method, of class DatabaseManager.
*/
/*
@Test
public void testLoadSql_Reader() throws Exception
{
System.out.println("loadSql");
Reader r = null;
DatabaseManager.loadSql(r);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of process method, of class DatabaseManager.
*/
/*
@Test
public void testProcess_ResultSet_String() throws Exception
{
System.out.println("process");
ResultSet results = null;
String table = "";
TableRow expResult = null;
TableRow result = DatabaseManager.process(results, table);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of process method, of class DatabaseManager.
*/
/*
@Test
public void testProcess_3args() throws Exception
{
System.out.println("process");
ResultSet results = null;
String table = "";
List<String> pColumnNames = null;
TableRow expResult = null;
TableRow result = DatabaseManager.process(results, table, pColumnNames);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of getPrimaryKeyColumn method, of class DatabaseManager.
*/
/*
@Test
public void testGetPrimaryKeyColumn_TableRow() throws Exception
{
System.out.println("getPrimaryKeyColumn");
TableRow row = null;
String expResult = "";
String result = DatabaseManager.getPrimaryKeyColumn(row);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of getPrimaryKeyColumn method, of class DatabaseManager.
*/
/*
@Test
public void testGetPrimaryKeyColumn_String() throws Exception
{
System.out.println("getPrimaryKeyColumn");
String table = "";
String expResult = "";
String result = DatabaseManager.getPrimaryKeyColumn(table);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of getPrimaryKeyColumnInfo method, of class DatabaseManager.
*/
/*
@Test
public void testGetPrimaryKeyColumnInfo() throws Exception
{
System.out.println("getPrimaryKeyColumnInfo");
String table = "";
ColumnInfo expResult = null;
ColumnInfo result = DatabaseManager.getPrimaryKeyColumnInfo(table);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of shutdown method, of class DatabaseManager.
*/
/*
@Test
public void testShutdown() throws Exception
{
System.out.println("shutdown");
DatabaseManager.shutdown();
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of getDbName method, of class DatabaseManager.
*/
@Test
public void testGetDbName()
{
System.out.println("getDbName");
String expResult = "H2";
String result = DatabaseManager.getDbName();
assertEquals(expResult, result);
}
/**
* Test of loadParameters method, of class DatabaseManager.
*/
/*
@Test
public void testLoadParameters() throws Exception
{
System.out.println("loadParameters");
PreparedStatement statement = null;
Object[] parameters = null;
DatabaseManager.loadParameters(statement, parameters);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of main method, of class DatabaseManager.
*/
/*
@Test
public void testMain()
{
System.out.println("main");
String[] args = null;
DatabaseManager.main(args);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
/**
* Test of applyOffsetAndLimit method, of class DatabaseManager.
*/
/*
@Test
public void testApplyOffsetAndLimit()
{
System.out.println("applyOffsetAndLimit");
StringBuffer query = null;
List<Serializable> params = null;
int offset = 0;
int limit = 0;
DatabaseManager.applyOffsetAndLimit(query, params, offset, limit);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
*/
}

View File

@@ -14,7 +14,6 @@ import java.sql.Statement;
import java.sql.Types;
import java.util.List;
import mockit.Deencapsulation;
import mockit.Mock;
import mockit.MockUp;
@@ -36,10 +35,8 @@ public final class MockDatabaseManager
// Set our logger to specify the Mock class, so we know which logs are from the "real" vs "mock" class
private static final Logger log = Logger.getLogger(MockDatabaseManager.class);
// Get the values of private static variables 'isOracle' and 'isPostgres' from
// DatabaseManager itself (by using Deencapsulation)
private static final boolean isOracle = Deencapsulation.getField(DatabaseManager.class, "isOracle");
private static final boolean isPostgres = Deencapsulation.getField(DatabaseManager.class, "isPostgres");
/** Is our DBMS Oracle-like? */
private static final boolean isOracle = DatabaseManager.isOracle();
/**
* Override/Mock the default "setConstraintDeferred()" method in order to