Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Dec 8, 2016
2 parents f5d41fb + bf9b401 commit 95a5a8f
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 12 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -102,6 +102,12 @@ public static <T> void assertPropertyValue(PrismContainer<?> container, QName pr
assertSame("Wrong parent for value of container "+container, container, containerValue.getParent());
assertPropertyValue(containerValue, propQName, realPropValues);
}

public static <T> void assertPropertyValueMatch(PrismContainer<?> container, QName propQName, MatchingRule<T> matchingRule, T... realPropValues) throws SchemaException {
PrismContainerValue<?> containerValue = container.getValue();
assertSame("Wrong parent for value of container "+container, container, containerValue.getParent());
assertPropertyValueMatch(containerValue, propQName, matchingRule, realPropValues);
}

public static <T> void assertPropertyValue(PrismContainerValue<?> containerValue, QName propQName, T... realPropValues) {
PrismProperty<T> property = containerValue.findProperty(propQName);
Expand All @@ -110,6 +116,13 @@ public static <T> void assertPropertyValue(PrismContainerValue<?> containerValue
assertPropertyValueDesc(property, containerValue.getParent().toString(), realPropValues);
}

public static <T> void assertPropertyValueMatch(PrismContainerValue<?> containerValue, QName propQName, MatchingRule<T> matchingRule, T... realPropValues) throws SchemaException {
PrismProperty<T> property = containerValue.findProperty(propQName);
assertNotNull("Property " + propQName + " not found in " + containerValue.getParent(), property);
assertSame("Wrong parent for property " + property, containerValue, property.getParent());
assertPropertyValueDesc(property, matchingRule, containerValue.getParent().toString(), realPropValues);
}

public static <T> void assertPropertyValue(PrismContainer<?> container, ItemPath propPath, T... realPropValues) {
PrismContainerValue<?> containerValue = container.getValue();
assertSame("Wrong parent for value of container "+container, container, containerValue.getParent());
Expand All @@ -125,13 +138,22 @@ public static <T> void assertPropertyValue(PrismContainerValue<?> containerValue
public static <T> void assertPropertyValue(PrismProperty<T> property, T... expectedPropValues) {
assertPropertyValueDesc(property, null, expectedPropValues);
}

public static <T> void assertPropertyValueDesc(PrismProperty<T> property, String contextDescrition, T... expectedPropValues) {
try {
assertPropertyValueDesc(property, null, contextDescrition, expectedPropValues);
} catch (SchemaException e) {
// null matching rule, cannot happen
throw new RuntimeException(e.getMessage(), e);
}
}

public static <T> void assertPropertyValueDesc(PrismProperty<T> property, MatchingRule<T> matchingRule, String contextDescrition, T... expectedPropValues) throws SchemaException {
Collection<PrismPropertyValue<T>> pvals = property.getValues();
QName propQName = property.getElementName();
assert pvals != null && !pvals.isEmpty() : "Empty property "+propQName;
assertSet("property "+propQName + (contextDescrition == null ? "" : " in " + contextDescrition),
"value", pvals, expectedPropValues);
"value", matchingRule, pvals, expectedPropValues);
}

public static <T> void assertPropertyValues(String message, Collection<T> expected, Collection<PrismPropertyValue<T>> results) {
Expand Down Expand Up @@ -811,20 +833,33 @@ public static <O extends Objectable> void assertEquivalent(String message, Prism
assert false: message + ": " + suffix;
}

private static <T> void assertSet(String inMessage, String setName, MatchingRule<T> matchingRule, Collection<PrismPropertyValue<T>> actualPValues, T[] expectedValues) throws SchemaException {
assertValues(setName + " set in " + inMessage, matchingRule, actualPValues, expectedValues);
}

private static <T> void assertSet(String inMessage, String setName, Collection<PrismPropertyValue<T>> actualPValues, T[] expectedValues) {
assertValues(setName + " set in " + inMessage, actualPValues, expectedValues);
}

public static <T> void assertValues(String message, Collection<PrismPropertyValue<T>> actualPValues, T... expectedValues) {
try {
assertValues(message, null, actualPValues, expectedValues);
} catch (SchemaException e) {
// null matching rule, cannot happen
throw new RuntimeException(e.getMessage(), e);
}
}

public static <T> void assertValues(String message, MatchingRule<T> matchingRule, Collection<PrismPropertyValue<T>> actualPValues, T... expectedValues) throws SchemaException {
assertNotNull("Null set in " + message, actualPValues);
if (expectedValues.length != actualPValues.size()) {
fail("Wrong number of values in " + message+ "; expected "+expectedValues.length+" (real values) "
+PrettyPrinter.prettyPrint(expectedValues)+"; has "+actualPValues.size()+" (pvalues) "+actualPValues);
}
for (PrismPropertyValue<?> actualPValue: actualPValues) {
for (PrismPropertyValue<T> actualPValue: actualPValues) {
boolean found = false;
for (T value: expectedValues) {
if (value.equals(actualPValue.getValue())) {
if (PrismUtil.equals(value, actualPValue.getValue(), matchingRule)) {
found = true;
}
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor;
import com.evolveum.midpoint.prism.marshaller.PrismUnmarshaller;
import com.evolveum.midpoint.prism.match.MatchingRule;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.polystring.PolyStringNormalizer;
import com.evolveum.midpoint.prism.xml.XsdTypeMapper;
Expand Down Expand Up @@ -190,4 +191,18 @@ public static <O extends Objectable> void setDeltaOldValue(PrismObject<O> oldObj
}
}

public static <T> boolean equals(T a, T b, MatchingRule<T> matchingRule) throws SchemaException {
if (a == null && b == null) {
return true;
}
if (a == null || b == null) {
return false;
}
if (matchingRule == null) {
return a.equals(b);
} else {
return matchingRule.match(a, b);
}
}

}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -425,7 +425,7 @@ public static void assertUserJackContent(PrismObject<UserType> user, boolean exp

}

private static void assertUserJackExtension(PrismObject<UserType> user) {
private static void assertUserJackExtension(PrismObject<UserType> user) throws SchemaException {

PrismContainer<?> extension = user.getExtension();
assertContainerDefinition(extension, "extension", DOMUtil.XSD_ANY, 0, 1);
Expand Down Expand Up @@ -463,7 +463,7 @@ private static void assertUserJackExtension(PrismObject<UserType> user) {

}

public static void assertPropertyValue(PrismContainer<?> container, String propName, Object propValue) {
public static void assertPropertyValue(PrismContainer<?> container, String propName, Object propValue) throws SchemaException {
QName propQName = new QName(NS_FOO, propName);
PrismAsserts.assertPropertyValue(container, propQName, propValue);
}
Expand Down
Expand Up @@ -632,7 +632,12 @@ protected QName getGroupObjectClass(ResourceType resourceType) {
}

protected void assertShadowCommon(PrismObject<ShadowType> shadow, String oid, String username, ResourceType resourceType,
QName objectClass, MatchingRule<String> nameMatchingRule, boolean requireNormalizedIdentfiers) throws SchemaException {
QName objectClass, MatchingRule<String> nameMatchingRule, boolean requireNormalizedIdentfiers) throws SchemaException {
assertShadowCommon(shadow, oid, username, resourceType, objectClass, nameMatchingRule, requireNormalizedIdentfiers, false);
}

protected void assertShadowCommon(PrismObject<ShadowType> shadow, String oid, String username, ResourceType resourceType,
QName objectClass, final MatchingRule<String> nameMatchingRule, boolean requireNormalizedIdentfiers, boolean useMatchingRuleForShadowName) throws SchemaException {
assertShadow(shadow);
if (oid != null) {
assertEquals("Shadow OID mismatch (prism)", oid, shadow.getOid());
Expand All @@ -647,7 +652,39 @@ protected void assertShadowCommon(PrismObject<ShadowType> shadow, String oid, St
assertNotNull("Null attributes in shadow for "+username, attributesContainer);
assertFalse("Empty attributes in shadow for "+username, attributesContainer.isEmpty());

PrismAsserts.assertPropertyValue(shadow, ShadowType.F_NAME, PrismTestUtil.createPolyString(username));
if (useMatchingRuleForShadowName) {
MatchingRule<PolyString> polyMatchingRule = new MatchingRule<PolyString>() {

@Override
public QName getName() {
return nameMatchingRule.getName();
}

@Override
public boolean isSupported(QName xsdType) {
return nameMatchingRule.isSupported(xsdType);
}

@Override
public boolean match(PolyString a, PolyString b) throws SchemaException {
return nameMatchingRule.match(a.getOrig(), b.getOrig());
}

@Override
public boolean matchRegex(PolyString a, String regex) throws SchemaException {
return nameMatchingRule.matchRegex(a.getOrig(), regex);
}

@Override
public PolyString normalize(PolyString original) throws SchemaException {
return new PolyString(nameMatchingRule.normalize(original.getOrig()));
}

};
PrismAsserts.assertPropertyValueMatch(shadow, ShadowType.F_NAME, polyMatchingRule, PrismTestUtil.createPolyString(username));
} else {
PrismAsserts.assertPropertyValue(shadow, ShadowType.F_NAME, PrismTestUtil.createPolyString(username));
}

RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType);
ObjectClassComplexTypeDefinition ocDef = rSchema.findObjectClassDefinition(objectClass);
Expand Down
Expand Up @@ -902,7 +902,7 @@ protected void assertAccountRepoShadow(PrismObject<ShadowType> shadow, String dn
}

protected void assertGroupShadow(PrismObject<ShadowType> shadow, String dn) throws SchemaException {
assertShadowCommon(shadow, null, dn, resourceType, getGroupObjectClass(), ciMatchingRule, false);
assertShadowCommon(shadow, null, dn, resourceType, getGroupObjectClass(), ciMatchingRule, false, true);
}

protected long roundTsDown(long ts) {
Expand Down

0 comments on commit 95a5a8f

Please sign in to comment.