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 = 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
}
use of com.evolveum.midpoint.schema.processor.ResourceSchema in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test022ParsedSchema.
@Test
public void test022ParsedSchema() throws Exception {
final String TEST_NAME = "test022ParsedSchema";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
// THEN
// The returned type should have the schema pre-parsed
assertNotNull(RefinedResourceSchemaImpl.hasParsedSchema(resourceType));
// Also test if the utility method returns the same thing
ResourceSchema returnedSchema = RefinedResourceSchemaImpl.getResourceSchema(resourceType, prismContext);
display("Parsed resource schema", returnedSchema);
// Check whether it is reusing the existing schema and not parsing it
// all over again
// Not equals() but == ... we want to really know if exactly the same
// object instance is returned
assertTrue("Broken caching", returnedSchema == RefinedResourceSchemaImpl.getResourceSchema(resourceType, prismContext));
assertSchemaSanity(returnedSchema, resourceType);
rememberResourceSchema(returnedSchema);
assertSteadyResource();
}
use of com.evolveum.midpoint.schema.processor.ResourceSchema in project midpoint by Evolveum.
the class ConnectorManager method createConfiguredConnectorInstance.
private ConnectorInstance createConfiguredConnectorInstance(ConnectorSpec connectorSpec, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException {
ConnectorType connectorType = getConnectorTypeReadOnly(connectorSpec, result);
ConnectorFactory connectorFactory = determineConnectorFactory(connectorType);
ConnectorInstance connector = null;
try {
connector = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(connectorSpec.getResource()), connectorSpec.toString());
} catch (ObjectNotFoundException e) {
result.recordFatalError(e.getMessage(), e);
throw new ObjectNotFoundException(e.getMessage(), e);
}
PrismContainerValue<ConnectorConfigurationType> connectorConfigurationVal = connectorSpec.getConnectorConfiguration().getValue();
if (connectorConfigurationVal == null) {
SchemaException e = new SchemaException("No connector configuration in " + connectorSpec);
result.recordFatalError(e);
throw e;
}
try {
connector.configure(connectorConfigurationVal, result);
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(connectorSpec.getResource(), prismContext);
Collection<Object> capabilities = ResourceTypeUtil.getNativeCapabilitiesCollection(connectorSpec.getResource().asObjectable());
connector.initialize(resourceSchema, capabilities, ResourceTypeUtil.isCaseIgnoreAttributeNames(connectorSpec.getResource().asObjectable()), result);
InternalMonitor.recordConnectorInstanceInitialization();
} catch (GenericFrameworkException e) {
// Not expected. Transform to system exception
result.recordFatalError("Generic provisioning framework error", e);
throw new SystemException("Generic provisioning framework error: " + e.getMessage(), e);
} catch (CommunicationException e) {
result.recordFatalError(e);
throw e;
} catch (ConfigurationException e) {
result.recordFatalError(e);
throw e;
}
// This log message should be INFO level. It happens only occasionally.
// If it happens often, it may be an
// indication of a problem. Therefore it is good for admin to see it.
LOGGER.info("Created new connector instance for {}: {} v{}", connectorSpec, connectorType.getConnectorType(), connectorType.getConnectorVersion());
return connector;
}
use of com.evolveum.midpoint.schema.processor.ResourceSchema in project midpoint by Evolveum.
the class TestDummy method createOnOffQuery.
private ObjectQuery createOnOffQuery() throws SchemaException {
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
ObjectClassComplexTypeDefinition objectClassDef = resourceSchema.findObjectClassDefinition(SchemaTestConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME);
ResourceAttributeDefinition<String> attrDef = objectClassDef.findAttributeDefinition(dummyResourceCtl.getAttributeQName(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME));
ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, prismContext).item(ShadowType.F_RESOURCE_REF).ref(RESOURCE_DUMMY_OID).and().item(ShadowType.F_OBJECT_CLASS).eq(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), SchemaConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME)).and().itemWithDef(attrDef, ShadowType.F_ATTRIBUTES, attrDef.getName()).eq("Sea Monkey").and().item(ShadowType.F_DEAD).eq(true).build();
display("Query", query);
return query;
}
use of com.evolveum.midpoint.schema.processor.ResourceSchema in project midpoint by Evolveum.
the class TestDummy method test502ModifyProtectedAccountShadowAttributes.
/**
* Attribute modification should fail.
*/
@Test
public void test502ModifyProtectedAccountShadowAttributes() throws Exception {
final String TEST_NAME = "test502ModifyProtectedAccountShadowAttributes";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
syncServiceMock.reset();
Collection<? extends ItemDelta> modifications = new ArrayList<ItemDelta>(1);
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
ObjectClassComplexTypeDefinition defaultAccountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
ResourceAttributeDefinition fullnameAttrDef = defaultAccountDefinition.findAttributeDefinition("fullname");
ResourceAttribute fullnameAttr = fullnameAttrDef.instantiate();
PropertyDelta fullnameDelta = fullnameAttr.createDelta(new ItemPath(ShadowType.F_ATTRIBUTES, fullnameAttrDef.getName()));
fullnameDelta.setValueToReplace(new PrismPropertyValue<String>("Good Daemon"));
((Collection) modifications).add(fullnameDelta);
// WHEN
try {
provisioningService.modifyObject(ShadowType.class, ACCOUNT_DAEMON_OID, modifications, null, null, task, result);
AssertJUnit.fail("Expected security exception while modifying 'daemon' account");
} catch (SecurityViolationException e) {
// This is expected
display("Expected exception", e);
}
result.computeStatus();
display("modifyObject result (expected failure)", result);
TestUtil.assertFailure(result);
syncServiceMock.assertNotifyFailureOnly();
// checkConsistency();
assertSteadyResource();
}
Aggregations