Search in sources :

Example 66 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestRecomputeTask method test100RecomputeAll.

@Test
public void test100RecomputeAll() throws Exception {
    final String TEST_NAME = "test100RecomputeAll";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    // Preconditions
    assertUsers(5);
    assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
    assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
    // Do some ordinary operations
    assignRole(USER_GUYBRUSH_OID, ROLE_PIRATE_OID, task, result);
    assignRole(USER_JACK_OID, ROLE_JUDGE_OID, task, result);
    addObject(USER_HERMAN_FILE);
    assignRole(USER_HERMAN_OID, ROLE_JUDGE_OID, task, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    // Now do something evil
    // change definition of role "pirate". midPoint will not recompute automatically
    // the recompute task should do it
    // One simple change
    modifyRoleAddConstruction(ROLE_JUDGE_OID, 1111L, RESOURCE_DUMMY_RED_OID);
    // More complicated change
    PrismObject<RoleType> rolePirate = modelService.getObject(RoleType.class, ROLE_PIRATE_OID, null, task, result);
    ItemPath attrItemPath = new ItemPath(new NameItemPathSegment(RoleType.F_INDUCEMENT), new IdItemPathSegment(1111L), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION), new IdItemPathSegment(60004L), new NameItemPathSegment(ConstructionType.F_ATTRIBUTE));
    PrismProperty<ResourceAttributeDefinitionType> attributeProperty = rolePirate.findProperty(attrItemPath);
    assertNotNull("No attribute property in " + rolePirate);
    PrismPropertyValue<ResourceAttributeDefinitionType> oldAttrPVal = null;
    for (PrismPropertyValue<ResourceAttributeDefinitionType> pval : attributeProperty.getValues()) {
        ResourceAttributeDefinitionType attrType = pval.getValue();
        if (ItemPathUtil.getOnlySegmentQName(attrType.getRef()).getLocalPart().equals(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME)) {
            oldAttrPVal = pval;
        }
    }
    assertNotNull("Definition for weapon attribute not found in " + rolePirate);
    PrismPropertyValue<ResourceAttributeDefinitionType> newAttrPVal = oldAttrPVal.clone();
    JAXBElement<?> cutlassExpressionEvalJaxbElement = newAttrPVal.getValue().getOutbound().getExpression().getExpressionEvaluator().get(0);
    RawType cutlassValueEvaluator = (RawType) cutlassExpressionEvalJaxbElement.getValue();
    RawType daggerValueEvaluator = new RawType(new PrimitiveXNode<String>("dagger"), prismContext);
    JAXBElement<?> daggerExpressionEvalJaxbElement = new JAXBElement<Object>(SchemaConstants.C_VALUE, Object.class, daggerValueEvaluator);
    newAttrPVal.getValue().getOutbound().getExpression().getExpressionEvaluator().add(daggerExpressionEvalJaxbElement);
    newAttrPVal.getValue().getOutbound().setStrength(MappingStrengthType.STRONG);
    ObjectDelta<RoleType> rolePirateDelta = ObjectDelta.createModificationDeleteProperty(RoleType.class, ROLE_PIRATE_OID, attrItemPath, prismContext, oldAttrPVal.getValue());
    IntegrationTestTools.displayJaxb("AAAAAAAAAAA", newAttrPVal.getValue(), ConstructionType.F_ATTRIBUTE);
    display("BBBBBB", newAttrPVal.getValue().toString());
    rolePirateDelta.addModificationAddProperty(attrItemPath, newAttrPVal.getValue());
    display("Role pirate delta", rolePirateDelta);
    modelService.executeChanges(MiscSchemaUtil.createCollection(rolePirateDelta), null, task, result);
    displayRoles(task, result);
    assertDummyAccount(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", true);
    assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    display("User jack (before)", userJack);
    assertDummyAccount(null, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
    assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    addObject(TASK_USER_RECOMPUTE_FILE);
    dummyAuditService.clear();
    waitForTaskStart(TASK_USER_RECOMPUTE_OID, false);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    waitForTaskFinish(TASK_USER_RECOMPUTE_OID, true, 40000);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, null, null, task, result);
    display("Users after recompute", users);
    assertDummyAccount(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", true);
    assertDummyAccountAttribute(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "cutlass", "dagger");
    assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
    userJack = getUser(USER_JACK_OID);
    display("User jack (after)", userJack);
    assertNoDummyAccount(null, ACCOUNT_JACK_DUMMY_USERNAME);
    assertDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
    assertUsers(6);
    // Check audit
    display("Audit", dummyAuditService);
    List<AuditEventRecord> auditRecords = dummyAuditService.getRecords();
    int i = 0;
    int modifications = 0;
    for (; i < (auditRecords.size() - 1); i += 2) {
        AuditEventRecord requestRecord = auditRecords.get(i);
        assertNotNull("No request audit record (" + i + ")", requestRecord);
        assertEquals("Got this instead of request audit record (" + i + "): " + requestRecord, AuditEventStage.REQUEST, requestRecord.getEventStage());
        assertTrue("Unexpected delta in request audit record " + requestRecord, requestRecord.getDeltas() == null || requestRecord.getDeltas().isEmpty());
        AuditEventRecord executionRecord = auditRecords.get(i + 1);
        assertNotNull("No execution audit record (" + i + ")", executionRecord);
        assertEquals("Got this instead of execution audit record (" + i + "): " + executionRecord, AuditEventStage.EXECUTION, executionRecord.getEventStage());
        assertTrue("Empty deltas in execution audit record " + executionRecord, executionRecord.getDeltas() != null && !executionRecord.getDeltas().isEmpty());
        modifications++;
        // check next records
        while (i < (auditRecords.size() - 2)) {
            AuditEventRecord nextRecord = auditRecords.get(i + 2);
            if (nextRecord.getEventStage() == AuditEventStage.EXECUTION) {
                // more than one execution record is OK
                i++;
            } else {
                break;
            }
        }
    }
    assertEquals("Unexpected number of audit modifications", 6, modifications);
    deleteObject(TaskType.class, TASK_USER_RECOMPUTE_OID, task, result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) JAXBElement(javax.xml.bind.JAXBElement) PrismObject(com.evolveum.midpoint.prism.PrismObject) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 67 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestValidityRecomputeTask method test146BarbossaDisableBothRedAssignments.

@Test
public void test146BarbossaDisableBothRedAssignments() throws Exception {
    final String TEST_NAME = "test146BarbossaDisableBothRedAssignments";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TestValidityRecomputeTask.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    AssignmentType judgeAssignment = getUserAssignment(USER_BARBOSSA_OID, ROLE_RED_JUDGE_OID);
    AssignmentType sailorAssignment = getUserAssignment(USER_BARBOSSA_OID, ROLE_RED_SAILOR_OID);
    ObjectDelta<UserType> objectDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_BARBOSSA_OID, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(judgeAssignment.getId()), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_ADMINISTRATIVE_STATUS)), prismContext, ActivationStatusType.DISABLED);
    objectDelta.addModificationReplaceProperty(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(sailorAssignment.getId()), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_ADMINISTRATIVE_STATUS)), ActivationStatusType.DISABLED);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(MiscSchemaUtil.createCollection(objectDelta), null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertDummyAccount(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, false);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    waitForTaskNextRunAssertSuccess(TASK_VALIDITY_SCANNER_OID, true);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertDummyAccount(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, false);
    assertNoDummyAccountAttribute(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME);
    assertNoDummyAccountAttribute(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME);
    PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
    display("User after", user);
    assertLinks(user, 1);
    MidPointPrincipal principal = userProfileService.getPrincipal(user);
    assertNotAuthorized(principal, AUTZ_PUNISH_URL);
}
Also used : TestTriggerTask(com.evolveum.midpoint.model.intest.TestTriggerTask) Task(com.evolveum.midpoint.task.api.Task) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 68 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestValidityRecomputeTask method test149BarbossaDisableBothRedAssignmentsUnassign.

