Why Check Collection Object assertion throws the error "Number of tokens are more than the size of the collection"?
search cancel

Why Check Collection Object assertion throws the error "Number of tokens are more than the size of the collection"?

book

Article ID: 134511

calendar_today

Updated On:

Products

CA Application Test

Issue/Introduction

The Check Content of Collection object fails with error "Number of tokens are more than the size of the collection" when the size of the property being evaluated is 25, and the tokens to find are 7.  

Environment

All Supported DevTest Releases.

Component : CA Application Test

Cause

Per the documentation on Check Content of Collection Object Assertion the assertion works on JAVA Collections or on Arrays. If the response is a JSON array or something else other than JAVA Collection or JAVA Array will see the error.

Resolution

Converting JSON array to JAVA array using custom code and saving it into property then using that property in "Check Content of Collection Object" Assertion should resolve the issue. Here is some sample code but can write own code to handle functionality in a "Scripted Assertion" and return true but set the logic "If False To Fail the Test".

----

import org.json.JSONArray;

//Set the existing JSON array from a property to a new property

testExec.setStateValue("JsonArray_text",JsonArray_text); 

//declare the new java list/array

ArrayList list = new ArrayList();

// since the DevTest interpreter treats the filtered json result as a string when imported to this step, it needs to be redefined as a JSON array     

JSONArray jsonArray = new JSONArray(JsonArray_text);

if (jsonArray != null) {

   int len = jsonArray.length();

   for (int i=0;i<len;i++){

    list.add(jsonArray.get(i).toString());

   }

}

// assign the resulting java array (list) into a property "convertedJavaArray" for use in the assertion

testExec.setStateValue("convertedJavaArray",list); 

return true;

-----

So now "convertedJavaarray" can be used in the property field and any number of values can be used in the assertion