Skip to content

Commit

Permalink
Merge branch 'post-3.7-fixes' into support-3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Feb 12, 2018
2 parents 0062fd7 + 315f4d6 commit b094fc7
Show file tree
Hide file tree
Showing 10 changed files with 650 additions and 324 deletions.
Expand Up @@ -163,97 +163,19 @@ public abstract class AbstractDirectManualResourceTest extends AbstractManualRes
private XMLGregorianCalendar roleTwoValidFromTimestamp;

protected String accountBarbossaOid;
protected String accountDrakeOid;

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

addObject(USER_BARBOSSA_FILE);
addObject(USER_DRAKE_FILE);
}

@Override
protected boolean isDirect() {
return true;
}

protected int getConcurrentTestNumberOfThreads() {
return 4;
}

protected int getConcurrentTestRandomStartDelayRangeAssign() {
return 1000;
}

protected int getConcurrentTestRandomStartDelayRangeUnassign() {
return 5;
}

protected boolean are9xxTestsEnabled() {
// Disabled by default. These are intense parallel tests and they will fail for resources
// that do not have extra consistency checks and do not use proposed shadows.
return false;
}



// @Test
// public void test202RecomputeWill() throws Exception {
// final String TEST_NAME = "test202RecomputeWill";
// displayTestTitle(TEST_NAME);
// // GIVEN
// Task task = createTask(TEST_NAME);
// OperationResult result = task.getResult();
//
// // WHEN
// displayWhen(TEST_NAME);
// recomputeUser(userWillOid, task, result);
//
// // THEN
// displayThen(TEST_NAME);
// assertSuccess(result);
//
// PrismObject<ShadowType> shadowRepo = repositoryService.getObject(ShadowType.class, accountWillOid, null, result);
// display("Repo shadow", shadowRepo);
// PendingOperationType pendingOperation = assertSinglePendingOperation(shadowRepo, accountWillReqestTimestampStart, accountWillReqestTimestampEnd);
// assertNotNull("No ID in pending operation", pendingOperation.getId());
// // Still old data in the repo. The operation is not completed yet.
// assertShadowActivationAdministrativeStatusFromCache(shadowRepo, ActivationStatusType.ENABLED);
// assertAttribute(shadowRepo, ATTR_USERNAME_QNAME, USER_WILL_NAME);
// assertAttributeFromCache(shadowRepo, ATTR_FULLNAME_QNAME, USER_WILL_FULL_NAME);
//
// PrismObject<ShadowType> shadowModel = modelService.getObject(ShadowType.class,
// accountWillOid, null, task, result);
//
// display("Model shadow", shadowModel);
// ShadowType shadowTypeProvisioning = shadowModel.asObjectable();
// assertShadowName(shadowModel, USER_WILL_NAME);
// assertEquals("Wrong kind (provisioning)", ShadowKindType.ACCOUNT, shadowTypeProvisioning.getKind());
// assertShadowActivationAdministrativeStatus(shadowModel, ActivationStatusType.ENABLED);
// assertAttribute(shadowModel, ATTR_USERNAME_QNAME, USER_WILL_NAME);
// assertAttribute(shadowModel, ATTR_FULLNAME_QNAME, USER_WILL_FULL_NAME);
// assertShadowPassword(shadowModel);
//
// assertSinglePendingOperation(shadowModel, accountWillReqestTimestampStart, accountWillReqestTimestampEnd);
//
// PrismObject<ShadowType> shadowProvisioningFuture = modelService.getObject(ShadowType.class,
// accountWillOid,
// SelectorOptions.createCollection(GetOperationOptions.createPointInTimeType(PointInTimeType.FUTURE)),
// task, result);
// display("Model shadow (future)", shadowProvisioningFuture);
// assertShadowName(shadowProvisioningFuture, USER_WILL_NAME);
// assertEquals("Wrong kind (provisioning)", ShadowKindType.ACCOUNT, shadowProvisioningFuture.asObjectable().getKind());
// assertShadowActivationAdministrativeStatus(shadowProvisioningFuture, ActivationStatusType.ENABLED);
// assertAttribute(shadowProvisioningFuture, ATTR_USERNAME_QNAME, USER_WILL_NAME);
// assertAttribute(shadowProvisioningFuture, ATTR_FULLNAME_QNAME, USER_WILL_FULL_NAME_PIRATE);
// assertShadowPassword(shadowProvisioningFuture);
//
// assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_OPEN);
//
// }


