use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class TestPrismObjectConstruction method testClone.
@Test
public void testClone() throws Exception {
final String TEST_NAME = "testClone";
PrismInternalTestUtil.displayTestTitle(TEST_NAME);
// GIVEN
PrismContext ctx = constructInitializedPrismContext();
PrismObjectDefinition<UserType> userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO, "user"));
PrismObject<UserType> user = userDefinition.instantiate();
fillInUserDrake(user, true);
// precondition
assertUserDrake(user, true, ctx);
// WHEN
PrismObject<UserType> clone = user.clone();
// THEN
System.out.println("Cloned user:");
System.out.println(clone.debugDump());
// Check if the values are correct, also checking definitions
assertUserDrake(clone, true, ctx);
}
use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class TestPrismObjectConstruction method testDefinitionlessConstructionAndSchemaApplication.
/**
* Construct object without schema. Starts by creating object "out of the blue" and
* the working downwards. Then apply the schema. Check definitions.
*/
// @Test
public void testDefinitionlessConstructionAndSchemaApplication() throws Exception {
final String TEST_NAME = "testDefinitionlessConstructionAndSchemaApplication";
PrismInternalTestUtil.displayTestTitle(TEST_NAME);
// GIVEN
// No context needed (yet)
PrismObject<UserType> user = new PrismObject<UserType>(USER_QNAME, UserType.class);
// Fill-in object values, no schema checking
fillInUserDrake(user, false);
// Make sure the object is OK
PrismContext ctx = constructInitializedPrismContext();
assertUserDrake(user, false, ctx);
PrismObjectDefinition<UserType> userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO, "user"));
// WHEN
user.applyDefinition(userDefinition);
// THEN
System.out.println("User:");
System.out.println(user.debugDump());
// Check schema now
assertUserDrake(user, true, ctx);
}
use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class TestPrismObjectConstruction method testCloneEquals.
@Test
public void testCloneEquals() throws Exception {
final String TEST_NAME = "testCloneEquals";
PrismInternalTestUtil.displayTestTitle(TEST_NAME);
// GIVEN
PrismContext ctx = constructInitializedPrismContext();
PrismObjectDefinition<UserType> userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO, "user"));
PrismObject<UserType> user = userDefinition.instantiate();
fillInUserDrake(user, true);
PrismObject<UserType> clone = user.clone();
// WHEN, THEN
assertTrue("Clone not equal", clone.equals(user));
assertTrue("Clone not equivalent", clone.equivalent(user));
}
use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class TestPrismObjectConstruction method testConstructionWithSchema.
/**
* Construct object with schema. Starts by instantiating a definition and working downwards.
* All the items in the object should have proper definition.
*/
@Test
public void testConstructionWithSchema() throws Exception {
final String TEST_NAME = "testConstructionWithSchema";
PrismInternalTestUtil.displayTestTitle(TEST_NAME);
// GIVEN
PrismContext ctx = constructInitializedPrismContext();
PrismObjectDefinition<UserType> userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO, "user"));
// WHEN
PrismObject<UserType> user = userDefinition.instantiate();
// Fill-in object values, checking presence of definition while doing so
fillInUserDrake(user, true);
// THEN
System.out.println("User:");
System.out.println(user.debugDump());
// Check if the values are correct, also checking definitions
assertUserDrake(user, true, ctx);
}
use of javax.xml.namespace.QName in project midpoint by Evolveum.
the class TestPrismParsing method test300MeleeContext.
@Test
public void test300MeleeContext() throws Exception {
final String TEST_NAME = "test300MeleeContext";
PrismInternalTestUtil.displayTestTitle(TEST_NAME);
// GIVEN
PrismContext prismContext = constructInitializedPrismContext();
PrismObject<UserType> userJack = prismContext.parseObject(getFile(USER_JACK_FILE_BASENAME));
PrismContainer<Containerable> meleeContextContainer = userJack.findOrCreateContainer(new ItemPath(UserType.F_EXTENSION, EXTENSION_MELEE_CONTEXT_ELEMENT));
PrismReference opponentRef = meleeContextContainer.findOrCreateReference(EXTENSION_MELEE_CONTEXT_OPPONENT_REF_ELEMENT);
PrismObject<UserType> userBarbossa = prismContext.parseObject(getFile(USER_BARBOSSA_FILE_BASENAME));
// Cosmetics to make sure the equivalence assert below works
userBarbossa.setElementName(EXTENSION_MELEE_CONTEXT_OPPONENT_ELEMENT);
PrismReferenceValue opponentRefValue = new PrismReferenceValue();
opponentRefValue.setObject(userBarbossa);
opponentRef.add(opponentRefValue);
System.out.println("User jack:");
System.out.println(userJack.debugDump());
// WHEN
String elementJack = prismContext.serializeObjectToString(userJack, getOutputFormat());
// THEN
System.out.println("Serialized user jack:");
System.out.println(elementJack);
// TODO: see that there is really the serialized barbossa
// WHEN
PrismObject<UserType> reparsedUserJack = prismContext.parseObject(elementJack);
// THEN
System.out.println("Re-parsed user jack:");
System.out.println(reparsedUserJack.debugDump());
PrismReference reparsedOpponentRef = reparsedUserJack.findReference(new ItemPath(UserType.F_EXTENSION, EXTENSION_MELEE_CONTEXT_ELEMENT, EXTENSION_MELEE_CONTEXT_OPPONENT_REF_ELEMENT));
assertNotNull("No opponent ref (reparsed)", reparsedOpponentRef);
PrismReferenceValue reparsedOpponentRefValue = reparsedOpponentRef.getValue();
assertNotNull("No opponent ref value (reparsed)", reparsedOpponentRefValue);
PrismObject<UserType> reparsedUserBarbossa = reparsedOpponentRefValue.getObject();
assertNotNull("No object in opponent ref value (reparsed)", reparsedUserBarbossa);
PrismAsserts.assertEquivalent("User barbossa", userBarbossa, reparsedUserBarbossa);
// Make the original user jack suitable for comparison.
// Some of the accountRef information is (intentionally) lost in re-parsing therefore erase it before comparing
PrismReference jackAccountRef = userJack.findReference(UserType.F_ACCOUNT_REF);
for (PrismReferenceValue accRefVal : jackAccountRef.getValues()) {
String oid = accRefVal.getOid();
QName targetType = accRefVal.getTargetType();
accRefVal.setObject(null);
accRefVal.setOid(oid);
accRefVal.setTargetType(targetType);
}
PrismAsserts.assertEquivalent("User jack", userJack, reparsedUserJack);
}
Aggregations