Source:
<code>public void testGetTaskInstancesAsExcludedOwner() { query = new SqlQueryDefinition("getMyTaskInstances", dataSourceJNDIname, Target.PO_TASK); query.setExpression(PO_TASK_QUERY); queryService.registerQuery(query); List<QueryDefinition> queries = queryService.getQueries(new QueryContext()); assertNotNull(queries); assertEquals(1, queries.size()); QueryDefinition registeredQuery = queries.get(0); assertNotNull(registeredQuery); assertEquals(query.getName(), registeredQuery.getName()); assertEquals(query.getSource(), registeredQuery.getSource()); assertEquals(query.getExpression(), registeredQuery.getExpression()); assertEquals(query.getTarget(), registeredQuery.getTarget()); registeredQuery = queryService.getQuery(query.getName()); assertNotNull(registeredQuery); assertEquals(query.getName(), registeredQuery.getName()); assertEquals(query.getSource(), registeredQuery.getSource()); assertEquals(query.getExpression(), registeredQuery.getExpression()); assertEquals(query.getTarget(), registeredQuery.getTarget()); processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.ExcludedOwner", new HashMap<String, Object>()); assertNotNull(processInstanceId); <START> identityProvider.setName("maciej"); <END> identityProvider.setRoles(Arrays.asList("admins")); List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext()); assertNotNull(taskInstanceLogs); assertEquals(1, taskInstanceLogs.size()); identityProvider.setName("kris"); identityProvider.setRoles(Arrays.asList("admins")); taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext()); assertNotNull(taskInstanceLogs); assertEquals(0, taskInstanceLogs.size()); processService.abortProcessInstance(processInstanceId); processInstanceId = null; }</code><technical_language>for sake of test readability, named constants actual user Id's, lines of: String potentialOwner = "maciej" String excludedOwner = "kris"</technical_language>

Target:
public void testGetTaskInstancesAsExcludedOwner() { final String potentialOwner = "maciej"; final String excludedOwner = "kris"; final List<String> roles = Arrays.asList("admins"); query = new SqlQueryDefinition("getMyTaskInstances", dataSourceJNDIname, Target.PO_TASK); query.setExpression(PO_TASK_QUERY); queryService.registerQuery(query); List<QueryDefinition> queries = queryService.getQueries(new QueryContext()); assertNotNull(queries); assertEquals(1, queries.size()); QueryDefinition registeredQuery = queries.get(0); assertNotNull(registeredQuery); assertEquals(query.getName(), registeredQuery.getName()); assertEquals(query.getSource(), registeredQuery.getSource()); assertEquals(query.getExpression(), registeredQuery.getExpression()); assertEquals(query.getTarget(), registeredQuery.getTarget()); registeredQuery = queryService.getQuery(query.getName()); assertNotNull(registeredQuery); assertEquals(query.getName(), registeredQuery.getName()); assertEquals(query.getSource(), registeredQuery.getSource()); assertEquals(query.getExpression(), registeredQuery.getExpression()); assertEquals(query.getTarget(), registeredQuery.getTarget()); processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.ExcludedOwner", new HashMap<String, Object>()); assertNotNull(processInstanceId); identityProvider.setName(potentialOwner); identityProvider.setRoles(roles); List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext()); assertNotNull(taskInstanceLogs); assertEquals(1, taskInstanceLogs.size()); identityProvider.setName(excludedOwner); identityProvider.setRoles(roles); taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext()); assertNotNull(taskInstanceLogs); assertEquals(0, taskInstanceLogs.size()); processService.abortProcessInstance(processInstanceId); processInstanceId = null; }