use of com.evolveum.midpoint.prism.foo.UserType 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 com.evolveum.midpoint.prism.foo.UserType 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 com.evolveum.midpoint.prism.foo.UserType 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);
}
use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.
the class TestUnknownItems method test110ParseWrongNamespaceStrict.
// Currently we simply mark the unknown value as raw.
// This might or might not be correct.
// (We should probably throw SchemaException instead.)
// TODO discuss this
@Test(enabled = false, expectedExceptions = SchemaException.class)
public void test110ParseWrongNamespaceStrict() throws Exception {
final String TEST_NAME = "test110ParseWrongNamespaceStrict";
PrismInternalTestUtil.displayTestTitle(TEST_NAME);
// GIVEN
PrismContext prismContext = constructInitializedPrismContext();
// WHEN+THEN
PrismObject<UserType> user = prismContext.parseObject(WRONG_NAMESPACE_FILE);
System.out.println("User:");
System.out.println(user.debugDump());
assertNotNull(user);
}
use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.
the class TestUnknownItems method test020ParseWrongItemCompat.
@Test
public void test020ParseWrongItemCompat() throws Exception {
final String TEST_NAME = "testParseWrongItemCompat";
PrismInternalTestUtil.displayTestTitle(TEST_NAME);
// GIVEN
PrismContext prismContext = constructInitializedPrismContext();
// WHEN
PrismObject<UserType> user = prismContext.parserFor(WRONG_ITEM_FILE).compat().parse();
// THEN
System.out.println("User:");
System.out.println(user.debugDump());
assertNotNull(user);
}
Aggregations