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 May 17, 2018
2 parents f180b53 + d5d9a25 commit 16ae2f8
Show file tree
Hide file tree
Showing 23 changed files with 416 additions and 29 deletions.
Expand Up @@ -194,6 +194,9 @@ private IModel<String> getAssociationLabelModel(ContainerValueWrapper<Assignment
@Override
protected List<ContainerValueWrapper<AssignmentType>> postSearch(List<ContainerValueWrapper<AssignmentType>> assignments) {
List<ContainerValueWrapper<AssignmentType>> filteredAssignments = new ArrayList<>();
if (assignments == null){
return filteredAssignments;
}
assignments.forEach(assignmentWrapper -> {
AssignmentType assignment = assignmentWrapper.getContainerValue().asContainerable();
if (assignment.getConstruction() != null && assignment.getConstruction().getAssociation() != null) {
Expand Down
Expand Up @@ -107,7 +107,7 @@ protected boolean isDirect() {
}

@Override
protected void runPropagation() throws Exception {
protected void runPropagation(OperationResultStatusType expectedStatus) throws Exception {
if (propagationTaskOid == null) {
addTask(getPropagationTaskFile());
propagationTaskOid = getPropagationTaskOid();
Expand All @@ -117,15 +117,23 @@ protected void runPropagation() throws Exception {
restartTask(propagationTaskOid);
}
Task finishedTask = waitForTaskFinish(propagationTaskOid, true);
assertFinishedPropagationTask(finishedTask);
assertFinishedPropagationTask(finishedTask, expectedStatus);
}

protected void assertNewPropagationTask() throws Exception {

}

protected void assertFinishedPropagationTask(Task finishedTask) {

protected void assertFinishedPropagationTask(Task finishedTask, OperationResultStatusType expectedStatus) {
display("Finished propagation task", finishedTask);
OperationResultStatusType resultStatus = finishedTask.getResultStatus();
if (expectedStatus == null) {
if ( resultStatus != OperationResultStatusType.SUCCESS && resultStatus != OperationResultStatusType.IN_PROGRESS ) {
fail("Unexpected propagation task result " + resultStatus);
}
} else {
assertEquals("Unexpected propagation task result", expectedStatus, resultStatus);
}
}

protected abstract String getPropagationTaskOid();
Expand Down
Expand Up @@ -53,6 +53,7 @@

import com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl;
import com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest;
import com.evolveum.midpoint.model.test.AbstractModelIntegrationTest;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectQuery;
Expand All @@ -71,6 +72,8 @@
import com.evolveum.midpoint.schema.processor.ResourceSchema;
import com.evolveum.midpoint.schema.processor.ResourceSchemaImpl;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
Expand Down Expand Up @@ -103,6 +106,7 @@
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ReadCapabilityType;
import com.evolveum.prism.xml.ns._public.types_3.ChangeTypeType;
import com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;

/**
Expand All @@ -122,6 +126,14 @@ public abstract class AbstractManualResourceTest extends AbstractConfiguredModel
protected static final String NS_MANUAL_CONF = "http://midpoint.evolveum.com/xml/ns/public/connector/builtin-1/bundle/com.evolveum.midpoint.provisioning.ucf.impl.builtin/ManualConnector";
protected static final QName CONF_PROPERTY_DEFAULT_ASSIGNEE_QNAME = new QName(NS_MANUAL_CONF, "defaultAssignee");

protected static final File USER_PHANTOM_FILE = new File(TEST_DIR, "user-phantom.xml");
protected static final String USER_PHANTOM_OID = "5b12cc6e-575c-11e8-bc16-3744f9bfcac8";
public static final String USER_PHANTOM_USERNAME = "phantom";
public static final String USER_PHANTOM_FULL_NAME = "Thomas Phantom";
public static final String USER_PHANTOM_FULL_NAME_WRONG = "Tom Funtom";
public static final String ACCOUNT_PHANTOM_DESCRIPTION_MANUAL = "Phantom menace of the opera";
public static final String ACCOUNT_PHANTOM_PASSWORD_MANUAL = "PhanthomaS";

protected static final String USER_WILL_NAME = "will";
protected static final String USER_WILL_GIVEN_NAME = "Will";
protected static final String USER_WILL_FAMILY_NAME = "Turner";
Expand Down Expand Up @@ -1321,6 +1333,84 @@ public void test212UpdateBackingStoreAndGetAccountWill() throws Exception {
assertSteadyResources();
}

/**
* Create phantom account in the backing store. MidPoint does not know anything about it.
* At the same time, there is phantom user that has the account assigned. But it is not yet
* provisioned. MidPoint should find existing account and it it should figure out that
* there is nothing to do. Just to link the account.
* related to MID-4614
*/
@Test
public void test400PhantomAccount() throws Exception {
final String TEST_NAME = "test400PhantomAccount";
displayTestTitle(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();

setupPhantom(TEST_NAME);

// WHEN
displayWhen(TEST_NAME);
reconcileUser(USER_PHANTOM_OID, task, result);

// THEN
displayThen(TEST_NAME);
result.computeStatus();
// This should theoretically always return IN_PROGRESS, as there is
// reconciliation operation going on. But due to various "peculiarities"
// of a consistency mechanism this sometimes returns in progress and
// sometimes it is just success.
OperationResultStatus status = result.getStatus();
if (status != OperationResultStatus.IN_PROGRESS && status != OperationResultStatus.SUCCESS) {
fail("Unexpected result status in "+result);
}

// WHEN
displayWhen(TEST_NAME);
runPropagation();

// THEN
displayThen(TEST_NAME);

PrismObject<UserType> userAfter = getUser(USER_PHANTOM_OID);
display("User after", userAfter);
String shadowOid = getSingleLinkOid(userAfter);
PrismObject<ShadowType> shadowModel = getShadowModel(shadowOid);
display("Shadow after", shadowModel);

assertAttribute(shadowModel, ATTR_USERNAME_QNAME, USER_PHANTOM_USERNAME);
if (supportsBackingStore()) {
assertAttribute(shadowModel, ATTR_FULLNAME_QNAME, USER_PHANTOM_FULL_NAME_WRONG);
} else {
assertAttribute(shadowModel, ATTR_FULLNAME_QNAME, USER_PHANTOM_FULL_NAME);
}
assertAttributeFromBackingStore(shadowModel, ATTR_DESCRIPTION_QNAME, ACCOUNT_PHANTOM_DESCRIPTION_MANUAL);
assertShadowPassword(shadowModel);

if (isDirect()) {
assertSinglePendingOperation(shadowModel, PendingOperationExecutionStatusType.EXECUTING, OperationResultStatusType.IN_PROGRESS);
} else {
assertSinglePendingOperation(shadowModel, PendingOperationExecutionStatusType.EXECUTION_PENDING, null);
}

assertSteadyResources();
}

protected void setupPhantom(final String TEST_NAME) throws Exception {
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();

addObject(USER_PHANTOM_FILE);
ObjectDelta<UserType> userDelta = createAccountAssignmentUserDelta(USER_PHANTOM_OID, getResourceOid(), null, true);
repositoryService.modifyObject(UserType.class, USER_PHANTOM_OID, userDelta.getModifications(), result);
PrismObject<UserType> userBefore = getUser(USER_PHANTOM_OID);
display("User before", userBefore);

backingStoreAddPhantom();
}

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.
Expand Down Expand Up @@ -1664,6 +1754,12 @@ protected void backingStoreDeleteJack() throws IOException {
backingStore.deleteJack();
}
}

protected void backingStoreAddPhantom() throws IOException {
if (backingStore != null) {
backingStore.addPhantom();
}
}

protected void assignWillRoleOne(final String TEST_NAME, String expectedFullName, PendingOperationExecutionStatusType executionStage) throws Exception {
displayTestTitle(TEST_NAME);
Expand Down Expand Up @@ -1862,6 +1958,13 @@ protected PendingOperationType assertSinglePendingOperation(PrismObject<ShadowTy
return assertSinglePendingOperation(shadow, requestStart, requestEnd,
OperationResultStatusType.IN_PROGRESS, null, null);
}

protected PendingOperationType assertSinglePendingOperation(PrismObject<ShadowType> shadow,
PendingOperationExecutionStatusType expectedExecutionStatus, OperationResultStatusType expectedResultStatus) {
assertPendingOperationDeltas(shadow, 1);
return assertPendingOperation(shadow, shadow.asObjectable().getPendingOperation().get(0),
null, null, expectedExecutionStatus, expectedResultStatus, null, null);
}

protected PendingOperationType assertSinglePendingOperation(PrismObject<ShadowType> shadow,
XMLGregorianCalendar requestStart, XMLGregorianCalendar requestEnd,
Expand All @@ -1879,6 +1982,19 @@ protected PendingOperationType assertPendingOperation(
OperationResultStatusType.IN_PROGRESS, null, null);
}

protected PendingOperationType assertPendingOperation(
PrismObject<ShadowType> shadow, PendingOperationType pendingOperation,
PendingOperationExecutionStatusType expectedExecutionStatus, OperationResultStatusType expectedResultStatus) {
return assertPendingOperation(shadow, pendingOperation, null, null,
expectedExecutionStatus, expectedResultStatus, null, null);
}

protected PendingOperationType assertPendingOperation(
PrismObject<ShadowType> shadow, PendingOperationType pendingOperation) {
return assertPendingOperation(shadow, pendingOperation, null, null,
OperationResultStatusType.IN_PROGRESS, null, null);
}

protected PendingOperationType assertPendingOperation(
PrismObject<ShadowType> shadow, PendingOperationType pendingOperation,
XMLGregorianCalendar requestStart, XMLGregorianCalendar requestEnd,
Expand Down Expand Up @@ -2036,6 +2152,10 @@ protected void assertCase(String oid, String expectedState, PendingOperationExec
}

protected void runPropagation() throws Exception {
runPropagation(null);
}

protected void runPropagation(OperationResultStatusType expectedStatus) throws Exception {
// nothing by default
}

Expand All @@ -2062,5 +2182,14 @@ protected void assertSteadyResources() {
}
assertEquals("Resource version mismatch", lastResourceVersion, currentResourceVersion);
}

protected void assertHasModification(ObjectDeltaType deltaType, ItemPath itemPath) {
for (ItemDeltaType itemDelta: deltaType.getItemDelta()) {
if (itemPath.equivalent(itemDelta.getPath().getItemPath())) {
return;
}
}
fail("No modification for "+itemPath+" in delta");
}

}
Expand Up @@ -37,6 +37,8 @@ public interface BackingStore {

void deleteJack() throws IOException;

void addPhantom() throws IOException;

void deleteAccount(String username) throws IOException;

void displayContent() throws IOException;
Expand Down
Expand Up @@ -118,6 +118,20 @@ public void deleteJack() throws IOException {
deprovisionInCsv(AbstractManualResourceTest.USER_JACK_USERNAME);
}

@Override
public void addPhantom() throws IOException {
appendToCsv(new String[]{
AbstractManualResourceTest.USER_PHANTOM_USERNAME,
// Wrong fullname here ... by purpose. We wonder whether reconciliation fixes this.
AbstractManualResourceTest.USER_PHANTOM_FULL_NAME_WRONG,
AbstractManualResourceTest.ACCOUNT_PHANTOM_DESCRIPTION_MANUAL,
"",
"false",
AbstractManualResourceTest.ACCOUNT_PHANTOM_PASSWORD_MANUAL
});
}


@Override
public void deleteAccount(String username) throws IOException {
deleteInCsv(username);
Expand Down Expand Up @@ -193,7 +207,7 @@ protected void deleteInCsv(String username) throws IOException {
}

private String formatCsvLine(String[] data) {
return Arrays.stream(data).map(s -> "\""+s+"\"").collect(Collectors.joining(","));
return Arrays.stream(data).map(s -> "\""+s+"\"").collect(Collectors.joining(",")) + "\n";
}

@Override
Expand Down
Expand Up @@ -26,8 +26,15 @@
import org.springframework.test.context.ContextConfiguration;
import org.testng.AssertJUnit;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.w3c.dom.Element;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

/**
* MID-4347
*
Expand Down Expand Up @@ -82,4 +89,5 @@ protected File getPropagationTaskFile() {
protected void assertResourceSchemaBeforeTest(Element resourceXsdSchemaElementBefore) {
AssertJUnit.assertNotNull("No schema before test connection. Bad test setup?", resourceXsdSchemaElementBefore);
}

}

0 comments on commit 16ae2f8

Please sign in to comment.