Integer usersPre = restTemplate.getForObject(BASE_URL + "user/count.json", Integer.class);
assertNotNull(usersPre);
// Update sync task
SyncTaskTO task = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, 4);
assertNotNull(task);
// add custom SyncJob actions
task.setJobActionsClassName(TestSyncJobActions.class.getName());
// add user template
UserTO template = new UserTO();
AttributeTO attrTO = new AttributeTO();
attrTO.setSchema("type");
attrTO.addValue("email == 'test8@syncope.apache.org'? 'TYPE_8': 'TYPE_OTHER'");
template.addAttribute(attrTO);
attrTO = new AttributeTO();
attrTO.setSchema("cn");
template.addDerivedAttribute(attrTO);
template.addResource("resource-testdb");
MembershipTO membershipTO = new MembershipTO();
membershipTO.setRoleId(8L);
AttributeTO membershipAttr = new AttributeTO();
membershipAttr.setSchema("subscriptionDate");
membershipAttr.addValue("'2009-08-18T16:33:12.203+0200'");
membershipTO.addAttribute(membershipAttr);
template.addMembership(membershipTO);
task.setUserTemplate(template);
SyncTaskTO actual = restTemplate.postForObject(BASE_URL + "task/update/sync", task, SyncTaskTO.class);
assertNotNull(actual);
assertEquals(task.getId(), actual.getId());
assertEquals(TestSyncJobActions.class.getName(), actual.getJobActionsClassName());
SyncTaskTO taskTO = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, 4L);
assertNotNull(taskTO);
assertNotNull(taskTO.getExecutions());
// read executions before sync (dryrun test could be executed before)
int preSyncSize = taskTO.getExecutions().size();
TaskExecTO execution = restTemplate.postForObject(BASE_URL + "task/execute/{taskId}", null, TaskExecTO.class,
taskTO.getId());
assertEquals("JOB_FIRED", execution.getStatus());
int i = 0;
int maxit = 50;
// wait for sync completion (executions incremented)
do {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
taskTO = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, taskTO.getId());
assertNotNull(taskTO);
assertNotNull(taskTO.getExecutions());
i++;
} while (preSyncSize == taskTO.getExecutions().size() && i < maxit);
// check for sync policy
userTO = restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class, userTO.getId());
assertNotNull(userTO);