Package org.apache.syncope.client.to

Examples of org.apache.syncope.client.to.SyncTaskTO


        assertFalse(actions.isEmpty());
    }

    @Test
    public void create() {
        SyncTaskTO task = new SyncTaskTO();
        task.setResource("ws-target-resource-2");

        UserTO template = new UserTO();
        template.addResource("ws-target-resource-2");
        MembershipTO membershipTO = new MembershipTO();
        membershipTO.setRoleId(8L);
        template.addMembership(membershipTO);
        task.setUserTemplate(template);

        SyncTaskTO actual = restTemplate.postForObject(BASE_URL + "task/create/sync", task, SyncTaskTO.class);
        assertNotNull(actual);

        task = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, actual.getId());
        assertNotNull(task);
        assertEquals(actual.getId(), task.getId());
        assertEquals(actual.getJobClassName(), task.getJobClassName());
    }
View Full Code Here


        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);
View Full Code Here

    }

    @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);
View Full Code Here

        assertNotNull(execution.getTask());
    }

    @Test
    public void dryRun() {
        SyncTaskTO taskTO = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, 4L);

        assertNotNull(taskTO);
        assertNotNull(taskTO.getExecutions());

        int preDryRunSize = taskTO.getExecutions().size();

        TaskExecTO execution = restTemplate.postForObject(BASE_URL + "task/execute/{taskId}?dryRun=true", null,
                TaskExecTO.class, 4);
        assertNotNull(execution);

        // 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());

        } while (preDryRunSize == taskTO.getExecutions().size());

        assertEquals("SUCCESS", taskTO.getExecutions().get(0).getStatus());
    }
View Full Code Here

        template.addResource("ws-target-resource-nopropagation4");
        //-----------------------------

        // Update sync task
        SyncTaskTO task = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, 9);
        assertNotNull(task);

        task.setUserTemplate(template);

        SyncTaskTO actual = restTemplate.postForObject(BASE_URL + "task/update/sync", task, SyncTaskTO.class);
        assertNotNull(actual);
        assertEquals(task.getId(), actual.getId());
        assertFalse(actual.getUserTemplate().getResources().isEmpty());
        assertFalse(actual.getUserTemplate().getMemberships().isEmpty());

        // read executions before sync (dryrun test could be executed before)
        int preSyncSize = actual.getExecutions().size();

        TaskExecTO execution =
                restTemplate.postForObject(BASE_URL + "task/execute/{taskId}", null, TaskExecTO.class, actual.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) {
            }

            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());

        final String status = actual.getExecutions().get(0).getStatus();
        assertNotNull(status);
        assertTrue(PropagationTaskExecStatus.valueOf(status).isSuccessful());

        userTO = restTemplate.getForObject(BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "testuser2");
        assertNotNull(userTO);
View Full Code Here

    }

    @Test
    public void issueSYNCOPE230() {
        // 1. read SyncTask for resource-db-sync (table TESTSYNC on external H2)
        SyncTaskTO task = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, 10);
        assertNotNull(task);

        int preSyncSize = task.getExecutions().size();

        // 2. execute the SyncTask for the first time
        TaskExecTO execution = restTemplate.postForObject(BASE_URL + "task/execute/{taskId}", null, TaskExecTO.class,
                task.getId());
        assertEquals("JOB_FIRED", execution.getStatus());

        int i = 0;
        final int maxit = 20;
        do {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }

            task = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, task.getId());

            assertNotNull(task);
            assertNotNull(task.getExecutions());

            i++;
        } while (preSyncSize == task.getExecutions().size() && i < maxit);
        assertEquals(1, task.getExecutions().size());

        // 3. read e-mail address for user created by the SyncTask first execution
        UserTO userTO = restTemplate.getForObject(
                BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "issuesyncope230");
        assertNotNull(userTO);
        String email = userTO.getAttributeMap().get("email").getValues().iterator().next();
        assertNotNull(email);

        // 4. update TESTSYNC on external H2 by changing e-mail address
        JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
        jdbcTemplate.execute("UPDATE TESTSYNC SET email='updatedSYNCOPE230@syncope.apache.org'");

        // 5. re-execute the SyncTask
        execution = restTemplate.postForObject(BASE_URL + "task/execute/{taskId}", null, TaskExecTO.class,
                task.getId());
        assertEquals("JOB_FIRED", execution.getStatus());

        preSyncSize = task.getExecutions().size();
        i = 0;
        do {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }

            task = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, task.getId());

            assertNotNull(task);
            assertNotNull(task.getExecutions());

            i++;
        } while (preSyncSize == task.getExecutions().size() && i < maxit);
        assertEquals(2, task.getExecutions().size());

        // 6. verify that the e-mail was updated
        userTO = restTemplate.getForObject(
                BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "issuesyncope230");
        assertNotNull(userTO);
