diff --git a/pom.xml b/pom.xml
index 321c4226d..7967c4c9b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,10 +48,11 @@
clientCertAuth - - For tests requiring client certificate authentication
setup (excluded by default) - - - - - - - - - - - - - - - - - - - - - - -
requireSecret - For tests requiring setting up secrets manually
+ JSONTest - For tests using JSON data type
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Default testing enabled with SQL Server 2019 (SQLv15) -->
- xSQLv12,xSQLv15,NTLM,MSI,reqExternalSetup,clientCertAuth,fedAuth,kerberos,requireSecret
+ xSQLv12,xSQLv15,NTLM,MSI,reqExternalSetup,clientCertAuth,fedAuth,kerberos,requireSecret,JSONTest
-preview
diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/JSONFunctionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/JSONFunctionTest.java
index e775c2cb2..4c0ffdf86 100644
--- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/JSONFunctionTest.java
+++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/JSONFunctionTest.java
@@ -20,11 +20,13 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Tag;
import com.microsoft.sqlserver.jdbc.RandomUtil;
import com.microsoft.sqlserver.jdbc.TestUtils;
import com.microsoft.sqlserver.testframework.AbstractSQLGenerator;
import com.microsoft.sqlserver.testframework.AbstractTest;
+import com.microsoft.sqlserver.testframework.Constants;
@RunWith(JUnitPlatform.class)
@DisplayName("Test Json Functions")
@@ -40,6 +42,7 @@ public static void setupTests() throws Exception {
* ISJSON -> Tests whether a string contains valid JSON.
*/
@Test
+ @Tag(Constants.JSONTest)
public void testISJSON() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -78,6 +81,7 @@ public void testISJSON() throws SQLException {
* ISJSON -> Tests whether a string contains valid JSON.
*/
@Test
+ @Tag(Constants.JSONTest)
public void testISJSONWithVariousInputs() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier("dstTable"));
@@ -130,6 +134,7 @@ public void testISJSONWithVariousInputs() throws SQLException {
* output: ["value1",123]
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONArrayWithoutNulls() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -164,6 +169,7 @@ public void testJSONArrayWithoutNulls() throws SQLException {
* output: ["value1",123,null,"value2"]
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONArrayWithNulls() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -198,6 +204,7 @@ public void testJSONArrayWithNulls() throws SQLException {
* output: ["a",{"name":"value","type":1},[1,null,2]]
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONArrayWithMixedElements() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -232,6 +239,7 @@ public void testJSONArrayWithMixedElements() throws SQLException {
* output: [1,"",""]
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONArrayWithVariablesAndExpressions() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -272,6 +280,7 @@ public void testJSONArrayWithVariablesAndExpressions() throws SQLException {
* output: ["","",""]
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONArrayPerRow() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -312,6 +321,7 @@ public void testJSONArrayPerRow() throws SQLException {
* output: ["",""]
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONArrayAgg() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -348,6 +358,7 @@ public void testJSONArrayAgg() throws SQLException {
* output: ["c","b","a"]
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONArrayAggWithThreeElements() throws SQLException {
String select = "SELECT JSON_ARRAYAGG(c1) AS jsonArrayAgg FROM (VALUES ('c'), ('b'), ('a')) AS t(c1)";
try (Connection conn = DriverManager.getConnection(connectionString);
@@ -367,6 +378,7 @@ public void testJSONArrayAggWithThreeElements() throws SQLException {
* output: ["a","b","c"]
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONArrayAggWithOrderedElements() throws SQLException {
String select = "SELECT JSON_ARRAYAGG(c1 ORDER BY c1) AS jsonArrayAgg FROM (VALUES ('c'), ('b'), ('a')) AS t(c1)";
try (Connection conn = DriverManager.getConnection(connectionString);
@@ -386,6 +398,7 @@ public void testJSONArrayAggWithOrderedElements() throws SQLException {
* output: ["column1","column2"]
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONArrayAggWithTwoColumns() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -434,6 +447,7 @@ public void testJSONArrayAggWithTwoColumns() throws SQLException {
* output: {"key":"value2"}
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONModify() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -509,6 +523,7 @@ public void testJSONModify() throws SQLException {
* output: {"name":"Mike","skills":["C#","SQL","Azure"],"surname":"Smith"}
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONModifyMultipleUpdates() throws SQLException {
String json = "{\"name\":\"John\",\"skills\":[\"C#\",\"SQL\"]}";
String expectedJson = "{\"name\":\"Mike\",\"skills\":[\"C#\",\"SQL\",\"Azure\"],\"surname\":\"Smith\"}";
@@ -533,6 +548,7 @@ public void testJSONModifyMultipleUpdates() throws SQLException {
* output: {"Price":49.99}
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONModifyRenameKey() throws SQLException {
String json = "{\"price\":49.99}";
String expectedJson = "{\"Price\":49.99}";
@@ -557,6 +573,7 @@ public void testJSONModifyRenameKey() throws SQLException {
* output: {"click_count":174}
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONModifyIncrementValue() throws SQLException {
String json = "{\"click_count\":173}";
String expectedJson = "{\"click_count\":174}";
@@ -581,6 +598,7 @@ public void testJSONModifyIncrementValue() throws SQLException {
* output: {"info":{"address":{"town":"London"}}}
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONModifyUpdateJsonColumn() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -620,6 +638,7 @@ public void testJSONModifyUpdateJsonColumn() throws SQLException {
* output: {}
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONObjectEmpty() throws SQLException {
String select = "SELECT JSON_OBJECT() AS jsonObject";
try (Connection conn = DriverManager.getConnection(connectionString);
@@ -639,6 +658,7 @@ public void testJSONObjectEmpty() throws SQLException {
* output: {"name":"value"}
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONObjectWithMultipleKeys() throws SQLException {
String select = "SELECT JSON_OBJECT('name':'value', 'type':NULL ABSENT ON NULL) AS jsonObject";
try (Connection conn = DriverManager.getConnection(connectionString);
@@ -658,6 +678,7 @@ public void testJSONObjectWithMultipleKeys() throws SQLException {
* output: {"name":"value","type":[1,2]}
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONObjectWithJsonArray() throws SQLException {
String select = "SELECT JSON_OBJECT('name':'value', 'type':JSON_ARRAY(1, 2)) AS jsonObject";
try (Connection conn = DriverManager.getConnection(connectionString);
@@ -677,6 +698,7 @@ public void testJSONObjectWithJsonArray() throws SQLException {
* output: {"name":"value","type":{"type_id":1,"name":"a"}}
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONObjectWithNestedJsonObject() throws SQLException {
String select = "SELECT JSON_OBJECT('name':'value', 'type':JSON_OBJECT('type_id':1, 'name':'a')) AS jsonObject";
try (Connection conn = DriverManager.getConnection(connectionString);
@@ -696,6 +718,7 @@ public void testJSONObjectWithNestedJsonObject() throws SQLException {
* output: {"security_id":"","login":"","status":""}
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONObjectPerRow() throws SQLException {
String select = "SELECT s.session_id, JSON_OBJECT('security_id':s.security_id, 'login':s.login_name, 'status':s.status) AS info " +
"FROM sys.dm_exec_sessions AS s " +
@@ -722,6 +745,7 @@ public void testJSONObjectPerRow() throws SQLException {
* output: {"key1":"c","key2":"b","key3":"a"}
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONObjectAggWithThreeProperties() throws SQLException {
String select = "SELECT JSON_OBJECTAGG(c1:c2) AS jsonObjectAgg FROM (VALUES('key1', 'c'), ('key2', 'b'), ('key3','a')) AS t(c1, c2)";
try (Connection conn = DriverManager.getConnection(connectionString);
@@ -738,10 +762,11 @@ public void testJSONObjectAggWithThreeProperties() throws SQLException {
* Test JSON_OBJECTAGG function to return a result with two columns. The first column contains the object_id value.
* The second column contains a JSON object where the key is the column name and value is the column_id.
* JSON_OBJECTAGG() -> Constructs a JSON object with column names and column IDs.
- * input: JSON_OBJECTAGG(c.name:c.column_id) ->
+ * input: JSON_OBJECTAGG(c.name:c.column_id) ->
* output: {"column1":1,"column2":2}
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONObjectAggWithColumnNamesAndIDs() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -789,6 +814,7 @@ public void testJSONObjectAggWithColumnNamesAndIDs() throws SQLException {
* output: 1
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONPathExistsTrue() throws SQLException {
String jsonInfo = "{\"info\":{\"address\":[{\"town\":\"Paris\"},{\"town\":\"London\"}]}}";
String select = "DECLARE @jsonInfo AS JSON = N'" + jsonInfo + "'; " +
@@ -810,6 +836,7 @@ public void testJSONPathExistsTrue() throws SQLException {
* output: 0
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONPathExistsFalse() throws SQLException {
String jsonInfo = "{\"info\":{\"address\":[{\"town\":\"Paris\"},{\"town\":\"London\"}]}}";
String select = "DECLARE @jsonInfo AS JSON = N'" + jsonInfo + "'; " +
@@ -831,6 +858,7 @@ public void testJSONPathExistsFalse() throws SQLException {
* output: JSON fragment of OtherLanguages
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONQueryFragment() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -876,6 +904,7 @@ public void testJSONQueryFragment() throws SQLException {
* output: JSON fragments in the output of the FOR JSON clause
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONQueryForJSONClause() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -925,6 +954,7 @@ public void testJSONQueryForJSONClause() throws SQLException {
* output: JSON property value of town
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONValueInQueryResults() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
@@ -973,6 +1003,7 @@ public void testJSONValueInQueryResults() throws SQLException {
* output: JSON property value of longitude
*/
@Test
+ @Tag(Constants.JSONTest)
public void testJSONValueComputedColumns() throws SQLException {
String dstTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("dstTable")));
diff --git a/src/test/java/com/microsoft/sqlserver/testframework/Constants.java b/src/test/java/com/microsoft/sqlserver/testframework/Constants.java
index 3009d2213..733ff07f1 100644
--- a/src/test/java/com/microsoft/sqlserver/testframework/Constants.java
+++ b/src/test/java/com/microsoft/sqlserver/testframework/Constants.java
@@ -29,6 +29,7 @@ private Constants() {}
* reqExternalSetup - For tests requiring external setup
* clientCertAuth - - For tests requiring client certificate authentication setup
* Fedauth - - - - - - For Fedauth tests
+ * JSONTest - - - - - For tests requiring JSON setup
*
*/
public static final String xJDBC42 = "xJDBC42";
@@ -48,6 +49,7 @@ private Constants() {}
public static final String clientCertAuth = "clientCertAuth";
public static final String fedAuth = "fedAuth";
public static final String requireSecret = "requireSecret";
+ public static final String JSONTest = "JSONTest";
public static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current();
public static final Logger LOGGER = Logger.getLogger("AbstractTest");