Skip to content

Commit

Permalink
Add (disabled) tests for various issues
Browse files Browse the repository at this point in the history
Namely:
- MID-4593: First password change sets no metadata
- MID-4688: Non-literal prism diff honoring metadata is broken
- MID-4689: Specify ObjectDelta.findItemDelta semantics
- MID-4690: ObjectDelta.merge fails on some occasions

(cherry picked from commit 131c8fb)
  • Loading branch information
mederly committed May 31, 2018
1 parent 9bed5af commit 96f34ac
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 19 deletions.
Expand Up @@ -15,10 +15,8 @@
*/
package com.evolveum.midpoint.prism;

import static org.testng.AssertJUnit.assertTrue;
import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.*;

import java.io.IOException;
import java.util.Collection;
Expand Down Expand Up @@ -1087,7 +1085,7 @@ public void testObjectDeltaFindItemDeltaModifyProperty() throws Exception {
System.out.println("\n\n===[ testObjectDeltaFindItemDeltaModifyProperty ]===\n");
// GIVEN

ObjectDelta<UserType> userDelta = createDeltaForFindItem();
ObjectDelta<UserType> userDelta = createDeltaForFindItem(false);
ItemPath itemDeltaPath = new ItemPath(UserType.F_GIVEN_NAME);

// WHEN
Expand All @@ -1101,10 +1099,11 @@ public void testObjectDeltaFindItemDeltaModifyProperty() throws Exception {
}

@Test
public void testObjectDeltaFindItemDeltaModifyPropertyInContainer() throws Exception {
System.out.println("\n\n===[ testObjectDeltaFindItemDeltaModifyPropertyInContainer ]===\n");
public void testObjectDeltaFindItemDeltaModifyPropertyInAddedContainer() throws Exception {
final String TEST_NAME="testObjectDeltaFindItemDeltaModifyPropertyInAddedContainer";
displayTestTitle(TEST_NAME);
// GIVEN
ObjectDelta<UserType> userDelta = createDeltaForFindItem();
ObjectDelta<UserType> userDelta = createDeltaForFindItem(false);
System.out.println("Object delta:\n"+userDelta.debugDump());

ItemPath itemDeltaPath = new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ENABLED);
Expand All @@ -1120,14 +1119,82 @@ public void testObjectDeltaFindItemDeltaModifyPropertyInContainer() throws Excep
((PropertyDelta)itemDelta).getValuesToAdd(), Boolean.TRUE);
}

private ObjectDelta<UserType> createDeltaForFindItem() throws SchemaException {
@Test
public void testObjectDeltaFindItemDeltaModifyNonExistentPropertyInAddedContainer() throws Exception {
final String TEST_NAME="testObjectDeltaFindItemDeltaModifyNonExistentPropertyInAddedContainer";
displayTestTitle(TEST_NAME);
// GIVEN
ObjectDelta<UserType> userDelta = createDeltaForFindItem(false);
System.out.println("Object delta:\n"+userDelta.debugDump());

ItemPath itemDeltaPath = new ItemPath(UserType.F_ACTIVATION, ActivationType.F_VALID_TO); // not present in the delta

// WHEN
ItemDelta<PrismValue, ItemDefinition> itemDelta = userDelta.findItemDelta(itemDeltaPath);

// THEN
System.out.println("Item delta:\n"+(itemDelta==null?"null":itemDelta.debugDump()));
assertNull("Found delta even if it shouldn't", itemDelta);
}

@Test
public void testObjectDeltaFindItemDeltaModifyPropertyInReplacedContainer() throws Exception {
final String TEST_NAME="testObjectDeltaFindItemDeltaModifyPropertyInReplacedContainer";
displayTestTitle(TEST_NAME);
// GIVEN
ObjectDelta<UserType> userDelta = createDeltaForFindItem(true);
System.out.println("Object delta:\n"+userDelta.debugDump());

ItemPath itemDeltaPath = new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ENABLED);

// WHEN
ItemDelta<PrismValue, ItemDefinition> itemDelta = userDelta.findItemDelta(itemDeltaPath);

// THEN
System.out.println("Item delta:\n"+(itemDelta==null?"null":itemDelta.debugDump()));
PrismAsserts.assertInstanceOf(PropertyDelta.class, itemDelta);
assertEquals(itemDeltaPath, itemDelta.getPath());
// TODO
// What kind of delta should we return? Currently we return REPLACE one. But this can
// cause problems when finding deltas during delta merge operation. FindItemDelta should
// be specified more precisely.
//
// See MID-4689
//
// PrismAsserts.assertPropertyValues("Wrong replace values in "+itemDelta,
// ((PropertyDelta)itemDelta).getValuesToReplace(), Boolean.TRUE);
}

