Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")) });
Expand Down Expand Up @@ -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") });
Expand Down Expand Up @@ -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) });
Expand All @@ -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") });
Expand All @@ -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) });
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,39 @@
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;
import org.junit.jupiter.api.extension.ExtendWith;
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;

@ExtendWith(RequiresML11.class)
public class ColumnInfoTest {

private RowManager rowManager;
private static final ObjectMapper objectMapper = new ObjectMapper();

@BeforeEach
void beforeEach() {
rowManager = Common.connect().newRowManager();
}

@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" +
Expand Down Expand Up @@ -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 " +
Expand All @@ -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());
}
}
Loading