Search in sources :

Example 1 with XmlSchemaType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType in project midpoint by Evolveum.

the class TestResourceSchema method testResourceSchemaJaxbRoundTrip.

// The support for the xsd:any properties is missing in JAXB generator. Otherwise this test should work.
@Test(enabled = false)
public void testResourceSchemaJaxbRoundTrip() throws SchemaException {
    // GIVEN
    ResourceSchema schema = createResourceSchema();
    System.out.println("Resource schema before serializing to XSD: ");
    System.out.println(schema.debugDump());
    System.out.println();
    Document xsd = schema.serializeToXsd();
    ResourceType resource = new ResourceType();
    resource.setName(PrismTestUtil.createPolyStringType("JAXB With Dynamic Schemas Test"));
    ResourceTypeUtil.setResourceXsdSchema(resource, DOMUtil.getFirstChildElement(xsd));
    // WHEN
    String marshalledResource = PrismTestUtil.serializeObjectToString(resource.asPrismObject());
    System.out.println("Marshalled resource");
    System.out.println(marshalledResource);
    ResourceType unmarshalledResource = (ResourceType) PrismTestUtil.parseObject(marshalledResource).asObjectable();
    System.out.println("unmarshalled resource");
    System.out.println(ObjectTypeUtil.dump(unmarshalledResource));
    XmlSchemaType unXmlSchemaType = unmarshalledResource.getSchema();
    Element unXsd = unXmlSchemaType.getDefinition().getAny().get(0);
    ResourceSchema unSchema = ResourceSchemaParser.parse(unXsd, "unmarshalled resource");
    System.out.println("unmarshalled schema");
    System.out.println(unSchema.debugDump());
    // THEN
    assertResourceSchema(unSchema);
}
Also used : Element(org.w3c.dom.Element) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Document(org.w3c.dom.Document) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) Test(org.testng.annotations.Test) AbstractSchemaTest(com.evolveum.midpoint.schema.AbstractSchemaTest)

Example 2 with XmlSchemaType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType in project midpoint by Evolveum.

the class TestResourceSchema method testResourceSchemaSerializationInResource.

@Test
public void testResourceSchemaSerializationInResource() throws SchemaException {
    // GIVEN
    ResourceSchema schema = createResourceSchema();
    // WHEN
    Document xsdDocument = schema.serializeToXsd();
    Element xsdElement = DOMUtil.getFirstChildElement(xsdDocument);
    PrismObject<ResourceType> resource = wrapInResource(xsdElement);
    String resourceXmlString = PrismTestUtil.getPrismContext().xmlSerializer().serialize(resource);
    System.out.println("Serialized resource");
    System.out.println(resourceXmlString);
    PrismObject<ResourceType> reparsedResource = PrismTestUtil.getPrismContext().parseObject(resourceXmlString);
    System.out.println("Re-parsed resource");
    System.out.println(reparsedResource.debugDump());
    XmlSchemaType reparsedSchemaType = reparsedResource.asObjectable().getSchema();
    Element reparsedXsdElement = ObjectTypeUtil.findXsdElement(reparsedSchemaType);
    System.out.println("Reparsed XSD schema");
    System.out.println(DOMUtil.serializeDOMToString(reparsedXsdElement));
    assertDomSchema(reparsedXsdElement);
}
Also used : Element(org.w3c.dom.Element) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Document(org.w3c.dom.Document) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) Test(org.testng.annotations.Test) AbstractSchemaTest(com.evolveum.midpoint.schema.AbstractSchemaTest)

Example 3 with XmlSchemaType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType in project midpoint by Evolveum.

the class TestParseResource method assertResourceJaxb.

