int [] pageInfo = { 0, 10 };
int maxResults = 1000;
Map<String, String[]> queryParams = new HashMap<String, String[]>();
// simple (everything)
JaxbQueryProcessInstanceResult result = queryProcInstHelper.queryTasksOrProcInstsAndVariables(queryParams, pageInfo, maxResults);
assertNotNull( "null result", result );
assertFalse( "empty result (all)", result.getProcessInstanceInfoList().isEmpty() );
assertTrue( "not enough proc info's: " + result.getProcessInstanceInfoList().size(), result.getProcessInstanceInfoList().size() > 2 );
long procInstMin = Long.MAX_VALUE;
long procInstMax = -1l;
for( JaxbQueryProcessInstanceInfo procInfo : result.getProcessInstanceInfoList() ) {
long procInstId = procInfo.getProcessInstance().getId();
if( procInstId > procInstMax ) {
procInstMax = procInstId;
}
if( procInstId < procInstMin ) {
procInstMin = procInstId;
}
String procId = procInfo.getProcessInstance().getProcessId();
boolean myType = procId.contains("object");
for( JaxbVariableInfo varInfo : procInfo.getVariables() ) {
String varVal = (String) varInfo.getValue();
String varName = varInfo.getName();
assertTrue( procId + ": var value [" + varVal + "]", varVal.contains("{") || ! myType );
assertTrue( procInstId + ": var value [" + varVal + "]", varVal.contains("check") || ! varName.equals("inputStr"));
}
}
roundTripJson(result);
roundTripXml(result);
// complicated
Long procInstId = null;
String varName = null;
String varVal = null;
for( JaxbQueryProcessInstanceInfo procInfo : result.getProcessInstanceInfoList() ) {
if( procInfo.getProcessInstance().getProcessId().equals(PROCESS_OBJ_VAR_ID) ) {
procInstId = procInfo.getProcessInstance().getId();
JaxbVariableInfo varInfo = procInfo.getVariables().get(0);
if( ! varInfo.getName().equals("inputStr") ) {
varInfo = procInfo.getVariables().get(1);
}
varName = varInfo.getName();
varVal = (String) varInfo.getValue();
break;
}
}
assertNotNull( "proc inst id", procInstId );
assertNotNull( "var id", varName );
assertNotNull( "var value ", varVal );
addParams(queryParams, "processinstanceid", procInstId + "");
addParams(queryParams, "processid_re", "*" + PROCESS_OBJ_VAR_ID.substring(10));
Calendar cal = GregorianCalendar.getInstance();
cal.roll(Calendar.DAY_OF_YEAR, +2);
String tomorowStr = QUERY_PARAM_DATE_FORMAT.format(cal.getTime()).substring(0, 8);
addParams(queryParams, "enddate_max", tomorowStr);
String yesterdayStr = "00:00:01";
addParams(queryParams, "stdt_min", yesterdayStr);
addParams(queryParams, "var_" + varName, varVal );
result = queryProcInstHelper.queryTasksOrProcInstsAndVariables(queryParams, pageInfo, maxResults);
assertNotNull( "null result", result );
assertFalse( "empty result", result.getProcessInstanceInfoList().isEmpty() );
assertTrue( "more than 1 result", result.getProcessInstanceInfoList().size() == 1 );
JaxbQueryProcessInstanceInfo procInfo = result.getProcessInstanceInfoList().get(0);
assertNotNull( "no proc instance", procInfo.getProcessInstance() );
assertEquals( "num variables", 1, procInfo.getVariables().size() );
roundTripJson(result);
roundTripXml(result);
// more complicated
queryParams.clear();
--procInstMax;
++procInstMin;
addParams(queryParams, "piid_min", String.valueOf(procInstMin));
addParams(queryParams, "processinstanceid_max", String.valueOf(procInstMax));
result = queryProcInstHelper.queryTasksOrProcInstsAndVariables(queryParams, pageInfo, maxResults);
assertNotNull( "null result", result );
assertFalse( "empty result", result.getProcessInstanceInfoList().isEmpty() );
assertEquals( "number results", procInstMax - procInstMin+1, result.getProcessInstanceInfoList().size() );
long findMin = Long.MAX_VALUE;
long findMax = -1;
for( JaxbQueryProcessInstanceInfo jaxbProcInfo : result.getProcessInstanceInfoList() ) {
procInstId = jaxbProcInfo.getProcessInstance().getId();
if( procInstId > findMax ) {
findMax = procInstId;
}
if( procInstId < findMin ) {
findMin = procInstId;
}
}
assertEquals( "process instance id max", procInstMax, findMax );
assertEquals( "process instance id min", procInstMin, findMin );
// test bad parameter
addParams(queryParams, "taskowner", USER_ID );
boolean exThrown = false;
try {
result = queryProcInstHelper.queryTasksOrProcInstsAndVariables(queryParams, pageInfo, maxResults);
} catch( Exception e ) {
exThrown = true;
}
assertTrue( "Exception not thrown on invalid parameter 'taskowner'", exThrown);
// varregex test
queryParams.clear();
addParams(queryParams, "processinstanceid", procInstId + "");
addParams(queryParams, "processid_re", "*" + PROCESS_OBJ_VAR_ID.substring(10));
addParams(queryParams, "vr_" + varName, "X" + varVal.substring(0, 3) + "*" );
result = queryProcInstHelper.queryTasksOrProcInstsAndVariables(queryParams, pageInfo, maxResults);
assertNotNull( "null result", result );
assertTrue( "Expected empty result: " + result.getProcessInstanceInfoList().size(), result.getProcessInstanceInfoList().isEmpty() );
}