/**
* disable - do not complete yet (do not wait for delta to expire, we want several deltas at once).
*/
Expand Down Expand Up @@ -2111,245 +2033,6 @@ public void test840AddToBackingStoreAndGetAccountWill() throws Exception {
assertNoShadowPassword(shadowRepo);
assertShadowExists(shadowRepo, true);
}

/**
* Set up roles used in parallel tests.
*/
@Test
public void test900SetUpRoles() throws Exception {
final String TEST_NAME = "test900SetUpRoles";
displayTestTitle(TEST_NAME);
if (!are9xxTestsEnabled()) {
displaySkip(TEST_NAME);
return;
}

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

SystemConfigurationType systemConfiguration = getSystemConfiguration();
display("System config", systemConfiguration);
ConflictResolutionActionType conflictResolutionAction = systemConfiguration.getDefaultObjectPolicyConfiguration().get(0).getConflictResolution().getAction();
if (!ConflictResolutionActionType.RECOMPUTE.equals(conflictResolutionAction) && !ConflictResolutionActionType.RECONCILE.equals(conflictResolutionAction)) {
fail("Wrong conflict resolution action: " + conflictResolutionAction);
}


for (int i = 0; i < getConcurrentTestNumberOfThreads(); i++) {
PrismObject<RoleType> role = parseObject(getRoleOneFile());
role.setOid(getRoleOid(i));
role.asObjectable().setName(createPolyStringType(getRoleName(i)));
List<ResourceAttributeDefinitionType> outboundAttributes = role.asObjectable().getInducement().get(0).getConstruction().getAttribute();
if (hasMultivalueInterests()) {
ExpressionType outboundExpression = outboundAttributes.get(0).getOutbound().getExpression();
JAXBElement jaxbElement = outboundExpression.getExpressionEvaluator().get(0);
jaxbElement.setValue(getRoleInterest(i));
} else {
outboundAttributes.remove(0);
}
addObject(role);
}
}

private String getRoleOid(int i) {
return String.format("f363260a-8d7a-11e7-bd67-%012d", i);
}

private String getRoleName(int i) {
return String.format("role-%012d", i);
}

private String getRoleInterest(int i) {
return String.format("i%012d", i);
}

// MID-4047, MID-4112
@Test
public void test910ConcurrentRolesAssign() throws Exception {
final String TEST_NAME = "test910ConcurrentRolesAssign";
displayTestTitle(TEST_NAME);
if (!are9xxTestsEnabled()) {
displaySkip(TEST_NAME);
return;
}

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

int numberOfCasesBefore = getObjectCount(CaseType.class);
PrismObject<UserType> userBefore = getUser(USER_DRAKE_OID);
display("user before", userBefore);
assertLinks(userBefore, 0);

final long TIMEOUT = 60000L;

// WHEN
displayWhen(TEST_NAME);

ParallelTestThread[] threads = multithread(TEST_NAME,
(i) -> {
login(userAdministrator);
Task localTask = createTask(TEST_NAME + ".local");

assignRole(USER_DRAKE_OID, getRoleOid(i), localTask, localTask.getResult());

}, getConcurrentTestNumberOfThreads(), getConcurrentTestRandomStartDelayRangeAssign());

// THEN
displayThen(TEST_NAME);
waitForThreads(threads, TIMEOUT);

PrismObject<UserType> userAfter = getUser(USER_DRAKE_OID);
display("user after", userAfter);
assertAssignments(userAfter, getConcurrentTestNumberOfThreads());
assertEquals("Wrong # of links", 1, userAfter.asObjectable().getLinkRef().size());
accountDrakeOid = userAfter.asObjectable().getLinkRef().get(0).getOid();

PrismObject<ShadowType> shadowRepo = repositoryService.getObject(ShadowType.class, accountDrakeOid, null, result);
display("Repo shadow", shadowRepo);
assertShadowNotDead(shadowRepo);

assertTest910ShadowRepo(shadowRepo, task, result);

Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createPointInTimeType(PointInTimeType.FUTURE));
PrismObject<ShadowType> shadowModel = modelService.getObject(ShadowType.class, accountDrakeOid, options, task, result);
display("Shadow after (model, future)", shadowModel);

