Skip to content

Commit

Permalink
Fixing more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Oct 12, 2017
1 parent 00f11c7 commit f751205
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
Expand Up @@ -39,6 +39,8 @@
import com.evolveum.midpoint.audit.api.AuditEventRecord;
import com.evolveum.midpoint.audit.api.AuditEventStage;
import com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismPropertyValue;
Expand Down Expand Up @@ -136,29 +138,27 @@ public void test100RecomputeAll() throws Exception {
new NameItemPathSegment(AssignmentType.F_CONSTRUCTION),
new IdItemPathSegment(60004L),
new NameItemPathSegment(ConstructionType.F_ATTRIBUTE));
PrismProperty<ResourceAttributeDefinitionType> attributeProperty = rolePirate.findProperty(attrItemPath);
PrismContainer<ResourceAttributeDefinitionType> attributeCont = rolePirate.findContainer(attrItemPath);
assertNotNull("No attribute property in "+rolePirate);
PrismPropertyValue<ResourceAttributeDefinitionType> oldAttrPVal = null;
for (PrismPropertyValue<ResourceAttributeDefinitionType> pval: attributeProperty.getValues()) {
ResourceAttributeDefinitionType attrType = pval.getValue();
PrismContainerValue<ResourceAttributeDefinitionType> oldAttrCVal = null;
for (PrismContainerValue<ResourceAttributeDefinitionType> cval: attributeCont.getValues()) {
ResourceAttributeDefinitionType attrType = cval.getValue();
if (ItemPathUtil.getOnlySegmentQName(attrType.getRef()).getLocalPart().equals(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME)) {
oldAttrPVal = pval;
oldAttrCVal = cval;
}
}
assertNotNull("Definition for weapon attribute not found in "+rolePirate);
PrismPropertyValue<ResourceAttributeDefinitionType> newAttrPVal = oldAttrPVal.clone();
JAXBElement<?> cutlassExpressionEvalJaxbElement = newAttrPVal.getValue().getOutbound().getExpression().getExpressionEvaluator().get(0);
PrismContainerValue<ResourceAttributeDefinitionType> newAttrCVal = oldAttrCVal.clone();
JAXBElement<?> cutlassExpressionEvalJaxbElement = newAttrCVal.getValue().getOutbound().getExpression().getExpressionEvaluator().get(0);
RawType cutlassValueEvaluator = (RawType) cutlassExpressionEvalJaxbElement.getValue();
RawType daggerValueEvaluator = new RawType(new PrimitiveXNode<String>("dagger"), prismContext);
JAXBElement<?> daggerExpressionEvalJaxbElement = new JAXBElement<Object>(SchemaConstants.C_VALUE, Object.class, daggerValueEvaluator);
newAttrPVal.getValue().getOutbound().getExpression().getExpressionEvaluator().add(daggerExpressionEvalJaxbElement);
newAttrPVal.getValue().getOutbound().setStrength(MappingStrengthType.STRONG);

ObjectDelta<RoleType> rolePirateDelta = ObjectDelta.createModificationDeleteProperty(RoleType.class, ROLE_PIRATE_OID,
attrItemPath, prismContext, oldAttrPVal.getValue());
IntegrationTestTools.displayJaxb("AAAAAAAAAAA", newAttrPVal.getValue(), ConstructionType.F_ATTRIBUTE);
display("BBBBBB", newAttrPVal.getValue().toString());
rolePirateDelta.addModificationAddProperty(attrItemPath, newAttrPVal.getValue());
newAttrCVal.getValue().getOutbound().getExpression().getExpressionEvaluator().add(daggerExpressionEvalJaxbElement);
newAttrCVal.getValue().getOutbound().setStrength(MappingStrengthType.STRONG);

ObjectDelta<RoleType> rolePirateDelta = ObjectDelta.createModificationDeleteContainer(RoleType.class, ROLE_PIRATE_OID,
attrItemPath, prismContext, oldAttrCVal.getValue().clone());
rolePirateDelta.addModificationAddContainer(attrItemPath, newAttrCVal.getValue());

display("Role pirate delta", rolePirateDelta);
modelService.executeChanges(MiscSchemaUtil.createCollection(rolePirateDelta), null, task, result);
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2013-2015 Evolveum
~ Copyright (c) 2013-2017 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 @@ -28,7 +28,7 @@

<item>
<ref>roleType</ref>
<valueEnumerationRef oid="70000000-0000-0000-1111-000000000021"/>
<valueEnumerationRef oid="70000000-0000-0000-1111-000000000021" type="LookupTableType"/>
</item>

<mapping>
Expand Down
Expand Up @@ -149,8 +149,8 @@ private void addGetCompare(File file) throws Exception {
int count = 0;
elements = prismContext.parserFor(file).parseObjects();
for (int i = 0; i < elements.size(); i++) {
PrismObject object = elements.get(i);
try {
PrismObject object = elements.get(i);
object.asObjectable().setOid(oids.get(i));

Class<? extends ObjectType> clazz = object.getCompileTimeClass();
Expand All @@ -168,7 +168,7 @@ private void addGetCompare(File file) throws Exception {
}
PrismObject<? extends ObjectType> newObject = repositoryService.getObject(clazz, oids.get(i), o, result);

LOGGER.info("Old\n{}\nnew\n{}", new Object[]{object.debugDump(3), newObject.debugDump(3)});
LOGGER.info("AFTER READ: {}\nOld\n{}\nnew\n{}", object, object.debugDump(3), newObject.debugDump(3));
checkContainersSize(newObject, object);
System.out.println("OLD: " + object.findProperty(ObjectType.F_NAME).getValue());
System.out.println("NEW: " + newObject.findProperty(ObjectType.F_NAME).getValue());
Expand Down Expand Up @@ -196,9 +196,9 @@ private void addGetCompare(File file) throws Exception {
}
LOGGER.error("{}", prismContext.serializeObjectToString(newObject, PrismContext.LANG_XML));
}
} catch (Exception ex) {
LOGGER.error("Exception occurred", ex);
throw ex;
} catch (Throwable ex) {
LOGGER.error("Exception occurred for {}", object, ex);
throw new RuntimeException("Exception during processing of "+object+": "+ex.getMessage(), ex);
}
}

Expand All @@ -215,7 +215,7 @@ private Integer size(PrismContainerValue value) {

private void checkContainerValuesSize(QName parentName, PrismContainerValue newValue, PrismContainerValue oldValue) {
LOGGER.info("Checking: " + parentName);
AssertJUnit.assertEquals("Count doesn't match for '" + parentName + "'", size(oldValue), size(newValue));
AssertJUnit.assertEquals("Count doesn't match for '" + parentName + "' id="+newValue.getId(), size(oldValue), size(newValue));

List<QName> checked = new ArrayList<QName>();

Expand Down Expand Up @@ -248,6 +248,11 @@ private void checkContainersSize(PrismContainer newContainer, PrismContainer old
newContainer.getElementName(), newContainer.size(), oldContainer.size());
AssertJUnit.assertEquals(newContainer.size(), oldContainer.size());

PrismContainerDefinition def = oldContainer.getDefinition();
if (def != null && def.isMultiValue()) {
// Comparison item-by-item is not reliable
return;
}
List<Long> checked = new ArrayList<Long>();
List<PrismContainerValue> newValues = newContainer.getValues();
for (PrismContainerValue value : newValues) {
Expand Down

0 comments on commit f751205

Please sign in to comment.