Search in sources :

Example 31 with DummyAccount

use of com.evolveum.icf.dummy.resource.DummyAccount in project midpoint by Evolveum.

the class ShadowAttributeIdSyncStoreReadTest method initSystem.

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
    super.initSystem(initTask, initResult);
    dummy = initDummyResource("id", RESOURCE_DUMMY_FILE, RESOURCE_ID, controller -> {
        controller.extendSchemaPirate();
        DummyObjectClass accountClazz = controller.getDummyResource().getAccountObjectClass();
        accountClazz.addAttributeDefinition("familyName");
        accountClazz.addAttributeDefinition("id");
    }, initTask, initResult);
    DummyAccount testAccount = dummy.addAccount("idTest");
    // testAccount.setId(SHADOW_ID);
    // testAccount.addAttributeValue("oid", SHADOW_ID);
    testAccount.setEnabled(true);
    testAccount.addAttributeValue("id", SHADOW_ID);
    testAccount.addAttributeValue("familyName", "Snow");
    List<PrismObject<ShadowType>> shadows = repositoryService.searchObjects(ShadowType.class, null, null, initResult);
    for (PrismObject<ShadowType> shadow : shadows) {
        repositoryService.deleteObject(ShadowType.class, shadow.getOid(), initResult);
    }
// repoAddObjectFromFile(SHADOW_3_FILE, initResult);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) MidPointTestConstants(com.evolveum.midpoint.test.util.MidPointTestConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) DummyResourceContoller(com.evolveum.midpoint.test.DummyResourceContoller) SerializationOptions(com.evolveum.midpoint.prism.SerializationOptions) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ClassMode(org.springframework.test.annotation.DirtiesContext.ClassMode) Collection(java.util.Collection) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) DummyObjectClass(com.evolveum.icf.dummy.resource.DummyObjectClass) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest) List(java.util.List) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ContextConfiguration(org.springframework.test.context.ContextConfiguration) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) QName(javax.xml.namespace.QName) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) NotNull(org.jetbrains.annotations.NotNull) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) DummyObjectClass(com.evolveum.icf.dummy.resource.DummyObjectClass) PrismObject(com.evolveum.midpoint.prism.PrismObject) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount)

Example 32 with DummyAccount

use of com.evolveum.icf.dummy.resource.DummyAccount in project midpoint by Evolveum.

the class TestModelServiceContract method test190ModifyUserJackAssignAccountAndModify.

/**
 * We try to both assign an account and modify that account in one operation.
 * Some changes should be reflected to account (e.g.  weapon) as the mapping is weak,
 * other should be overridden (e.g. fullname) as the mapping is strong.
 */
