Search in sources :

Example 21 with ResourceSchema

use of com.evolveum.midpoint.schema.processor.ResourceSchema 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 = provisioningService.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) AbstractProvisioningIntegrationTest(com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest)

Example 22 with ResourceSchema

use of com.evolveum.midpoint.schema.processor.ResourceSchema in project midpoint by Evolveum.

the class TestOpenDjNegative method test004ResourceAndConnectorCaching.

@Test
public void test004ResourceAndConnectorCaching() throws Exception {
    TestUtil.displayTestTile("test004ResourceAndConnectorCaching");
    OperationResult result = new OperationResult(TestOpenDjNegative.class.getName() + ".test004ResourceAndConnectorCaching");
    Task task = taskManager.createTaskInstance();
    // WHEN
    // This should NOT throw an exception. It should just indicate the failure in results
    resource = provisioningService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, task, result);
    ResourceType resourceType = resource.asObjectable();
    // THEN
    result.computeStatus();
    display("getObject(resource) result", result);
    TestUtil.assertFailure(result);
    TestUtil.assertFailure(resource.asObjectable().getFetchResult());
    ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    assertNull("Resource schema found", resourceSchema);
    // WHEN
    PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, task, result);
    // THEN
    result.computeStatus();
    display("getObject(resourceAgain) result", result);
    TestUtil.assertFailure(result);
    TestUtil.assertFailure(resourceAgain.asObjectable().getFetchResult());
    ResourceType resourceTypeAgain = resourceAgain.asObjectable();
    assertNotNull("No connector ref", resourceTypeAgain.getConnectorRef());
    assertNotNull("No connector ref OID", resourceTypeAgain.getConnectorRef().getOid());
    PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    PrismContainer<Containerable> configurationContainerAgain = resourceAgain.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertTrue("Configurations not equivalent", configurationContainer.equivalent(configurationContainerAgain));
    assertTrue("Configurations not equals", configurationContainer.equals(configurationContainerAgain));
    ResourceSchema resourceSchemaAgain = RefinedResourceSchemaImpl.getResourceSchema(resourceAgain, prismContext);
    assertNull("Resource schema (again)", resourceSchemaAgain);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Containerable(com.evolveum.midpoint.prism.Containerable) Test(org.testng.annotations.Test)

Example 23 with ResourceSchema

use of com.evolveum.midpoint.schema.processor.ResourceSchema in project midpoint by Evolveum.

the class ConsistencyTest method checkOpenDjSchema.

private void checkOpenDjSchema(ResourceType resource, String source) throws SchemaException {
    ResourceSchema schema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    ObjectClassComplexTypeDefinition accountDefinition = schema.findObjectClassDefinition(RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    assertNotNull("Schema does not define any account (resource from " + source + ")", accountDefinition);
    Collection<? extends ResourceAttributeDefinition> identifiers = accountDefinition.getPrimaryIdentifiers();
    assertFalse("No account identifiers (resource from " + source + ")", identifiers == null || identifiers.isEmpty());
    // TODO: check for naming attributes and display names, etc
    ActivationCapabilityType capActivation = ResourceTypeUtil.getEffectiveCapability(resource, ActivationCapabilityType.class);
    if (capActivation != null && capActivation.getStatus() != null && capActivation.getStatus().getAttribute() != null) {
        // There is simulated activation capability, check if the attribute is in schema.
        QName enableAttrName = capActivation.getStatus().getAttribute();
        ResourceAttributeDefinition enableAttrDef = accountDefinition.findAttributeDefinition(enableAttrName);
        display("Simulated activation attribute definition", enableAttrDef);
        assertNotNull("No definition for enable attribute " + enableAttrName + " in account (resource from " + source + ")", enableAttrDef);
        assertTrue("Enable attribute " + enableAttrName + " is not ignored (resource from " + source + ")", enableAttrDef.isIgnored());
    }
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ActivationCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType) QName(javax.xml.namespace.QName) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)

Example 24 with ResourceSchema

use of com.evolveum.midpoint.schema.processor.ResourceSchema in project midpoint by Evolveum.

the class AbstractLdapTest method test020Schema.

