use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class TestSchemaRegistry method testReferenceInExtension.
@Test
public void testReferenceInExtension() throws SchemaException, SAXException, IOException {
MidPointPrismContextFactory factory = getContextFactory();
PrismContext context = factory.createInitializedPrismContext();
SchemaRegistry schemaRegistry = context.getSchemaRegistry();
// Common schema should be parsed during creation of the context
((SchemaRegistryImpl) schemaRegistry).loadPrismSchemaResource("schema/extension.xsd");
// Check that the extension schema was loaded
PrismSchema extensionSchema = schemaRegistry.findSchemaByNamespace(EXTENSION_SCHEMA_NAMESPACE);
assertNotNull("Extension schema not parsed", extensionSchema);
ItemDefinition itemDefinition = schemaRegistry.findItemDefinitionByElementName(TestConstants.EXTENSION_USER_REF_ELEMENT);
assertNotNull("userRef element definition was not found", itemDefinition);
System.out.println("UserRef definition:");
System.out.println(itemDefinition.debugDump());
assertEquals("Wrong userRef definition class", PrismReferenceDefinitionImpl.class, itemDefinition.getClass());
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class TestSchemaRegistry method testCommonSchemaAccountType.
@Test
public void testCommonSchemaAccountType() throws SchemaException, SAXException, IOException {
MidPointPrismContextFactory factory = getContextFactory();
PrismContext context = factory.createInitializedPrismContext();
SchemaRegistry schemaRegistry = context.getSchemaRegistry();
PrismObjectDefinition<ShadowType> accountDef = schemaRegistry.findObjectDefinitionByCompileTimeClass(ShadowType.class);
assertNotNull("No account definition", accountDef);
System.out.println("testCommonSchemaAccountType:");
System.out.println(accountDef.debugDump());
PrismPropertyDefinition nameDef = accountDef.findPropertyDefinition(ShadowType.F_NAME);
assertNotNull("No name definition", nameDef);
PrismContainerDefinition extensionDef = accountDef.findContainerDefinition(ShadowType.F_EXTENSION);
assertNotNull("No 'extension' definition", extensionDef);
assertTrue("'extension' definition is not marked as runtime", extensionDef.isRuntimeSchema());
PrismContainerDefinition attributesDef = accountDef.findContainerDefinition(ShadowType.F_ATTRIBUTES);
assertNotNull("No 'attributes' definition", attributesDef);
assertTrue("'attributes' definition is not marked as runtime", attributesDef.isRuntimeSchema());
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class TestSchemaRegistry method testBasic.
/**
* Test whether the midpoint prism context was constructed OK and if it can validate
* ordinary user object.
*/
@Test
public void testBasic() throws SAXException, IOException, SchemaException {
MidPointPrismContextFactory factory = getContextFactory();
PrismContext context = factory.createInitializedPrismContext();
SchemaRegistry reg = context.getSchemaRegistry();
Schema javaxSchema = reg.getJavaxSchema();
assertNotNull(javaxSchema);
// Try to use the schema to validate Jack
// PrismObject<UserType> user = context.parseObject(new File("src/test/resources/common/user-jack.xml"));
// Element document = context.serializeToDom(user);
Document document = DOMUtil.parseFile("src/test/resources/common/user-jack.xml");
Validator validator = javaxSchema.newValidator();
DOMResult validationResult = new DOMResult();
validator.validate(new DOMSource(document), validationResult);
// System.out.println("Validation result:");
// System.out.println(DOMUtil.serializeDOMToString(validationResult.getNode()));
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class TestSchemaRegistry method testRoleType.
@Test
public void testRoleType() throws Exception {
MidPointPrismContextFactory factory = getContextFactory();
PrismContext context = factory.createInitializedPrismContext();
SchemaRegistry schemaRegistry = context.getSchemaRegistry();
PrismObjectDefinition<RoleType> roleDefinition = schemaRegistry.findObjectDefinitionByCompileTimeClass(RoleType.class);
assertNotNull("No role definition", roleDefinition);
assertFalse("Role definition is marked as runtime", roleDefinition.isRuntimeSchema());
PrismPropertyDefinition nameDef = roleDefinition.findPropertyDefinition(ObjectType.F_NAME);
assertNotNull("No name definition", nameDef);
PrismContainerDefinition extensionDef = roleDefinition.findContainerDefinition(ObjectType.F_EXTENSION);
assertNotNull("No 'extension' definition", extensionDef);
assertTrue("Extension definition is NOT marked as runtime", extensionDef.isRuntimeSchema());
PrismPropertyDefinition identifierDef = roleDefinition.findPropertyDefinition(RoleType.F_IDENTIFIER);
assertNotNull("No identifier definition", identifierDef);
// Just make sure this does not end with NPE or stack overflow
PrismObjectDefinition<RoleType> shallowClone = roleDefinition.clone();
PrismObjectDefinition<RoleType> deepClone = roleDefinition.deepClone(false);
PrismObjectDefinition<RoleType> ultraDeepClone = roleDefinition.deepClone(true);
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.
the class TestSchemaSanity method testResourceDefinition.
@Test
public void testResourceDefinition() {
System.out.println("===[ testResourceDefinition ]===");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
// WHEN
PrismObjectDefinition<ResourceType> resourceDefinition = schemaRegistry.findObjectDefinitionByElementName(new QName(SchemaConstantsGenerated.NS_COMMON, "resource"));
assertNotNull("No resource definition", resourceDefinition);
System.out.println("Resource definition:");
System.out.println(resourceDefinition.debugDump());
PrismObjectDefinition<ResourceType> resourceDefinitionByClass = schemaRegistry.findObjectDefinitionByCompileTimeClass(ResourceType.class);
assertTrue("Different user def", resourceDefinition == resourceDefinitionByClass);
assertEquals("Wrong compile-time class in resource definition", ResourceType.class, resourceDefinition.getCompileTimeClass());
PrismAsserts.assertPropertyDefinition(resourceDefinition, ResourceType.F_NAME, PolyStringType.COMPLEX_TYPE, 0, 1);
PrismAsserts.assertPropertyDefinition(resourceDefinition, ResourceType.F_DESCRIPTION, DOMUtil.XSD_STRING, 0, 1);
assertFalse("Resource definition is marked as runtime", resourceDefinition.isRuntimeSchema());
PrismContainerDefinition<ConnectorConfigurationType> connectorConfContainerDef = resourceDefinition.findContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION);
PrismAsserts.assertDefinition(connectorConfContainerDef, ResourceType.F_CONNECTOR_CONFIGURATION, ConnectorConfigurationType.COMPLEX_TYPE, 1, 1);
assertTrue("<connectorConfiguration> is NOT dynamic", connectorConfContainerDef.isDynamic());
// assertFalse("<connectorConfiguration> is runtime", connectorConfContainerDef.isRuntimeSchema());
assertEquals("Wrong compile-time class for <connectorConfiguration> in resource definition", ConnectorConfigurationType.class, connectorConfContainerDef.getCompileTimeClass());
PrismContainerDefinition<XmlSchemaType> schemaContainerDef = resourceDefinition.findContainerDefinition(ResourceType.F_SCHEMA);
PrismAsserts.assertDefinition(schemaContainerDef, ResourceType.F_SCHEMA, XmlSchemaType.COMPLEX_TYPE, 0, 1);
assertFalse("Schema is runtime", schemaContainerDef.isRuntimeSchema());
assertEquals("Wrong compile-time class for <schema> in resource definition", XmlSchemaType.class, schemaContainerDef.getCompileTimeClass());
assertEquals("Unexpected number of definitions in <schema>", 3, schemaContainerDef.getDefinitions().size());
PrismAsserts.assertPropertyDefinition(schemaContainerDef, XmlSchemaType.F_CACHING_METADATA, CachingMetadataType.COMPLEX_TYPE, 0, 1);
PrismAsserts.assertPropertyDefinition(schemaContainerDef, XmlSchemaType.F_DEFINITION, SchemaDefinitionType.COMPLEX_TYPE, 0, 1);
PrismPropertyDefinition definitionPropertyDef = schemaContainerDef.findPropertyDefinition(XmlSchemaType.F_DEFINITION);
assertNotNull("Null <definition> definition", definitionPropertyDef);
// assertFalse("schema/definition is NOT runtime", definitionPropertyDef.isRuntimeSchema());
}
Aggregations