use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.
the class TestDummySchemaless method resourceStaticSchemaResourceAndConnectorCaching.
private void resourceStaticSchemaResourceAndConnectorCaching() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = createOperationResult();
// re-read the resource before tests so we have a clean slate, e.g. configuration properly parsed (no raw elements)
resourceStaticSchema = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_STATIC_SCHEMA_OID, null, task, result);
ConnectorInstance currentConnectorInstance = resourceManager.getConfiguredConnectorInstance(resourceStaticSchema, ReadCapabilityType.class, false, result);
IntegrationTestTools.displayXml("Initialized static schema resource", resourceStaticSchema);
rememberCounter(InternalCounters.RESOURCE_SCHEMA_FETCH_COUNT);
rememberCounter(InternalCounters.CONNECTOR_SCHEMA_PARSE_COUNT);
rememberCounter(InternalCounters.CONNECTOR_CAPABILITIES_FETCH_COUNT);
rememberCounter(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT);
rememberCounter(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT);
rememberCounter(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT);
rememberSchemaMetadata(resourceStaticSchema);
rememberConnectorInstance(currentConnectorInstance);
rememberResourceCacheStats();
ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(resourceStaticSchema, ReadCapabilityType.class, false, result);
assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
ResourceSchema resourceSchemaBefore = ResourceSchemaFactory.getRawSchema(resourceStaticSchema);
assertNotNull("No resource schema", resourceSchemaBefore);
assertStaticSchemaSanity(resourceSchemaBefore);
// WHEN
when();
PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_STATIC_SCHEMA_OID, null, task, result);
// THEN
then();
assertSuccess(result);
ResourceType resourceTypeAgain = resourceAgain.asObjectable();
assertNotNull("No connector ref", resourceTypeAgain.getConnectorRef());
assertNotNull("No connector ref OID", resourceTypeAgain.getConnectorRef().getOid());
PrismContainer<Containerable> configurationContainer = resourceStaticSchema.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 = ResourceSchemaFactory.getRawSchema(resourceAgain);
assertNotNull("No resource schema (again)", resourceSchemaAgain);
assertSame("Resource schema was not cached", resourceSchemaBefore, resourceSchemaAgain);
// Check capabilities caching
CapabilitiesType capabilitiesType = resourceStaticSchema.asObjectable().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
resourceStaticSchema.asObjectable().setFetchResult(null);
resourceAgain.asObjectable().setFetchResult(null);
ObjectDelta<ResourceType> dummyResourceDiff = DiffUtil.diff(resourceStaticSchema, resourceAgain);
displayDumpable("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);
assertSame("Connector instance was not cached", configuredConnectorInstance, configuredConnectorInstanceAgain);
// Check if the connector still works.
OperationResult testResult = createOperationResult("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);
assertSame("Connector instance was not cached", configuredConnectorInstanceAgain, configuredConnectorInstanceAfterTest);
assertSteadyResource();
}
use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.
the class ResourceObjectReferenceResolver method resolvePrimaryIdentifier.
/**
* Resolve primary identifier from a collection of identifiers that may contain only secondary identifiers.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
Collection<? extends ResourceAttribute<?>> resolvePrimaryIdentifier(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, final String desc, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
if (identifiers == null) {
return null;
}
ResourceObjectDefinition objDef = ctx.getObjectDefinitionRequired();
Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(identifiers, objDef);
PrismObject<ShadowType> repoShadow = shadowManager.lookupShadowBySecondaryIds(ctx, secondaryIdentifiers, result);
if (repoShadow == null) {
return null;
}
shadowsFacade.applyDefinition(repoShadow, ctx.getTask(), result);
PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer == null) {
return null;
}
Collection primaryIdentifiers = new ArrayList<>();
for (PrismProperty property : attributesContainer.getValue().getProperties()) {
if (objDef.isPrimaryIdentifier(property.getElementName())) {
ResourceAttributeDefinition<?> attrDef = objDef.findAttributeDefinition(property.getElementName());
if (attrDef == null) {
throw new IllegalStateException("No definition for attribute " + property);
}
ResourceAttribute primaryIdentifier = attrDef.instantiate();
primaryIdentifier.setRealValue(property.getRealValue());
primaryIdentifiers.add(primaryIdentifier);
}
}
LOGGER.trace("Resolved identifiers {} to primary identifiers {} (object class {})", identifiers, primaryIdentifiers, objDef);
return primaryIdentifiers;
}
Aggregations