mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
[DS-1738] Reflect changes in MockDatabaseManager too. Provide unit tests.
This commit is contained in:
@@ -153,12 +153,28 @@ public class TableRow
|
||||
throw new IllegalArgumentException("Column " + column + " not present");
|
||||
}
|
||||
|
||||
if (!(value instanceof Integer))
|
||||
if (value instanceof Integer)
|
||||
{
|
||||
return ((Integer) value);
|
||||
}
|
||||
else if (value instanceof Long)
|
||||
{
|
||||
long longValue = (Long)value;
|
||||
if ((longValue > Integer.MAX_VALUE) || longValue < Integer.MIN_VALUE)
|
||||
throw new IllegalArgumentException("Value for " + column + " does not fit in an Integer");
|
||||
else
|
||||
{
|
||||
return (int)longValue;
|
||||
}
|
||||
}
|
||||
else if (value instanceof BigDecimal)
|
||||
{
|
||||
return ((BigDecimal)value).intValueExact();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("Value for " + column + " is not an integer");
|
||||
}
|
||||
|
||||
return ((Integer) value).intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,13 +208,18 @@ public class TableRow
|
||||
{
|
||||
return ((Integer) value).longValue();
|
||||
}
|
||||
|
||||
if (!(value instanceof Long))
|
||||
else if (value instanceof Long)
|
||||
{
|
||||
return ((Long) value);
|
||||
}
|
||||
else if (value instanceof BigDecimal)
|
||||
{
|
||||
return ((BigDecimal)value).longValueExact();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("Value for " + column + " is not a long");
|
||||
}
|
||||
|
||||
return ((Long) value).longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,6 +363,14 @@ public class TableRow
|
||||
|
||||
return true; // nonzero is true
|
||||
}
|
||||
else if (value instanceof Long)
|
||||
{
|
||||
return ((Long) value) != 0;
|
||||
}
|
||||
else if (value instanceof BigDecimal)
|
||||
{
|
||||
return ! ((BigDecimal) value).equals(BigDecimal.ZERO);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("Value is not a boolean or an integer");
|
||||
|
@@ -20,6 +20,7 @@ import mockit.MockUp;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.core.Context;
|
||||
|
||||
import static org.dspace.storage.rdbms.DatabaseManager.getColumnNames;
|
||||
|
||||
/**
|
||||
@@ -177,7 +178,6 @@ public final class MockDatabaseManager
|
||||
break;
|
||||
|
||||
case Types.INTEGER:
|
||||
case Types.NUMERIC:
|
||||
if (isOracle)
|
||||
{
|
||||
long longValue = results.getLong(i);
|
||||
@@ -196,33 +196,10 @@ public final class MockDatabaseManager
|
||||
}
|
||||
break;
|
||||
|
||||
case Types.NUMERIC:
|
||||
case Types.DECIMAL:
|
||||
// For H2 database, NUMBER() fields are mapped to DECIMAL data type.
|
||||
// See: http://www.h2database.com/html/datatypes.html#decimal_type
|
||||
// But, our Oracle schema uses NUMBER() to represent INTEGER values 1 or 0
|
||||
// (which are then mapped to Boolean true/false by TableRow.getBooleanColumn()).
|
||||
// So, for H2 to "act like Oracle", we need to try to convert
|
||||
// DECIMAL types to INTEGER values, so they can be mapped to
|
||||
// corresponding Boolean.
|
||||
if (isOracle)
|
||||
{
|
||||
long longValue = results.getLong(i);
|
||||
// If this value actually a valid Integer, convert it to an int
|
||||
if (longValue <= (long)Integer.MAX_VALUE)
|
||||
{
|
||||
row.setColumn(name, (int) longValue);
|
||||
}
|
||||
else // Otherwise, leave it as a long value
|
||||
{
|
||||
row.setColumn(name, longValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
row.setColumn(name, results.getLong(i));
|
||||
}
|
||||
row.setColumn(name, results.getBigDecimal(i));
|
||||
break;
|
||||
//END ADDED for H2
|
||||
|
||||
case Types.BIGINT:
|
||||
row.setColumn(name, results.getLong(i));
|
||||
@@ -298,5 +275,4 @@ public final class MockDatabaseManager
|
||||
row.resetChanged();
|
||||
return row;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,500 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package org.dspace.storage.rdbms;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author mwood
|
||||
*/
|
||||
public class TableRowTest
|
||||
{
|
||||
|
||||
public TableRowTest()
|
||||
{
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass()
|
||||
{
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass()
|
||||
{
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getTable method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetTable()
|
||||
{
|
||||
System.out.println("getTable");
|
||||
TableRow instance = null;
|
||||
String expResult = "";
|
||||
String result = instance.getTable();
|
||||
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 setTable method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testSetTable()
|
||||
{
|
||||
System.out.println("setTable");
|
||||
String table = "";
|
||||
TableRow instance = null;
|
||||
instance.setTable(table);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of hasColumn method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testHasColumn()
|
||||
{
|
||||
System.out.println("hasColumn");
|
||||
String column = "";
|
||||
TableRow instance = null;
|
||||
boolean expResult = false;
|
||||
boolean result = instance.hasColumn(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 hasColumnChanged method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testHasColumnChanged()
|
||||
{
|
||||
System.out.println("hasColumnChanged");
|
||||
String column = "";
|
||||
TableRow instance = null;
|
||||
boolean expResult = false;
|
||||
boolean result = instance.hasColumnChanged(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 hasColumnChangedCanonicalized method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testHasColumnChangedCanonicalized()
|
||||
{
|
||||
System.out.println("hasColumnChangedCanonicalized");
|
||||
String column = "";
|
||||
TableRow instance = null;
|
||||
boolean expResult = false;
|
||||
boolean result = instance.hasColumnChangedCanonicalized(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 isColumnNull method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testIsColumnNull()
|
||||
{
|
||||
System.out.println("isColumnNull");
|
||||
String column = "";
|
||||
TableRow instance = null;
|
||||
boolean expResult = false;
|
||||
boolean result = instance.isColumnNull(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 isColumnNullCanonicalized method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testIsColumnNullCanonicalized()
|
||||
{
|
||||
System.out.println("isColumnNullCanonicalized");
|
||||
String column = "";
|
||||
TableRow instance = null;
|
||||
boolean expResult = false;
|
||||
boolean result = instance.isColumnNullCanonicalized(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 getIntColumn method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetIntColumn()
|
||||
{
|
||||
System.out.println("getIntColumn");
|
||||
String column = "";
|
||||
TableRow instance = null;
|
||||
int expResult = 0;
|
||||
int result = instance.getIntColumn(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 getLongColumn method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetLongColumn()
|
||||
{
|
||||
System.out.println("getLongColumn");
|
||||
String column = "";
|
||||
TableRow instance = null;
|
||||
long expResult = 0L;
|
||||
long result = instance.getLongColumn(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 getNumericColumn method, of class TableRow.
|
||||
*/
|
||||
@Test
|
||||
public void testGetNumericColumn()
|
||||
{
|
||||
System.out.println("getNumericColumn");
|
||||
String column = "fifth";
|
||||
List columns = new ArrayList<String>();
|
||||
columns.add(column);
|
||||
TableRow instance = new TableRow("row", columns);
|
||||
instance.setColumn(column, BigDecimal.ONE);
|
||||
BigDecimal expResult = BigDecimal.ONE;
|
||||
BigDecimal result = instance.getNumericColumn(column);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getDoubleColumn method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetDoubleColumn()
|
||||
{
|
||||
System.out.println("getDoubleColumn");
|
||||
String column = "";
|
||||
TableRow instance = null;
|
||||
double expResult = 0.0;
|
||||
double result = instance.getDoubleColumn(column);
|
||||
assertEquals(expResult, result, 0.0);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of getStringColumn method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetStringColumn()
|
||||
{
|
||||
System.out.println("getStringColumn");
|
||||
String column = "";
|
||||
TableRow instance = null;
|
||||
String expResult = "";
|
||||
String result = instance.getStringColumn(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 getBooleanColumn method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetBooleanColumn()
|
||||
{
|
||||
System.out.println("getBooleanColumn");
|
||||
String column = "";
|
||||
TableRow instance = null;
|
||||
boolean expResult = false;
|
||||
boolean result = instance.getBooleanColumn(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 getDateColumn method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetDateColumn()
|
||||
{
|
||||
System.out.println("getDateColumn");
|
||||
String column = "";
|
||||
TableRow instance = null;
|
||||
Date expResult = null;
|
||||
Date result = instance.getDateColumn(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 setColumnNull method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testSetColumnNull()
|
||||
{
|
||||
System.out.println("setColumnNull");
|
||||
String column = "";
|
||||
TableRow instance = null;
|
||||
instance.setColumnNull(column);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of setColumn method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testSetColumn_String_boolean()
|
||||
{
|
||||
System.out.println("setColumn");
|
||||
String column = "";
|
||||
boolean b = false;
|
||||
TableRow instance = null;
|
||||
instance.setColumn(column, b);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of setColumn method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testSetColumn_String_String()
|
||||
{
|
||||
System.out.println("setColumn");
|
||||
String column = "";
|
||||
String s = "";
|
||||
TableRow instance = null;
|
||||
instance.setColumn(column, s);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of setColumn method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testSetColumn_String_int()
|
||||
{
|
||||
System.out.println("setColumn");
|
||||
String column = "";
|
||||
int i = 0;
|
||||
TableRow instance = null;
|
||||
instance.setColumn(column, i);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of setColumn method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testSetColumn_String_long()
|
||||
{
|
||||
System.out.println("setColumn");
|
||||
String column = "";
|
||||
long l = 0L;
|
||||
TableRow instance = null;
|
||||
instance.setColumn(column, l);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of setColumn method, of class TableRow.
|
||||
*/
|
||||
@Test
|
||||
public void testSetColumn_String_BigDecimal()
|
||||
{
|
||||
System.out.println("setColumn");
|
||||
String column = "Corinthian";
|
||||
List<String> columns = new ArrayList<String>();
|
||||
columns.add(column);
|
||||
BigDecimal bd = BigDecimal.ONE;
|
||||
TableRow instance = new TableRow("row", columns);
|
||||
instance.setColumn(column, bd);
|
||||
BigDecimal result = instance.getNumericColumn(column);
|
||||
assertEquals("Should give back the same value set", bd, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of setColumn method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testSetColumn_String_double()
|
||||
{
|
||||
System.out.println("setColumn");
|
||||
String column = "";
|
||||
double d = 0.0;
|
||||
TableRow instance = null;
|
||||
instance.setColumn(column, d);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of setColumn method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testSetColumn_String_Date()
|
||||
{
|
||||
System.out.println("setColumn");
|
||||
String column = "";
|
||||
Date d = null;
|
||||
TableRow instance = null;
|
||||
instance.setColumn(column, d);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of toString method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testToString()
|
||||
{
|
||||
System.out.println("toString");
|
||||
TableRow instance = null;
|
||||
String expResult = "";
|
||||
String result = instance.toString();
|
||||
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 hashCode method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testHashCode()
|
||||
{
|
||||
System.out.println("hashCode");
|
||||
TableRow instance = null;
|
||||
int expResult = 0;
|
||||
int result = instance.hashCode();
|
||||
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 equals method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testEquals()
|
||||
{
|
||||
System.out.println("equals");
|
||||
Object obj = null;
|
||||
TableRow instance = null;
|
||||
boolean expResult = false;
|
||||
boolean result = instance.equals(obj);
|
||||
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 resetChanged method, of class TableRow.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testResetChanged()
|
||||
{
|
||||
System.out.println("resetChanged");
|
||||
TableRow instance = null;
|
||||
instance.resetChanged();
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
}
|
Reference in New Issue
Block a user