|
| 1 | +const test = require("/test/test-helper.xqy"); |
| 2 | + |
| 3 | +function invokeService(entityIRI, propertyPath, referenceType, pattern, limit) { |
| 4 | + return fn.head(xdmp.invoke( |
| 5 | + "/data-hub/5/data-services/entitySearch/getMatchingPropertyValues.sjs", |
| 6 | + { |
| 7 | + "entityIRI": entityIRI, |
| 8 | + "propertyPath": propertyPath, |
| 9 | + "referenceType": referenceType, |
| 10 | + "pattern": pattern, |
| 11 | + "limit": limit |
| 12 | + } |
| 13 | + )); |
| 14 | +} |
| 15 | + |
| 16 | +// Uncomment the tests when DHFPROD-4494 bug is resolved. |
| 17 | +/*function testMatchingValuesStartingWithPattern() { |
| 18 | + let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity"; |
| 19 | + let propertyPath = "numStrEntityProp/strCityProp"; |
| 20 | + const result = invokeService(entityIRI, propertyPath, "path", "doc2", 10); |
| 21 | + return [ |
| 22 | + test.assertEqual(2, result.length), |
| 23 | + test.assertTrue(result.includes("doc2City1Prop")), |
| 24 | + test.assertTrue(result.includes("doc2City2Prop")) |
| 25 | + ]; |
| 26 | +} |
| 27 | +
|
| 28 | +function testMatchingValuesWithPatternInBetween() { |
| 29 | + let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity"; |
| 30 | + let propertyPath = "numStrEntityProp/strCityProp"; |
| 31 | + const result = invokeService(entityIRI, propertyPath, "path", "city", 10); |
| 32 | + return [ |
| 33 | + test.assertEqual(4, result.length), |
| 34 | + test.assertTrue(result.includes("doc2City1Prop")), |
| 35 | + test.assertTrue(result.includes("doc2City2Prop")), |
| 36 | + test.assertTrue(result.includes("doc1City1Prop")), |
| 37 | + test.assertTrue(result.includes("doc1City2Prop")) |
| 38 | + ]; |
| 39 | +} |
| 40 | +
|
| 41 | +function testMatchingValuesOnRangePathOneLevelNesting() { |
| 42 | + let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity"; |
| 43 | + let propertyPath = "numStrEntityProp/strCityProp"; |
| 44 | + const result = invokeService(entityIRI, propertyPath, "path", "city", 10); |
| 45 | + return [ |
| 46 | + test.assertEqual(4, result.length), |
| 47 | + test.assertTrue(result.includes("doc2City1Prop")), |
| 48 | + test.assertTrue(result.includes("doc2City2Prop")), |
| 49 | + test.assertTrue(result.includes("doc1City1Prop")), |
| 50 | + test.assertTrue(result.includes("doc1City2Prop")) |
| 51 | + ]; |
| 52 | +} |
| 53 | +
|
| 54 | +function testMatchingValuesOnRangePathNoNesting() { |
| 55 | + let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity"; |
| 56 | + let propertyPath = "srchEntyProp2"; |
| 57 | + const result = invokeService(entityIRI, propertyPath, "path", "city", 10); |
| 58 | + return [ |
| 59 | + test.assertEqual(2, result.length), |
| 60 | + test.assertTrue(result.includes("doc1SrchEntyProp2")), |
| 61 | + test.assertTrue(result.includes("doc2SrchEntyProp2")), |
| 62 | + ]; |
| 63 | +} |
| 64 | +
|
| 65 | +function testMatchingValuesWithLimit() { |
| 66 | + let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity"; |
| 67 | + let propertyPath = "numStrEntityProp/strCityProp"; |
| 68 | + const result = invokeService(entityIRI, propertyPath, "path", "city", 3); |
| 69 | + return [ |
| 70 | + test.assertEqual(3, result.length) |
| 71 | + ]; |
| 72 | +}*/ |
| 73 | + |
| 74 | +function testMatchingValuesOnRangeElementIndexes() { |
| 75 | + let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity"; |
| 76 | + let propertyPath = "strNameProp"; |
| 77 | + const result = invokeService(entityIRI, propertyPath, "element", "name", 10); |
| 78 | + return [ |
| 79 | + test.assertEqual(4, result.length), |
| 80 | + test.assertTrue(result.includes("doc2Name1Prop")), |
| 81 | + test.assertTrue(result.includes("doc2Name2Prop")), |
| 82 | + test.assertTrue(result.includes("doc1Name1Prop")), |
| 83 | + test.assertTrue(result.includes("doc1Name2Prop")) |
| 84 | + ]; |
| 85 | +} |
| 86 | + |
| 87 | +function testMatchingValuesOnRangeFieldIndexes() { |
| 88 | + let entityIRI = "http://marklogic.com/EntitiesSearchEntity-0.0.1/EntitiesSearchEntity"; |
| 89 | + let propertyPath = "datahubCreatedInFlow"; |
| 90 | + const result = invokeService(entityIRI, propertyPath, "field", "flow", 10); |
| 91 | + return [ |
| 92 | + test.assertEqual(2, result.length), |
| 93 | + test.assertTrue(result.includes("my-flow-1")), |
| 94 | + test.assertTrue(result.includes("my-flow-2")) |
| 95 | + ]; |
| 96 | +} |
| 97 | + |
| 98 | +function testMatchingValuesOnCollectionNames() { |
| 99 | + let entityIRI = ""; |
| 100 | + let propertyPath = ""; |
| 101 | + const result = invokeService(entityIRI, propertyPath,"collection", "doc", 10); |
| 102 | + return [ |
| 103 | + test.assertEqual(2, result.length), |
| 104 | + test.assertTrue(result.includes("doc1")), |
| 105 | + test.assertTrue(result.includes("doc2")) |
| 106 | + ]; |
| 107 | +} |
| 108 | + |
| 109 | +[] |
| 110 | +.concat(testMatchingValuesOnRangeElementIndexes()) |
| 111 | +.concat(testMatchingValuesOnRangeFieldIndexes()) |
| 112 | +.concat(testMatchingValuesOnCollectionNames()); |
| 113 | +/* |
| 114 | +.concat(testMatchingValuesStartingWithPattern()) |
| 115 | +.concat(testMatchingValuesWithPatternInBetween()) |
| 116 | +.concat(testMatchingValuesOnRangePathOneLevelNesting()) |
| 117 | +.concat(testMatchingValuesOnRangePathNoNesting()) |
| 118 | +.concat(testMatchingValuesWithLimit()) |
| 119 | +.concat(testMatchingValuesOnRangeElementIndexes()) |
| 120 | +.concat(testMatchingValuesOnRangeFieldIndexes()) |
| 121 | +.concat(testMatchingValuesOnCollectionNames());*/ |
0 commit comments