View Full Code Here

        assertNotNull(userTO);
        assertEquals(1, userTO.getPropagationTOs().size());
        assertTrue(userTO.getPropagationTOs().get(0).getStatus().isSuccessful());

        // Update sync task
        SyncTaskTO task = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, 7);
        task.setFullReconciliation(true);
        assertNotNull(task);

        //  add user template
        UserTO template = new UserTO();

        AttributeTO attrTO = new AttributeTO();
        attrTO.setSchema("firstname");
        attrTO.setValues(Collections.singletonList(""));
        template.addAttribute(attrTO);

        attrTO = new AttributeTO();
        attrTO.setSchema("userId");
        attrTO.addValue("'test'");
        template.addAttribute(attrTO);

        attrTO = new AttributeTO();
        attrTO.setSchema("'fullname");
        attrTO.addValue("'test'");
        template.addAttribute(attrTO);

        attrTO = new AttributeTO();
        attrTO.setSchema("surname");
        attrTO.addValue("'test'");
        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();

        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());

        final String status = actual.getExecutions().get(preSyncSize).getStatus();
        assertNotNull(status);
        assertTrue(PropagationTaskExecStatus.valueOf(status).isSuccessful());

        final UserTO updateTO =
                restTemplate.getForObject(BASE_URL
View Full Code Here

        userTO = restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class, userTO.getId());
        assertEquals("virtualvalue", userTO.getVirtualAttributeMap().get("virtualdata").getValues().get(0));

        // Update sync task
        SyncTaskTO task = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, 11);
        assertNotNull(task);

        //  add user template
        UserTO template = new UserTO();
        template.addResource("resource-db-virattr");

        task.setUserTemplate(template);

        SyncTaskTO taskTO = restTemplate.postForObject(BASE_URL + "task/update/sync", task, SyncTaskTO.class);
        assertEquals(task.getId(), taskTO.getId());

        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());
        assertEquals("virtualvalue", userTO.getVirtualAttributeMap().get("virtualdata").getValues().get(0));
View Full Code Here

            case SYNC:
                if (!(taskTO instanceof SyncTaskTO)) {
                    throw new ClassCastException("taskUtil is type SyncTask but taskTO is not SyncTaskTO: " + taskTO.
                            getClass().getName());
                }
                SyncTaskTO syncTaskTO = (SyncTaskTO) taskTO;

                ExternalResource resource = resourceDAO.find(syncTaskTO.getResource());
                if (resource == null) {
                    throw new NotFoundException("Resource " + syncTaskTO.getResource());
                }
                ((SyncTask) task).setResource(resource);

                fill((SyncTask) task, syncTaskTO);
                break;
View Full Code Here

        assertFalse(actions.isEmpty());
    }

    @Test
    public void create() {
        SyncTaskTO task = new SyncTaskTO();
        task.setResource("ws-target-resource-2");

        UserTO template = new UserTO();
        template.addResource("ws-target-resource-2");
        MembershipTO membershipTO = new MembershipTO();
        membershipTO.setRoleId(8L);
        template.addMembership(membershipTO);
        task.setUserTemplate(template);

        SyncTaskTO actual = restTemplate.postForObject(BASE_URL + "task/create/sync", task, SyncTaskTO.class);
        assertNotNull(actual);

        task = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class, actual.getId());
        assertNotNull(task);
        assertEquals(actual.getId(), task.getId());
        assertEquals(actual.getJobClassName(), task.getJobClassName());
    }
View Full Code Here

TOP

Related Classes of org.apache.syncope.client.to.SyncTaskTO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.