Search in sources :

Example 26 with Checker

use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.

the class TestSanity method test440ReconcileResourceOpenDj.

@Test
public void test440ReconcileResourceOpenDj() throws Exception {
    final String TEST_NAME = "test440ReconcileResourceOpenDj";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    final OperationResult result = new OperationResult(TestSanity.class.getName() + "." + TEST_NAME);
    // Create LDAP account without an owner. The liveSync is off, so it will not be picked up
    Entry ldifEntry = openDJController.addEntryFromLdifFile(LDIF_ELAINE_FILENAME);
    display("Entry from LDIF", ldifEntry);
    // Guybrush's attributes were set up by a role in the previous test. Let's mess the up a bit. Recon should sort it out.
    List<RawModification> modifications = new ArrayList<RawModification>();
    // Expect that a correct title will be added to this one
    RawModification titleMod = RawModification.create(ModificationType.REPLACE, "title", "Scurvy earthworm");
    modifications.add(titleMod);
    // Expect that the correct location will replace this one
    RawModification lMod = RawModification.create(ModificationType.REPLACE, "l", "Davie Jones' locker");
    modifications.add(lMod);
    // Expect that this will be untouched
    RawModification poMod = RawModification.create(ModificationType.REPLACE, "postOfficeBox", "X marks the spot");
    modifications.add(poMod);
    ModifyOperation modifyOperation = openDJController.getInternalConnection().processModify(USER_GUYBRUSH_LDAP_DN, modifications);
    if (ResultCode.SUCCESS != modifyOperation.getResultCode()) {
        AssertJUnit.fail("LDAP operation failed: " + modifyOperation.getErrorMessage());
    }
    // TODO: setup more "inconsistent" state
    // Add reconciliation task. This will trigger reconciliation
    repoAddObjectFromFile(TASK_OPENDJ_RECON_FILENAME, result);
    // We need to wait for a sync interval, so the task scanner has a chance
    // to pick up this
    // task
    waitFor("Waiting for task to finish first run", new Checker() {

        public boolean check() throws ObjectNotFoundException, SchemaException {
            Task task = taskManager.getTask(TASK_OPENDJ_RECON_OID, result);
            display("Task while waiting for task manager to pick up the task", task);
            // wait until the task is finished
            return task.getLastRunFinishTimestamp() != null;
        }

        @Override
        public void timeout() {
        // No reaction, the test will fail right after return from this
        }
    }, 180000);
    // Check task status
    Task task = taskManager.getTask(TASK_OPENDJ_RECON_OID, result);
    result.computeStatus();
    display("getTask result", result);
    TestUtil.assertSuccess("getTask has failed", result);
    AssertJUnit.assertNotNull(task);
    display("Task after pickup", task);
    PrismObject<TaskType> o = repositoryService.getObject(TaskType.class, TASK_OPENDJ_RECON_OID, null, result);
    display("Task after pickup in the repository", o.asObjectable());
    // .. it should be running
    AssertJUnit.assertEquals(TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
    // .. and claimed
    //        AssertJUnit.assertEquals(TaskExclusivityStatus.CLAIMED, task.getExclusivityStatus());
    // .. and last run should not be zero
    assertNotNull("Null last run start in recon task", task.getLastRunStartTimestamp());
    AssertJUnit.assertFalse("Zero last run start in recon task", task.getLastRunStartTimestamp().longValue() == 0);
    assertNotNull("Null last run finish in recon task", task.getLastRunFinishTimestamp());
    AssertJUnit.assertFalse("Zero last run finish in recon task", task.getLastRunFinishTimestamp().longValue() == 0);
    // The progress should be 0, as there were no changes yet
    // [pm] commented out, as progress in recon task is now determined not only using # of changes
    //AssertJUnit.assertEquals(0, task.getProgress());
    // Test for presence of a result. It should be there and it should
    // indicate success
    OperationResult taskResult = task.getResult();
    AssertJUnit.assertNotNull(taskResult);
    // STOP the task. We don't need it any more and we don't want to give it a chance to run more than once
    taskManager.deleteTask(TASK_OPENDJ_RECON_OID, result);
    // CHECK RESULT: account for user guybrush should be still there and unchanged
    // Check if user object was modified in the repo
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<UserType> uObject = repositoryService.getObject(UserType.class, USER_GUYBRUSH_OID, null, repoResult);
    UserType repoUser = uObject.asObjectable();
    repoResult.computeStatus();
    displayJaxb("User (repository)", repoUser, new QName("user"));
    List<ObjectReferenceType> accountRefs = repoUser.getLinkRef();
    assertEquals("Guybrush has wrong number of accounts", 1, accountRefs.size());
    ObjectReferenceType accountRef = accountRefs.get(0);
    accountShadowOidGuybrushOpendj = accountRef.getOid();
    assertFalse(accountShadowOidGuybrushOpendj.isEmpty());
    // Check if shadow was created in the repo
    repoResult = new OperationResult("getObject");
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidGuybrushOpendj, null, repoResult);
    ShadowType repoShadowType = repoShadow.asObjectable();
    repoResult.computeStatus();
    TestUtil.assertSuccess("getObject has failed", repoResult);
    displayJaxb("Shadow (repository)", repoShadowType, new QName("shadow"));
    assertNotNull(repoShadowType);
    assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());
    accountGuybrushOpendjEntryUuuid = checkRepoShadow(repoShadow);
    // check if account was created in LDAP
    Entry entry = openDJController.searchAndAssertByEntryUuid(accountGuybrushOpendjEntryUuuid);
    display("LDAP account", entry);
    OpenDJController.assertAttribute(entry, "uid", "guybrush");
    OpenDJController.assertAttribute(entry, "givenName", "Guybrush");
    OpenDJController.assertAttribute(entry, "sn", "Threepwood");
    OpenDJController.assertAttribute(entry, "cn", "Guybrush Threepwood");
    OpenDJController.assertAttribute(entry, "displayName", "Guybrush Threepwood");
    // The "l" attribute is assigned indirectly through schemaHandling and
    // config object. It is not tolerant, therefore the other value should be gone now
    OpenDJController.assertAttribute(entry, "l", "Deep in the Caribbean");
    // Set by the role
    OpenDJController.assertAttribute(entry, "employeeType", "sailor");
    // "title" is tolerant, so it will retain the original value as well as the one provided by the role
    OpenDJController.assertAttribute(entry, "title", "Scurvy earthworm", "Honorable Captain");
    OpenDJController.assertAttribute(entry, "carLicense", "C4PT41N");
    OpenDJController.assertAttribute(entry, "businessCategory", "cruise");
    // No setting for "postOfficeBox", so the value should be unchanged
    OpenDJController.assertAttribute(entry, "postOfficeBox", "X marks the spot");
    String guybrushPassword = OpenDJController.getAttributeValue(entry, "userPassword");
    assertNotNull("Pasword was not set on create", guybrushPassword);
    //        QueryType query = QueryUtil.createNameQuery(ELAINE_NAME);
    //        ObjectQuery query = ObjectQuery.createObjectQuery(EqualsFilter.createEqual(UserType.class, prismContext, UserType.F_NAME, ELAINE_NAME));
    ObjectQuery query = ObjectQueryUtil.createNameQuery(ELAINE_NAME, prismContext);
    List<PrismObject<UserType>> users = repositoryService.searchObjects(UserType.class, query, null, repoResult);
    assertEquals("Wrong number of Elaines", 1, users.size());
    repoUser = users.get(0).asObjectable();
    repoResult.computeStatus();
    displayJaxb("User Elaine (repository)", repoUser, new QName("user"));
    assertNotNull(repoUser.getOid());
    assertEquals(PrismTestUtil.createPolyStringType(ELAINE_NAME), repoUser.getName());
    PrismAsserts.assertEqualsPolyString("wrong repo givenName", "Elaine", repoUser.getGivenName());
    PrismAsserts.assertEqualsPolyString("wrong repo familyName", "Marley", repoUser.getFamilyName());
    PrismAsserts.assertEqualsPolyString("wrong repo fullName", "Elaine Marley", repoUser.getFullName());
    accountRefs = repoUser.getLinkRef();
    assertEquals("Elaine has wrong number of accounts", 1, accountRefs.size());
    accountRef = accountRefs.get(0);
    String accountShadowOidElaineOpendj = accountRef.getOid();
    assertFalse(accountShadowOidElaineOpendj.isEmpty());
    // Check if shadow was created in the repo
    repoResult = new OperationResult("getObject");
    repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidElaineOpendj, null, repoResult);
    repoShadowType = repoShadow.asObjectable();
    repoResult.computeStatus();
    TestUtil.assertSuccess("getObject has failed", repoResult);
    displayJaxb("Shadow (repository)", repoShadowType, new QName("shadow"));
    assertNotNull(repoShadowType);
    assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());
    String accountElainehOpendjEntryUuuid = checkRepoShadow(repoShadow);
    // check if account is still in LDAP
    entry = openDJController.searchAndAssertByEntryUuid(accountElainehOpendjEntryUuuid);
    display("LDAP account", entry);
    OpenDJController.assertAttribute(entry, "uid", ELAINE_NAME);
    OpenDJController.assertAttribute(entry, "givenName", "Elaine");
    OpenDJController.assertAttribute(entry, "sn", "Marley");
    OpenDJController.assertAttribute(entry, "cn", "Elaine Marley");
    OpenDJController.assertAttribute(entry, "displayName", "Elaine Marley");
    // The "l" attribute is assigned indirectly through schemaHandling and
    // config object
    // FIXME
    //OpenDJController.assertAttribute(entry, "l", "middle of nowhere");
    // Set by the role
    OpenDJController.assertAttribute(entry, "employeeType", "governor");
    OpenDJController.assertAttribute(entry, "title", "Governor");
    OpenDJController.assertAttribute(entry, "businessCategory", "state");
    String elainePassword = OpenDJController.getAttributeValue(entry, "userPassword");
    assertNotNull("Password of Elaine has disappeared", elainePassword);
    checkAllShadows();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) Checker(com.evolveum.midpoint.test.Checker) ObjectChecker(com.evolveum.midpoint.test.ObjectChecker) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ModifyOperation(org.opends.server.core.ModifyOperation) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 27 with Checker