@Test(enabled = false) // MID-4689
public void testObjectDeltaFindItemDeltaModifyNonExistentPropertyInReplacedContainer() throws Exception {
final String TEST_NAME="testObjectDeltaFindItemDeltaModifyNonExistentPropertyInReplacedContainer";
displayTestTitle(TEST_NAME);
// GIVEN
ObjectDelta<UserType> userDelta = createDeltaForFindItem(true);
System.out.println("Object delta:\n"+userDelta.debugDump());

ItemPath itemDeltaPath = new ItemPath(UserType.F_ACTIVATION, ActivationType.F_VALID_TO); // not present in the delta

// WHEN
ItemDelta<PrismValue, ItemDefinition> itemDelta = userDelta.findItemDelta(itemDeltaPath);

// THEN
System.out.println("Item delta:\n"+(itemDelta==null?"null":itemDelta.debugDump()));
assertNull("Found delta even if it shouldn't", itemDelta);
}

private ObjectDelta<UserType> createDeltaForFindItem(boolean containerReplace) throws SchemaException {
ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddProperty(UserType.class, USER_FOO_OID,
UserType.F_LOCALITY, PrismTestUtil.getPrismContext(), "Caribbean");
userDelta.addModificationReplaceProperty(UserType.F_GIVEN_NAME, "Guybrush");

ContainerDelta<ActivationType> activationDelta = userDelta.createContainerModification(new ItemPath(UserType.F_ACTIVATION));
PrismContainerValue<ActivationType> activationCVal = new PrismContainerValue();
activationDelta.addValueToAdd(activationCVal);
if (containerReplace) {
activationDelta.addValueToReplace(activationCVal);
} else {
activationDelta.addValueToAdd(activationCVal);
}

PrismProperty<Boolean> enabledProperty = activationCVal.createProperty(ActivationType.F_ENABLED);
enabledProperty.setRealValue(Boolean.TRUE);
Expand Down Expand Up @@ -1550,7 +1617,7 @@ private PrismObject<UserType> createUserNoAssignment() throws SchemaException {
user.setPropertyRealValue(UserType.F_NAME, PrismTestUtil.createPolyString("foo"));
PrismProperty<PolyString> anamesProp = user.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES);
anamesProp.addRealValue(PrismTestUtil.createPolyString("foobar"));

return user;
}

Expand Down
Expand Up @@ -32,6 +32,7 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -509,4 +510,45 @@ public void diffRoles() throws Exception {
assertFalse(delta.isEmpty());
}

@Test(enabled = false) // MID-4688
public void testDiffWithMetadata() {
System.out.println("\n\n===[ testDiffWithMetadata ]===\n");
PrismContext prismContext = PrismTestUtil.getPrismContext();

ProtectedStringType value = new ProtectedStringType();
value.setClearValue("abc");

PrismObject<UserType> user1 = new UserType(prismContext)
.beginCredentials()
.beginPassword()
.value(value.clone())
.beginMetadata()
.requestorComment("hi")
.<PasswordType>end()
.<CredentialsType>end()
.<UserType>end()
.asPrismObject();
PrismObject<UserType> user2 = new UserType(prismContext)
.beginCredentials()
.beginPassword()
.value(value.clone())
.beginMetadata()
.<PasswordType>end()
.<CredentialsType>end()
.<UserType>end()
.asPrismObject();

ObjectDelta<UserType> diffIgnoreMetadataNotLiteral = user1.diff(user2, true, false);
ObjectDelta<UserType> diffWithMetadataAndLiteral = user1.diff(user2, false, true);
ObjectDelta<UserType> diffWithMetadataNotLiteral = user1.diff(user2, false, false);

assertTrue("Diff ignoring metadata is not empty:\n" + diffIgnoreMetadataNotLiteral.debugDump(),
diffIgnoreMetadataNotLiteral.isEmpty());
assertFalse("Diff not ignoring metadata (literal) is empty:\n" + diffWithMetadataAndLiteral.debugDump(),
diffWithMetadataAndLiteral.isEmpty());
assertFalse("Diff not ignoring metadata (non-literal) is empty:\n" + diffWithMetadataNotLiteral.debugDump(),
diffWithMetadataNotLiteral.isEmpty());
}


}
Expand Up @@ -23,6 +23,8 @@
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
import org.testng.annotations.Test;

