@@ -59,8 +59,8 @@ public class TestEvalJavaScript extends BasicJavaClientREST {
5959 @ BeforeClass
6060 public static void setUpBeforeClass () throws Exception {
6161 System .out .println ("In setup" );
62- setupJavaRESTServer (dbName , fNames [0 ], restServerName ,restPort );
63- TestEvalXquery .createUserRolesWithPrevilages ("test-eval" , "xdbc:eval" ,"any-uri" ,"xdbc:invoke" );
62+ setupJavaRESTServer (dbName , fNames [0 ], restServerName ,restPort , false );
63+ TestEvalXquery .createUserRolesWithPrevilages ("test-eval" , "xdbc:eval" , "xdbc:eval-in" , "xdmp:eval-in" , "xdbc:invoke-in" , "any-uri" ,"xdbc:invoke" );
6464 TestEvalXquery .createRESTUser ("eval-user" , "x" , "test-eval" );
6565// System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "debug");
6666 }
@@ -75,7 +75,7 @@ public static void tearDownAfterClass() throws Exception {
7575
7676 @ Before
7777 public void setUp () throws Exception {
78- client = DatabaseClientFactory .newClient ("localhost" , restPort ,"eval-user" , "x" , Authentication .DIGEST );
78+ client = DatabaseClientFactory .newClient ("localhost" , restPort ,dbName , "eval-user" , "x" , Authentication .DIGEST );
7979 }
8080
8181 @ After
@@ -85,24 +85,14 @@ public void tearDown() throws Exception {
8585 client .release ();
8686 }
8787/*
88- This method is validating all the return values from java script
88+ This method is validating all the return values from java script, this method has more types than we test them here
8989 */
9090 void validateReturnTypes (EvalResultIterator evr ) throws Exception {
9191
9292 while (evr .hasNext ())
9393 {
9494 EvalResult er =evr .next ();
95- if (er .getType ().equals (Type .XML )){
96- DOMHandle dh = new DOMHandle ();
97- dh =er .get (dh );
98- if (dh .get ().getDocumentElement ().hasChildNodes ()){
99- // System.out.println("Type XML :"+convertXMLDocumentToString(dh.get()));
100- assertEquals ("document has content" ,"<foo attr=\" attribute\" ><?processing instruction?><!--comment-->test1</foo>" ,convertXMLDocumentToString (dh .get ()));
101- }else {
102- assertEquals ("element node " ,"<test1/>" ,convertXMLDocumentToString (dh .get ()));
103- }
104- }
105- else if (er .getType ().equals (Type .JSON )){
95+ if (er .getType ().equals (Type .JSON )){
10696
10797 JacksonHandle jh = new JacksonHandle ();
10898 jh =er .get (jh );
@@ -159,7 +149,7 @@ else if(er.getType().equals(Type.TEXTNODE)){
159149// System.out.println("type boolean:"+er.getBoolean());
160150 }
161151 else if (er .getType ().equals (Type .INTEGER )){
162- // System.out.println("type Integer: "+er.getNumber().longValue());
152+ System .out .println ("type Integer: " +er .getNumber ().longValue ());
163153 assertEquals ("count of documents " ,31 ,er .getNumber ().intValue ());
164154 }
165155 else if (er .getType ().equals (Type .STRING )){
@@ -188,7 +178,7 @@ else if(er.getType().equals(Type.STRING)){
188178
189179 }else if (er .getType ().equals (Type .DECIMAL )){
190180// System.out.println("Testing is Decimal? "+er.getAs(String.class));
191- assertEquals ("Returns me a Decimal :" ,"10.5 " ,er .getAs (String .class ));
181+ assertEquals ("Returns me a Decimal :" ,"1.0471975511966 " ,er .getAs (String .class ));
192182
193183 }else if (er .getType ().equals (Type .DOUBLE )){
194184// System.out.println("Testing is Double? "+er.getAs(String.class));
@@ -317,7 +307,7 @@ else if(er.getType().equals(Type.TEXTNODE)){
317307
318308 }
319309 }
320- //This test is intended to test eval(T handle), passing input stream handle with xqueries that retruns different types, formats
310+ //This test is intended to test eval(T handle), passing input stream handle with javascript that retruns different types, formats
321311 @ Test
322312 public void testJSReturningDifferentTypesOrder2 () throws Exception {
323313
@@ -376,22 +366,23 @@ public void testJSDifferentVariableTypes() throws Exception {
376366 +"var myBool ;"
377367 +"var myInteger;"
378368 +"var myDecimal;"
379- +"var myDouble ;"
380- +"var myFloat;"
381369 +"var myJsonObject;"
382370 +"var myNull;"
383371 + "var myJsonArray;"
384372 + "var myJsonNull;"
385- + "results.push(myString,myBool,myInteger,myDecimal,myDouble,myFloat,myNull, myJsonObject,myJsonArray,myJsonNull );"
373+ + "results.push(myString,myBool,myInteger,myDecimal,myJsonObject,myJsonArray);"
386374 +"xdmp.arrayValues(results)" ;
387375
388376 ServerEvaluationCall evl = client .newServerEval ().javascript (query1 );
389377 evl .addVariable ("myString" , "xml" )
390- .addVariable ("myBool" , true ).addVariable ("myInteger" , (int )31 )
391- .addVariable ("myDecimal" , 10.5 ).addVariable ("myDouble" , 1.0471975511966 )
392- .addVariable ("myFloat" ,20 ).addVariableAs ("myJsonObject" ,new ObjectMapper ().createObjectNode ().put ("foo" , "v1" ).putNull ("testNull" ))
393- .addVariableAs ("myNull" ,(String ) null ).addVariableAs ("myJsonArray" ,new ObjectMapper ().createArrayNode ().add (1 ).add (2 ).add (3 ))
394- .addVariableAs ("myJsonNull" ,new ObjectMapper ().createObjectNode ().nullNode () );
378+ .addVariable ("myBool" , true )
379+ .addVariable ("myInteger" , (int )31 )
380+ .addVariable ("myDecimal" , (double )1.0471975511966 )
381+ .addVariableAs ("myJsonObject" ,new ObjectMapper ().createObjectNode ().put ("foo" , "v1" ).putNull ("testNull" ))
382+ .addVariableAs ("myNull" ,(String ) null )
383+ .addVariableAs ("myJsonArray" ,new ObjectMapper ().createArrayNode ().add (1 ).add (2 ).add (3 ))
384+ .addVariableAs ("myJsonNull" ,new ObjectMapper ().createObjectNode ().nullNode () )
385+ ;
395386 System .out .println (query1 );
396387 EvalResultIterator evr = evl .eval ();
397388 this .validateReturnTypes (evr );
0 commit comments