Skip to content

Commit

Permalink
Marking weak construction in EvaluatedConstruction (MID-4119)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Nov 10, 2017
1 parent 93aa186 commit a82e803
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 55 deletions.
Expand Up @@ -33,4 +33,6 @@ public interface EvaluatedConstruction extends DebugDumpable {
String getIntent();

boolean isDirectlyAssigned();

boolean isWeak();
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,11 +32,20 @@
*/
public class EvaluatedConstructionImpl implements EvaluatedConstruction {

private PrismObject<ResourceType> resource;
private ShadowKindType kind;
private String intent;
private boolean directlyAssigned;
final private PrismObject<ResourceType> resource;
final private ShadowKindType kind;
final private String intent;
final private boolean directlyAssigned;
final private boolean weak;

public <F extends FocusType> EvaluatedConstructionImpl(Construction<F> construction, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
resource = construction.getResource(task, result).asPrismObject();
kind = construction.getKind();
intent = construction.getIntent();
directlyAssigned = construction.getAssignmentPath() == null || construction.getAssignmentPath().size() == 1;
weak = construction.isWeak();
}

@Override
public PrismObject<ResourceType> getResource() {
return resource;
Expand All @@ -57,43 +66,29 @@ public boolean isDirectlyAssigned() {
return directlyAssigned;
}

public void setDirectlyAssigned(boolean directlyAssigned) {
this.directlyAssigned = directlyAssigned;
}

public <F extends FocusType> EvaluatedConstructionImpl(Construction<F> construction, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
resource = construction.getResource(task, result).asPrismObject();
kind = construction.getKind();
intent = construction.getIntent();
directlyAssigned = construction.getAssignmentPath() == null || construction.getAssignmentPath().size() == 1;
}

@Override
public String debugDump() {
return debugDump(0);
}
public boolean isWeak() {
return weak;
}

// TODO polish
@Override
public String debugDump(int indent) {
StringBuilder sb = new StringBuilder();
DebugUtil.debugDumpLabel(sb, "EvaluatedConstruction", indent);
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "Resource", resource, indent + 1);
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "Kind", kind.value(), indent + 1);
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "Intent", intent, indent + 1);
DebugUtil.debugDumpLabelLn(sb, "EvaluatedConstruction", indent);
DebugUtil.debugDumpWithLabelLn(sb, "resource", resource, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "kind", kind.value(), indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "intent", intent, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "directlyAssigned", directlyAssigned, indent + 1);
DebugUtil.debugDumpWithLabel(sb, "weak", weak, indent + 1);
return sb.toString();
}

