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);
}
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);
}
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()));
}
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());
}
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);
}
Aggregations