use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.
the class TestExtraSchema method testUserExtensionSchemaLoad.
/**
* Test if a schema directory can be loaded to the schema registry. This contains definition of
* user extension, therefore check if it is applied to the user definition.
*/
@Test
public void testUserExtensionSchemaLoad() throws SAXException, IOException, SchemaException {
System.out.println("===[ testUserExtensionSchemaLoad ]===");
PrismContext context = constructPrismContext();
SchemaRegistryImpl reg = (SchemaRegistryImpl) context.getSchemaRegistry();
reg.registerPrismSchemasFromDirectory(EXTRA_SCHEMA_DIR);
context.initialize();
System.out.println("Initialized registry");
System.out.println(reg.debugDump());
// Try midpoint schemas by parsing a XML file
PrismSchema schema = reg.getSchema(NS_FOO);
System.out.println("Parsed foo schema:");
System.out.println(schema.debugDump());
// TODO: assert user
schema = reg.getSchema(NS_USER_EXT);
System.out.println("Parsed user ext schema:");
System.out.println(schema.debugDump());
ComplexTypeDefinition userExtComplexType = schema.findComplexTypeDefinition(USER_EXTENSION_TYPE_QNAME);
assertEquals("Extension type ref does not match", USER_TYPE_QNAME, userExtComplexType.getExtensionForType());
}
use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.
the class TestPrismSchemaConstruction method testConstructSchema.
@Test
public void testConstructSchema() throws SchemaException, SAXException, IOException {
System.out.println("===[ testConstructSchema ]===");
// GIVEN
PrismContext ctx = constructInitializedPrismContext();
// WHEN
PrismSchema schema = constructSchema(ctx);
// THEN
System.out.println("Constructed schema");
System.out.println(schema.debugDump());
assertSchema(schema);
}
use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.
the class PrismBeanInspector method findTypeNameUncached.
private QName findTypeNameUncached(Field field, Class contentClass, String schemaNamespace) {
if (field != null) {
XmlSchemaType xmlSchemaType = field.getAnnotation(XmlSchemaType.class);
if (xmlSchemaType != null) {
return new QName(xmlSchemaType.namespace(), xmlSchemaType.name());
}
}
QName typeName = XsdTypeMapper.getJavaToXsdMapping(contentClass);
if (typeName != null) {
return typeName;
}
// TODO the following code is similar to determineTypeForClass
XmlType xmlType = (XmlType) contentClass.getAnnotation(XmlType.class);
if (xmlType != null) {
String propTypeLocalPart = xmlType.name();
String propTypeNamespace = xmlType.namespace();
if (propTypeNamespace.equals(BeanMarshaller.DEFAULT_PLACEHOLDER)) {
PrismSchema schema = prismContext.getSchemaRegistry().findSchemaByCompileTimeClass(contentClass);
if (schema != null && schema.getNamespace() != null) {
// should be non-null for properly initialized schemas
propTypeNamespace = schema.getNamespace();
} else {
// schemaNamespace is only a poor indicator of required namespace (consider e.g. having c:UserType in apit:ObjectListType)
// so we use it only if we couldn't find anything else
propTypeNamespace = schemaNamespace;
}
}
return new QName(propTypeNamespace, propTypeLocalPart);
}
return null;
}
use of com.evolveum.midpoint.prism.schema.PrismSchema 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.PrismSchema in project midpoint by Evolveum.
the class TestSchemaSanity method testExtensionSchema.
/**
* Extension schema should be loaded from src/test/resources/schema during test initialization.
*/
@Test
public void testExtensionSchema() {
System.out.println("===[ testExtensionSchema ]===");
// WHEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
assertNotNull("No prism context", prismContext);
SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
assertNotNull("No schema registry in context", schemaRegistry);
PrismSchema extensionSchema = schemaRegistry.findSchemaByNamespace(SchemaTestConstants.NS_EXTENSION);
assertNotNull("No extension schema", extensionSchema);
System.out.println("Extension schema:");
System.out.println(extensionSchema.debugDump());
PrismPropertyDefinition locationsProperty = extensionSchema.findPropertyDefinitionByElementName(EXTENSION_LOCATIONS_ELEMENT);
PrismAsserts.assertDefinition(locationsProperty, EXTENSION_LOCATIONS_ELEMENT, EXTENSION_LOCATIONS_TYPE, 0, -1);
}
Aggregations