use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.

the class TestSanity method test400ImportFromResource.

@Test
public void test400ImportFromResource() throws Exception {
    final String TEST_NAME = "test400ImportFromResource";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    checkAllShadows();
    assertNoRepoCache();
    OperationResult result = new OperationResult(TestSanity.class.getName() + "." + TEST_NAME);
    // Make sure Mr. Gibbs has "l" attribute set to the same value as an outbound expression is setting
    ChangeRecordEntry entry = openDJController.executeLdifChange(LDIF_GIBBS_MODIFY_FILE);
    display("Entry from LDIF", entry);
    // Let's add an entry with multiple uids.
    Entry addEntry = openDJController.addEntryFromLdifFile(LDIF_HERMAN_FILENAME);
    display("Entry from LDIF", addEntry);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    TaskType taskType = modelWeb.importFromResource(RESOURCE_OPENDJ_OID, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertNoRepoCache();
    displayJaxb("importFromResource result", taskType.getResult(), SchemaConstants.C_RESULT);
    AssertJUnit.assertEquals("importFromResource has failed", OperationResultStatusType.IN_PROGRESS, taskType.getResult().getStatus());
    // Convert the returned TaskType to a more usable Task
    Task task = taskManager.createTaskInstance(taskType.asPrismObject(), result);
    AssertJUnit.assertNotNull(task);
    assertNotNull(task.getOid());
    AssertJUnit.assertTrue(task.isAsynchronous());
    AssertJUnit.assertEquals(TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
    //        AssertJUnit.assertEquals(TaskExclusivityStatus.CLAIMED, task.getExclusivityStatus());
    display("Import task after launch", task);
    PrismObject<TaskType> tObject = repositoryService.getObject(TaskType.class, task.getOid(), null, result);
    TaskType taskAfter = tObject.asObjectable();
    display("Import task in repo after launch", taskAfter);
    result.computeStatus();
    TestUtil.assertSuccess("getObject has failed", result);
    final String taskOid = task.getOid();
    waitFor("Waiting for import to complete", new Checker() {

        @Override
        public boolean check() throws CommonException {
            Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
            Holder<ObjectType> objectHolder = new Holder<ObjectType>();
            OperationResult opResult = new OperationResult("import check");
            assertNoRepoCache();
            SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
            try {
                modelWeb.getObject(ObjectTypes.TASK.getTypeQName(), taskOid, options, objectHolder, resultHolder);
            } catch (FaultMessage faultMessage) {
                throw new SystemException(faultMessage);
            }
            assertNoRepoCache();
            //				display("getObject result (wait loop)",resultHolder.value);
            TestUtil.assertSuccess("getObject has failed", resultHolder.value);
            Task task = taskManager.createTaskInstance((PrismObject<TaskType>) objectHolder.value.asPrismObject(), opResult);
            System.out.println(new Date() + ": Import task status: " + task.getExecutionStatus() + ", progress: " + task.getProgress());
            if (task.getExecutionStatus() == TaskExecutionStatus.CLOSED) {
                // Task closed, wait finished
                return true;
            }
            //				IntegrationTestTools.display("Task result while waiting: ", task.getResult());
            return false;
        }

        @Override
        public void timeout() {
        // No reaction, the test will fail right after return from this
        }
    }, 180000);
    // wait a second until the task will be definitely saved
    Thread.sleep(1000);
    //### Check task state after the task is finished ###
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    assertNoRepoCache();
    modelWeb.getObject(ObjectTypes.TASK.getTypeQName(), task.getOid(), options, objectHolder, resultHolder);
    assertNoRepoCache();
    TestUtil.assertSuccess("getObject has failed", resultHolder.value);
    task = taskManager.createTaskInstance((PrismObject<TaskType>) objectHolder.value.asPrismObject(), result);
    display("Import task after finish (fetched from model)", task);
    AssertJUnit.assertEquals(TaskExecutionStatus.CLOSED, task.getExecutionStatus());
    assertNotNull("Null lastRunStartTimestamp in " + task, task.getLastRunStartTimestamp());
    assertNotNull("Null lastRunFinishTimestamp in " + task, task.getLastRunFinishTimestamp());
    long importDuration = task.getLastRunFinishTimestamp() - task.getLastRunStartTimestamp();
    double usersPerSec = (task.getProgress() * 1000) / importDuration;
    display("Imported " + task.getProgress() + " users in " + importDuration + " milliseconds (" + usersPerSec + " users/sec)");
    OperationResult taskResult = task.getResult();
    AssertJUnit.assertNotNull("Task has no result", taskResult);
    TestUtil.assertSuccess("Import task result is not success", taskResult);
    AssertJUnit.assertTrue("Task failed", taskResult.isSuccess());
    AssertJUnit.assertTrue("No progress", task.getProgress() > 0);
    //### Check if the import created users and shadows ###
    // Listing of shadows is not supported by the provisioning. So we need
    // to look directly into repository
    List<PrismObject<ShadowType>> sobjects = repositoryService.searchObjects(ShadowType.class, null, null, result);
    result.computeStatus();
    TestUtil.assertSuccess("listObjects has failed", result);
    AssertJUnit.assertFalse("No shadows created", sobjects.isEmpty());
    for (PrismObject<ShadowType> aObject : sobjects) {
        ShadowType shadow = aObject.asObjectable();
        display("Shadow object after import (repo)", shadow);
        // This would be really strange ;-)
        assertNotEmpty("No OID in shadow", shadow.getOid());
        assertNotEmpty("No name in shadow", shadow.getName());
        AssertJUnit.assertNotNull("No objectclass in shadow", shadow.getObjectClass());
        AssertJUnit.assertNotNull("Null attributes in shadow", shadow.getAttributes());
        String resourceOid = shadow.getResourceRef().getOid();
        if (resourceOid.equals(RESOURCE_OPENDJ_OID)) {
            assertAttributeNotNull("No identifier in shadow", shadow, getOpenDjPrimaryIdentifierQName());
        } else {
            assertAttributeNotNull("No UID in shadow", shadow, SchemaConstants.ICFS_UID);
        }
    }
    Holder<ObjectListType> listHolder = new Holder<>();
    assertNoRepoCache();
    modelWeb.searchObjects(ObjectTypes.USER.getTypeQName(), null, null, listHolder, resultHolder);
    assertNoRepoCache();
    ObjectListType uobjects = listHolder.value;
    TestUtil.assertSuccess("listObjects has failed", resultHolder.value);
    AssertJUnit.assertFalse("No users created", uobjects.getObject().isEmpty());
    // TODO: use another account, not guybrush
    display("Users after import " + uobjects.getObject().size());
    for (ObjectType oo : uobjects.getObject()) {
        UserType user = (UserType) oo;
        if (SystemObjectsType.USER_ADMINISTRATOR.value().equals(user.getOid())) {
            //skip administrator check
            continue;
        }
        display("User after import (repo)", user);
        // This would be
        assertNotEmpty("No OID in user", user.getOid());
        // really
        // strange ;-)
        assertNotEmpty("No name in user", user.getName());
        assertNotNull("No fullName in user", user.getFullName());
        assertNotEmpty("No fullName in user", user.getFullName().getOrig());
        assertNotEmpty("No familyName in user", user.getFamilyName().getOrig());
        if (user.getName().getOrig().equals(USER_GUYBRUSH_USERNAME)) {
            // skip the rest of checks for guybrush, he does not have LDAP account now
            continue;
        }
        assertTrue("User " + user.getName() + " is disabled (" + user.getActivation().getAdministrativeStatus() + ")", user.getActivation() == null || user.getActivation().getAdministrativeStatus() == ActivationStatusType.ENABLED);
        List<ObjectReferenceType> accountRefs = user.getLinkRef();
        AssertJUnit.assertEquals("Wrong accountRef for user " + user.getName(), 1, accountRefs.size());
        ObjectReferenceType accountRef = accountRefs.get(0);
        boolean found = false;
        for (PrismObject<ShadowType> aObject : sobjects) {
            ShadowType acc = aObject.asObjectable();
            if (accountRef.getOid().equals(acc.getOid())) {
                found = true;
                break;
            }
        }
        if (!found) {
            AssertJUnit.fail("accountRef does not point to existing account " + accountRef.getOid());
        }
        PrismObject<ShadowType> aObject = modelService.getObject(ShadowType.class, accountRef.getOid(), null, task, result);
        ShadowType account = aObject.asObjectable();
        display("Account after import ", account);
        String attributeValueL = ShadowUtil.getMultiStringAttributeValueAsSingle(account, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "l"));
        //            assertEquals("Unexcpected value of l", "middle of nowhere", attributeValueL);
        assertEquals("Unexcpected value of l", getUserLocality(user), attributeValueL);
    }
    // This also includes "idm" user imported from LDAP. Later we need to ignore that one.
    assertEquals("Wrong number of users after import", 10, uobjects.getObject().size());
    checkAllShadows();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GenericObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) Checker(com.evolveum.midpoint.test.Checker) ObjectChecker(com.evolveum.midpoint.test.ObjectChecker) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) Holder(javax.xml.ws.Holder) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) Date(java.util.Date) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 28 with Checker

