diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/util/PrismAsserts.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/util/PrismAsserts.java index 6d9f05defa2..315b24241a5 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/util/PrismAsserts.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/util/PrismAsserts.java @@ -334,8 +334,14 @@ public static void assertPropertyReplace(ObjectDelta objectDelta, QName prope assertNotNull("Property delta for "+propertyName+" not found",propertyDelta); assertReplace(propertyDelta, expectedValues); } - - public static void assertReplace(PropertyDelta propertyDelta, T... expectedValues) { + + public static void assertPropertyReplaceSimple(ObjectDelta objectDelta, QName propertyName) { + PropertyDelta propertyDelta = objectDelta.findPropertyDelta(propertyName); + assertNotNull("Property delta for "+propertyName+" not found",propertyDelta); + assertTrue("No values to replace", propertyDelta.getValuesToReplace() != null && !propertyDelta.getValuesToReplace().isEmpty()); + } + + public static void assertReplace(PropertyDelta propertyDelta, T... expectedValues) { assertSet("delta "+propertyDelta+" for "+propertyDelta.getElementName(), "replace", propertyDelta.getValuesToReplace(), expectedValues); } @@ -851,8 +857,12 @@ public static void assertRefFilter(ObjectFilter objectFilter, QName expectedFilt static void assertNotNull(String string, Object object) { assert object != null : string; } - - public static void assertEquals(String message, Object expected, Object actual) { + + private static void assertTrue(String message, boolean test) { + assert test : message; + } + + public static void assertEquals(String message, Object expected, Object actual) { assert MiscUtil.equals(expected, actual) : message + ": expected " + MiscUtil.getValueWithClass(expected) + ", was " + MiscUtil.getValueWithClass(actual); diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/xnode/MapXNode.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/xnode/MapXNode.java index 0d41322fdc5..b0058355708 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/xnode/MapXNode.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/xnode/MapXNode.java @@ -270,7 +270,7 @@ public boolean equals(Object o) { return false; } MapXNode other = (MapXNode) o; - return MiscUtil.unorderedCollectionEquals(this.values(), other.values()); + return MiscUtil.unorderedCollectionEquals(this.entrySet(), other.entrySet()); } public int hashCode() { @@ -379,7 +379,39 @@ public XNode setValue(XNode value) { public String toString() { return "E(" + key + ": " + value + ")"; } - - } + + /** + * Compares two entries of the MapXNode. + * + * It is questionable whether to compare QNames exactly or approximately (using QNameUtil.match) here. + * For the time being, exact comparison was chosen. The immediate reason is to enable correct + * processing of diff on RawTypes (e.g. to make "debug edit" to be able to change from xyz to c:xyz + * in element names, see MID-1969). + * + * TODO: In the long run, we have to think out where exactly we want to use approximate matching of QNames. + * E.g. it is reasonable to use it only where "deployer input" is expected (e.g. import of data objects), + * not in the internals of midPoint. + */ + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Entry entry = (Entry) o; + + if (key != null ? !key.equals(entry.key) : entry.key != null) return false; + if (value != null ? !value.equals(entry.value) : entry.value != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = key != null ? key.hashCode() : 0; + result = 31 * result + (value != null ? value.hashCode() : 0); + return result; + } + } } diff --git a/infra/schema/src/test/java/com/evolveum/midpoint/schema/TestParseDiffPatch.java b/infra/schema/src/test/java/com/evolveum/midpoint/schema/TestParseDiffPatch.java index d6c6aea0e05..feba8eefb93 100644 --- a/infra/schema/src/test/java/com/evolveum/midpoint/schema/TestParseDiffPatch.java +++ b/infra/schema/src/test/java/com/evolveum/midpoint/schema/TestParseDiffPatch.java @@ -427,13 +427,14 @@ public void testResource() throws SchemaException, SAXException, IOException, JA assertEquals("Wrong delta OID", "ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff", resourceDelta.getOid()); assertEquals("Wrong change type", ChangeType.MODIFY, resourceDelta.getChangeType()); Collection modifications = resourceDelta.getModifications(); - assertEquals("Unexpected number of modifications", 6, modifications.size()); + assertEquals("Unexpected number of modifications", 7, modifications.size()); PrismAsserts.assertContainerDelete(resourceDelta, ResourceType.F_SCHEMA); PrismAsserts.assertPropertyReplace(resourceDelta, pathTimeouts("update"), 3); PrismAsserts.assertPropertyReplace(resourceDelta, pathTimeouts("scriptOnResource"), 4); PrismAsserts.assertPropertyDelete(resourceDelta, new ItemPath(ResourceType.F_CONNECTOR_CONFIGURATION, new QName(SchemaTestConstants.NS_ICFC, "producerBufferSize")), 100); + PrismAsserts.assertPropertyReplaceSimple(resourceDelta, ResourceType.F_SYNCHRONIZATION); // Configuration properties changes assertConfigurationPropertyChange(resourceDelta, "principal"); assertConfigurationPropertyChange(resourceDelta, "credentials"); diff --git a/infra/schema/src/test/resources/diff/resource-after-ns-change.xml b/infra/schema/src/test/resources/diff/resource-after-ns-change.xml index 2a6a9a211c7..3689d95bae5 100644 --- a/infra/schema/src/test/resources/diff/resource-after-ns-change.xml +++ b/infra/schema/src/test/resources/diff/resource-after-ns-change.xml @@ -209,5 +209,18 @@ - + + + + + + c:name + + $account/attributes/ri:uid + + + + + + diff --git a/infra/schema/src/test/resources/diff/resource-after.xml b/infra/schema/src/test/resources/diff/resource-after.xml index 1b9fa7f2e60..f997ae30044 100644 --- a/infra/schema/src/test/resources/diff/resource-after.xml +++ b/infra/schema/src/test/resources/diff/resource-after.xml @@ -87,5 +87,18 @@ - + + + + + + c:name + + $account/attributes/ri:uid + + + + + + diff --git a/infra/schema/src/test/resources/diff/resource-before.xml b/infra/schema/src/test/resources/diff/resource-before.xml index cfa3a90d337..666f10a9fbc 100644 --- a/infra/schema/src/test/resources/diff/resource-before.xml +++ b/infra/schema/src/test/resources/diff/resource-before.xml @@ -201,5 +201,17 @@ - + + + + + + c:name + + $account/attributes/ri:uid + + + + +