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 Nov 09 '09, 10:25 a.m.
JAZZ DEVELOPER
Sorry for the delay. I would expect that to work. Maybe it's getting confused by the use of a dynamic query model, but I believe the dynamic approach should work fine.

You could try instead using the static query model:

IQueryModel model = com.ibm.team.process.internal.common.query.BaseProjectAreaQueryModel.ProjectAreaQueryModel;
...


I realize this is referring to an internal class, but I don't see any other way of doing it. This approach is used in the Process component's own code, in:
com.ibm.team.process.internal.service.web.ProcessRestService.getProjectAreas()
and
com.ibm.team.process.internal.client.ProcessClientService.findAllProjectAreas(Collection, IProgressMonitor)

Regards,
Nick

permanent link
Meghana Pandey (15111514) | answered Nov 13 '09, 3:41 a.m.
Hi,

Thanks for your reply and after using the static query model it worked for me.

I have another query related to scheduled tasks:

The current implementation of my task fetches all the workitems belonging to all the project areas(except archived) in the repo and sends reminder mail to the owners ,if the workitems are still in LIVE state even post their due dates.

Wanted to know, if there was a way to turn this task, on/off on the server proprieties.
Or any other way by which one can subscribe or unsubscribe with this task.

Thanks & Regards,
Meghana

permanent link
Nick Edgar (6.5k711) | answered Nov 17 '09, 2:41 p.m.
JAZZ DEVELOPER
There are lots of options here:
- a global property for the service that an admin could tweak via the admin web UI, similar to the property for how often the task runs,
- per-project configuration data settings, similar to how one can configure work item types and their presentation,
- per-user settings, with contributed UI in the user editor, similar to how work item email notifications work

Let me know which one you want to explore, and I can give you some pointers.

permanent link
Meghana Pandey (15111514) | answered Nov 19 '09, 12:53 p.m.
Hi,
Thanks for your reply.
We would like to implement all the three ways you mentioned . So plz provide me some pointers on these to start off.
But most importantly and urgently, I need to know how to set the global property for the service that an admin could change via the admin web UI.

Thanks & Regards
Meghana

permanent link
Nick Edgar (6.5k711) | answered Nov 19 '09, 2:47 p.m.
JAZZ DEVELOPER
For the global property option, any service may define configuration properties. For example, the Build scheduler task is declared as:

<extension
point="com.ibm.team.repository.service.asynchronousTask">
<asynchronousTask
taskId="BuildSchedulerTask">
<extensionService
componentId="com.ibm.team.build"
implementationClass="com.ibm.team.build.internal.service.schedule.BuildSchedulerTask">
<prerequisites>
<requiredService interface="com.ibm.team.build.internal.service.IInternalTeamBuildService"/>
<configurationProperties>
<configurationProperty
accessPolicy="OPEN"
description="%BuildSchedulerTask.FixedDelay.Description"
displayableName="%BuildSchedulerTask.FixedDelay.DisplayName"
name="BuildSchedulerTask.fixedDelay"
type="LONG"
default="60"
required="true"
updatePolicy="FRAMEWORK_RESTART_REQUIRED">
</configurationProperty>
...
</configurationProperties>
</prerequisites>
</extensionService>
</asynchronousTask>
</extension>


In this case, the property name (<taskId>.fixedDelay) is one that's specially recognized for all such tasks, but that doesn't really matter -- you may define as many properties as you like.

These are editable in the admin web UI:
- go to <repo address>/admin
- click on 'Advanced Properties' in the bar at left

