From da1a57e6ccae22b2aa39bc093b4e5a3f295ffbc1 Mon Sep 17 00:00:00 2001 From: Rob Rudin Date: Mon, 4 Mar 2024 12:46:37 -0500 Subject: [PATCH] Test fixes for 12 nightly --- .../client/test/PlanGeneratedTest.java | 9 + .../test/junit5/RequiresML11OrLower.java | 22 ++ .../client/test/rows/ColumnInfoTest.java | 30 +- .../allTypes-marklogic-11.json} | 0 .../columnInfo/allTypes-marklogic-12.json | 292 ++++++++++++++++++ 5 files changed, 342 insertions(+), 11 deletions(-) create mode 100644 marklogic-client-api/src/test/java/com/marklogic/client/test/junit5/RequiresML11OrLower.java rename marklogic-client-api/src/test/resources/{allTypes-columnInfo.json => columnInfo/allTypes-marklogic-11.json} (100%) create mode 100644 marklogic-client-api/src/test/resources/columnInfo/allTypes-marklogic-12.json diff --git a/marklogic-client-api/src/test/java/com/marklogic/client/test/PlanGeneratedTest.java b/marklogic-client-api/src/test/java/com/marklogic/client/test/PlanGeneratedTest.java index 6c3f6e998..481d9c2f1 100644 --- a/marklogic-client-api/src/test/java/com/marklogic/client/test/PlanGeneratedTest.java +++ b/marklogic-client-api/src/test/java/com/marklogic/client/test/PlanGeneratedTest.java @@ -18,12 +18,15 @@ import com.marklogic.client.io.Format; import com.marklogic.client.test.junit5.RequiresML11; +import com.marklogic.client.test.junit5.RequiresML11OrLower; import com.marklogic.client.type.ServerExpression; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; // IMPORTANT: Do not edit. This file is generated. // Exception - some of these tests cannot pass on ML <= 10. Those have been modified to not run unless ML is >= 11. +// Other tests have been disabled to not run on ML >= 12. Getting those tests to pass would require running the Optic +// code generator workspace on src/main/java, which would then prevent many of the tests from passing on ML <= 11. public class PlanGeneratedTest extends PlanGeneratedBase { @Test @@ -326,6 +329,7 @@ public void testFnFormatTime2Exec() { executeTester("testFnFormatTime2", p.fn.formatTime(p.col("1"), p.col("2")), false, null, null, null, "10:09:08:00", new ServerExpression[]{ p.xs.time("10:09:08Z"), p.xs.string("[H01]:[m01]:[s01]:[f01]") }); } + @ExtendWith(RequiresML11OrLower.class) @Test public void testFnHead1Exec() { executeTester("testFnHead1", p.fn.head(p.col("1")), false, null, null, null, "a", new ServerExpression[]{ p.xs.stringSeq(p.xs.string("a"), p.xs.string("b"), p.xs.string("c")) }); @@ -471,6 +475,7 @@ public void testFnNumber1Exec() { executeTester("testFnNumber1", p.fn.number(p.col("1")), false, null, null, null, "1.1", new ServerExpression[]{ p.xs.string("1.1") }); } + @ExtendWith(RequiresML11OrLower.class) @Test public void testFnPrefixFromQName1Exec() { executeTester("testFnPrefixFromQName1", p.fn.prefixFromQName(p.col("1")), false, null, null, Format.JSON, null, new ServerExpression[]{ p.xs.QName("abc") }); @@ -1825,6 +1830,7 @@ public void testXsNCName1Exec() { executeTester("testXsNCName1", p.xs.NCName(p.col("1")), false, null, null, null, "a-b-c", new ServerExpression[]{ p.xs.string("a-b-c") }); } + @ExtendWith(RequiresML11OrLower.class) @Test public void testXsNegativeInteger1Exec() { executeTester("testXsNegativeInteger1", p.xs.negativeInteger(p.col("1")), false, null, null, null, "-1", new ServerExpression[]{ p.xs.doubleVal(-1) }); @@ -1835,11 +1841,13 @@ public void testXsNMTOKEN1Exec() { executeTester("testXsNMTOKEN1", p.xs.NMTOKEN(p.col("1")), false, null, null, null, "a:b:c", new ServerExpression[]{ p.xs.string("a:b:c") }); } + @ExtendWith(RequiresML11OrLower.class) @Test public void testXsNonNegativeInteger1Exec() { executeTester("testXsNonNegativeInteger1", p.xs.nonNegativeInteger(p.col("1")), false, null, null, null, "0", new ServerExpression[]{ p.xs.string("0") }); } + @ExtendWith(RequiresML11OrLower.class) @Test public void testXsNonPositiveInteger1Exec() { executeTester("testXsNonPositiveInteger1", p.xs.nonPositiveInteger(p.col("1")), false, null, null, null, "0", new ServerExpression[]{ p.xs.string("0") }); @@ -1855,6 +1863,7 @@ public void testXsNumeric1Exec() { executeTester("testXsNumeric1", p.xs.numeric(p.col("1")), false, null, null, null, "1.2", new ServerExpression[]{ p.xs.doubleVal(1.2) }); } + @ExtendWith(RequiresML11OrLower.class) @Test public void testXsPositiveInteger1Exec() { executeTester("testXsPositiveInteger1", p.xs.positiveInteger(p.col("1")), false, null, null, null, "1", new ServerExpression[]{ p.xs.doubleVal(1) }); diff --git a/marklogic-client-api/src/test/java/com/marklogic/client/test/junit5/RequiresML11OrLower.java b/marklogic-client-api/src/test/java/com/marklogic/client/test/junit5/RequiresML11OrLower.java new file mode 100644 index 000000000..2eee83c76 --- /dev/null +++ b/marklogic-client-api/src/test/java/com/marklogic/client/test/junit5/RequiresML11OrLower.java @@ -0,0 +1,22 @@ +package com.marklogic.client.test.junit5; + +import com.marklogic.client.test.Common; +import com.marklogic.client.test.MarkLogicVersion; +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; + +public class RequiresML11OrLower implements ExecutionCondition { + + private static MarkLogicVersion markLogicVersion; + + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + if (markLogicVersion == null) { + markLogicVersion = Common.getMarkLogicVersion(); + } + return markLogicVersion.getMajor() <= 11 ? + ConditionEvaluationResult.enabled("MarkLogic major version is 11 or lower") : + ConditionEvaluationResult.disabled("MarkLogic major version is 12 or higher"); + } +} diff --git a/marklogic-client-api/src/test/java/com/marklogic/client/test/rows/ColumnInfoTest.java b/marklogic-client-api/src/test/java/com/marklogic/client/test/rows/ColumnInfoTest.java index 33234b92a..0cdec93b6 100644 --- a/marklogic-client-api/src/test/java/com/marklogic/client/test/rows/ColumnInfoTest.java +++ b/marklogic-client-api/src/test/java/com/marklogic/client/test/rows/ColumnInfoTest.java @@ -8,6 +8,7 @@ import com.marklogic.client.row.RawQueryDSLPlan; import com.marklogic.client.row.RowManager; import com.marklogic.client.test.Common; +import com.marklogic.client.test.MarkLogicVersion; import com.marklogic.client.test.junit5.RequiresML11; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -15,6 +16,8 @@ import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.core.io.ClassPathResource; +import java.io.IOException; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -22,6 +25,7 @@ public class ColumnInfoTest { private RowManager rowManager; + private static final ObjectMapper objectMapper = new ObjectMapper(); @BeforeEach void beforeEach() { @@ -29,14 +33,14 @@ void beforeEach() { } @Test - void allTypesWithDSLPlan() { + void allTypesWithDSLPlan() throws Exception { String query = "op.fromView('javaClient', 'allTypes')"; RawQueryDSLPlan plan = rowManager.newRawQueryDSLPlan(new StringHandle(query)); verifyColumnInfo(plan); } @Test - void allTypesWithSerializedPlan() { + void allTypesWithSerializedPlan() throws Exception { String serializedQuery = "{\n" + " \"$optic\": {\n" + " \"ns\": \"op\",\n" + @@ -64,7 +68,7 @@ void allTypesWithSerializedPlan() { * * @param plan */ - private void verifyColumnInfo(PlanBuilder.Plan plan) { + private void verifyColumnInfo(PlanBuilder.Plan plan) throws Exception { StringHandle output = Common.client.newRowManager().columnInfo(plan, new StringHandle()); assertTrue(output.getServerTimestamp() > 0, "The server timestamp should be present so that a client, such as " + @@ -74,13 +78,17 @@ private void verifyColumnInfo(PlanBuilder.Plan plan) { assertEquals(36, columnInfos.length, "There are 35 column definitions in the allTypes TDE, and then a 36th " + "column info is added for the rowid column."); - ObjectMapper mapper = new ObjectMapper(); - try { - JsonNode actualColumnInfo = mapper.readTree("[" + String.join(",", columnInfos) + "]"); - JsonNode expectedColumnInfo = mapper.readTree(new ClassPathResource("allTypes-columnInfo.json").getInputStream()); - JSONAssert.assertEquals(expectedColumnInfo.toString(), actualColumnInfo.toString(), true); - } catch (Exception ex) { - throw new RuntimeException(ex); - } + JsonNode actualColumnInfo = objectMapper.readTree("[" + String.join(",", columnInfos) + "]"); + JsonNode expectedColumnInfo = getExpectedColumnInfo(); + JSONAssert.assertEquals(expectedColumnInfo.toString(), actualColumnInfo.toString(), true); + } + + private JsonNode getExpectedColumnInfo() throws IOException { + MarkLogicVersion version = Common.getMarkLogicVersion(); + String file = version.getMajor() <= 11 ? + "columnInfo/allTypes-marklogic-11.json" : + "columnInfo/allTypes-marklogic-12.json"; + + return objectMapper.readTree(new ClassPathResource(file).getInputStream()); } } diff --git a/marklogic-client-api/src/test/resources/allTypes-columnInfo.json b/marklogic-client-api/src/test/resources/columnInfo/allTypes-marklogic-11.json similarity index 100% rename from marklogic-client-api/src/test/resources/allTypes-columnInfo.json rename to marklogic-client-api/src/test/resources/columnInfo/allTypes-marklogic-11.json diff --git a/marklogic-client-api/src/test/resources/columnInfo/allTypes-marklogic-12.json b/marklogic-client-api/src/test/resources/columnInfo/allTypes-marklogic-12.json new file mode 100644 index 000000000..6e0b88125 --- /dev/null +++ b/marklogic-client-api/src/test/resources/columnInfo/allTypes-marklogic-12.json @@ -0,0 +1,292 @@ +[ + { + "schema": "javaClient", + "view": "allTypes", + "column": "intValue", + "type": "int", + "hidden": false, + "nullable": false + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "unsignedIntValue", + "type": "unsignedInt", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "longValue", + "type": "long", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "unsignedLongValue", + "type": "unsignedLong", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "floatValue", + "type": "float", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "doubleValue", + "type": "double", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "decimalValue", + "type": "decimal", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "dateTimeValue", + "type": "dateTime", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "timeValue", + "type": "time", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "dateValue", + "type": "date", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "gYearMonthValue", + "type": "gYearMonth", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "gYearValue", + "type": "gYear", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "gMonthValue", + "type": "gMonth", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "gDayValue", + "type": "gDay", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "yearMonthDurationValue", + "type": "yearMonthDuration", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "dayTimeDurationValue", + "type": "dayTimeDuration", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "stringValue", + "type": "string", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "anyURIValue", + "type": "anyUri", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "pointValue", + "type": "point", + "hidden": false, + "nullable": true, + "coordinate-system": "wgs84" + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "longLatPointValue", + "type": "point", + "hidden": false, + "nullable": true, + "coordinate-system": "wgs84" + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "booleanValue", + "type": "boolean", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "base64BinaryValue", + "type": "base64Binary", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "hexBinaryValue", + "type": "hexBinary", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "byteValue", + "type": "byte", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "durationValue", + "type": "duration", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "gMonthDayValue", + "type": "gMonthDay", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "integerValue", + "type": "integer", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "negativeIntegerValue", + "type": "negativeInteger", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "nonNegativeIntegerValue", + "type": "nonNegativeInteger", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "nonPositiveIntegerValue", + "type": "nonPositiveInteger", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "positiveIntegerValue", + "type": "positiveInteger", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "shortValue", + "type": "short", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "unsignedByteValue", + "type": "unsignedByte", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "unsignedShortValue", + "type": "unsignedShort", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "IRIValue", + "type": "iri", + "hidden": false, + "nullable": true + }, + { + "schema": "javaClient", + "view": "allTypes", + "column": "rowid", + "type": "rowid", + "hidden": true, + "nullable": false + } +]