How to use JUnit to test IOperationParticipant?
Hi,
I'm trying to optimize the tests on my customizations. I read several materials about it: (https://jazz.net/wiki/bin/view/Main/JazzTalkWalkthrough, http://jazz.net/wiki/bin/view/Main/JazzBotWalkthrough, http://jazz.net/forums/viewtopic.php?t=7009&highlight=junit). But I have to admit, I'm still struggling to understand it.
I'd use JUnit before on regular projects and I have a little experience developing bundles for RTC, but I had a cloud of doubt above me.
For example, I'm not quite sure how can I select a project area and create an workitem to test a follow-up action and get the message that would be displayed to the user.
I guess I have to use Plain Java Libraries right?
I start with something like this:
Where I go from here? or more important what I've done is correct so far?
Another doubt, I have to make this as a plugin to extend AbstractRemoteServiceTestCase or a standalone JUnit do the job?
I'm trying to optimize the tests on my customizations. I read several materials about it: (https://jazz.net/wiki/bin/view/Main/JazzTalkWalkthrough, http://jazz.net/wiki/bin/view/Main/JazzBotWalkthrough, http://jazz.net/forums/viewtopic.php?t=7009&highlight=junit). But I have to admit, I'm still struggling to understand it.
I'd use JUnit before on regular projects and I have a little experience developing bundles for RTC, but I had a cloud of doubt above me.
For example, I'm not quite sure how can I select a project area and create an workitem to test a follow-up action and get the message that would be displayed to the user.
I guess I have to use Plain Java Libraries right?
I start with something like this:
private ITeamRepository repo;
private static String REPOSITORY_ADDRESS = System.getProperty("repositoryAddress", "https://rtclocaljazz:9443/jazz");
protected void setUp() throws Exception {
super.setUp();
if (!TeamPlatform.isStarted())
TeamPlatform.startup();
repo = login();
}
protected void tearDown() throws Exception {
repo.logout();
assertFalse(repo.loggedIn());
repo = null;
super.tearDown();
}
private ITeamRepository login() throws TeamRepositoryException {
ITeamRepository repository = TeamPlatform.getTeamRepositoryService().getTeamRepository(REPOSITORY_ADDRESS);
assertFalse(repository.loggedIn());
repository.registerLoginHandler(new ITeamRepository.ILoginHandler() {
public ILoginInfo challenge(ITeamRepository repo) {
return new ILoginInfo() {
public String getUserId() {
return "test";
}
public String getPassword() {
return "test";
}
};
}
});
repository.login(null);
assertTrue(repository.loggedIn());
return repository;
}
Where I go from here? or more important what I've done is correct so far?
Another doubt, I have to make this as a plugin to extend AbstractRemoteServiceTestCase or a standalone JUnit do the job?
One answer
Here are some advises:
1. You will need to use AbstractRemoteServiceTestCase.
2. In the class that implements IOperationParticipant, you can use
IParticipantInfoCollector.createInfo() and IParticipantInfoCollector
addInfo() to create any message.
3. You should have a default project area created for testing. You can do
this in setup method.
4. You should have already had the operation object.
5. In the test method, you should use IServerProcess to execute the
operation and use the report to do the validation.
IServerProcess serverProcess = getService(IProcessInternalServerService.
class).getServerProcess(aProjectArea);
IOperationReport report = serverProcess.adviseAndExecute(operation);
IParticipantReport[] participantReports = report.getParticipantReports();
IParticipantReport myReport = null;
for (int i = 0; i < participantReports.length; i++) {
IParticipantReport participantReport = participantReports;
if
(participantReport.getParticipantIdentifier().equals(TheParticipant.
ID_PARTICIPANT)) {
myReport = participantReport;
break;
}
}
assertNotNull(myReport);
IReportInfo[] infos = testReport.getInfos();
//check the infos
1. You will need to use AbstractRemoteServiceTestCase.
2. In the class that implements IOperationParticipant, you can use
IParticipantInfoCollector.createInfo() and IParticipantInfoCollector
addInfo() to create any message.
3. You should have a default project area created for testing. You can do
this in setup method.
4. You should have already had the operation object.
5. In the test method, you should use IServerProcess to execute the
operation and use the report to do the validation.
IServerProcess serverProcess = getService(IProcessInternalServerService.
class).getServerProcess(aProjectArea);
IOperationReport report = serverProcess.adviseAndExecute(operation);
IParticipantReport[] participantReports = report.getParticipantReports();
IParticipantReport myReport = null;
for (int i = 0; i < participantReports.length; i++) {
IParticipantReport participantReport = participantReports;
if
(participantReport.getParticipantIdentifier().equals(TheParticipant.
ID_PARTICIPANT)) {
myReport = participantReport;
break;
}
}
assertNotNull(myReport);
IReportInfo[] infos = testReport.getInfos();
//check the infos