Skip to content

Commit

Permalink
Fixing MID-1969, point #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jul 12, 2014
1 parent d37082d commit 80f22d1
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 11 deletions.
Expand Up @@ -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 <T> void assertReplace(PropertyDelta<T> propertyDelta, T... expectedValues) {

public static void assertPropertyReplaceSimple(ObjectDelta<?> objectDelta, QName propertyName) {
PropertyDelta<Object> 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 <T> void assertReplace(PropertyDelta<T> propertyDelta, T... expectedValues) {
assertSet("delta "+propertyDelta+" for "+propertyDelta.getElementName(), "replace", propertyDelta.getValuesToReplace(), expectedValues);
}

Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}

}
Expand Up @@ -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<? extends ItemDelta> 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");
Expand Down
Expand Up @@ -209,5 +209,18 @@
<cap:testConnection/>
</configured>
</capabilities>


<synchronization>
<objectSynchronization>
<correlation>
<q:equal xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3">
<q:path>c:name</q:path>
<expression>
<path>$account/attributes/ri:uid</path>
</expression>
</q:equal>
</correlation>
</objectSynchronization>
</synchronization>

</resource>
15 changes: 14 additions & 1 deletion infra/schema/src/test/resources/diff/resource-after.xml
Expand Up @@ -87,5 +87,18 @@
<cap:testConnection/>
</configured>
</capabilities>


<synchronization>
<objectSynchronization>
<correlation>
<q:equal xmlns:q="http://CHANGED-CHANGED-CHANGED">
<q:path>c:name</q:path>
<expression>
<path>$account/attributes/ri:uid</path>
</expression>
</q:equal>
</correlation>
</objectSynchronization>
</synchronization>

</resource>
14 changes: 13 additions & 1 deletion infra/schema/src/test/resources/diff/resource-before.xml
Expand Up @@ -201,5 +201,17 @@
<cap:testConnection/>
</configured>
</capabilities>


<synchronization>
<objectSynchronization>
<correlation>
<q:equal xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3">
<q:path>c:name</q:path>
<expression>
<path>$account/attributes/ri:uid</path>
</expression>
</q:equal>
</correlation>
</objectSynchronization>
</synchronization>
</resource>

0 comments on commit 80f22d1

Please sign in to comment.