Skip to content
Snippets Groups Projects
Commit 2c79eb6f authored by gmantele's avatar gmantele
Browse files

[ALL] Restore some sleeping JUnit tests + Allow a reset of custom types

in DBType.DBDatatype (for UNKNOWN and UNKNOWN_NUMERIC). This reset is performed
after each JUnit setting a special custom value (otherwise it prevents other
JUnit to run correctly)
parent 2a136e65
No related branches found
No related tags found
No related merge requests found
......@@ -29,9 +29,9 @@ package adql.db;
*
* <p>All datatypes declared in the IVOA recommendation document of TAP are listed in an enumeration type: {@link DBDatatype}.
* It is used to set the attribute type/datatype of this class.</p>
*
*
* @author Gr&eacute;gory Mantelet (ARI)
* @version 1.4 (03/2016)
* @version 1.4 (07/2016)
* @since 1.3
*/
public class DBType {
......@@ -40,12 +40,12 @@ public class DBType {
* List of all datatypes declared in the IVOA recommendation of TAP (in the section UPLOAD).
*
* @author Gr&eacute;gory Mantelet (ARI)
* @version 1.4 (03/2016)
* @version 1.4 (07/2016)
* @since 1.3
*/
public static enum DBDatatype{
SMALLINT, INTEGER, BIGINT, REAL, DOUBLE, BINARY, VARBINARY, CHAR, VARCHAR, BLOB, CLOB, TIMESTAMP, POINT, REGION,
/** Type to use when the precise datatype is unknown.
/** Type to use when the precise datatype is unknown.
* @since 1.4 */
UNKNOWN,
/** <p>Type to use when the type is known as numeric but there is no precise datatype
......@@ -70,8 +70,9 @@ public class DBType {
* <b>ONLY FOR {@link #UNKNOWN} and {@link #UNKNOWN_NUMERIC} {@link DBDatatype}s</b>.</p>
*
* <p><i><b>Important:</b>
* If this {@link DBDatatype} is not {@link #UNKNOWN} or {@link #UNKNOWN_NUMERIC} or
* if the given name is NULL or empty, this function has no effect.
* If this {@link DBDatatype} is not {@link #UNKNOWN} or {@link #UNKNOWN_NUMERIC} this function has no effect.
* But if the given name is NULL or empty, no custom type will be set ; instead the default value (i.e. name of
* the unknown enum item) will be returned.
* </i></p>
*
* @param typeName User type name.
......@@ -79,8 +80,12 @@ public class DBType {
* @since 1.4
*/
public void setCustomType(final String typeName){
if ((this == UNKNOWN || this == UNKNOWN_NUMERIC) && typeName != null && typeName.trim().length() > 0)
strExp = "?" + typeName.trim() + "?";
if ((this == UNKNOWN || this == UNKNOWN_NUMERIC)){
if (typeName != null && typeName.trim().length() > 0)
strExp = "?" + typeName.trim() + "?";
else
strExp = this.name();
}
}
}
......
......@@ -5,6 +5,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.AfterClass;
import org.junit.Test;
import adql.db.DBType.DBDatatype;
......@@ -20,6 +21,11 @@ import adql.query.operand.function.geometry.PointFunction;
public class TestFunctionDef {
@AfterClass
public static void tearDownAfterClass() throws Exception{
DBType.DBDatatype.UNKNOWN.setCustomType(null);
}
@Test
public void testIsString(){
for(DBDatatype type : DBDatatype.values()){
......
......@@ -26,13 +26,15 @@ import adql.db.DefaultDBTable;
import adql.db.FunctionDef;
import adql.query.ADQLQuery;
public class UnknownTypes {
public class TestUnknownTypes {
@BeforeClass
public static void setUpBeforeClass() throws Exception{}
@AfterClass
public static void tearDownAfterClass() throws Exception{}
public static void tearDownAfterClass() throws Exception{
DBType.DBDatatype.UNKNOWN.setCustomType(null);
}
@Before
public void setUp() throws Exception{}
......
......@@ -21,13 +21,13 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import tap.TAPException;
import tap.metadata.TableSetParser.ForeignKey;
import adql.db.DBType;
import adql.db.DBType.DBDatatype;
import tap.TAPException;
import tap.metadata.TableSetParser.ForeignKey;
@SuppressWarnings("deprecation")
public class TableSetParserTest {
public class TestTableSetParser {
private static TableSetParser parser = null;
private static XMLInputFactory factory = null;
......@@ -903,7 +903,7 @@ public class TableSetParserTest {
col = parser.parseColumn(reader);
assertEquals("col1", col.getADQLName());
assertNull(col.getDescription());
assertEquals(DBDatatype.VARCHAR, col.getDatatype().type);
assertEquals(DBDatatype.UNKNOWN, col.getDatatype().type);
assertEquals(-1, col.getDatatype().length);
assertNull(col.getUtype());
assertNull(col.getUcd());
......
......@@ -31,7 +31,7 @@ import javax.servlet.http.Part;
import org.junit.Before;
import org.junit.Test;
public class UWSUrlTest {
public class TestUWSUrl {
public static final class TestHttpServletRequest implements HttpServletRequest {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment