Skip to content

Commit

Permalink
Making prismContext optional in deltas.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jul 11, 2014
1 parent f936865 commit 392fa1d
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 106 deletions.
Expand Up @@ -77,31 +77,31 @@ protected ItemDelta(ItemDefinition itemDefinition, PrismContext prismContext) {
if (itemDefinition == null) {
throw new IllegalArgumentException("Attempt to create item delta without a definition");
}
checkPrismContext(prismContext, itemDefinition);
//checkPrismContext(prismContext, itemDefinition);
this.prismContext = prismContext;
this.elementName = itemDefinition.getName();
this.parentPath = new ItemPath();
this.definition = itemDefinition;
}

protected ItemDelta(QName elementName, ItemDefinition itemDefinition, PrismContext prismContext) {
checkPrismContext(prismContext, itemDefinition);
//checkPrismContext(prismContext, itemDefinition);
this.prismContext = prismContext;
this.elementName = elementName;
this.parentPath = new ItemPath();
this.definition = itemDefinition;
}

protected ItemDelta(ItemPath parentPath, QName elementName, ItemDefinition itemDefinition, PrismContext prismContext) {
checkPrismContext(prismContext, itemDefinition);
//checkPrismContext(prismContext, itemDefinition);
this.prismContext = prismContext;
this.elementName = elementName;
this.parentPath = parentPath;
this.definition = itemDefinition;
}

protected ItemDelta(ItemPath path, ItemDefinition itemDefinition, PrismContext prismContext) {
checkPrismContext(prismContext, itemDefinition);
//checkPrismContext(prismContext, itemDefinition);
this.prismContext = prismContext;

if (path == null) {
Expand All @@ -120,11 +120,12 @@ protected ItemDelta(ItemPath path, ItemDefinition itemDefinition, PrismContext p
this.definition = itemDefinition;
}

private void checkPrismContext(PrismContext prismContext, ItemDefinition itemDefinition) {
if (prismContext == null) {
throw new IllegalStateException("No prismContext in delta for " + itemDefinition);
}
}
// currently unused; we allow deltas without prismContext, except for some operations (e.g. serialization to ItemDeltaType)
// private void checkPrismContext(PrismContext prismContext, ItemDefinition itemDefinition) {
// if (prismContext == null) {
// throw new IllegalStateException("No prismContext in delta for " + itemDefinition);
// }
// }

public QName getElementName() {
return elementName;
Expand Down
Expand Up @@ -100,7 +100,7 @@ public class ObjectDelta<T extends Objectable> implements DebugDumpable, Visitab
public ObjectDelta(Class<T> objectTypeClass, ChangeType changeType, PrismContext prismContext) {
Validate.notNull(objectTypeClass,"No objectTypeClass");
Validate.notNull(changeType,"No changeType");
Validate.notNull(prismContext, "No prismContext");
//Validate.notNull(prismContext, "No prismContext");

this.changeType = changeType;
this.objectTypeClass = objectTypeClass;
Expand Down
Expand Up @@ -28,7 +28,6 @@
import javax.xml.validation.Schema;
import javax.xml.validation.Validator;

import com.evolveum.midpoint.prism.util.PrismTestUtil;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
Expand All @@ -54,7 +53,7 @@ public class TestPrismObjectConstruction {


@BeforeSuite
public void setupDebug() throws SAXException, IOException, SchemaException {
public void setupDebug() {
PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX);
}

Expand All @@ -74,7 +73,7 @@ public void testConstructionWithSchema() throws Exception {
// WHEN
PrismObject<UserType> user = userDefinition.instantiate();
// Fill-in object values, checking presence of definition while doing so
fillInUserDrake(user, true, ctx);
fillInUserDrake(user, true);

// THEN
System.out.println("User:");
Expand All @@ -93,18 +92,18 @@ public void testDefinitionlessConstruction() throws Exception {
PrismInternalTestUtil.displayTestTitle(TEST_NAME);

// GIVEN
PrismContext ctx = constructInitializedPrismContext(); // we need this context to do even basic object operations (mergeValue in this case)
// No context needed

// WHEN
PrismObject<UserType> user = new PrismObject<UserType>(USER_QNAME, UserType.class);
user.revive(ctx); // there is no definition yet
// Fill-in object values, no schema checking
fillInUserDrake(user, false, ctx);
fillInUserDrake(user, false);

// THEN
System.out.println("User:");
System.out.println(user.debugDump());
// Check if the values are correct, no schema checking
PrismContext ctx = constructInitializedPrismContext();
assertUserDrake(user, false, ctx);
}

Expand All @@ -118,11 +117,12 @@ public void testDefinitionlessConstructionAndSchemaApplication() throws Exceptio
PrismInternalTestUtil.displayTestTitle(TEST_NAME);

// GIVEN
// No context needed (yet)
PrismObject<UserType> user = new PrismObject<UserType>(USER_QNAME, UserType.class);
PrismContext ctx = constructInitializedPrismContext();
// Fill-in object values, no schema checking
fillInUserDrake(user, false, ctx);
fillInUserDrake(user, false);
// Make sure the object is OK
PrismContext ctx = constructInitializedPrismContext();
assertUserDrake(user, false, ctx);


Expand Down Expand Up @@ -150,7 +150,7 @@ public void testClone() throws Exception {
PrismContext ctx = constructInitializedPrismContext();
PrismObjectDefinition<UserType> userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO,"user"));
PrismObject<UserType> user = userDefinition.instantiate();
fillInUserDrake(user, true, ctx);
fillInUserDrake(user, true);
// precondition
assertUserDrake(user, true, ctx);

Expand All @@ -173,7 +173,7 @@ public void testCloneEquals() throws Exception {
PrismContext ctx = constructInitializedPrismContext();
PrismObjectDefinition<UserType> userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO,"user"));
PrismObject<UserType> user = userDefinition.instantiate();
fillInUserDrake(user, true, ctx);
fillInUserDrake(user, true);
PrismObject<UserType> clone = user.clone();

// WHEN, THEN
Expand All @@ -182,7 +182,7 @@ public void testCloneEquals() throws Exception {
}


private void fillInUserDrake(PrismObject<UserType> user, boolean assertDefinitions, PrismContext prismContext) throws SchemaException {
private void fillInUserDrake(PrismObject<UserType> user, boolean assertDefinitions) throws SchemaException {
user.setOid(USER_OID);

// fullName
Expand Down Expand Up @@ -226,7 +226,7 @@ private void fillInUserDrake(PrismObject<UserType> user, boolean assertDefinitio
assertEquals("Wrong number of assignment values (empty)", 0, assignmentContainer.getValues().size());

// assignment values: construct assignment value as a new container "out of the blue" and then add it.
PrismContainer<AssignmentType> assBlueContainer = new PrismContainer<AssignmentType>(USER_ASSIGNMENT_QNAME, prismContext);
PrismContainer<AssignmentType> assBlueContainer = new PrismContainer<AssignmentType>(USER_ASSIGNMENT_QNAME);
PrismProperty<String> assBlueDescriptionProperty = assBlueContainer.findOrCreateProperty(USER_DESCRIPTION_QNAME);
assBlueDescriptionProperty.addValue(new PrismPropertyValue<String>("Assignment created out of the blue"));
PrismAsserts.assertParentConsistency(user);
Expand All @@ -235,7 +235,7 @@ private void fillInUserDrake(PrismObject<UserType> user, boolean assertDefinitio
PrismAsserts.assertParentConsistency(user);

// assignment values: construct assignment value as a new container value "out of the blue" and then add it.
PrismContainerValue<AssignmentType> assCyanContainerValue = new PrismContainerValue<AssignmentType>(prismContext);
PrismContainerValue<AssignmentType> assCyanContainerValue = new PrismContainerValue<AssignmentType>();
PrismProperty<String> assCyanDescriptionProperty = assCyanContainerValue.findOrCreateProperty(USER_DESCRIPTION_QNAME);
assCyanDescriptionProperty.addValue(new PrismPropertyValue<String>("Assignment created out of the cyan"));
assignmentContainer.mergeValue(assCyanContainerValue);
Expand Down

0 comments on commit 392fa1d

Please sign in to comment.