permanent link
Nick Edgar (6.5k711) | answered Nov 19 '09, 3:11 p.m.
JAZZ DEVELOPER
The service can obtain the value of the property with the following methods on itself (they're protected methods defined in AbstractService):
getConfigurationProperty(String propertyId)
getBooleanConfigProperty...
getLongConfigProperty...
getIntegerConfigProperty...
getStringConfigProperty

The method used should correspond to the type declared in the extension.

permanent link
Nick Edgar (6.5k711) | answered Nov 19 '09, 3:38 p.m.
JAZZ DEVELOPER
For the approach of using per-project configuration data (i.e. configured in the project area editor's Process Specification tab), see the Configuration Data sections at: https://jazz.net/wiki/bin/view/Main/TeamProcessDeveloperGuide

UI for editing such configuration can also be contributed. See https://jazz.net/wiki/bin/view/Main/ProcessAspectEditorCreation

For per-user configuration, you can look at how the Work Items component contributes the Mail Configuration tab in the user editor. To see this, choose Open My User Editor on the repository connection node in the Team Artifacts view. There's an extension for this:

<extension
point="com.ibm.team.process.ide.ui.internalContributorEditorPages">
<editorPages
factoryClass="com.ibm.team.workitem.ide.ui.internal.mailconfig.MailConfigEditorPageFactory">
</editorPages>
</extension>


But apparently this uses an extension point that's intended to be internal to RTC. You could use it, but there's no guarantee that it won't change or go away.

To store the extra info, it uses string extensions on the IContributorDetails item for a given IContributor. For more details, see the implementation of:
com.ibm.team.workitem.ide.ui.internal.mailconfig.MailConfigEditorInput.loadContributorDetails(IProgressMonitor)
and
com.ibm.team.workitem.ide.ui.internal.mailconfig.MailConfigFormPage.loadConfiguration().

permanent link
Meghana Pandey (15111514) | answered Nov 25 '09, 8:15 a.m.
Hi,

Thanks a lot again.
I was able to add the global property and am trying to implement it at project area level. :)

For now, Iam facing some other issue related to creation(contribution) of a new link type.

Here is the snippet from plugin.xml (of a common plug in)to contribute a new linktype:

<extension

point="com.ibm.team.repository.common.linkTypes">
<linkType
constrained="false"
id="com.ibm.af.workitem.link.common.continuationLinkType2"
internal="false">
<target>
<endpoint
displayName="Continues By"
id="af.continues.by"
multiplicity="0..n">
<itemReferenceType
itemTypeName="WorkItem"
packageURI="com.ibm.team.workitem">
</itemReferenceType></endpoint>
</target>
<source>
<endpoint
displayName="Continues"
id="af.continues"
multiplicity="0..n">
<itemReferenceType
itemTypeName="WorkItem"
packageURI="com.ibm.team.workitem">
</itemReferenceType></endpoint>
</source>
</linkType>
</extension>


Now after installing this on the server, when I go to the workitem editor, and hit the add link button on the Links page, I don't see this new link type there? Now my question is, is there something I have missed here?

Also, from my REST service, this is how I try to create a new link of this new type as follows :

IWorkItemCommon workItemCommon = getService(IWorkItemCommon.class);


ILinkServiceLibrary linkService = getLinkServiceLibrary();

IItemReference source = IReferenceFactory.INSTANCE
.createReferenceToItem(sourceHandle);
IItemReference target = IReferenceFactory.INSTANCE
.createReferenceToItem(targetHandle);

ILink link = linkService.createLink(type, source, target);


private ILinkServiceLibrary getLinkServiceLibrary() {
return (ILinkServiceLibrary) getService(ILinkService.class).getServiceLibrary(ILinkServiceLibrary.class);
}


and saved the workitem, I couldnot see any new link created nor is there any exception thrown.

Can you please guide me what went wrong or is there a better way to create
this new link from the server side.

Thanks & Regards,
Meghana

permanent link
Nick Edgar (6.5k711) | answered Nov 25 '09, 11:32 a.m.
JAZZ DEVELOPER
This all looks OK to me. You could try tracing through how the Add menu is populated in com.ibm.team.workitem.ide.ui.internal.editor.part.LinksPart.AddLinkDropDown.getMenu(Control)

permanent link
Zachary K (19354339) | answered Jan 25 '10, 9:15 p.m.
Hi,
I'm trying to do something similar. I can contribute a menu for a new link type in the workitem UI but I don't know where I should add the code to invoke a service to create a new link of this new type. I've created a new plugin for my REST service but where should I invoke it without changing the RTC workitem.common and workitem.service plugins?
Also is it possible to invoke one's own UI when selecting the menu to create the new link type.
If you could share some of your discoveries that would be very helpful.
Thanks in advance.

Zac.

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.