/**
	 * Unassign disabled assignments.
	 */
@Test
public void test149BarbossaDisableBothRedAssignmentsUnassign() throws Exception {
    final String TEST_NAME = "test149BarbossaDisableBothRedAssignmentsUnassign";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TestValidityRecomputeTask.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    AssignmentType judgeAssignment = getUserAssignment(USER_BARBOSSA_OID, ROLE_RED_JUDGE_OID);
    AssignmentType judgeAssignmentLight = new AssignmentType();
    judgeAssignmentLight.setId(judgeAssignment.getId());
    AssignmentType sailorAssignment = getUserAssignment(USER_BARBOSSA_OID, ROLE_RED_SAILOR_OID);
    AssignmentType sailorAssignmentLight = new AssignmentType();
    sailorAssignmentLight.setId(sailorAssignment.getId());
    ObjectDelta<UserType> objectDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_BARBOSSA_OID, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(judgeAssignment.getId()), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_ADMINISTRATIVE_STATUS)), prismContext, ActivationStatusType.DISABLED);
    objectDelta.addModificationReplaceProperty(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(sailorAssignment.getId()), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_ADMINISTRATIVE_STATUS)), ActivationStatusType.DISABLED);
    modelService.executeChanges(MiscSchemaUtil.createCollection(objectDelta), null, task, result);
    assertNoDummyAccount(null, USER_BARBOSSA_USERNAME);
    waitForTaskNextRunAssertSuccess(TASK_VALIDITY_SCANNER_OID, true);
    assertNoDummyAccount(null, USER_BARBOSSA_USERNAME);
    PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
    display("User after", user);
    assertLinks(user, 1);
    MidPointPrincipal principal = userProfileService.getPrincipal(user);
    assertNotAuthorized(principal, AUTZ_PUNISH_URL);
    objectDelta = ObjectDelta.createModificationDeleteContainer(UserType.class, USER_BARBOSSA_OID, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT)), prismContext, judgeAssignmentLight);
    objectDelta.addModificationDeleteContainer(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT)), sailorAssignmentLight);
    display("Unassign delta", objectDelta);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(MiscSchemaUtil.createCollection(objectDelta), null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertDummyAccount(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, false);
    // to be on the safe side
    assertNoDummyAccount(null, USER_BARBOSSA_USERNAME);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    waitForTaskNextRunAssertSuccess(TASK_VALIDITY_SCANNER_OID, true);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertDummyAccount(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, false);
    assertNoDummyAccountAttribute(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME);
    assertNoDummyAccountAttribute(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME);
    // to be on the safe side
    assertNoDummyAccount(null, USER_BARBOSSA_USERNAME);
    user = getUser(USER_BARBOSSA_OID);
    display("User after", user);
    assertLinks(user, 1);
    assertNoAssignments(user);
    principal = userProfileService.getPrincipal(user);
    assertNotAuthorized(principal, AUTZ_PUNISH_URL);
}
Also used : TestTriggerTask(com.evolveum.midpoint.model.intest.TestTriggerTask) Task(com.evolveum.midpoint.task.api.Task) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 69 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.