@Test
public void test190ModifyUserJackAssignAccountAndModify() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    preTestCleanup(AssignmentPolicyEnforcementType.FULL);
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
    ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_JACK_OID, RESOURCE_DUMMY_OID, null, true);
    ShadowCoordinatesQualifiedObjectDelta<ShadowType> accountDelta = RefineryObjectFactory.createShadowDiscriminatorModificationReplaceProperty(ShadowType.class, RESOURCE_DUMMY_OID, ShadowKindType.ACCOUNT, null, dummyResourceCtl.getAttributeFullnamePath(), prismContext, "Cpt. Jack Sparrow");
    accountDelta.addModificationAddProperty(dummyResourceCtl.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME), "smell");
    deltas.add(accountDelta);
    deltas.add(accountAssignmentUserDelta);
    XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();
    when();
    executeChanges(deltas, null, task, result);
    then();
    assertSuccess(result);
    XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
    assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    display("User after change execution", userJack);
    assertUserJack(userJack, "Jack Sparrow");
    accountJackOid = getSingleLinkOid(userJack);
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, SelectorOptions.createCollection(GetOperationOptions.createRaw()), result);
    assertDummyAccountShadowRepo(accountShadow, accountJackOid, USER_JACK_USERNAME);
    assertEnableTimestampShadow(accountShadow, startTime, endTime);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
    assertDummyAccountShadowModel(accountModel, accountJackOid, USER_JACK_USERNAME, "Cpt. Jack Sparrow");
    assertEnableTimestampShadow(accountModel, startTime, endTime);
    // Check account in dummy resource
    assertDefaultDummyAccount(USER_JACK_USERNAME, "Cpt. Jack Sparrow", true);
    DummyAccount dummyAccount = getDummyAccount(null, USER_JACK_USERNAME);
    assertDummyAccountAttribute(null, USER_JACK_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "smell");
    assertNull("Unexpected loot", dummyAccount.getAttributeValue("loot", Integer.class));
    assertDummyScriptsAdd(userJack, accountModel, getDummyResourceType());
    // Check audit
    displayDumpable("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(3);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
    dummyAuditService.assertTarget(USER_JACK_OID);
    dummyAuditService.assertExecutionSuccess();
    // Check notifications
    notificationManager.setDisabled(true);
    checkDummyTransportMessages(NOTIFIER_ACCOUNT_PASSWORD_NAME, 1);
    checkDummyTransportMessages("userPasswordNotifier", 0);
    checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 1);
    checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
    checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 1);
    checkDummyTransportMessages("simpleAccountNotifier-DELETE-SUCCESS", 0);
    checkDummyTransportMessages("simpleUserNotifier", 1);
    checkDummyTransportMessages("simpleUserNotifier-ADD", 0);
    assertCounterIncrement(InternalCounters.SCRIPT_COMPILE_COUNT, 0);
    assertSteadyResources();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Example 33 with DummyAccount

use of com.evolveum.icf.dummy.resource.DummyAccount in project midpoint by Evolveum.

the class TestPreviewChanges method test240GuybrushAssignAccountDummyRelative.

/**
 * Make sure that Guybrush has an existing account and that it is properly populated.
 * We will use this setup in following tests.
 */
@Test
public void test240GuybrushAssignAccountDummyRelative() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
    // WHEN
    when();
    assignAccountToUser(USER_GUYBRUSH_OID, RESOURCE_DUMMY_RELATIVE_OID, null, task, result);
    // THEN
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    DummyAccount dummyAccount = assertDummyAccount(RESOURCE_DUMMY_RELATIVE_NAME, USER_GUYBRUSH_USERNAME, USER_GUYBRUSH_FULL_NAME, true);
    displayDumpable("Dummy account after", dummyAccount);
    dummyAccount.addAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Great Pirate");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Example 34 with DummyAccount

use of com.evolveum.icf.dummy.resource.DummyAccount in project midpoint by Evolveum.

the class TestMappingAdvanced method test320GiveMagnusExtraValuesAndModifyUser.

/**
 * Add some extra values to the account and simply modify magnus. Ranges should throw (some of) them out.
 *
 * Extra values:
 * - attribute/organization: mp_garbage (should be thrown out)
 * - attribute/organization: valid (should be kept as it does not belong to mapping range)
 * - association/group: mp_testers (should be thrown out)
 * - association/group: validGroup (should be kept)
 */
@Test
public void test320GiveMagnusExtraValuesAndModifyUser() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    DummyAccount magnus = RESOURCE_DUMMY_RANGES_DIRECT.controller.getDummyResource().getAccountByUsername(MAGNUS);
    magnus.addAttributeValue(ATTR_ORGANIZATION, "mp_garbage");
    DummyGroup testers = RESOURCE_DUMMY_RANGES_DIRECT.controller.getDummyResource().getGroupByName(MP_TESTERS);
    testers.addMember(MAGNUS);
    ObjectDelta<UserType> delta = deltaFor(UserType.class).item(UserType.F_FULL_NAME).replace(PolyString.fromOrig("Magnus Carlsen")).asObjectDelta(USER_MAGNUS.oid);
    when();
    traced(() -> executeChanges(delta, null, task, result));
    then();
    assertSuccess(task);
    assertDummyAccountByUsername(RESOURCE_DUMMY_RANGES_DIRECT.name, MAGNUS).display().assertAttribute(ATTR_ORGANIZATION, "mp_FIDE", "valid");
    assertDummyGroupByName(RESOURCE_DUMMY_RANGES_DIRECT.name, MP_USERS).display().assertMembers(MAGNUS);
    assertDummyGroupByName(RESOURCE_DUMMY_RANGES_DIRECT.name, VALID_GROUP).display().assertMembers(MAGNUS);
    assertDummyGroupByName(RESOURCE_DUMMY_RANGES_DIRECT.name, MP_TESTERS).display().assertMembers();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) Test(org.testng.annotations.Test) AbstractEmptyModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractEmptyModelIntegrationTest)

