Search in sources :

Example 1 with SchemaRegistryImpl

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()));
}
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 2 with SchemaRegistryImpl

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);
}
Also used : SchemaRegistryImpl(com.evolveum.midpoint.prism.schema.SchemaRegistryImpl) UserType(com.evolveum.midpoint.prism.foo.UserType) Test(org.testng.annotations.Test)

Example 3 with SchemaRegistryImpl

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());
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) SchemaRegistryImpl(com.evolveum.midpoint.prism.schema.SchemaRegistryImpl) Test(org.testng.annotations.Test)

Example 4 with SchemaRegistryImpl

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);
}
Also used : ObjectFactory(com.evolveum.midpoint.prism.foo.ObjectFactory) SchemaRegistryImpl(com.evolveum.midpoint.prism.schema.SchemaRegistryImpl) GlobalDynamicNamespacePrefixMapper(com.evolveum.midpoint.prism.xml.GlobalDynamicNamespacePrefixMapper) GlobalDynamicNamespacePrefixMapper(com.evolveum.midpoint.prism.xml.GlobalDynamicNamespacePrefixMapper) DynamicNamespacePrefixMapper(com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper)

Example 5 with SchemaRegistryImpl

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;
}
Also used : SchemaRegistryImpl(com.evolveum.midpoint.prism.schema.SchemaRegistryImpl) GlobalDynamicNamespacePrefixMapper(com.evolveum.midpoint.prism.xml.GlobalDynamicNamespacePrefixMapper) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SchemaRegistryImpl (com.evolveum.midpoint.prism.schema.SchemaRegistryImpl)8 Test (org.testng.annotations.Test)5 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)4 UserType (com.evolveum.midpoint.prism.foo.UserType)2 GlobalDynamicNamespacePrefixMapper (com.evolveum.midpoint.prism.xml.GlobalDynamicNamespacePrefixMapper)2 DOMResult (javax.xml.transform.dom.DOMResult)2 DOMSource (javax.xml.transform.dom.DOMSource)2 Schema (javax.xml.validation.Schema)2 Validator (javax.xml.validation.Validator)2 Document (org.w3c.dom.Document)2 PrismContextImpl (com.evolveum.midpoint.prism.PrismContextImpl)1 ObjectFactory (com.evolveum.midpoint.prism.foo.ObjectFactory)1 SchemaDefinitionFactory (com.evolveum.midpoint.prism.schema.SchemaDefinitionFactory)1 DynamicNamespacePrefixMapper (com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 File (java.io.File)1 QName (javax.xml.namespace.QName)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 NotNull (org.jetbrains.annotations.NotNull)1 SAXException (org.xml.sax.SAXException)1