// TODO polish
@Override
public String toString() {
return "EvaluatedConstruction{" +
return "EvaluatedConstruction(" +
"resource=" + resource +
", kind=" + kind +
", intent='" + intent + '\'' +
'}';
", intent='" + intent +
')';
}
}
Expand Up @@ -43,6 +43,7 @@
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.api.context.EvaluatedAssignment;
import com.evolveum.midpoint.model.api.context.EvaluatedAssignmentTarget;
import com.evolveum.midpoint.model.api.context.EvaluatedConstruction;
import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest;
import com.evolveum.midpoint.prism.PrismContainer;
Expand Down Expand Up @@ -88,6 +89,8 @@ public class TestRbac extends AbstractRbacTest {

private final String EXISTING_GOSSIP = "Black spot!";

private String accountJackRedOid;

@Override
public void initSystem(Task initTask, OperationResult initResult)
throws Exception {
Expand Down Expand Up @@ -2468,10 +2471,13 @@ public void test703JackModifyJudgeDeleteInducementHonorabilityRecompute() throws

// THEN
displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertSuccess(result);

PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User after", userAfter);

assertAssignedRole(USER_JACK_OID, ROLE_JUDGE_OID, task, result);
assertAssignedRole(userAfter, ROLE_JUDGE_OID);
accountJackRedOid = getSingleLinkOid(userAfter);

assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);

Expand Down Expand Up @@ -2688,7 +2694,6 @@ public void test750JackAssignRoleOmnimanager() throws Exception {
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

Task task = createTask(TEST_NAME);
task.setOwner(getUser(USER_ADMINISTRATOR_OID));
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
Expand All @@ -2700,8 +2705,7 @@ public void test750JackAssignRoleOmnimanager() throws Exception {

// THEN
displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertSuccess(result);

PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
Expand Down Expand Up @@ -2737,8 +2741,7 @@ public void test755AddProjectAndRecomputeJack() throws Exception {

// THEN
displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertSuccess(result);

PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
Expand All @@ -2759,7 +2762,6 @@ public void test759JackUnassignRoleOmnimanager() throws Exception {
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

Task task = createTask(TEST_NAME);
task.setOwner(getUser(USER_ADMINISTRATOR_OID));
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
Expand All @@ -2771,8 +2773,7 @@ public void test759JackUnassignRoleOmnimanager() throws Exception {

// THEN
displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertSuccess(result);

PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
Expand All @@ -2793,23 +2794,24 @@ public void test760JackAssignRoleWeakGossiper() throws Exception {
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

Task task = createTask(TEST_NAME);
task.setOwner(getUser(USER_ADMINISTRATOR_OID));
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
display("User jack before", userBefore);
assertAssignedNoRole(userBefore);
assertLinks(userBefore, 1);
assertLinked(userBefore, accountJackRedOid);

assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
assertDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, false);

// WHEN
displayWhen(TEST_NAME);
assignRole(USER_JACK_OID, ROLE_WEAK_GOSSIPER_OID, getDefaultOptions(), task, result);

// THEN
displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertSuccess(result);

PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
Expand All @@ -2823,13 +2825,12 @@ public void test760JackAssignRoleWeakGossiper() throws Exception {
* MID-2850
*/
@Test
public void test762JackRecompute() throws Exception {
final String TEST_NAME = "test762JackRecompute";
public void test761JackRecompute() throws Exception {
final String TEST_NAME = "test761JackRecompute";
displayTestTitle(TEST_NAME);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

Task task = createTask(TEST_NAME);
task.setOwner(getUser(USER_ADMINISTRATOR_OID));
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
Expand All @@ -2844,8 +2845,7 @@ public void test762JackRecompute() throws Exception {

// THEN
displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertSuccess(result);

PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);
Expand All @@ -2859,13 +2859,12 @@ public void test762JackRecompute() throws Exception {
* MID-2850
*/
@Test
public void test763JackReconcile() throws Exception {
final String TEST_NAME = "test763JackReconcile";
public void test762JackReconcile() throws Exception {
final String TEST_NAME = "test762JackReconcile";
displayTestTitle(TEST_NAME);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

Task task = createTask(TEST_NAME);
task.setOwner(getUser(USER_ADMINISTRATOR_OID));
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
Expand All @@ -2880,9 +2879,65 @@ public void test763JackReconcile() throws Exception {

// THEN
displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertSuccess(result);

PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);

assertAssignedRole(userAfter, ROLE_WEAK_GOSSIPER_OID);

assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
}

/**
* MID-2850, MID-4119
*/
@Test
public void test763PreviewChanges() throws Exception {
final String TEST_NAME = "test763PreviewChanges";
displayTestTitle(TEST_NAME);

Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
display("User jack before", userBefore);
assertAssignedRole(userBefore, ROLE_WEAK_GOSSIPER_OID);

assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);

ObjectDelta<UserType> delta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);

// WHEN
displayWhen(TEST_NAME);
ModelContext<ObjectType> context = modelInteractionService.previewChanges(MiscSchemaUtil.createCollection(delta), null, task, result);

// THEN
displayThen(TEST_NAME);
assertSuccess(result);

display("Preview context", context);
assertNotNull("Null focus context", context.getFocusContext());
assertEquals("Wrong number of projection contexts", 1, context.getProjectionContexts().size());
DeltaSetTriple<? extends EvaluatedAssignment<?>> evaluatedAssignmentTriple = context.getEvaluatedAssignmentTriple();
assertNotNull("null evaluatedAssignmentTriple", evaluatedAssignmentTriple);
assertTrue("Unexpected plus set in evaluatedAssignmentTriple", evaluatedAssignmentTriple.getPlusSet().isEmpty());
assertTrue("Unexpected minus set in evaluatedAssignmentTriple", evaluatedAssignmentTriple.getMinusSet().isEmpty());
Collection<? extends EvaluatedAssignment<?>> assignmentZeroSet = evaluatedAssignmentTriple.getZeroSet();
assertNotNull("null zero set in evaluatedAssignmentTriple", assignmentZeroSet);
assertEquals("Wrong size of zero set in evaluatedAssignmentTriple", 1, assignmentZeroSet.size());
EvaluatedAssignment<?> evaluatedAssignment = assignmentZeroSet.iterator().next();
display("Evaluated weak assignment", evaluatedAssignment);

DeltaSetTriple<EvaluatedConstruction> evaluatedConstructions = evaluatedAssignment.getEvaluatedConstructions(task, result);
assertTrue("Unexpected plus set in evaluatedConstructions", evaluatedConstructions.getPlusSet().isEmpty());
assertTrue("Unexpected minus set in evaluatedConstructions", evaluatedConstructions.getMinusSet().isEmpty());
Collection<EvaluatedConstruction> constructionsZeroSet = evaluatedConstructions.getZeroSet();
assertEquals("Wrong size of zero set in evaluatedConstructions", 1, constructionsZeroSet.size());
EvaluatedConstruction evaluatedConstruction = constructionsZeroSet.iterator().next();
display("Evaluated weak evaluatedConstruction", evaluatedConstruction);
assertTrue("Construction not weak", evaluatedConstruction.isWeak());

PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User jack after", userAfter);

Expand Down

0 comments on commit a82e803

Please sign in to comment.