use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.
the class TestSanity 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());
}
}
use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.
the class TestUcfDummyMulti method test100AddAccount.
@Test
public void test100AddAccount() throws Exception {
final String TEST_NAME = "test100AddAccount";
TestUtil.displayTestTile(this, TEST_NAME);
OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME);
ObjectClassComplexTypeDefinition defaultAccountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
ShadowType shadowType = new ShadowType();
PrismTestUtil.getPrismContext().adopt(shadowType);
shadowType.setName(PrismTestUtil.createPolyStringType(ACCOUNT_JACK_USERNAME));
ObjectReferenceType resourceRef = new ObjectReferenceType();
resourceRef.setOid(resource.getOid());
shadowType.setResourceRef(resourceRef);
shadowType.setObjectClass(defaultAccountDefinition.getTypeName());
PrismObject<ShadowType> shadow = shadowType.asPrismObject();
ResourceAttributeContainer attributesContainer = ShadowUtil.getOrCreateAttributesContainer(shadow, defaultAccountDefinition);
ResourceAttribute<String> icfsNameProp = attributesContainer.findOrCreateAttribute(SchemaConstants.ICFS_NAME);
icfsNameProp.setRealValue(ACCOUNT_JACK_USERNAME);
// WHEN
cc.addObject(shadow, null, null, result);
// THEN
DummyAccount dummyAccount = dummyResource.getAccountByUsername(ACCOUNT_JACK_USERNAME);
assertNotNull("Account " + ACCOUNT_JACK_USERNAME + " was not created", dummyAccount);
assertNotNull("Account " + ACCOUNT_JACK_USERNAME + " has no username", dummyAccount.getName());
}
use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.
the class TestUcfDummyMulti method test200BlockingSearch.
@Test
public void test200BlockingSearch() throws Exception {
final String TEST_NAME = "test200BlockingSearch";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
final OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME);
final ObjectClassComplexTypeDefinition accountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
// Determine object class from the schema
final List<PrismObject<ShadowType>> searchResults = new ArrayList<PrismObject<ShadowType>>();
final ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {
@Override
public boolean handle(PrismObject<ShadowType> shadow) {
checkUcfShadow(shadow, accountDefinition);
searchResults.add(shadow);
return true;
}
};
dummyResource.setBlockOperations(true);
// WHEN
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
cc.search(accountDefinition, new ObjectQuery(), handler, null, null, null, null, result);
} catch (CommunicationException | GenericFrameworkException | SchemaException | SecurityViolationException | ObjectNotFoundException e) {
LOGGER.error("Error in the search: {}", e.getMessage(), e);
}
}
});
t.setName("search1");
t.start();
// Give the new thread a chance to get blocked
Thread.sleep(500);
ConnectorOperationalStatus opStat = cc.getOperationalStatus();
display("stats (blocked)", opStat);
assertEquals("Wrong pool active", (Integer) 1, opStat.getPoolStatusNumActive());
assertEquals("Wrong pool active", (Integer) 0, opStat.getPoolStatusNumIdle());
assertEquals("Unexpected number of search results", 0, searchResults.size());
dummyResource.unblock();
t.join();
dummyResource.setBlockOperations(false);
// THEN
assertEquals("Unexpected number of search results", 1, searchResults.size());
opStat = cc.getOperationalStatus();
display("stats (final)", opStat);
assertEquals("Wrong pool active", (Integer) 0, opStat.getPoolStatusNumActive());
assertEquals("Wrong pool active", (Integer) 1, opStat.getPoolStatusNumIdle());
PrismObject<ShadowType> searchResult = searchResults.get(0);
display("Search result", searchResult);
}
use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.
the class AbstractIntegrationTest method assertShadowRepo.
protected void assertShadowRepo(PrismObject<ShadowType> accountShadow, String oid, String username, ResourceType resourceType, QName objectClass, MatchingRule<String> nameMatchingRule) throws SchemaException {
assertShadowCommon(accountShadow, oid, username, resourceType, objectClass, nameMatchingRule, true);
PrismContainer<Containerable> attributesContainer = accountShadow.findContainer(ShadowType.F_ATTRIBUTES);
List<Item<?, ?>> attributes = attributesContainer.getValue().getItems();
// Collection secIdentifiers = ShadowUtil.getSecondaryIdentifiers(accountShadow);
if (attributes == null) {
AssertJUnit.fail("No attributes in repo shadow");
}
RefinedResourceSchema refinedSchema = null;
try {
refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType);
} catch (SchemaException e) {
AssertJUnit.fail(e.getMessage());
}
ObjectClassComplexTypeDefinition objClassDef = refinedSchema.getRefinedDefinition(objectClass);
Collection secIdentifiers = objClassDef.getSecondaryIdentifiers();
if (secIdentifiers == null) {
AssertJUnit.fail("No secondary identifiers in repo shadow");
}
// repo shadow should contains all secondary identifiers + ICF_UID
assertRepoShadowAttributes(attributes, secIdentifiers.size() + 1);
}
use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.
the class IntegrationTestTools method checkShadow.
public static void checkShadow(ShadowType shadowType, ResourceType resourceType, RepositoryService repositoryService, ObjectChecker<ShadowType> checker, MatchingRule<String> uidMatchingRule, PrismContext prismContext, OperationResult parentResult) throws SchemaException {
LOGGER.trace("Checking shadow:\n{}", shadowType.asPrismObject().debugDump());
shadowType.asPrismObject().checkConsistence(true, true, ConsistencyCheckScope.THOROUGH);
assertNotNull("no OID", shadowType.getOid());
assertNotNull("no name", shadowType.getName());
assertEquals(resourceType.getOid(), shadowType.getResourceRef().getOid());
PrismContainer<?> attrs = shadowType.asPrismObject().findContainer(ShadowType.F_ATTRIBUTES);
assertNotNull("no attributes", attrs);
assertFalse("empty attributes", attrs.isEmpty());
RefinedResourceSchema rschema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType);
ObjectClassComplexTypeDefinition objectClassDef = rschema.findObjectClassDefinition(shadowType);
assertNotNull("cannot determine object class for " + shadowType, objectClassDef);
String icfUid = ShadowUtil.getSingleStringAttributeValue(shadowType, SchemaTestConstants.ICFS_UID);
if (icfUid == null) {
Collection<? extends ResourceAttributeDefinition> identifierDefs = objectClassDef.getPrimaryIdentifiers();
assertFalse("No identifiers for " + objectClassDef, identifierDefs == null || identifierDefs.isEmpty());
for (ResourceAttributeDefinition idDef : identifierDefs) {
String id = ShadowUtil.getSingleStringAttributeValue(shadowType, idDef.getName());
assertNotNull("No identifier " + idDef.getName() + " in " + shadowType, id);
}
}
String resourceOid = ShadowUtil.getResourceOid(shadowType);
assertNotNull("No resource OID in " + shadowType, resourceOid);
assertNotNull("Null OID in " + shadowType, shadowType.getOid());
PrismObject<ShadowType> repoShadow = null;
try {
repoShadow = repositoryService.getObject(ShadowType.class, shadowType.getOid(), null, parentResult);
} catch (Exception e) {
AssertJUnit.fail("Got exception while trying to read " + shadowType + ": " + e.getCause() + ": " + e.getMessage());
}
checkShadowUniqueness(shadowType, objectClassDef, repositoryService, uidMatchingRule, prismContext, parentResult);
String repoResourceOid = ShadowUtil.getResourceOid(repoShadow.asObjectable());
assertNotNull("No resource OID in the repository shadow " + repoShadow);
assertEquals("Resource OID mismatch", resourceOid, repoResourceOid);
try {
repositoryService.getObject(ResourceType.class, resourceOid, null, parentResult);
} catch (Exception e) {
AssertJUnit.fail("Got exception while trying to read resource " + resourceOid + " as specified in current shadow " + shadowType + ": " + e.getCause() + ": " + e.getMessage());
}
if (checker != null) {
checker.check(shadowType);
}
}
Aggregations