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; ...@@ -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}. * <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> * It is used to set the attribute type/datatype of this class.</p>
* *
* @author Gr&eacute;gory Mantelet (ARI) * @author Gr&eacute;gory Mantelet (ARI)
* @version 1.4 (03/2016) * @version 1.4 (07/2016)
* @since 1.3 * @since 1.3
*/ */
public class DBType { public class DBType {
...@@ -40,12 +40,12 @@ 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). * List of all datatypes declared in the IVOA recommendation of TAP (in the section UPLOAD).
* *
* @author Gr&eacute;gory Mantelet (ARI) * @author Gr&eacute;gory Mantelet (ARI)
* @version 1.4 (03/2016) * @version 1.4 (07/2016)
* @since 1.3 * @since 1.3
*/ */
public static enum DBDatatype{ public static enum DBDatatype{
SMALLINT, INTEGER, BIGINT, REAL, DOUBLE, BINARY, VARBINARY, CHAR, VARCHAR, BLOB, CLOB, TIMESTAMP, POINT, REGION, 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 */ * @since 1.4 */
UNKNOWN, UNKNOWN,
/** <p>Type to use when the type is known as numeric but there is no precise datatype /** <p>Type to use when the type is known as numeric but there is no precise datatype
...@@ -70,8 +70,9 @@ public class DBType { ...@@ -70,8 +70,9 @@ public class DBType {
* <b>ONLY FOR {@link #UNKNOWN} and {@link #UNKNOWN_NUMERIC} {@link DBDatatype}s</b>.</p> * <b>ONLY FOR {@link #UNKNOWN} and {@link #UNKNOWN_NUMERIC} {@link DBDatatype}s</b>.</p>
* *
* <p><i><b>Important:</b> * <p><i><b>Important:</b>
* If this {@link DBDatatype} is not {@link #UNKNOWN} or {@link #UNKNOWN_NUMERIC} or * If this {@link DBDatatype} is not {@link #UNKNOWN} or {@link #UNKNOWN_NUMERIC} this function has no effect.
* if the given name is NULL or empty, 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> * </i></p>
* *
* @param typeName User type name. * @param typeName User type name.
...@@ -79,8 +80,12 @@ public class DBType { ...@@ -79,8 +80,12 @@ public class DBType {
* @since 1.4 * @since 1.4
*/ */
public void setCustomType(final String typeName){ public void setCustomType(final String typeName){
if ((this == UNKNOWN || this == UNKNOWN_NUMERIC) && typeName != null && typeName.trim().length() > 0) if ((this == UNKNOWN || this == UNKNOWN_NUMERIC)){
strExp = "?" + typeName.trim() + "?"; if (typeName != null && typeName.trim().length() > 0)
strExp = "?" + typeName.trim() + "?";
else
strExp = this.name();
}
} }
} }
......
...@@ -5,6 +5,7 @@ import static org.junit.Assert.assertFalse; ...@@ -5,6 +5,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import org.junit.AfterClass;
import org.junit.Test; import org.junit.Test;
import adql.db.DBType.DBDatatype; import adql.db.DBType.DBDatatype;
...@@ -20,6 +21,11 @@ import adql.query.operand.function.geometry.PointFunction; ...@@ -20,6 +21,11 @@ import adql.query.operand.function.geometry.PointFunction;
public class TestFunctionDef { public class TestFunctionDef {
@AfterClass
public static void tearDownAfterClass() throws Exception{
DBType.DBDatatype.UNKNOWN.setCustomType(null);
}
@Test @Test
public void testIsString(){ public void testIsString(){
for(DBDatatype type : DBDatatype.values()){ for(DBDatatype type : DBDatatype.values()){
......
...@@ -26,13 +26,15 @@ import adql.db.DefaultDBTable; ...@@ -26,13 +26,15 @@ import adql.db.DefaultDBTable;
import adql.db.FunctionDef; import adql.db.FunctionDef;
import adql.query.ADQLQuery; import adql.query.ADQLQuery;
public class UnknownTypes { public class TestUnknownTypes {
@BeforeClass @BeforeClass
public static void setUpBeforeClass() throws Exception{} public static void setUpBeforeClass() throws Exception{}
@AfterClass @AfterClass
public static void tearDownAfterClass() throws Exception{} public static void tearDownAfterClass() throws Exception{
DBType.DBDatatype.UNKNOWN.setCustomType(null);
}
@Before @Before
public void setUp() throws Exception{} public void setUp() throws Exception{}
......
...@@ -21,13 +21,13 @@ import org.junit.Before; ...@@ -21,13 +21,13 @@ import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import tap.TAPException;
import tap.metadata.TableSetParser.ForeignKey;
import adql.db.DBType; import adql.db.DBType;
import adql.db.DBType.DBDatatype; import adql.db.DBType.DBDatatype;
import tap.TAPException;
import tap.metadata.TableSetParser.ForeignKey;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class TableSetParserTest { public class TestTableSetParser {
private static TableSetParser parser = null; private static TableSetParser parser = null;
private static XMLInputFactory factory = null; private static XMLInputFactory factory = null;
...@@ -903,7 +903,7 @@ public class TableSetParserTest { ...@@ -903,7 +903,7 @@ public class TableSetParserTest {
col = parser.parseColumn(reader); col = parser.parseColumn(reader);
assertEquals("col1", col.getADQLName()); assertEquals("col1", col.getADQLName());
assertNull(col.getDescription()); assertNull(col.getDescription());
assertEquals(DBDatatype.VARCHAR, col.getDatatype().type); assertEquals(DBDatatype.UNKNOWN, col.getDatatype().type);
assertEquals(-1, col.getDatatype().length); assertEquals(-1, col.getDatatype().length);
assertNull(col.getUtype()); assertNull(col.getUtype());
assertNull(col.getUcd()); assertNull(col.getUcd());
......
...@@ -31,7 +31,7 @@ import javax.servlet.http.Part; ...@@ -31,7 +31,7 @@ import javax.servlet.http.Part;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class UWSUrlTest { public class TestUWSUrl {
public static final class TestHttpServletRequest implements HttpServletRequest { 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