@Test
public void saveSyncTask() {
ExternalResource resource = resourceDAO.find("ws-target-resource-1");
assertNotNull(resource);
SyncTask task = new SyncTask();
task.setName("saveSyncTask");
task.setDescription("SyncTask description");
task.setUserTemplate(new UserTO());
task.setCronExpression("BLA BLA");
task.setMatchingRule(MatchingRule.UPDATE);
task.setUnmatchingRule(UnmatchingRule.PROVISION);
// this save() fails because of an invalid Cron Expression
InvalidEntityException exception = null;
try {
taskDAO.save(task);
} catch (InvalidEntityException e) {
exception = e;
}
assertNotNull(exception);
task.setCronExpression(null);
// this save() fails because a SyncTask requires a target resource
exception = null;
try {
taskDAO.save(task);
} catch (InvalidEntityException e) {
exception = e;
}
assertNotNull(exception);
task.setResource(resource);
task.getActionsClassNames().add(getClass().getName());
// this save() fails because jobActionsClassName does not implement
// the right interface
exception = null;
try {
taskDAO.save(task);
} catch (InvalidEntityException e) {
exception = e;
}
assertNotNull(exception);
task.getActionsClassNames().clear();
task.getActionsClassNames().add(TestSyncActions.class.getName());
// this save() finally works
task = taskDAO.save(task);
assertNotNull(task);
SyncTask actual = taskDAO.find(task.getId());
assertEquals(task, actual);
}