// assertObjects(CaseType.class, numberOfCasesBefore + getConcurrentTestNumberOfThreads());
}

protected void assertTest910ShadowRepo(PrismObject<ShadowType> shadowRepo, Task task, OperationResult result) throws Exception {
assertShadowNotDead(shadowRepo);
ObjectDeltaType addPendingDelta = null;
for (PendingOperationType pendingOperation: shadowRepo.asObjectable().getPendingOperation()) {
ObjectDeltaType delta = pendingOperation.getDelta();
if (delta.getChangeType() == ChangeTypeType.ADD) {
ObjectType objectToAdd = delta.getObjectToAdd();
display("Pending ADD object", objectToAdd.asPrismObject());
if (addPendingDelta != null) {
fail("More than one add pending delta found:\n"+addPendingDelta+"\n"+delta);
}
addPendingDelta = delta;
}
if (delta.getChangeType() == ChangeTypeType.DELETE) {
fail("Unexpected delete pending delta found:\n"+delta);
}
if (isActivationStatusModifyDelta(delta, ActivationStatusType.ENABLED)) {
fail("Unexpected enable pending delta found:\n"+delta);
}
}
assertNotNull("No add pending delta", addPendingDelta);
}

// MID-4112
@Test
public void test919ConcurrentRoleUnassign() throws Exception {
final String TEST_NAME = "test919ConcurrentRoleUnassign";
displayTestTitle(TEST_NAME);
if (!are9xxTestsEnabled()) {
displaySkip(TEST_NAME);
return;
}

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

int numberOfCasesBefore = getObjectCount(CaseType.class);
PrismObject<UserType> userBefore = getUser(USER_DRAKE_OID);
display("user before", userBefore);
assertAssignments(userBefore, getConcurrentTestNumberOfThreads());

final long TIMEOUT = 60000L;

// WHEN
displayWhen(TEST_NAME);

ParallelTestThread[] threads = multithread(TEST_NAME,
(i) -> {
display("Thread "+Thread.currentThread().getName()+" START");
login(userAdministrator);
Task localTask = createTask(TEST_NAME + ".local");
OperationResult localResult = localTask.getResult();

unassignRole(USER_DRAKE_OID, getRoleOid(i), localTask, localResult);

localResult.computeStatus();

display("Thread "+Thread.currentThread().getName()+" DONE, result", localResult);

}, getConcurrentTestNumberOfThreads(), getConcurrentTestRandomStartDelayRangeUnassign());

// THEN
displayThen(TEST_NAME);
waitForThreads(threads, TIMEOUT);

PrismObject<UserType> userAfter = getUser(USER_DRAKE_OID);
display("user after", userAfter);
assertAssignments(userAfter, 0);
assertEquals("Wrong # of links", 1, userAfter.asObjectable().getLinkRef().size());

PrismObject<ShadowType> shadowRepo = repositoryService.getObject(ShadowType.class, accountDrakeOid, null, result);
display("Repo shadow", shadowRepo);

PrismObject<ShadowType> shadowModel = modelService.getObject(ShadowType.class, accountDrakeOid, null, task, result);
display("Shadow after (model)", shadowModel);

Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createPointInTimeType(PointInTimeType.FUTURE));
PrismObject<ShadowType> shadowModelFuture = modelService.getObject(ShadowType.class, accountDrakeOid, options, task, result);
display("Shadow after (model, future)", shadowModelFuture);