Example 35 with DummyAccount

use of com.evolveum.icf.dummy.resource.DummyAccount in project midpoint by Evolveum.

the class TestMappingAdvanced method test360GiveVladimirExtraValuesAndRecompute.

/**
 * Add some extra values to the account and use recompute. Ranges should throw (some of) them out.
 *
 * Extra values:
 * - attribute/organization: mp_garbage (should be thrown out)
 * - attribute/organization: valid (should be kept as it does not belong to mapping range)
 * - association/group: mp_testers (should be thrown out)
 * - association/group: validGroup (should be kept)
 */
@Test
public void test360GiveVladimirExtraValuesAndRecompute() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    DummyAccount vladimir = RESOURCE_DUMMY_RANGES_ROLE.controller.getDummyResource().getAccountByUsername(VLADIMIR);
    vladimir.addAttributeValue(ATTR_ORGANIZATION, "mp_garbage");
    vladimir.addAttributeValue(ATTR_ORGANIZATION, "valid");
    DummyGroup testers = RESOURCE_DUMMY_RANGES_ROLE.controller.getDummyResource().getGroupByName(MP_TESTERS);
    testers.addMember(VLADIMIR);
    DummyGroup validGroup = RESOURCE_DUMMY_RANGES_ROLE.controller.getDummyResource().getGroupByName(VALID_GROUP);
    validGroup.addMember(VLADIMIR);
    when();
    traced(() -> recomputeUser(USER_VLADIMIR.oid, task, result));
    then();
    assertSuccess(task);
    assertDummyAccountByUsername(RESOURCE_DUMMY_RANGES_ROLE.name, VLADIMIR).display().assertAttribute(ATTR_ORGANIZATION, "mp_FIDE", "valid");
    assertDummyGroupByName(RESOURCE_DUMMY_RANGES_ROLE.name, MP_USERS).display().assertMembers(VLADIMIR);
    assertDummyGroupByName(RESOURCE_DUMMY_RANGES_ROLE.name, VALID_GROUP).display().assertMembers(VLADIMIR);
    assertDummyGroupByName(RESOURCE_DUMMY_RANGES_ROLE.name, MP_TESTERS).display().assertMembers();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) Test(org.testng.annotations.Test) AbstractEmptyModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractEmptyModelIntegrationTest)

Aggregations

DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)261 Test (org.testng.annotations.Test)211 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)158 Task (com.evolveum.midpoint.task.api.Task)152 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)40 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)40 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)24 DummyGroup (com.evolveum.icf.dummy.resource.DummyGroup)20 PrismObject (com.evolveum.midpoint.prism.PrismObject)19 ArrayList (java.util.ArrayList)19 OperationProvisioningScriptsType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationProvisioningScriptsType)18 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)16 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)14 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)14 DummyPrivilege (com.evolveum.icf.dummy.resource.DummyPrivilege)12 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)12 SchemaViolationException (com.evolveum.icf.dummy.resource.SchemaViolationException)10 QName (javax.xml.namespace.QName)10 ConflictException (com.evolveum.icf.dummy.resource.ConflictException)9 DummyOrg (com.evolveum.icf.dummy.resource.DummyOrg)9