private void assertResourceJaxb(ResourceType resourceType, boolean isSimple) throws SchemaException {
    assertEquals("Wrong oid (JAXB)", TestConstants.RESOURCE_OID, resourceType.getOid());
    assertEquals("Wrong name (JAXB)", PrismTestUtil.createPolyStringType("Embedded Test OpenDJ"), resourceType.getName());
    assertEquals("Wrong namespace (JAXB)", MidPointConstants.NS_RI, MidPointConstants.NS_RI);
    ObjectReferenceType connectorRef = resourceType.getConnectorRef();
    assertNotNull("No connectorRef (JAXB)", connectorRef);
    assertEquals("Wrong type in connectorRef (JAXB)", ConnectorType.COMPLEX_TYPE, connectorRef.getType());
    SearchFilterType filter = connectorRef.getFilter();
    assertNotNull("No filter in connectorRef (JAXB)", filter);
    MapXNode filterElement = filter.getFilterClauseXNode();
    assertNotNull("No filter element in connectorRef (JAXB)", filterElement);
    EvaluationTimeType resolutionTime = connectorRef.getResolutionTime();
    if (isSimple) {
        assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.RUN, resolutionTime);
    } else {
        assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.IMPORT, resolutionTime);
    }
    XmlSchemaType xmlSchemaType = resourceType.getSchema();
    SchemaHandlingType schemaHandling = resourceType.getSchemaHandling();
    if (isSimple) {
        assertNull("Schema sneaked in", xmlSchemaType);
        assertNull("SchemaHandling sneaked in", schemaHandling);
    } else {
        assertNotNull("No schema element (JAXB)", xmlSchemaType);
        SchemaDefinitionType definition = xmlSchemaType.getDefinition();
        assertNotNull("No definition element in schema (JAXB)", definition);
        List<Element> anyElements = definition.getAny();
        assertNotNull("Null element list in definition element in schema (JAXB)", anyElements);
        assertFalse("Empty element list in definition element in schema (JAXB)", anyElements.isEmpty());
        assertNotNull("No schema handling (JAXB)", schemaHandling);
        for (ResourceObjectTypeDefinitionType accountType : schemaHandling.getObjectType()) {
            String name = accountType.getIntent();
            assertNotNull("Account type without a name", name);
            assertNotNull("Account type " + name + " does not have an objectClass", accountType.getObjectClass());
            boolean foundDescription = false;
            boolean foundDepartmentNumber = false;
            for (ResourceAttributeDefinitionType attributeDefinitionType : accountType.getAttribute()) {
                if ("description".equals(ItemPathTypeUtil.asSingleNameOrFail(attributeDefinitionType.getRef()).getLocalPart())) {
                    foundDescription = true;
                    MappingType outbound = attributeDefinitionType.getOutbound();
                    JAXBElement<?> valueEvaluator = outbound.getExpression().getExpressionEvaluator().get(0);
                    System.out.println("value evaluator for description = " + valueEvaluator);
                    assertNotNull("no expression evaluator for description", valueEvaluator);
                    assertEquals("wrong expression evaluator element name for description", SchemaConstantsGenerated.C_VALUE, valueEvaluator.getName());
                    assertEquals("wrong expression evaluator actual type for description", RawType.class, valueEvaluator.getValue().getClass());
                } else if ("departmentNumber".equals(ItemPathTypeUtil.asSingleNameOrFail(attributeDefinitionType.getRef()).getLocalPart())) {
                    foundDepartmentNumber = true;
                    MappingType outbound = attributeDefinitionType.getOutbound();
                    VariableBindingDefinitionType source = outbound.getSource().get(0);
                    System.out.println("source for departmentNumber = " + source);
                    assertNotNull("no source for outbound mapping for departmentNumber", source);
                    // <path xmlns:z="http://z/">$user/extension/z:dept</path>
                    ItemPath expected = ItemPath.create(new VariableItemPathSegment(new QName("user")), new QName("extension"), namespaces ? new QName("http://z/", "dept") : new QName("dept"));
                    PrismAsserts.assertPathEqualsExceptForPrefixes("source for departmentNubmer", expected, source.getPath().getItemPath());
                }
            }
            assertTrue("ri:description attribute was not found", foundDescription);
            assertTrue("ri:departmentNumber attribute was not found", foundDepartmentNumber);
        }
        // checking <class> element in fetch result
        OperationResultType fetchResult = resourceType.getFetchResult();
        assertNotNull("No fetchResult (JAXB)", fetchResult);
        JAXBElement<?> value = fetchResult.getParams().getEntry().get(0).getEntryValue();
        assertNotNull("No fetchResult param value (JAXB)", value);
        assertEquals("Wrong value class", UnknownJavaObjectType.class, value.getValue().getClass());
        UnknownJavaObjectType unknownJavaObjectType = (UnknownJavaObjectType) value.getValue();
        assertEquals("Wrong value class", "my.class", unknownJavaObjectType.getClazz());
        assertEquals("Wrong value toString value", "my.value", unknownJavaObjectType.getToString());
    }
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) VariableItemPathSegment(com.evolveum.midpoint.prism.path.VariableItemPathSegment) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 4 with XmlSchemaType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType in project midpoint by Evolveum.

the class ResourceUtils method deleteSchema.