@Test
public void test020Schema() throws Exception {
    final String TEST_NAME = "test020Schema";
    TestUtil.displayTestTile(this, TEST_NAME);
    ResourceSchema resourceSchema = RefinedResourceSchema.getResourceSchema(resource, prismContext);
    display("Resource schema", resourceSchema);
    RefinedResourceSchema refinedSchema = RefinedResourceSchema.getRefinedSchema(resource);
    display("Refined schema", refinedSchema);
    accountObjectClassDefinition = refinedSchema.findObjectClassDefinition(getAccountObjectClass());
    assertNotNull("No definition for object class " + getAccountObjectClass(), accountObjectClassDefinition);
    display("Account object class def", accountObjectClassDefinition);
    ResourceAttributeDefinition<String> cnDef = accountObjectClassDefinition.findAttributeDefinition("cn");
    PrismAsserts.assertDefinition(cnDef, new QName(MidPointConstants.NS_RI, "cn"), DOMUtil.XSD_STRING, 1, -1);
    assertTrue("cn read", cnDef.canRead());
    assertTrue("cn modify", cnDef.canModify());
    assertTrue("cn add", cnDef.canAdd());
    ResourceAttributeDefinition<String> oDef = accountObjectClassDefinition.findAttributeDefinition("o");
    PrismAsserts.assertDefinition(oDef, new QName(MidPointConstants.NS_RI, "o"), DOMUtil.XSD_STRING, 0, -1);
    assertTrue("o read", oDef.canRead());
    assertTrue("o modify", oDef.canModify());
    assertTrue("o add", oDef.canAdd());
    ResourceAttributeDefinition<Long> createTimestampDef = accountObjectClassDefinition.findAttributeDefinition("createTimestamp");
    PrismAsserts.assertDefinition(createTimestampDef, new QName(MidPointConstants.NS_RI, "createTimestamp"), DOMUtil.XSD_LONG, 0, 1);
    assertTrue("createTimestampDef read", createTimestampDef.canRead());
    assertFalse("createTimestampDef read", createTimestampDef.canModify());
    assertFalse("createTimestampDef read", createTimestampDef.canAdd());
    assertStableSystem();
}
Also used : RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) QName(javax.xml.namespace.QName) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 25 with ResourceSchema

use of com.evolveum.midpoint.schema.processor.ResourceSchema in project midpoint by Evolveum.

the class TestSanityLegacy method checkOpenDjSchema.

private void checkOpenDjSchema(ResourceType resource, String source) throws SchemaException {
    ResourceSchema schema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    ObjectClassComplexTypeDefinition accountDefinition = schema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
    assertNotNull("Schema does not define any account (resource from " + source + ")", accountDefinition);
    Collection<? extends ResourceAttributeDefinition> identifiers = accountDefinition.getPrimaryIdentifiers();
    assertFalse("No account identifiers (resource from " + source + ")", identifiers == null || identifiers.isEmpty());
    // TODO: check for naming attributes and display names, etc
    ActivationCapabilityType capActivation = ResourceTypeUtil.getEffectiveCapability(resource, ActivationCapabilityType.class);
    if (capActivation != null && capActivation.getStatus() != null && capActivation.getStatus().getAttribute() != null) {
        // There is simulated activation capability, check if the attribute is in schema.
        QName enableAttrName = capActivation.getStatus().getAttribute();
        ResourceAttributeDefinition enableAttrDef = accountDefinition.findAttributeDefinition(enableAttrName);
        display("Simulated activation attribute definition", enableAttrDef);
        assertNotNull("No definition for enable attribute " + enableAttrName + " in account (resource from " + source + ")", enableAttrDef);
        assertTrue("Enable attribute " + enableAttrName + " is not ignored (resource from " + source + ")", enableAttrDef.isIgnored());
    }
}
Also used : RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ActivationCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType) QName(javax.xml.namespace.QName) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)

Aggregations

ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)48 Test (org.testng.annotations.Test)26 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)23 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)21 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)17 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)16 QName (javax.xml.namespace.QName)14 Task (com.evolveum.midpoint.task.api.Task)13 Element (org.w3c.dom.Element)8 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)7 CachingMetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType)7 ArrayList (java.util.ArrayList)7 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)6 XmlSchemaType (com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType)6 Containerable (com.evolveum.midpoint.prism.Containerable)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 AbstractProvisioningIntegrationTest (com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3