Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Feb 6, 2023
2 parents aec3ff9 + 0e0c2a8 commit c4853c8
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.*;
import java.util.stream.Collectors;

import com.evolveum.midpoint.schema.util.MarkTypeUtil;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -160,11 +162,15 @@ private boolean isEnabled(@NotNull MarkType mark, @NotNull Task task) {
return true;
}
SimulationTransaction simulationTransaction = task.getSimulationTransaction();
if (simulationTransaction == null) {
return false; // Event marks are currently used only for simulations
} else {
if (simulationTransaction != null) {
return simulationTransaction.getSimulationResult().isEventMarkEnabled(mark);
}
if (!task.isSimulatedExecution()) {
return false; // Event marks are currently used only for simulations
}
// We have no simulation [result] definition, so no custom inclusion/exclusion of event marks.
// Hence, the default setting has to be applied.
return MarkTypeUtil.isEnabledByDefault(mark);
}

/** Temporary */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import java.io.File;
import java.util.List;

import com.evolveum.midpoint.schema.TaskExecutionMode;
import com.evolveum.midpoint.test.DummyResourceContoller;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.evolveum.midpoint.model.test.CommonInitialObjects;
Expand Down Expand Up @@ -51,8 +53,8 @@ public class TestProjectionPolicyRules extends AbstractLensTest {
private ShadowType wheelShadow;
private ShadowType topOrgShadow;

private static final DummyTestResource RESOURCE_DUMMY_TAGS = new DummyTestResource(
TEST_DIR, "resource-dummy-tags.xml", "b951c40b-2f57-4f1d-a881-8ba37e973c11", "tags",
private static final DummyTestResource RESOURCE_DUMMY_EVENT_MARKS = new DummyTestResource(
TEST_DIR, "resource-dummy-event-marks.xml", "b951c40b-2f57-4f1d-a881-8ba37e973c11", "event-marks",
controller -> {
controller.populateWithDefaultSchema();
controller.addAttrDef(
Expand All @@ -61,52 +63,59 @@ public class TestProjectionPolicyRules extends AbstractLensTest {
controller.getAccountObjectClass(), ATTR_MEMBER_OF_ORG, String.class, false, true);
});

@BeforeMethod
public void onNativeOnly() {
skipIfNotNativeRepository();
}

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);

CommonInitialObjects.addMarks(this, initTask, initResult);

RESOURCE_DUMMY_TAGS.initAndTest(this, initTask, initResult);
RESOURCE_DUMMY_EVENT_MARKS.initAndTest(this, initTask, initResult);

RESOURCE_DUMMY_TAGS.controller.addGroup("wheel");
RESOURCE_DUMMY_EVENT_MARKS.controller.addGroup("wheel");
var groupShadows = provisioningService.searchObjects(
ShadowType.class,
Resource.of(RESOURCE_DUMMY_TAGS.get())
Resource.of(RESOURCE_DUMMY_EVENT_MARKS.get())
.queryFor(RI_GROUP_OBJECT_CLASS)
.build(),
null, initTask, initResult);
wheelShadow = MiscUtil.extractSingletonRequired(groupShadows).asObjectable();

RESOURCE_DUMMY_TAGS.controller.addOrgTop();
RESOURCE_DUMMY_EVENT_MARKS.controller.addOrgTop();
var orgShadows = provisioningService.searchObjects(
ShadowType.class,
Resource.of(RESOURCE_DUMMY_TAGS.get())
Resource.of(RESOURCE_DUMMY_EVENT_MARKS.get())
.queryFor(CUSTOM_ORG_OBJECT_CLASS)
.build(),
null, initTask, initResult);
topOrgShadow = MiscUtil.extractSingletonRequired(orgShadows).asObjectable();
}

/**
* Check that {@link SystemObjectsType#MARK_PROJECTION_DEACTIVATED} and {@link SystemObjectsType#MARK_PROJECTION_ACTIVATED}
* are set correctly.
* Check that {@link SystemObjectsType#MARK_PROJECTION_DEACTIVATED} is set correctly.
*/
@Test
public void test100DisableAndEnableAccount() throws Exception {
public void test100DisableAccount() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

given("a user with an account exists");
UserType user = createUserWithAccount("test100", task, result);
UserType user = createUserWithAccount("test100", null, task, result);

switchToSimulationMode(task);

when("user and account are disabled");
when("user and account are disabled (in simulation mode)");
ObjectDelta<UserType> disableDelta = deltaFor(UserType.class)
.item(PATH_ACTIVATION_ADMINISTRATIVE_STATUS).replace(ActivationStatusType.DISABLED)
.asObjectDelta(user.getOid());

LensContext<UserType> disableContext = runClockwork(disableDelta, null, task, result);

then("tags are set correctly");
then("marks are set correctly");
// @formatter:off
assertModelContext(disableContext, "disable context")
.focusContext()
Expand All @@ -115,14 +124,28 @@ public void test100DisableAndEnableAccount() throws Exception {
.projectionContexts()
.single()
.assertEventMarks(MARK_PROJECTION_DEACTIVATED);
}

/**
* Check that {{@link SystemObjectsType#MARK_PROJECTION_ACTIVATED} is set correctly.
*/
@Test
public void test105EnableAccount() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

given("a (disabled) user with an account exists");
UserType user = createUserWithAccount("test105", ActivationStatusType.DISABLED, task, result);

switchToSimulationMode(task);

when("user and account are enabled");
ObjectDelta<UserType> enableDelta = deltaFor(UserType.class)
.item(PATH_ACTIVATION_ADMINISTRATIVE_STATUS).replace() // intentionally without specifying "ENABLED" explicitly
.asObjectDelta(user.getOid());
LensContext<UserType> enableContext = runClockwork(enableDelta, null, task, result);

then("tags are set correctly");
then("marks are set correctly");
// @formatter:off
assertModelContext(enableContext, "enable context")
.focusContext()
Expand All @@ -134,12 +157,14 @@ public void test100DisableAndEnableAccount() throws Exception {
// @formatter:on
}

private UserType createUserWithAccount(String name, Task task, OperationResult result) throws CommonException {
private UserType createUserWithAccount(String name, ActivationStatusType status, Task task, OperationResult result)
throws CommonException {
UserType user = new UserType()
.name(name)
.activation(new ActivationType().administrativeStatus(status))
.assignment(new AssignmentType()
.construction(new ConstructionType()
.resourceRef(RESOURCE_DUMMY_TAGS.oid, ResourceType.COMPLEX_TYPE)));
.resourceRef(RESOURCE_DUMMY_EVENT_MARKS.oid, ResourceType.COMPLEX_TYPE)));
addObject(user, task, result);
return repositoryService.getObject(UserType.class, user.getOid(), null, result).asObjectable();
}
Expand All @@ -154,26 +179,26 @@ public void test110RenameAccount() throws Exception {
OperationResult result = task.getResult();

given("a user with an account exists");
UserType user = createUserWithAccount("test110", task, result);
UserType user = createUserWithAccount("test110", null, task, result);

switchToSimulationMode(task);

when("user and account are renamed");
ObjectDelta<UserType> delta = deltaFor(UserType.class)
.item(UserType.F_NAME).replace(PolyString.fromOrig("renamed"))
.asObjectDelta(user.getOid());
LensContext<UserType> lensContext = runClockwork(delta, null, task, result);

then("tags are set correctly");
if (areMarksSupported()) {
// @formatter:off
assertModelContext(lensContext, "context")
.focusContext()
.assertEventMarks(MARK_FOCUS_RENAMED)
.end()
.projectionContexts()
.single()
.assertEventMarks(MARK_PROJECTION_RENAMED, MARK_PROJECTION_IDENTIFIER_CHANGED);
// @formatter:on
}
then("marks are set correctly");
// @formatter:off
assertModelContext(lensContext, "context")
.focusContext()
.assertEventMarks(MARK_FOCUS_RENAMED)
.end()
.projectionContexts()
.single()
.assertEventMarks(MARK_PROJECTION_RENAMED, MARK_PROJECTION_IDENTIFIER_CHANGED);
// @formatter:on
}

/**
Expand All @@ -185,26 +210,26 @@ public void test120ChangeNonNamingIdentifier() throws Exception {
OperationResult result = task.getResult();

given("a user with an account exists");
UserType user = createUserWithAccount("test120", task, result);
UserType user = createUserWithAccount("test120", null, task, result);

switchToSimulationMode(task);

when("account non-naming identifier is changed");
ObjectDelta<UserType> delta = deltaFor(UserType.class)
.item(UserType.F_EMPLOYEE_NUMBER).replace("new-emp-id")
.asObjectDelta(user.getOid());
LensContext<UserType> lensContext = runClockwork(delta, null, task, result);

then("tags are set correctly");
if (areMarksSupported()) {
// @formatter:off
assertModelContext(lensContext, "context")
.focusContext()
.assertEventMarks()
.end()
.projectionContexts()
.single()
.assertEventMarks(MARK_PROJECTION_IDENTIFIER_CHANGED);
// @formatter:on
}
then("marks are set correctly");
// @formatter:off
assertModelContext(lensContext, "context")
.focusContext()
.assertEventMarks()
.end()
.projectionContexts()
.single()
.assertEventMarks(MARK_PROJECTION_IDENTIFIER_CHANGED);
// @formatter:on
}

/**
Expand All @@ -216,10 +241,12 @@ public void test130ChangeEntitlement() throws Exception {
OperationResult result = task.getResult();

given("a user with an account exists");
UserType user = createUserWithAccount("test130", task, result);
UserType user = createUserWithAccount("test130", null, task, result);

switchToSimulationMode(task);

when("account group membership is changed");
ObjectDelta<ShadowType> delta = Resource.of(RESOURCE_DUMMY_TAGS.get())
ObjectDelta<ShadowType> delta = Resource.of(RESOURCE_DUMMY_EVENT_MARKS.get())
.deltaFor(RI_ACCOUNT_OBJECT_CLASS)
.item(ShadowType.F_ASSOCIATION)
.add(new ShadowAssociationType()
Expand All @@ -228,18 +255,16 @@ public void test130ChangeEntitlement() throws Exception {
.asObjectDelta(user.getLinkRef().get(0).getOid());
LensContext<UserType> lensContext = runClockwork(List.of(delta), null, task, result);

then("tags are set correctly");
if (areMarksSupported()) {
// @formatter:off
assertModelContext(lensContext, "context")
.focusContext()
.assertEventMarks()
.end()
.projectionContexts()
.single()
.assertEventMarks(MARK_PROJECTION_ENTITLEMENT_CHANGED);
// @formatter:on
}
then("marks are set correctly");
// @formatter:off
assertModelContext(lensContext, "context")
.focusContext()
.assertEventMarks()
.end()
.projectionContexts()
.single()
.assertEventMarks(MARK_PROJECTION_ENTITLEMENT_CHANGED);
// @formatter:on
}

/**
Expand All @@ -252,10 +277,12 @@ public void test140ChangeNonEntitlementAssociation() throws Exception {
OperationResult result = task.getResult();

given("a user with an account exists");
UserType user = createUserWithAccount("test140", task, result);
UserType user = createUserWithAccount("test140", null, task, result);

switchToSimulationMode(task);

when("account org membership is changed");
ObjectDelta<ShadowType> delta = Resource.of(RESOURCE_DUMMY_TAGS.get())
ObjectDelta<ShadowType> delta = Resource.of(RESOURCE_DUMMY_EVENT_MARKS.get())
.deltaFor(RI_ACCOUNT_OBJECT_CLASS)
.item(ShadowType.F_ASSOCIATION)
.add(new ShadowAssociationType()
Expand All @@ -264,18 +291,16 @@ public void test140ChangeNonEntitlementAssociation() throws Exception {
.asObjectDelta(user.getLinkRef().get(0).getOid());
LensContext<UserType> lensContext = runClockwork(List.of(delta), null, task, result);

then("'entitlement changed' tag is not present");
if (areMarksSupported()) {
// @formatter:off
assertModelContext(lensContext, "context")
.focusContext()
.assertEventMarks()
.end()
.projectionContexts()
.single()
.assertEventMarks(); // "org" is not an entitlement
// @formatter:on
}
then("'entitlement changed' mark is not present");
// @formatter:off
assertModelContext(lensContext, "context")
.focusContext()
.assertEventMarks()
.end()
.projectionContexts()
.single()
.assertEventMarks(); // "org" is not an entitlement
// @formatter:on
}

/**
Expand All @@ -287,25 +312,30 @@ public void test150ChangeAccountPassword() throws Exception {
OperationResult result = task.getResult();

given("a user with an account exists");
UserType user = createUserWithAccount("test150", task, result);
UserType user = createUserWithAccount("test150", null, task, result);

switchToSimulationMode(task);

when("account password is changed");
ObjectDelta<UserType> delta = deltaFor(UserType.class)
.item(PATH_PASSWORD_VALUE).replace(protector.encryptString("secret"))
.asObjectDelta(user.getOid());
LensContext<UserType> lensContext = runClockwork(delta, null, task, result);

then("tags are set correctly");
if (areMarksSupported()) {
// @formatter:off
assertModelContext(lensContext, "context")
.focusContext()
.assertEventMarks()
.end()
.projectionContexts()
.single()
.assertEventMarks(MARK_PROJECTION_PASSWORD_CHANGED);
// @formatter:on
}
then("marks are set correctly");
// @formatter:off
assertModelContext(lensContext, "context")
.focusContext()
.assertEventMarks()
.end()
.projectionContexts()
.single()
.assertEventMarks(MARK_PROJECTION_PASSWORD_CHANGED);
// @formatter:on
}

/** Switching task to a simulation mode. Otherwise, event marks would not be applied. */
private static void switchToSimulationMode(Task task) {
task.setExecutionMode(TaskExecutionMode.SIMULATED_PRODUCTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<connectorConfiguration xmlns:icfi="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.icf.dummy/com.evolveum.icf.dummy.connector.DummyConnector"
xmlns:icfc="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/connector-schema-3">
<icfc:configurationProperties>
<icfi:instanceId>tags</icfi:instanceId>
<icfi:instanceId>event-marks</icfi:instanceId>
</icfc:configurationProperties>
<icfc:resultsHandlerConfiguration>
<icfc:enableNormalizingResultsHandler>false</icfc:enableNormalizingResultsHandler>
Expand Down
2 changes: 1 addition & 1 deletion model/model-impl/testng-unit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<class name="com.evolveum.midpoint.model.impl.lens.TestPasswordPolicy"/>
<class name="com.evolveum.midpoint.model.impl.lens.TestPolicyRules"/>
<class name="com.evolveum.midpoint.model.impl.lens.TestPolicyRules2"/>
<!--<class name="com.evolveum.midpoint.model.impl.lens.TestProjectionPolicyRules"/>--> <!-- temporarily disabled -->
<class name="com.evolveum.midpoint.model.impl.lens.TestProjectionPolicyRules"/>
<class name="com.evolveum.midpoint.model.impl.lens.TestPolicyStateRecording"/>
<class name="com.evolveum.midpoint.model.impl.lens.TestProjectorPersona"/>
</classes>
Expand Down

0 comments on commit c4853c8

Please sign in to comment.