Search in sources :

Example 6 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class AbstractBasicDummyTest method test030ResourceAndConnectorCaching.

@Test
public void test030ResourceAndConnectorCaching() throws Exception {
    TestUtil.displayTestTile("test030ResourceAndConnectorCaching");
    // GIVEN
    OperationResult result = new OperationResult(TestOpenDj.class.getName() + ".test010ResourceAndConnectorCaching");
    ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(resource, ReadCapabilityType.class, false, result);
    assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
    ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    assertNotNull("No resource schema", resourceSchema);
    // WHEN
    PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, result);
    // THEN
    result.computeStatus();
    display("getObject result", result);
    TestUtil.assertSuccess(result);
    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));
    // Check resource schema caching
    ResourceSchema resourceSchemaAgain = RefinedResourceSchemaImpl.getResourceSchema(resourceAgain, prismContext);
    assertNotNull("No resource schema (again)", resourceSchemaAgain);
    assertTrue("Resource schema was not cached", resourceSchema == resourceSchemaAgain);
    // Check capabilities caching
    CapabilitiesType capabilitiesType = resourceType.getCapabilities();
    assertNotNull("No capabilities fetched from provisioning", capabilitiesType);
    CachingMetadataType capCachingMetadataType = capabilitiesType.getCachingMetadata();
    assertNotNull("No capabilities caching metadata fetched from provisioning", capCachingMetadataType);
    CachingMetadataType capCachingMetadataTypeAgain = resourceTypeAgain.getCapabilities().getCachingMetadata();
    assertEquals("Capabilities caching metadata serial number has changed", capCachingMetadataType.getSerialNumber(), capCachingMetadataTypeAgain.getSerialNumber());
    assertEquals("Capabilities caching metadata timestamp has changed", capCachingMetadataType.getRetrievalTimestamp(), capCachingMetadataTypeAgain.getRetrievalTimestamp());
    // Rough test if everything is fine
    resource.asObjectable().setFetchResult(null);
    resourceAgain.asObjectable().setFetchResult(null);
    ObjectDelta<ResourceType> dummyResourceDiff = DiffUtil.diff(resource, resourceAgain);
    display("Dummy resource diff", dummyResourceDiff);
    assertTrue("The resource read again is not the same as the original. diff:" + dummyResourceDiff, dummyResourceDiff.isEmpty());
    // Now we stick our nose deep inside the provisioning impl. But we need
    // to make sure that the
    // configured connector is properly cached
    ConnectorInstance configuredConnectorInstanceAgain = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, false, result);
    assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAgain);
    assertTrue("Connector instance was not cached", configuredConnectorInstance == configuredConnectorInstanceAgain);
    // Check if the connector still works.
    OperationResult testResult = new OperationResult(TestOpenDj.class.getName() + ".test010ResourceAndConnectorCaching.test");
    configuredConnectorInstanceAgain.test(testResult);
    testResult.computeStatus();
    TestUtil.assertSuccess("Connector test failed", testResult);
    // Test connection should also refresh the connector by itself. So check if it has been refreshed
    ConnectorInstance configuredConnectorInstanceAfterTest = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, false, result);
    assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAfterTest);
    assertTrue("Connector instance was not cached", configuredConnectorInstanceAgain == configuredConnectorInstanceAfterTest);
    assertSteadyResource();
}
Also used : ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) CapabilitiesType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilitiesType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Containerable(com.evolveum.midpoint.prism.Containerable) CachingMetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType) Test(org.testng.annotations.Test)

Example 7 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class AbstractBasicDummyTest method test031ResourceAndConnectorCachingForceFresh.

@Test
public void test031ResourceAndConnectorCachingForceFresh() throws Exception {
    TestUtil.displayTestTile("test031ResourceAndConnectorCachingForceFresh");
    // GIVEN
    OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + ".test011ResourceAndConnectorCachingForceFresh");
    ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(resource, ReadCapabilityType.class, false, result);
    assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
    ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    assertNotNull("No resource schema", resourceSchema);
    // WHEN
    PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, result);
    // THEN
    result.computeStatus();
    display("getObject result", result);
    TestUtil.assertSuccess(result);
    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));
    ResourceSchema resourceSchemaAgain = RefinedResourceSchemaImpl.getResourceSchema(resourceAgain, prismContext);
    assertNotNull("No resource schema (again)", resourceSchemaAgain);
    assertTrue("Resource schema was not cached", resourceSchema == resourceSchemaAgain);
    // Now we stick our nose deep inside the provisioning impl. But we need
    // to make sure that the configured connector is properly refreshed
    // forceFresh = true
    ConnectorInstance configuredConnectorInstanceAgain = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, true, result);
    assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAgain);
    assertFalse("Connector instance was not refreshed", configuredConnectorInstance == configuredConnectorInstanceAgain);
    // Check if the connector still works
    OperationResult testResult = new OperationResult(TestOpenDj.class.getName() + ".test011ResourceAndConnectorCachingForceFresh.test");
    configuredConnectorInstanceAgain.test(testResult);
    testResult.computeStatus();
    TestUtil.assertSuccess("Connector test failed", testResult);
    assertConnectorInitializationCountIncrement(1);
    rememberConnectorInstance(configuredConnectorInstanceAgain);
    assertSteadyResource();
}
Also used : ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) 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 8 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class AbstractBasicDummyTest method test021Configuration.