assertTest919ShadowRepo(shadowRepo, task, result);

assertTest919ShadowFuture(shadowModelFuture, task, result);

// assertObjects(CaseType.class, numberOfCasesBefore + getConcurrentTestNumberOfThreads() + 1);
}

protected void assertTest919ShadowRepo(PrismObject<ShadowType> shadowRepo, Task task, OperationResult result) throws Exception {
ObjectDeltaType deletePendingDelta = null;
for (PendingOperationType pendingOperation: shadowRepo.asObjectable().getPendingOperation()) {
ObjectDeltaType delta = pendingOperation.getDelta();
if (delta.getChangeType() == ChangeTypeType.ADD) {
ObjectType objectToAdd = delta.getObjectToAdd();
display("Pending ADD object", objectToAdd.asPrismObject());
}
if (delta.getChangeType() == ChangeTypeType.DELETE) {
if (deletePendingDelta != null) {
fail("More than one delete pending delta found:\n"+deletePendingDelta+"\n"+delta);
}
deletePendingDelta = delta;
}
}
assertNotNull("No delete pending delta", deletePendingDelta);
}

protected boolean isActivationStatusModifyDelta(ObjectDeltaType delta, ActivationStatusType expected) throws SchemaException {
if (delta.getChangeType() != ChangeTypeType.MODIFY) {
return false;
}
for (ItemDeltaType itemDelta: delta.getItemDelta()) {
ItemPath deltaPath = itemDelta.getPath().getItemPath();
if (SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS.equivalent(deltaPath)) {
List<RawType> value = itemDelta.getValue();
PrismProperty<ActivationStatusType> parsedItem = (PrismProperty<ActivationStatusType>)(Item)
value.get(0).getParsedItem(getUserDefinition().findPropertyDefinition(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS));
ActivationStatusType status = parsedItem.getRealValue();
display("Delta status " + status, itemDelta);
if (expected.equals(status)) {
return true;
}
}
}
return false;
}

protected void assertTest919ShadowFuture(PrismObject<ShadowType> shadowModelFuture, Task task,
OperationResult result) {
assertShadowDead(shadowModelFuture);
}

// Direct execution. The operation is always executing immediately after it is requested.
protected PendingOperationExecutionStatusType getExpectedExecutionStatus(PendingOperationExecutionStatusType executionStage) {
Expand Down
Expand Up @@ -124,6 +124,8 @@ public abstract class AbstractGroupingManualResourceTest extends AbstractManualR
protected static final File RESOURCE_SEMI_MANUAL_GROUPING_FILE = new File(TEST_DIR, "resource-semi-manual-grouping.xml");
protected static final String RESOURCE_SEMI_MANUAL_GROUPING_OID = "9eddca88-f222-11e7-98dc-cb6e4b08800c";

protected static final File RESOURCE_SEMI_MANUAL_GROUPING_PROPOSED_FILE = new File(TEST_DIR, "resource-semi-manual-grouping-proposed.xml");

protected static final File ROLE_ONE_MANUAL_GROUPING_FILE = new File(TEST_DIR, "role-one-manual-grouping.xml");
protected static final String ROLE_ONE_MANUAL_GROUPING_OID = "bc586500-f092-11e7-9cda-f7cd4203a755";

Expand Down Expand Up @@ -940,6 +942,8 @@ public void test349CleanUp() throws Exception {
cleanupUser(TEST_NAME, userWillOid, USER_WILL_NAME, accountWillOid);
}

// TODO: test400: create -> modify -> propagation

protected void assertUnassignedShadow(PrismObject<ShadowType> shadow, ActivationStatusType expectAlternativeActivationStatus) {
assertShadowDead(shadow);
}
Expand Down

0 comments on commit b094fc7

Please sign in to comment.