Skip to content

Commit 3a86dec

Browse files
Ajit GeorgeAjit George
Ajit George
authored and
Ajit George
committed
New negative test for Bug Track Issue 43940
1 parent 74650a1 commit 3a86dec

File tree

2 files changed

+89
-2
lines changed

2 files changed

+89
-2
lines changed

test-complete/src/test/java/com/marklogic/client/functionaltest/TestRawCombinedQuery.java

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package com.marklogic.client.functionaltest;
1818

1919
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.Assert.*;
2221

2322
import java.io.File;
2423
import java.io.IOException;
@@ -38,13 +37,15 @@
3837
import org.w3c.dom.Document;
3938
import org.xml.sax.SAXException;
4039

40+
import com.fasterxml.jackson.databind.JsonNode;
4141
import com.marklogic.client.DatabaseClient;
4242
import com.marklogic.client.DatabaseClientFactory.Authentication;
4343
import com.marklogic.client.admin.ServerConfigurationManager;
4444
import com.marklogic.client.io.DOMHandle;
4545
import com.marklogic.client.io.DocumentMetadataHandle;
4646
import com.marklogic.client.io.FileHandle;
4747
import com.marklogic.client.io.Format;
48+
import com.marklogic.client.io.JacksonHandle;
4849
import com.marklogic.client.io.StringHandle;
4950
import com.marklogic.client.query.QueryManager;
5051
import com.marklogic.client.query.RawCombinedQueryDefinition;
@@ -772,7 +773,73 @@ public void test12RawCombinedQueryFieldJSON() throws KeyManagementException, NoS
772773
// release client
773774
client.release();
774775
}
776+
777+
/*
778+
* When searching using a structured query, the <search:metrics/> element in the response used to include
779+
* an empty <search:extract-resolution-time/>
780+
* This test makes sure that the response does not have
781+
* <search:extract-resolution-time>
782+
* element
783+
*/
784+
785+
@Test
786+
public void testBug43940() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
787+
{
788+
// Negative test
789+
System.out.println("Running testBug43940");
790+
791+
String[] filenames = {"constraint1.xml", "constraint2.xml", "constraint3.xml", "constraint4.xml", "constraint5.xml"};
792+
793+
DatabaseClient client = getDatabaseClient("rest-admin", "x", Authentication.DIGEST);
794+
795+
// set query option validation to true
796+
ServerConfigurationManager srvMgr = client.newServerConfigManager();
797+
srvMgr.readConfiguration();
798+
srvMgr.setQueryOptionValidation(true);
799+
srvMgr.writeConfiguration();
800+
801+
// write docs
802+
for(String filename : filenames)
803+
{
804+
writeDocumentUsingInputStreamHandle(client, filename, "/raw-combined-query/", "XML");
805+
}
806+
807+
// get the combined query
808+
File file = new File("src/test/java/com/marklogic/client/functionaltest/combined/combinedQueryMetricsTrue.xml");
809+
810+
String combinedQuery = convertFileToString(file);
811+
812+
// create a handle for the search criteria
813+
StringHandle rawHandle = new StringHandle(combinedQuery);
775814

815+
QueryManager queryMgr = client.newQueryManager();
816+
817+
// create a search definition based on the handle
818+
RawCombinedQueryDefinition querydef = queryMgr.newRawCombinedQueryDefinition(rawHandle);
819+
queryMgr.newStringDefinition("LinkResultDocumentsOpt.xml");
820+
821+
// create result handle
822+
JacksonHandle resultsHandle = new JacksonHandle();
823+
queryMgr.search(querydef, resultsHandle);
824+
825+
// get the result
826+
//Document resultDoc = resultsHandle.get();
827+
JsonNode resultNode = resultsHandle.get().get("metrics");
828+
System.out.println("Mime Type : "+resultsHandle.getMimetype());
829+
System.out.println(resultNode);
830+
// Make sure response does not have extract-resolution-time property in the metrics
831+
assertNull(resultNode.get("extract-resolution-time"));
832+
// End of Negative test
833+
834+
// Start of positive tests
835+
836+
837+
//End of positive tests
838+
839+
// release client
840+
client.release();
841+
}
842+
776843
@AfterClass
777844
public static void tearDown() throws Exception
778845
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<search xmlns="http://marklogic.com/appservices/search">
2+
<query>
3+
<value-constraint-query>
4+
<constraint-name>id</constraint-name>
5+
<text>0026</text>
6+
</value-constraint-query>
7+
</query>
8+
<options>
9+
<return-facets>true</return-facets>
10+
<return-metrics>true</return-metrics>
11+
<return-qtext>false</return-qtext>
12+
<debug>true</debug>
13+
<transform-results apply="raw"/>
14+
<constraint name="id">
15+
<value>
16+
<element ns="" name="id"/>
17+
</value>
18+
</constraint>
19+
</options>
20+
</search>

0 commit comments

Comments
 (0)