@Test
public void test021Configuration() throws Exception {
    final String TEST_NAME = "test021Configuration";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + "." + TEST_NAME);
    // WHEN
    resource = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, result);
    resourceType = resource.asObjectable();
    // THEN
    result.computeStatus();
    display("getObject result", result);
    TestUtil.assertSuccess(result);
    // There may be one parse. Previous test have changed the resource version
    // Schema for this version will not be re-parsed until getObject is tried
    assertResourceSchemaParseCountIncrement(1);
    assertResourceCacheMissesIncrement(1);
    PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertNotNull("No configuration container", configurationContainer);
    PrismContainerDefinition confContDef = configurationContainer.getDefinition();
    assertNotNull("No configuration container definition", confContDef);
    PrismContainer confingurationPropertiesContainer = configurationContainer.findContainer(SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_ELEMENT_QNAME);
    assertNotNull("No configuration properties container", confingurationPropertiesContainer);
    PrismContainerDefinition confPropsDef = confingurationPropertiesContainer.getDefinition();
    assertNotNull("No configuration properties container definition", confPropsDef);
    List<PrismProperty<?>> configurationProperties = confingurationPropertiesContainer.getValue().getItems();
    assertFalse("No configuration properties", configurationProperties.isEmpty());
    for (PrismProperty<?> confProp : configurationProperties) {
        PrismPropertyDefinition confPropDef = confProp.getDefinition();
        assertNotNull("No definition for configuration property " + confProp, confPropDef);
        assertFalse("Configuration property " + confProp + " is raw", confProp.isRaw());
        assertConfigurationProperty(confProp);
    }
    // The useless configuration variables should be reflected to the resource now
    assertEquals("Wrong useless string", "Shiver me timbers!", dummyResource.getUselessString());
    assertEquals("Wrong guarded useless string", "Dead men tell no tales", dummyResource.getUselessGuardedString());
    resource.checkConsistence();
    rememberSchemaMetadata(resource);
    rememberConnectorInstance(resource);
    assertSteadyResource();
}
Also used : PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) 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 9 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class AbstractIntegrationTest method assertShadowSecondaryIdentifier.

protected void assertShadowSecondaryIdentifier(PrismObject<ShadowType> shadow, String expectedIdentifier, ResourceType resourceType, MatchingRule<String> nameMatchingRule) throws SchemaException {
    RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType);
    ObjectClassComplexTypeDefinition ocDef = rSchema.findObjectClassDefinition(shadow.asObjectable().getObjectClass());
    ResourceAttributeDefinition idSecDef = ocDef.getSecondaryIdentifiers().iterator().next();
    PrismContainer<Containerable> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    PrismProperty<String> idProp = attributesContainer.findProperty(idSecDef.getName());
    assertNotNull("No secondary identifier (" + idSecDef.getName() + ") attribute in shadow for " + expectedIdentifier, idProp);
    if (nameMatchingRule == null) {
        assertEquals("Unexpected secondary identifier in shadow for " + expectedIdentifier, expectedIdentifier, idProp.getRealValue());
    } else {
        PrismAsserts.assertEquals("Unexpected secondary identifier in shadow for " + expectedIdentifier, nameMatchingRule, expectedIdentifier, idProp.getRealValue());
    }
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) Containerable(com.evolveum.midpoint.prism.Containerable) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 10 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class AbstractManualResourceTest method test004Configuration.

@Test
public void test004Configuration() throws Exception {
    final String TEST_NAME = "test004Configuration";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(AbstractManualResourceTest.class.getName() + "." + TEST_NAME);
    // WHEN
    resource = modelService.getObject(ResourceType.class, getResourceOid(), null, null, result);
    resourceType = resource.asObjectable();
    PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertNotNull("No configuration container", configurationContainer);
    PrismContainerDefinition confContDef = configurationContainer.getDefinition();
    assertNotNull("No configuration container definition", confContDef);
    PrismProperty<String> propDefaultAssignee = configurationContainer.findProperty(CONF_PROPERTY_DEFAULT_ASSIGNEE_QNAME);
    assertNotNull("No defaultAssignee conf prop", propDefaultAssignee);
//		assertNotNull("No configuration properties container", confingurationPropertiesContainer);
//		PrismContainerDefinition confPropDef = confingurationPropertiesContainer.getDefinition();
//		assertNotNull("No configuration properties container definition", confPropDef);
}
Also used : PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) 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) AbstractConfiguredModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)

Aggregations

Containerable (com.evolveum.midpoint.prism.Containerable)30 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 Test (org.testng.annotations.Test)12 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)9 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)7 QName (javax.xml.namespace.QName)7 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 Task (com.evolveum.midpoint.task.api.Task)6 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 ArrayList (java.util.ArrayList)6 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)4 Item (com.evolveum.midpoint.prism.Item)4 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)4 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)4 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)4 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)4 Collection (java.util.Collection)4