Skip to content

Commit ca81c9b

Browse files
georgeajitgeorgeajit
authored andcommitted
Added test to verify UTF-8 chars in doc URI
1 parent 0d8e324 commit ca81c9b

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/datamovement/functionaltests/StringQueryHostBatcherTest.java

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,4 +2221,109 @@ public void testQueryBatcherWithIterator() throws Exception {
22212221
clearDB();
22222222
}
22232223
}
2224+
2225+
// Verify UTF-8 char in URI. Refer to Git Issue 1163.
2226+
2227+
@Test
2228+
public void testUTF8InUri() throws Exception
2229+
{
2230+
System.out.println("Running testUTF8InUri");
2231+
DatabaseClient clientTmp = null;
2232+
DataMovementManager dmManagerTmp = null;
2233+
2234+
try {
2235+
System.out.println("Running testUTF8InUri");
2236+
2237+
String[] filenames = { "constraint1.xml", "constraint2.xml", "constraint3.xml", "constraint4.xml", "constraint5.xml" };
2238+
String combinedQueryFileName = "combinedQueryOptionJSON.json";
2239+
2240+
clientTmp = getDatabaseClient("eval-user", "x", getConnType());
2241+
dmManagerTmp = clientTmp.newDataMovementManager();
2242+
2243+
QueryManager queryMgr = clientTmp.newQueryManager();
2244+
String dataFileDir = dataConfigDirPath + "/data/";
2245+
String combQueryFileDir = dataConfigDirPath + "/combined/";
2246+
2247+
// Use WriteBatcher to write the same files.
2248+
WriteBatcher wbatcher = dmManagerTmp.newWriteBatcher();
2249+
2250+
wbatcher.withBatchSize(2);
2251+
InputStreamHandle contentHandle1 = new InputStreamHandle();
2252+
contentHandle1.set(new FileInputStream(dataFileDir + filenames[0]));
2253+
InputStreamHandle contentHandle2 = new InputStreamHandle();
2254+
contentHandle2.set(new FileInputStream(dataFileDir + filenames[1]));
2255+
InputStreamHandle contentHandle3 = new InputStreamHandle();
2256+
contentHandle3.set(new FileInputStream(dataFileDir + filenames[2]));
2257+
InputStreamHandle contentHandle4 = new InputStreamHandle();
2258+
contentHandle4.set(new FileInputStream(dataFileDir + filenames[3]));
2259+
InputStreamHandle contentHandle5 = new InputStreamHandle();
2260+
contentHandle5.set(new FileInputStream(dataFileDir + filenames[4]));
2261+
2262+
wbatcher.add(filenames[0], contentHandle1);
2263+
wbatcher.add(filenames[1], contentHandle2);
2264+
wbatcher.add(filenames[2], contentHandle3);
2265+
wbatcher.add(filenames[3], contentHandle4);
2266+
wbatcher.add("/CXXXX_Ü_testqa.xml", contentHandle5);
2267+
2268+
wbatcher.flushAndWait();
2269+
2270+
// get the combined query
2271+
File file = new File(combQueryFileDir + combinedQueryFileName);
2272+
2273+
// create a handle for the search criteria
2274+
FileHandle rawHandle = (new FileHandle(file)).withFormat(Format.JSON);
2275+
// create a search definition based on the handle
2276+
RawCombinedQueryDefinition querydef = queryMgr.newRawCombinedQueryDefinition(rawHandle);
2277+
2278+
StringBuilder batchResults = new StringBuilder();
2279+
StringBuilder batchFailResults = new StringBuilder();
2280+
2281+
// Run a QueryBatcher on the new URIs.
2282+
QueryBatcher queryBatcher1 = dmManagerTmp.newQueryBatcher(querydef);
2283+
2284+
queryBatcher1.onUrisReady(batch -> {
2285+
for (String str : batch.getItems()) {
2286+
batchResults.append(str)
2287+
.append('|');
2288+
}
2289+
});
2290+
queryBatcher1.onQueryFailure(throwable -> {
2291+
System.out.println("Exceptions thrown from callback onQueryFailure");
2292+
throwable.printStackTrace();
2293+
batchFailResults.append("Test has Exceptions");
2294+
});
2295+
2296+
dmManagerTmp.startJob(queryBatcher1);
2297+
boolean bJobFinished = queryBatcher1.awaitCompletion(3, TimeUnit.MINUTES);
2298+
2299+
if (bJobFinished) {
2300+
2301+
if (!batchFailResults.toString().isEmpty() && batchFailResults.toString().contains("Exceptions")) {
2302+
fail("Test failed due to exceptions");
2303+
}
2304+
2305+
// Verify the batch results now.
2306+
String[] res = batchResults.toString().split("\\|");
2307+
assertEquals("Number of reults returned is incorrect", 1, res.length);
2308+
assertTrue("URI returned not correct", res[0].trim().contains("/CXXXX_Ü_testqa.xml"));
2309+
2310+
// Read the document and assert on the value
2311+
DOMHandle contentHandle = new DOMHandle();
2312+
contentHandle = readDocumentUsingDOMHandle(clientTmp, "/CXXXX_Ü_testqa.xml", "XML");
2313+
Document readDoc = contentHandle.get();
2314+
System.out.println(convertXMLDocumentToString(readDoc));
2315+
2316+
assertTrue("Document content returned not correct", readDoc.getElementsByTagName("id").item(0).getTextContent().contains("0026"));
2317+
assertTrue("Document content returned not correct", readDoc.getElementsByTagName("title").item(0).getTextContent().contains("The memex"));
2318+
assertTrue("Document content returned not correct", readDoc.getElementsByTagName("date").item(0).getTextContent().contains("2009-05-05"));
2319+
}
2320+
} catch (Exception e) {
2321+
System.out.println("Exceptions thrown from testUTF8InUri");
2322+
System.out.println(e.getMessage());
2323+
fail("testUTF8InUri mathod failed");
2324+
} finally {
2325+
clientTmp.release();
2326+
clearDB();
2327+
}
2328+
}
22242329
}

0 commit comments

Comments
 (0)