It's all about the answers!

Ask a question

How to create Service test cases to schedule a task


Meghana Pandey (15111514) | asked Sep 25 '09, 7:00 a.m.
Hi,

I have implemented a scheduled task which extends AbstractAutoScheduledTask.
I want to create a service junit test case to programmatically schedule this task.
Iam referring to the following tutorial on WIKI:
http://jazz.net/wiki/bin/view/Main/QueryDevGuide, which says for that you will have to get the handle of
IAsynchronousTaskSchedulerService in your testcase.

Can you please share with me how to do this. Also, If you can share with me any RTC service test cases, it will be an immense help.

Regards,
Meghana

36 answers



permanent link
Nick Edgar (6.5k711) | answered Sep 25 '09, 10:52 p.m.
JAZZ DEVELOPER
You could take a look at how the Build component's service tests use IAsynchronousTaskSchedulerService (we use it to disable async tasks during tests).

For example, com.ibm.team.build.internal.service.process.event.tests.BuildProcessEventHandlerTests.testHandleEvent() does:

IAsynchronousTaskSchedulerService schedulerService = getService(IAsynchronousTaskSchedulerService.class);
schedulerService.unschedule("com.ibm.team.repository", "LogChangeEventAppenderTask");

...

BuildProcessEventHandlerTests extends AbstractBuildRemoteServiceTestCase, which implements com.ibm.team.repository.service.tests.remotetests.IRemoteServiceTestCase, which defines ITestHostService getTestHostService() and setTestHostService(ITestHostService). AbstractBuildRemoteServiceTestCase's getService method delegates to this ITestHostService. The remote test running support calls setTestHostService for you before running your test.

AbstractBuildRemoteServiceTestCase also overrides JUnit's run(TestResult) to delegate to the server if the test is run on the client. It does so by using helpers in com.ibm.team.repository.service.tests.remotetests.RemoteServiceTestCaseHelper.

Rather than replicating this setup, it may be simpler to extend com.ibm.team.repository.service.tests.AbstractRemoteServiceTestCase. The only reason AbstractBuildRemoteServiceTestCase essentially copies what's in AbstractRemoteServiceTestCase is because it also wants to inherit from AbstractBuildTestCase.

permanent link
Nick Edgar (6.5k711) | answered Sep 25 '09, 10:55 p.m.
JAZZ DEVELOPER
See also the "Server-side testing with AbstractRemoteServiceTestCase" section of http://jazz.net/wiki/bin/view/Main/JazzBotWalkthrough

permanent link
Meghana Pandey (15111514) | answered Oct 05 '09, 9:05 a.m.
See also the "Server-side testing with AbstractRemoteServiceTestCase" section of http://jazz.net/wiki/bin/view/Main/JazzBotWalkthrough


Hi Thanks a lot for your input.

I created a TestCaseClass by extending from AbstractRemoteServiceTestCase. Also added com.ibm.team.repository.service.tests plugin in dependencies.
The class has no specific test methods but just setup() and teardown() which call super. Just wanted to check the set up. Now when I try to run this as Junit plugin test, it throws following exception:

com.ibm.team.repository.common.transport.InsecureProtocolException: CRJAZ0096I Attempting to connect to "/jazz/team/service/com.ibm.team.repository.service.tests.remotetests.IRemoteTestService" using insecure "http" protocol - suggest using "https" protocol.
at com.ibm.team.repository.transport.client.ClientHttpUtil.executeHttpMethod(ClientHttpUtil.java:287)

Can you guide me what could have gone wrong here. Or have I missed anything in the configuration?

permanent link
Nick Edgar (6.5k711) | answered Oct 05 '09, 10:36 a.m.
JAZZ DEVELOPER
In the launch config that launches your test server, try adding the com.ibm.team.server.embedded.webapp.bridge plug-in instead of com.ibm.team.server.embedded.webapp.webui.

Alternatively, you can try adding the @Secure annotation to the test class. You'll need to import the Secure class too, e.g.

import com.ibm.team.repository.common.tests.Secure;
...
@Secure
public class MyTestClass extends AbstractRemoteServiceTestCase {
...


For the gory details, see:
74875: TeamCreateTestsDatabase does not work when targeting Eclipse 3.4
and
80273: Team Create Tests Databases failing with InsecureProtocolException

Regards,
Nick

permanent link
Nick Edgar (6.5k711) | answered Oct 05 '09, 10:37 a.m.
JAZZ DEVELOPER
I'm asking around to see if there's a better reference for getting set up for automated tests, and will let you know if I hear anything.

permanent link
Meghana Pandey (15111514) | answered Oct 07 '09, 7:35 a.m.
Hi,
Thanks again for your prompt response.
Iam now able to run the Junit plugin test after adding @Secure annotation.

Now Iam facing following problem:
I have actually created an asynhronous task and have set the fixed delay to as low as 120(in secs).
From my TestClass, as you suggested Iam getting the handle of IAsynchronousTaskSchedulerService and calling schedule() to schedule my asynchronous task. But while debugging, I find that it does not get scheduled as soon as I call schedule but after sometime say an hr or so.

Is there a way(like by setting some configuration properties) so that my task gets scheduled instantly on calling schedule() from my junit Test class?

Regards,
Meghana

permanent link
Nick Edgar (6.5k711) | answered Oct 07 '09, 7:43 p.m.
JAZZ DEVELOPER
> but after sometime say an * or so.
Not sure what you mean here. Looking at the implementation, it doesn't schedule the task immediately, but only after its configured delay. In your tests, you could try passing in a mock object wrappering your actual task that returns 0 for IScheduledTask.getFixedDelay().

If this isn't working the way you expect, or if you need more control, I suggest filing a work item against Jazz Foundation / Repository.

permanent link
Meghana Pandey (15111514) | answered Oct 08 '09, 10:47 a.m.
After setting the fixed delay property to 0 in config, it worked for me. Thanks.

One more help requested:

Iam trying to fetch the role of an IContributor type.
This is how I get contributor handle :
IContributorHandle[] members = teamArea.getMembers();

But I only see API to get the member's email id, user Id and name.

Please let me know how I should be retrieving role of a member.

Thanks
Meghana

permanent link
Nick Edgar (6.5k711) | answered Oct 08 '09, 11:22 a.m.
JAZZ DEVELOPER
The roles a user has for a given team area is not a property of the contributor, or of the just the team area, since roles can be assigned in parent process areas too.

If you have a team area, and are running server-side, try:

ITeamArea teamArea = ...;
IContributorHandle contributorHandle = ...;
com.ibm.team.process.service.IServerProcess serverProcess = getService(com.ibm.team.process.service.IProcessServerService.class).getServerProcess(teamArea);
com.ibm.team.process.common.IRole[] roles = serverProcess.getContributorRoles(contributorHandle, teamArea);


See also the discussion in http://jazz.net/forums/viewtopic.php?t=3993

Regards,
Nick

permanent link
Meghana Pandey (15111514) | answered Nov 05 '09, 6:43 a.m.
Hi, Iam trying to fetch all the projectArea Handles in the repository using ItemQueryIterator as follows:

IItemType itemType= IProjectArea.ITEM_TYPE;
IDynamicQueryModel model= itemType.getQueryModel();
IItemQuery query= IItemQuery.FACTORY.newInstance((IItemQueryModel) model);
ItemQueryIterator<IProjectAreaHandle> iterator= new ItemQueryIterator<IProjectAreaHandle>(getAuditableCommon(), query);


But while iterating, I have observed, that it does not fetch all the project areas. How can I change my above code, to get all the project area handles.

Thanks and Regards,
Meghana

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.