the class TestValidityRecomputeTask method test125JackDeleteAdministrativeStatusAssignmentJudge.

@Test
public void test125JackDeleteAdministrativeStatusAssignmentJudge() throws Exception {
    final String TEST_NAME = "test125JackDeleteAdministrativeStatusAssignmentJudge";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TestValidityRecomputeTask.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assertDummyAccount(null, USER_JACK_USERNAME);
    AssignmentType judgeAssignment = getJudgeAssignment(USER_JACK_OID);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modifyObjectDeleteProperty(UserType.class, USER_JACK_OID, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(judgeAssignment.getId()), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_ADMINISTRATIVE_STATUS)), task, result, ActivationStatusType.ENABLED);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    PrismObject<UserType> user = getUser(USER_JACK_OID);
    display("User after", user);
    assertDummyAccount(null, USER_JACK_USERNAME);
    assert11xUserOk(user);
}
Also used : TestTriggerTask(com.evolveum.midpoint.model.intest.TestTriggerTask) Task(com.evolveum.midpoint.task.api.Task) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Aggregations

NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)69 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)61 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)46 Test (org.testng.annotations.Test)35 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)22 QName (javax.xml.namespace.QName)20 Task (com.evolveum.midpoint.task.api.Task)19 ItemPathSegment (com.evolveum.midpoint.prism.path.ItemPathSegment)15 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)14 TestTriggerTask (com.evolveum.midpoint.model.intest.TestTriggerTask)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)10 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)10 UserType (com.evolveum.midpoint.prism.foo.UserType)7 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)7 AssignmentType (com.evolveum.midpoint.prism.foo.AssignmentType)6 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)6 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)5 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)4