Search in sources :

Example 16 with UserType

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));
}
Also used : QName(javax.xml.namespace.QName) UserType(com.evolveum.midpoint.prism.foo.UserType) Test(org.testng.annotations.Test)

Example 17 with UserType

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);
}
Also used : QName(javax.xml.namespace.QName) UserType(com.evolveum.midpoint.prism.foo.UserType) Test(org.testng.annotations.Test)

Example 18 with UserType

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);
}
Also used : QName(javax.xml.namespace.QName) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 19 with UserType

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);
}
Also used : PrismInternalTestUtil.constructInitializedPrismContext(com.evolveum.midpoint.prism.PrismInternalTestUtil.constructInitializedPrismContext) UserType(com.evolveum.midpoint.prism.foo.UserType) Test(org.testng.annotations.Test)

Example 20 with UserType

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);
}
Also used : PrismInternalTestUtil.constructInitializedPrismContext(com.evolveum.midpoint.prism.PrismInternalTestUtil.constructInitializedPrismContext) UserType(com.evolveum.midpoint.prism.foo.UserType) Test(org.testng.annotations.Test)

Aggregations

UserType (com.evolveum.midpoint.prism.foo.UserType)30 Test (org.testng.annotations.Test)27 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)14 QName (javax.xml.namespace.QName)10 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 AssignmentType (com.evolveum.midpoint.prism.foo.AssignmentType)7 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)7 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)6 ActivationType (com.evolveum.midpoint.prism.foo.ActivationType)4 PrismInternalTestUtil.constructInitializedPrismContext (com.evolveum.midpoint.prism.PrismInternalTestUtil.constructInitializedPrismContext)3 Document (org.w3c.dom.Document)3 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)2 SchemaRegistryImpl (com.evolveum.midpoint.prism.schema.SchemaRegistryImpl)2 RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 Element (org.w3c.dom.Element)2 AccountConstructionType (com.evolveum.midpoint.prism.foo.AccountConstructionType)1 AccountType (com.evolveum.midpoint.prism.foo.AccountType)1 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)1 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)1