From 2c79eb6fc308c76b2e4cce6c19c5667f27a03cfa Mon Sep 17 00:00:00 2001
From: gmantele <gmantele@ari.uni-heidelberg.de>
Date: Wed, 13 Jul 2016 15:49:21 +0200
Subject: [PATCH] [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)

---
 src/adql/db/DBType.java                       | 21 ++++++++++++-------
 test/adql/db/TestFunctionDef.java             |  6 ++++++
 ...nknownTypes.java => TestUnknownTypes.java} |  6 ++++--
 ...arserTest.java => TestTableSetParser.java} |  8 +++----
 .../{UWSUrlTest.java => TestUWSUrl.java}      |  2 +-
 5 files changed, 28 insertions(+), 15 deletions(-)
 rename test/adql/parser/{UnknownTypes.java => TestUnknownTypes.java} (95%)
 rename test/tap/metadata/{TableSetParserTest.java => TestTableSetParser.java} (99%)
 rename test/uws/service/{UWSUrlTest.java => TestUWSUrl.java} (99%)

diff --git a/src/adql/db/DBType.java b/src/adql/db/DBType.java
index b81d608..46eb7ec 100644
--- a/src/adql/db/DBType.java
+++ b/src/adql/db/DBType.java
@@ -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();
+			}
 		}
 	}
 
diff --git a/test/adql/db/TestFunctionDef.java b/test/adql/db/TestFunctionDef.java
index db30b5c..ee87a7d 100644
--- a/test/adql/db/TestFunctionDef.java
+++ b/test/adql/db/TestFunctionDef.java
@@ -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()){
diff --git a/test/adql/parser/UnknownTypes.java b/test/adql/parser/TestUnknownTypes.java
similarity index 95%
rename from test/adql/parser/UnknownTypes.java
rename to test/adql/parser/TestUnknownTypes.java
index 5f311a5..2116da0 100644
--- a/test/adql/parser/UnknownTypes.java
+++ b/test/adql/parser/TestUnknownTypes.java
@@ -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{}
diff --git a/test/tap/metadata/TableSetParserTest.java b/test/tap/metadata/TestTableSetParser.java
similarity index 99%
rename from test/tap/metadata/TableSetParserTest.java
rename to test/tap/metadata/TestTableSetParser.java
index ed42f40..f2e7041 100644
--- a/test/tap/metadata/TableSetParserTest.java
+++ b/test/tap/metadata/TestTableSetParser.java
@@ -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());
diff --git a/test/uws/service/UWSUrlTest.java b/test/uws/service/TestUWSUrl.java
similarity index 99%
rename from test/uws/service/UWSUrlTest.java
rename to test/uws/service/TestUWSUrl.java
index a61db70..a83b883 100644
--- a/test/uws/service/UWSUrlTest.java
+++ b/test/uws/service/TestUWSUrl.java
@@ -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 {
 
-- 
GitLab