use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.
the class ImportTest method test005ImportUsersWithOverwrite.
// Import the same thing again, this time with overwrite option. This should go well.
@Test
public void test005ImportUsersWithOverwrite() throws Exception {
TestUtil.displayTestTile(this, "test005ImportUsersWithOverwrite");
// GIVEN
Task task = taskManager.createTaskInstance();
OperationResult result = new OperationResult(ImportTest.class.getName() + "test005ImportUsersWithOverwrite");
FileInputStream stream = new FileInputStream(IMPORT_USERS_OVERWRITE_FILE);
ImportOptionsType options = getDefaultImportOptions();
options.setOverwrite(true);
dummyAuditService.clear();
// WHEN
modelService.importObjectsFromStream(stream, options, task, result);
// THEN
result.computeStatus();
display("Result after import with overwrite", result);
TestUtil.assertSuccess("Import failed (result)", result, 2);
// list all users
List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, new ObjectQuery(), null, task, result);
// Three old users, one new
assertEquals(5, users.size());
for (PrismObject<UserType> user : users) {
UserType userType = user.asObjectable();
if (userType.getName().equals("jack")) {
// OID and all the attributes should be the same
assertEquals(USER_JACK_OID, userType.getOid());
PrismAsserts.assertEqualsPolyString("wrong givenName", "Jack", userType.getGivenName());
PrismAsserts.assertEqualsPolyString("wrong familyName", "Sparrow", userType.getFamilyName());
PrismAsserts.assertEqualsPolyString("wrong fullName", "Cpt. Jack Sparrow", userType.getFullName());
}
if (userType.getName().equals("will")) {
// OID should be the same, and there should be an employee type
assertEquals(USER_WILL_OID, userType.getOid());
assertTrue("Wrong Will's employee type", userType.getEmployeeType().contains("legendary"));
}
if (userType.getName().equals("guybrush")) {
// OID may be different, there should be a locality attribute
guybrushOid = userType.getOid();
assertNotNull(guybrushOid);
PrismAsserts.assertEqualsPolyString("Guybrush is not in the Caribbean", "Deep in the Caribbean", userType.getLocality());
}
if (userType.getName().equals("ht")) {
// Herman should be here now
hermanOid = userType.getOid();
assertNotNull(hermanOid);
PrismAsserts.assertEqualsPolyString("Herman is confused", "Herman Toothrot", userType.getFullName());
PrismAsserts.assertEqualsPolyString("Herman is confused", "Herman", userType.getGivenName());
PrismAsserts.assertEqualsPolyString("Herman is confused", "Toothrot", userType.getFamilyName());
}
}
assertUsers(5);
// Check audit
display("Audit", dummyAuditService);
// 1 failed, 7 succeeded
dummyAuditService.assertRecords(8);
}
use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method assertHasShadow.
protected void assertHasShadow(String username, PrismObject<ResourceType> resource, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException {
ObjectQuery query = createAccountShadowQuery(username, resource);
List<PrismObject<ShadowType>> accounts = repositoryService.searchObjects(ShadowType.class, query, null, result);
if (accounts.isEmpty()) {
AssertJUnit.fail("No shadow for " + username + " on " + resource);
} else if (accounts.size() > 1) {
AssertJUnit.fail("Too many shadows for " + username + " on " + resource + " (" + accounts.size() + "): " + accounts);
}
}
use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.
the class TestDummy method test110SeachIterative.
@Test
public void test110SeachIterative() throws Exception {
final String TEST_NAME = "test110SeachIterative";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
// Make sure there is an account on resource that the provisioning has
// never seen before, so there is no shadow
// for it yet.
DummyAccount newAccount = new DummyAccount("meathook");
newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Meathook");
newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Sea Monkey");
newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
newAccount.addAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 666L);
newAccount.setEnabled(true);
newAccount.setPassword("parrotMonster");
dummyResource.addAccount(newAccount);
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(RESOURCE_DUMMY_OID, new QName(ResourceTypeUtil.getResourceNamespace(resourceType), SchemaConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME), prismContext);
final XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
final Holder<Boolean> seenMeathookHolder = new Holder<Boolean>(false);
final List<PrismObject<ShadowType>> foundObjects = new ArrayList<PrismObject<ShadowType>>();
ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {
@Override
public boolean handle(PrismObject<ShadowType> object, OperationResult parentResult) {
foundObjects.add(object);
display("Found", object);
XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
assertTrue(object.canRepresent(ShadowType.class));
try {
checkAccountShadow(object, parentResult, true, startTs, endTs);
} catch (SchemaException e) {
throw new SystemException(e.getMessage(), e);
}
assertCachingMetadata(object, false, startTs, endTs);
if (object.asObjectable().getName().getOrig().equals("meathook")) {
meathookAccountOid = object.getOid();
seenMeathookHolder.setValue(true);
try {
Long loot = ShadowUtil.getAttributeValue(object, dummyResourceCtl.getAttributeQName(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME));
assertEquals("Wrong meathook's loot", (Long) 666L, loot);
} catch (SchemaException e) {
throw new SystemException(e.getMessage(), e);
}
}
return true;
}
};
rememberShadowFetchOperationCount();
// WHEN
provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, null, result);
// THEN
XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
result.computeStatus();
display("searchObjectsIterative result", result);
TestUtil.assertSuccess(result);
assertShadowFetchOperationCountIncrement(1);
assertEquals(4, foundObjects.size());
checkConsistency(foundObjects);
assertProtected(foundObjects, 1);
PrismObject<ShadowType> shadowWillRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
assertRepoShadowCachedAttributeValue(shadowWillRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Flying Dutchman");
checkRepoAccountShadowWill(shadowWillRepo, startTs, endTs);
PrismObject<ShadowType> shadowMeathook = repositoryService.getObject(ShadowType.class, meathookAccountOid, null, result);
display("Meathook shadow", shadowMeathook);
assertRepoShadowCachedAttributeValue(shadowMeathook, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
assertRepoCachingMetadata(shadowMeathook, startTs, endTs);
// And again ...
foundObjects.clear();
rememberShadowFetchOperationCount();
XMLGregorianCalendar startTs2 = clock.currentTimeXMLGregorianCalendar();
// WHEN
provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, null, result);
// THEN
XMLGregorianCalendar endTs2 = clock.currentTimeXMLGregorianCalendar();
assertShadowFetchOperationCountIncrement(1);
display("Found shadows", foundObjects);
assertEquals(4, foundObjects.size());
checkConsistency(foundObjects);
assertProtected(foundObjects, 1);
shadowWillRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
checkRepoAccountShadowWill(shadowWillRepo, startTs2, endTs2);
shadowMeathook = repositoryService.getObject(ShadowType.class, meathookAccountOid, null, result);
assertRepoShadowCachedAttributeValue(shadowMeathook, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
assertRepoCachingMetadata(shadowMeathook, startTs2, endTs2);
assertSteadyResource();
}
use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.
the class TestRbac method test010SearchReuqestableRoles.
@Test
public void test010SearchReuqestableRoles() throws Exception {
final String TEST_NAME = "test010SearchReuqestableRoles";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
ObjectQuery query = QueryBuilder.queryFor(RoleType.class, prismContext).item(RoleType.F_REQUESTABLE).eq(true).build();
// WHEN
List<PrismObject<RoleType>> requestableRoles = modelService.searchObjects(RoleType.class, query, null, task, result);
// THEN
display("Requestable roles", requestableRoles);
assertEquals("Unexpected number of requestable roles", 3, requestableRoles.size());
}
use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.
the class ObjectAlreadyExistHandler method handleError.
@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (!doDiscovery) {
parentResult.recordFatalError(ex);
if (ex instanceof ObjectAlreadyExistsException) {
throw (ObjectAlreadyExistsException) ex;
} else {
throw new ObjectAlreadyExistsException(ex.getMessage(), ex);
}
}
LOGGER.trace("Start to hanlde ObjectAlreadyExitsException.");
OperationResult operationResult = parentResult.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.ObjectAlreadyExistHandler.handleError." + op.name());
operationResult.addParam("shadow", shadow);
operationResult.addParam("currentOperation", op);
operationResult.addParam("exception", ex.getMessage());
ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
change.setResource(shadow.getResource().asPrismObject());
change.setSourceChannel(QNameUtil.qNameToUri(SchemaConstants.CHANGE_CHANNEL_DISCOVERY));
ObjectQuery query = createQueryByIcfName(shadow);
final List<PrismObject<ShadowType>> foundAccount = getExistingAccount(query, task, operationResult);
PrismObject<ShadowType> resourceAccount = null;
if (!foundAccount.isEmpty() && foundAccount.size() == 1) {
resourceAccount = foundAccount.get(0);
}
LOGGER.trace("Found conflicting resource object: {}", resourceAccount);
try {
if (resourceAccount != null) {
// Original object and found object share the same object class, therefore they must
// also share a kind. We can use this short-cut.
resourceAccount.asObjectable().setKind(shadow.getKind());
change.setCurrentShadow(resourceAccount);
// TODO: task initialization
// Task task = taskManager.createTaskInstance();
changeNotificationDispatcher.notifyChange(change, task, operationResult);
}
} finally {
operationResult.computeStatus();
}
if (operationResult.isSuccess()) {
parentResult.recordSuccess();
parentResult.muteLastSubresultError();
}
if (compensate) {
throw new ObjectAlreadyExistsException(ex.getMessage(), ex);
}
return shadow;
}
Aggregations