Search in sources :

Example 6 with PrismSchema

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

Example 7 with PrismSchema

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

Example 8 with PrismSchema

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;
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) QName(javax.xml.namespace.QName) XmlSchemaType(javax.xml.bind.annotation.XmlSchemaType) XmlType(javax.xml.bind.annotation.XmlType)

Example 9 with PrismSchema

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

Example 10 with PrismSchema

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

Aggregations

PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)44 Test (org.testng.annotations.Test)20 QName (javax.xml.namespace.QName)10 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)8 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)8 Element (org.w3c.dom.Element)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)6 Task (com.evolveum.midpoint.task.api.Task)6 ConnectorConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 Document (org.w3c.dom.Document)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 PrismSchemaImpl (com.evolveum.midpoint.prism.schema.PrismSchemaImpl)3 SchemaRegistryImpl (com.evolveum.midpoint.prism.schema.SchemaRegistryImpl)3