public static void deleteSchema(PrismObject<ResourceType> resource, ModelService modelService, PrismContext prismContext, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    PrismContainer<XmlSchemaType> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
    if (schemaContainer != null && schemaContainer.getValue() != null) {
        PrismProperty<SchemaDefinitionType> definitionProperty = schemaContainer.findProperty(XmlSchemaType.F_DEFINITION);
        if (definitionProperty != null && !definitionProperty.isEmpty()) {
            PrismPropertyValue<SchemaDefinitionType> definitionValue = definitionProperty.getValue().clone();
            ObjectDelta<ResourceType> deleteSchemaDefinitionDelta = ObjectDelta.createModificationDeleteProperty(ResourceType.class, resource.getOid(), new ItemPath(ResourceType.F_SCHEMA, XmlSchemaType.F_DEFINITION), prismContext, // TODO ...or replace with null?
            definitionValue.getValue());
            // delete schema
            modelService.executeChanges(Collections.<ObjectDelta<? extends ObjectType>>singleton(deleteSchemaDefinitionDelta), null, task, parentResult);
        }
    }
}
Also used : SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 5 with XmlSchemaType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType in project midpoint by Evolveum.

the class AbstractManualResourceTest method test003Connection.

@Test
public void test003Connection() throws Exception {
    final String TEST_NAME = "test003Connection";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    // Check that there is a schema, but no capabilities before test (pre-condition)
    ResourceType resourceBefore = repositoryService.getObject(ResourceType.class, getResourceOid(), null, result).asObjectable();
    Element resourceXsdSchemaElementBefore = ResourceTypeUtil.getResourceXsdSchema(resourceBefore);
    assertResourceSchemaBeforeTest(resourceXsdSchemaElementBefore);
    CapabilitiesType capabilities = resourceBefore.getCapabilities();
    if (capabilities != null) {
        AssertJUnit.assertNull("Native capabilities present before test connection. Bad test setup?", capabilities.getNative());
    }
    // WHEN
    OperationResult testResult = modelService.testResource(getResourceOid(), task);
    // THEN
    display("Test result", testResult);
    TestUtil.assertSuccess("Test resource failed (result)", testResult);
    PrismObject<ResourceType> resourceRepoAfter = repositoryService.getObject(ResourceType.class, getResourceOid(), null, result);
    ResourceType resourceTypeRepoAfter = resourceRepoAfter.asObjectable();
    display("Resource after test", resourceTypeRepoAfter);
    XmlSchemaType xmlSchemaTypeAfter = resourceTypeRepoAfter.getSchema();
    assertNotNull("No schema after test connection", xmlSchemaTypeAfter);
    Element resourceXsdSchemaElementAfter = ResourceTypeUtil.getResourceXsdSchema(resourceTypeRepoAfter);
    assertNotNull("No schema after test connection", resourceXsdSchemaElementAfter);
    String resourceXml = prismContext.serializeObjectToString(resourceRepoAfter, PrismContext.LANG_XML);
    display("Resource XML", resourceXml);
    CachingMetadataType cachingMetadata = xmlSchemaTypeAfter.getCachingMetadata();
    assertNotNull("No caching metadata", cachingMetadata);
    assertNotNull("No retrievalTimestamp", cachingMetadata.getRetrievalTimestamp());
    assertNotNull("No serialNumber", cachingMetadata.getSerialNumber());
    Element xsdElement = ObjectTypeUtil.findXsdElement(xmlSchemaTypeAfter);
    ResourceSchema parsedSchema = ResourceSchemaImpl.parse(xsdElement, resourceBefore.toString(), prismContext);
    assertNotNull("No schema after parsing", parsedSchema);
// schema will be checked in next test
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) CapabilitiesType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilitiesType) Element(org.w3c.dom.Element) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) CachingMetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType) Test(org.testng.annotations.Test) AbstractConfiguredModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)

Aggregations

XmlSchemaType (com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType)12 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)10 Element (org.w3c.dom.Element)10 Test (org.testng.annotations.Test)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Task (com.evolveum.midpoint.task.api.Task)4 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)3 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)3 CachingMetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType)3 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 AbstractSchemaTest (com.evolveum.midpoint.schema.AbstractSchemaTest)2 SchemaDefinitionType (com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType)2 QName (javax.xml.namespace.QName)2 Document (org.w3c.dom.Document)2 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)1 AbstractConfiguredModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)1 ComplexTypeDefinition (com.evolveum.midpoint.prism.ComplexTypeDefinition)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 VariableItemPathSegment (com.evolveum.midpoint.prism.path.VariableItemPathSegment)1