use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.

the class TestSanity method test420RecomputeUsers.

@Test
public void test420RecomputeUsers() throws Exception {
    final String TEST_NAME = "test420RecomputeUsers";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    final OperationResult result = new OperationResult(TestSanity.class.getName() + "." + TEST_NAME);
    // Assign role to a user, but we do this using a repository instead of model.
    // The role assignment will not be executed and this created an inconsistent state.
    ObjectDeltaType changeAddRoleCaptain = unmarshallValueFromFile(REQUEST_USER_MODIFY_ADD_ROLE_CAPTAIN_1_FILENAME, ObjectDeltaType.class);
    Collection<? extends ItemDelta> modifications = DeltaConvertor.toModifications(changeAddRoleCaptain.getItemDelta(), getUserDefinition());
    repositoryService.modifyObject(UserType.class, changeAddRoleCaptain.getOid(), modifications, result);
    // TODO: setup more "inconsistent" state
    // Add reconciliation task. This will trigger reconciliation
    importObjectFromFile(TASK_USER_RECOMPUTE_FILENAME, result);
    // We need to wait for a sync interval, so the task scanner has a chance
    // to pick up this
    // task
    waitFor("Waiting for task to finish", new Checker() {

        public boolean check() throws ObjectNotFoundException, SchemaException {
            Task task = taskManager.getTask(TASK_USER_RECOMPUTE_OID, result);
            // wait until the task is finished
            if (TaskExecutionStatus.CLOSED == task.getExecutionStatus()) {
                return true;
            }
            return false;
        }

        @Override
        public void timeout() {
        // No reaction, the test will fail right after return from this
        }
    }, 40000);
    // wait a second until the task will be definitely saved
    Thread.sleep(1000);
    // Check task status
    Task task = taskManager.getTask(TASK_USER_RECOMPUTE_OID, result);
    result.computeStatus();
    display("getTask result", result);
    TestUtil.assertSuccess("getTask has failed", result);
    AssertJUnit.assertNotNull(task);
    display("Task after finish", task);
    AssertJUnit.assertNotNull(task.getTaskIdentifier());
    assertFalse(task.getTaskIdentifier().isEmpty());
    PrismObject<TaskType> o = repositoryService.getObject(TaskType.class, TASK_USER_RECOMPUTE_OID, null, result);
    display("Task after pickup in the repository", o.asObjectable());
    AssertJUnit.assertEquals(TaskExecutionStatus.CLOSED, task.getExecutionStatus());
    // .. and last run should not be zero
    assertNotNull(task.getLastRunStartTimestamp());
    AssertJUnit.assertFalse(task.getLastRunStartTimestamp().longValue() == 0);
    assertNotNull(task.getLastRunFinishTimestamp());
    AssertJUnit.assertFalse(task.getLastRunFinishTimestamp().longValue() == 0);
    AssertJUnit.assertEquals(10, task.getProgress());
    // Test for presence of a result. It should be there and it should
    // indicate success
    OperationResult taskResult = task.getResult();
    display("Recompute task result", taskResult);
    AssertJUnit.assertNotNull(taskResult);
    TestUtil.assertSuccess("Recompute task result", taskResult);
    // STOP the task. We don't need it any more and we don't want to give it a chance to run more than once
    taskManager.deleteTask(TASK_USER_RECOMPUTE_OID, result);
    // CHECK RESULT: account created for user guybrush
    // Check if user object was modified in the repo
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<UserType> object = repositoryService.getObject(UserType.class, USER_GUYBRUSH_OID, null, repoResult);
    UserType repoUser = object.asObjectable();
    repoResult.computeStatus();
    displayJaxb("User (repository)", repoUser, new QName("user"));
    List<ObjectReferenceType> accountRefs = repoUser.getLinkRef();
    assertEquals("Wrong number of accountRefs after recompute for user " + repoUser.getName(), 1, accountRefs.size());
    ObjectReferenceType accountRef = accountRefs.get(0);
    accountShadowOidGuybrushOpendj = accountRef.getOid();
    assertFalse(accountShadowOidGuybrushOpendj.isEmpty());
    // Check if shadow was created in the repo
    repoResult = new OperationResult("getObject");
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidGuybrushOpendj, null, repoResult);
    ShadowType repoShadowType = repoShadow.asObjectable();
    repoResult.computeStatus();
    TestUtil.assertSuccess("getObject has failed", repoResult);
    displayJaxb("Shadow (repository)", repoShadowType, new QName("shadow"));
    assertNotNull(repoShadowType);
    assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());
    accountGuybrushOpendjEntryUuuid = checkRepoShadow(repoShadow);
    // check if account was created in LDAP
    Entry entry = openDJController.searchAndAssertByEntryUuid(accountGuybrushOpendjEntryUuuid);
    display("LDAP account", entry);
    OpenDJController.assertAttribute(entry, "uid", "guybrush");
    OpenDJController.assertAttribute(entry, "givenName", "Guybrush");
    OpenDJController.assertAttribute(entry, "sn", "Threepwood");
    OpenDJController.assertAttribute(entry, "cn", "Guybrush Threepwood");
    OpenDJController.assertAttribute(entry, "displayName", "Guybrush Threepwood");
    // The "l" attribute is assigned indirectly through schemaHandling and
    // config object
    OpenDJController.assertAttribute(entry, "l", "Deep in the Caribbean");
    // Set by the role
    OpenDJController.assertAttribute(entry, "employeeType", "sailor");
    OpenDJController.assertAttribute(entry, "title", "Honorable Captain");
    OpenDJController.assertAttribute(entry, "carLicense", "C4PT41N");
    OpenDJController.assertAttribute(entry, "businessCategory", "cruise");
    String guybrushPassword = OpenDJController.getAttributeValue(entry, "userPassword");
    assertNotNull("Pasword was not set on create", guybrushPassword);
    checkAllShadows();
}
Also used : Checker(com.evolveum.midpoint.test.Checker) ObjectChecker(com.evolveum.midpoint.test.ObjectChecker) Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 29 with Checker

