}
@Test
public void reconcile() {
// update sync task
SyncTaskTO task = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, 7);
assertNotNull(task);
// add user template
UserTO template = new UserTO();
AttributeTO attrTO = new AttributeTO();
attrTO.setSchema("type");
attrTO.addValue("'type a'");
template.addAttribute(attrTO);
attrTO = new AttributeTO();
attrTO.setSchema("userId");
attrTO.addValue("'reconciled@syncope.apache.org'");
template.addAttribute(attrTO);
attrTO = new AttributeTO();
attrTO.setSchema("fullname");
attrTO.addValue("'reconciled fullname'");
template.addAttribute(attrTO);
attrTO = new AttributeTO();
attrTO.setSchema("surname");
attrTO.addValue("'surname'");
template.addAttribute(attrTO);
task.setUserTemplate(template);
SyncTaskTO actual = restTemplate.postForObject(BASE_URL + "task/update/sync", task, SyncTaskTO.class);
assertNotNull(actual);
assertEquals(task.getId(), actual.getId());
// read executions before sync (dryrun test could be executed before)
int preSyncSize = actual.getExecutions().size();
// trigger SyncTask execution
TaskExecTO execution = restTemplate.postForObject(BASE_URL + "task/execute/{taskId}", null, TaskExecTO.class,
actual.getId());
assertEquals("JOB_FIRED", execution.getStatus());
// wait for sync completion (executions incremented)
int i = 0;
final int maxit = 20;
do {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
actual = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, actual.getId());
assertNotNull(actual);
assertNotNull(actual.getExecutions());
i++;
} while (preSyncSize == actual.getExecutions().size() && i < maxit);
assertEquals(preSyncSize + 1, actual.getExecutions().size());
String status = actual.getExecutions().get(0).getStatus();
assertNotNull(status);
assertTrue(PropagationTaskExecStatus.valueOf(status).isSuccessful());
UserTO userTO =
restTemplate.getForObject(BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "testuser1");
assertNotNull(userTO);
assertEquals("reconciled@syncope.apache.org", userTO.getAttributeMap().get("userId").getValues().get(0));
assertEquals("suspended", userTO.getStatus());
// enable user on external resource
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
jdbcTemplate.execute("UPDATE TEST SET STATUS=TRUE");
// re-execute the same SyncTask: now user must be active
preSyncSize = actual.getExecutions().size();
execution = restTemplate.postForObject(BASE_URL + "task/execute/{taskId}", null, TaskExecTO.class,
actual.getId());
assertEquals("JOB_FIRED", execution.getStatus());
// wait for sync completion (executions incremented)
i = 0;
do {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
actual = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, actual.getId());
assertNotNull(actual);
assertNotNull(actual.getExecutions());
i++;
} while (preSyncSize == actual.getExecutions().size() && i < maxit);
assertEquals(preSyncSize + 1, actual.getExecutions().size());
status = actual.getExecutions().get(0).getStatus();
assertNotNull(status);
assertTrue(PropagationTaskExecStatus.valueOf(status).isSuccessful());
userTO = restTemplate.getForObject(BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "testuser1");
assertNotNull(userTO);