import com.evolveum.midpoint.prism.delta.ObjectDelta;
Expand All @@ -32,14 +34,8 @@
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

import static com.evolveum.midpoint.prism.util.PrismTestUtil.display;
import static com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext;
import static java.util.Arrays.asList;
import static java.util.Collections.singleton;
Expand Down Expand Up @@ -558,4 +554,47 @@ public void testFactorModifyDeltaForItemValues() throws Exception {
assertDeltaOid(offspring, OID);
}
}


/**
* Analogy of:
* MODIFY/replace (credentials/password) + MODIFY/add (credentials/password/metadata) [MID-4593]
*/
@Test(enabled = false) // MID-4690
public void testObjectDeltaUnion() throws Exception {
final String TEST_NAME="testObjectDeltaUnion";
displayTestTile(TEST_NAME);
// GIVEN

ProtectedStringType value = new ProtectedStringType();
value.setClearValue("hi");
PasswordType newPassword = new PasswordType(getPrismContext()).value(value);
ObjectDelta<UserType> userDelta1 = DeltaBuilder.deltaFor(UserType.class, getPrismContext())
.item(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD).replace(newPassword)
.asObjectDeltaCast("001");
MetadataType newMetadata = new MetadataType(getPrismContext()).requestorComment("comment");
ObjectDelta<UserType> userDelta2 = DeltaBuilder.deltaFor(UserType.class, getPrismContext())
.item(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_METADATA)
.add(newMetadata)
.asObjectDeltaCast("001");

// WHEN
ObjectDelta<UserType> userDeltaUnion = ObjectDelta.union(userDelta1, userDelta2);

// THEN
display("result", userDeltaUnion);

PrismObject<UserType> userWithSeparateDeltas = new UserType(getPrismContext()).asPrismObject();
userDelta1.applyTo(userWithSeparateDeltas);
userDelta2.applyTo(userWithSeparateDeltas);
display("userWithSeparateDeltas after", userWithSeparateDeltas);

PrismObject<UserType> userWithUnion = new UserType(getPrismContext()).asPrismObject();
userDeltaUnion.applyTo(userWithUnion);
display("userWithUnion after", userWithUnion);

ObjectDelta<UserType> diff = userWithSeparateDeltas.diff(userWithUnion, false, true); // set to isLiteral = false after fixing MID-4688
display("diff", diff.debugDump());
assertTrue("Deltas have different effects:\n" + diff.debugDump(), diff.isEmpty());
}
}
Expand Up @@ -282,7 +282,7 @@ public void process() throws ExpressionEvaluationException, ObjectNotFoundExcept
boolean credentialValueChanged = false;
boolean checkMinOccurs = false;
ObjectDelta<UserType> focusDelta = focusContext.getDelta();
ContainerDelta<R> containerDelta = focusDelta.findContainerDelta(getCredentialsContainerPath());
ContainerDelta<R> containerDelta = focusDelta.findContainerDelta(getCredentialsContainerPath()); // e.g. credentials/password
if (containerDelta != null) {
if (containerDelta.isAdd()) {
for (PrismContainerValue<R> cVal : containerDelta.getValuesToAdd()) {
Expand Down

0 comments on commit 96f34ac

Please sign in to comment.