use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.

the class TestSanity method test999Shutdown.

@Test
public void test999Shutdown() throws Exception {
    taskManager.shutdown();
    waitFor("waiting for task manager shutdown", new Checker() {

        @Override
        public boolean check() throws CommonException {
            try {
                return taskManager.getLocallyRunningTasks(new OperationResult("dummy")).isEmpty();
            } catch (TaskManagerException e) {
                throw new SystemException(e);
            }
        }

        @Override
        public void timeout() {
        // No reaction, the test will fail right after return from this
        }
    }, 10000);
    AssertJUnit.assertEquals("Some tasks left running after shutdown", new HashSet<Task>(), taskManager.getLocallyRunningTasks(new OperationResult("dummy")));
}
Also used : Checker(com.evolveum.midpoint.test.Checker) ObjectChecker(com.evolveum.midpoint.test.ObjectChecker) Task(com.evolveum.midpoint.task.api.Task) TaskManagerException(com.evolveum.midpoint.task.api.TaskManagerException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 30 with Checker

use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.

the class AbstractWfTestLegacy method waitForTaskClose.

protected void waitForTaskClose(final Task task, final int timeout) throws Exception {
    final OperationResult waitResult = new OperationResult(AbstractIntegrationTest.class + ".waitForTaskClose");
    Checker checker = new Checker() {

        @Override
        public boolean check() throws CommonException {
            task.refresh(waitResult);
            OperationResult result = task.getResult();
            if (verbose)
                display("Check result", result);
            return task.getExecutionStatus() == TaskExecutionStatus.CLOSED;
        }

        @Override
        public void timeout() {
            try {
                task.refresh(waitResult);
            } catch (ObjectNotFoundException e) {
                LOGGER.error("Exception during task refresh: {}", e, e);
            } catch (SchemaException e) {
                LOGGER.error("Exception during task refresh: {}", e, e);
            }
            OperationResult result = task.getResult();
            LOGGER.debug("Result of timed-out task:\n{}", result.debugDump());
            assert false : "Timeout (" + timeout + ") while waiting for " + task + " to finish. Last result " + result;
        }
    };
    IntegrationTestTools.waitFor("Waiting for " + task + " finish", checker, timeout, 1000);
}
Also used : AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Checker(com.evolveum.midpoint.test.Checker) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)35 Checker (com.evolveum.midpoint.test.Checker)35 Test (org.testng.annotations.Test)27 Task (com.evolveum.midpoint.task.api.Task)15 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)11 ObjectChecker (com.evolveum.midpoint.test.ObjectChecker)10 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)8 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)8 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)7 QName (javax.xml.namespace.QName)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)6 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 ChangeRecordEntry (org.opends.server.util.ChangeRecordEntry)6 TaskManagerException (com.evolveum.midpoint.task.api.TaskManagerException)3 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 ObjectListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType)2 GenericObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType)2