Search in sources :

Example 6 with UserType

use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.

the class TestDiff method testContainerValueDiffDesciptionNoPath.

@Test
public void testContainerValueDiffDesciptionNoPath() throws Exception {
    System.out.println("\n\n===[ testContainerValueDiffDesciptionNoPath ]===\n");
    // GIVEN
    PrismObjectDefinition<UserType> userDef = getUserTypeDefinition();
    PrismContainerDefinition<AssignmentType> assignmentContDef = userDef.findContainerDefinition(UserType.F_ASSIGNMENT);
    PrismContainer<AssignmentType> ass1 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass1cval = ass1.createNewValue();
    ass1cval.setPropertyRealValue(AssignmentType.F_DESCRIPTION, "blah blah", PrismTestUtil.getPrismContext());
    PrismContainer<AssignmentType> ass2 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass2cval = ass2.createNewValue();
    ass2cval.setPropertyRealValue(AssignmentType.F_DESCRIPTION, "chamalalia patlama paprtala", PrismTestUtil.getPrismContext());
    // WHEN
    Collection<? extends ItemDelta> modifications = ass1cval.diff(ass2cval);
    // THEN
    assertNotNull(modifications);
    System.out.println(DebugUtil.debugDump(modifications));
    assertEquals("Unexpected number of midifications", 1, modifications.size());
    PrismAsserts.assertPropertyReplace(modifications, new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_DESCRIPTION), "chamalalia patlama paprtala");
    ItemDelta.checkConsistence(modifications);
}
Also used : AssignmentType(com.evolveum.midpoint.prism.foo.AssignmentType) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 7 with UserType

use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.

the class TestDiff method testContainerDiffModificationsDesciption.

@Test
public void testContainerDiffModificationsDesciption() throws Exception {
    System.out.println("\n\n===[ testContainerDiffModificationsDesciption ]===\n");
    // GIVEN
    PrismObjectDefinition<UserType> userDef = getUserTypeDefinition();
    PrismContainerDefinition<AssignmentType> assignmentContDef = userDef.findContainerDefinition(UserType.F_ASSIGNMENT);
    PrismContainer<AssignmentType> ass1 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass1cval = ass1.createNewValue();
    ass1cval.setId(1L);
    ass1cval.setPropertyRealValue(AssignmentType.F_DESCRIPTION, "blah blah", PrismTestUtil.getPrismContext());
    PrismContainer<AssignmentType> ass2 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass2cval = ass2.createNewValue();
    ass2cval.setId(1L);
    ass2cval.setPropertyRealValue(AssignmentType.F_DESCRIPTION, "chamalalia patlama paprtala", PrismTestUtil.getPrismContext());
    // WHEN
    Collection<? extends ItemDelta> modifications = ass1.diffModifications(ass2);
    // THEN
    assertNotNull(modifications);
    System.out.println(DebugUtil.debugDump(modifications));
    assertEquals("Unexpected number of midifications", 1, modifications.size());
    PrismAsserts.assertPropertyReplace(modifications, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(1L), new NameItemPathSegment(AssignmentType.F_DESCRIPTION)), "chamalalia patlama paprtala");
    ItemDelta.checkConsistence(modifications);
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) AssignmentType(com.evolveum.midpoint.prism.foo.AssignmentType) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 8 with UserType

use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.

the class TestExtraSchema method testUserExtensionSchemaParseUser.

@Test
public void testUserExtensionSchemaParseUser() throws SAXException, IOException, SchemaException {
    System.out.println("===[ testUserExtensionSchemaParseUser ]===");
    Document dataDoc = DOMUtil.parseFile(USER_JACK_FILE_XML);
    PrismContext context = constructPrismContext();
    SchemaRegistryImpl reg = (SchemaRegistryImpl) context.getSchemaRegistry();
    reg.registerPrismSchemasFromDirectory(EXTRA_SCHEMA_DIR);
    context.initialize();
    // Parsing user
    // items from user extension are not correctly defined in the schema
    PrismObject<UserType> user = context.parserFor(DOMUtil.getFirstChildElement(dataDoc)).compat().parse();
    assertNotNull("No definition for user", user.getDefinition());
    System.out.println("Parsed root object:");
    System.out.println(user.debugDump());
    // TODO: assert user
    // Try javax schemas by validating a XML file
    Schema javaxSchema = reg.getJavaxSchema();
    assertNotNull(javaxSchema);
    Validator validator = javaxSchema.newValidator();
    DOMResult validationResult = new DOMResult();
    validator.validate(new DOMSource(dataDoc), validationResult);
//		System.out.println("Validation result:");
//		System.out.println(DOMUtil.serializeDOMToString(validationResult.getNode()));
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DOMResult(javax.xml.transform.dom.DOMResult) Schema(javax.xml.validation.Schema) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) Document(org.w3c.dom.Document) SchemaRegistryImpl(com.evolveum.midpoint.prism.schema.SchemaRegistryImpl) UserType(com.evolveum.midpoint.prism.foo.UserType) Validator(javax.xml.validation.Validator) Test(org.testng.annotations.Test)

Example 9 with UserType

use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.

the class TestPerformance method testPerfContainerNewValue.

/**
     * 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 testPerfContainerNewValue() throws Exception {
    final String TEST_NAME = "testPerfContainerNewValue";
    PrismInternalTestUtil.displayTestTitle(TEST_NAME);
    // GIVEN
    PrismContext ctx = constructInitializedPrismContext();
    PrismObjectDefinition<UserType> userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO, "user"));
    PrismObject<UserType> user = userDefinition.instantiate();
    PrismContainer<AssignmentType> assignmentContainer = user.findOrCreateContainer(UserType.F_ASSIGNMENT);
    PerfRecorder recorderCreateNewValue = new PerfRecorder("createNewValue");
    PerfRecorder recorderFindOrCreateProperty = new PerfRecorder("findOrCreateProperty");
    PerfRecorder recorderSetRealValue = new PerfRecorder("setRealValue");
    // WHEN
    for (int i = 0; i < ITERATIONS; i++) {
        long tsStart = System.nanoTime();
        PrismContainerValue<AssignmentType> newValue = assignmentContainer.createNewValue();
        long ts1 = System.nanoTime();
        PrismProperty<String> descriptionProperty = newValue.findOrCreateProperty(AssignmentType.F_DESCRIPTION);
        long ts2 = System.nanoTime();
        descriptionProperty.setRealValue("ass " + i);
        long tsEnd = System.nanoTime();
        recorderCreateNewValue.record(i, ((double) (ts1 - tsStart)) / 1000000);
        recorderFindOrCreateProperty.record(i, ((double) (ts2 - ts1)) / 1000000);
        recorderSetRealValue.record(i, ((double) (tsEnd - ts2)) / 1000000);
        System.out.println("Run " + i + ": total " + (((double) (tsEnd - tsStart)) / 1000000) + "ms");
    }
    // THEN
    System.out.println(recorderCreateNewValue.dump());
    System.out.println(recorderFindOrCreateProperty.dump());
    System.out.println(recorderCreateNewValue.dump());
    // Do not assert maximum here. The maximum values may jump around
    // quite wildly (e.g. because of garbage collector runs?)
    recorderCreateNewValue.assertAverageBelow(0.05D);
    recorderFindOrCreateProperty.assertAverageBelow(0.1D);
    recorderCreateNewValue.assertAverageBelow(0.05D);
    System.out.println("User:");
    System.out.println(user.debugDump());
}
Also used : QName(javax.xml.namespace.QName) AssignmentType(com.evolveum.midpoint.prism.foo.AssignmentType) UserType(com.evolveum.midpoint.prism.foo.UserType) Test(org.testng.annotations.Test)

Example 10 with UserType

use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.

the class TestPrismContext method testBasicSchemas.

@Test
public void testBasicSchemas() throws SchemaException, SAXException, IOException {
    System.out.println("===[ testBasicSchemas ]===");
    // WHEN
    PrismContext prismContext = constructInitializedPrismContext();
    // THEN
    assertNotNull("No prism context", prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull("No schema registry in context", schemaRegistry);
    System.out.println("Schema registry:");
    System.out.println(schemaRegistry.debugDump());
    PrismSchema fooSchema = schemaRegistry.findSchemaByNamespace(NS_FOO);
    System.out.println("Foo schema:");
    System.out.println(fooSchema.debugDump());
    // Assert USER definition
    PrismObjectDefinition<UserType> userDefinition = fooSchema.findObjectDefinitionByElementName(new QName(NS_FOO, "user"));
    assertNotNull("No user definition", userDefinition);
    System.out.println("User definition:");
    System.out.println(userDefinition.debugDump());
    PrismObjectDefinition<UserType> userDefinitionByClass = schemaRegistry.findObjectDefinitionByCompileTimeClass(UserType.class);
    assertTrue("Different user def", userDefinition == userDefinitionByClass);
    assertUserDefinition(userDefinition);
    // Assert ACCOUNT definition
    PrismObjectDefinition<AccountType> accountDefinition = fooSchema.findObjectDefinitionByElementName(new QName(NS_FOO, "account"));
    assertNotNull("No account definition", accountDefinition);
    System.out.println("Account definition:");
    System.out.println(accountDefinition.debugDump());
    PrismObjectDefinition<AccountType> accountDefinitionByClass = schemaRegistry.findObjectDefinitionByCompileTimeClass(AccountType.class);
    assertTrue("Different user def", accountDefinition == accountDefinitionByClass);
    assertAccountDefinition(accountDefinition);
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) QName(javax.xml.namespace.QName) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) UserType(com.evolveum.midpoint.prism.foo.UserType) AccountType(com.evolveum.midpoint.prism.foo.AccountType) 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