use of com.evolveum.midpoint.prism.schema.SchemaRegistryImpl 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.schema.SchemaRegistryImpl in project midpoint by Evolveum.
the class TestExtraSchema method testUserExtensionSchemaSchemaRegistry.
@Test
public void testUserExtensionSchemaSchemaRegistry() throws SAXException, IOException, SchemaException {
System.out.println("===[ testUserExtensionSchemaAsObjectSchema ]===");
PrismContext context = constructPrismContext();
SchemaRegistryImpl reg = (SchemaRegistryImpl) context.getSchemaRegistry();
reg.registerPrismSchemasFromDirectory(EXTRA_SCHEMA_DIR);
context.initialize();
PrismObjectDefinition<UserType> userDef = reg.findObjectDefinitionByType(USER_TYPE_QNAME);
System.out.println("User definition:");
System.out.println(userDef.debugDump());
assertUserDefinition(userDef);
PrismObjectDefinition<UserType> usedDefByClass = reg.findObjectDefinitionByCompileTimeClass(UserType.class);
assertUserDefinition(usedDefByClass);
PrismObjectDefinition<UserType> userDefByElement = reg.findObjectDefinitionByElementName(USER_QNAME);
assertUserDefinition(userDefByElement);
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistryImpl 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.SchemaRegistryImpl in project midpoint by Evolveum.
the class PrismInternalTestUtil method constructPrismContext.
public static PrismContextImpl constructPrismContext(File extraSchema) throws SchemaException, FileNotFoundException {
SchemaRegistryImpl schemaRegistry = new SchemaRegistryImpl();
schemaRegistry.setCatalogResourceName(TEST_CATALOG_RESOURCE_NAME);
DynamicNamespacePrefixMapper prefixMapper = new GlobalDynamicNamespacePrefixMapper();
// Set default namespace?
schemaRegistry.setNamespacePrefixMapper(prefixMapper);
schemaRegistry.registerPrismDefaultSchemaResource("xml/ns/test/foo-1.xsd", "foo", ObjectFactory.class.getPackage());
schemaRegistry.registerPrismSchemaResource("xml/ns/test/foo-types-1.xsd", "foot", null);
schemaRegistry.registerPrismSchemaResource("xml/ns/public/types-3.xsd", "t", com.evolveum.prism.xml.ns._public.types_3.ObjectFactory.class.getPackage());
schemaRegistry.registerPrismSchemaResource("xml/ns/public/query-3.xsd", "q", com.evolveum.prism.xml.ns._public.query_3.ObjectFactory.class.getPackage());
schemaRegistry.registerPrismSchemasFromDirectory(SCHEMA_DIR);
if (extraSchema != null) {
schemaRegistry.registerPrismSchemaFile(extraSchema);
}
prefixMapper.registerPrefix(XMLConstants.W3C_XML_SCHEMA_NS_URI, DOMUtil.NS_W3C_XML_SCHEMA_PREFIX, false);
prefixMapper.registerPrefix(PrismConstants.NS_ANNOTATION, PrismConstants.PREFIX_NS_ANNOTATION, false);
prefixMapper.registerPrefix(PrismInternalTestUtil.NS_WEAPONS, PrismInternalTestUtil.NS_WEAPONS_PREFIX, false);
return PrismContextImpl.create(schemaRegistry);
}
use of com.evolveum.midpoint.prism.schema.SchemaRegistryImpl in project midpoint by Evolveum.
the class SchemaDocMojo method createSchemaRegistry.
@NotNull
private SchemaRegistryImpl createSchemaRegistry() throws SchemaException {
SchemaRegistryImpl schemaRegistry = new SchemaRegistryImpl();
schemaRegistry.setNamespacePrefixMapper(new GlobalDynamicNamespacePrefixMapper());
return schemaRegistry;
}
Aggregations