use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method assertAllowRequestItems.
protected void assertAllowRequestItems(String userOid, String targetRoleOid, AuthorizationDecisionType expectedDefaultDecision, QName... expectedAllowedItemQNames) throws SchemaException, SecurityViolationException, CommunicationException, ObjectNotFoundException, ConfigurationException, ExpressionEvaluationException {
PrismObject<UserType> user = getUser(userOid);
PrismObject<RoleType> target = getRole(targetRoleOid);
ItemSecurityDecisions decisions = modelInteractionService.getAllowedRequestAssignmentItems(user, target);
display("Request decisions for " + target, decisions);
assertEquals("Wrong assign default decision", expectedDefaultDecision, decisions.getDefaultDecision());
assertEquals("Unexpected number of allowed items", expectedAllowedItemQNames.length, decisions.getItemDecisionMap().size());
decisions.getItemDecisionMap().forEach((path, decision) -> {
assertEquals("wrong item " + path + " decision", AuthorizationDecisionType.ALLOW, decision);
QName lastPathName = path.lastNamed().getName();
if (!Arrays.stream(expectedAllowedItemQNames).anyMatch(qname -> QNameUtil.match(qname, lastPathName))) {
AssertJUnit.fail("Unexpected path " + path);
}
});
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method waitForTaskCloseOrSuspend.
protected void waitForTaskCloseOrSuspend(final String taskOid, final int timeout, long sleepTime) throws Exception {
final OperationResult waitResult = new OperationResult(AbstractIntegrationTest.class + ".waitForTaskCloseOrSuspend");
Checker checker = new Checker() {
@Override
public boolean check() throws CommonException {
Task task = taskManager.getTask(taskOid, waitResult);
waitResult.summarize();
display("Task execution status = " + task.getExecutionStatus());
return task.getExecutionStatus() == TaskExecutionStatus.CLOSED || task.getExecutionStatus() == TaskExecutionStatus.SUSPENDED;
}
@Override
public void timeout() {
Task task = null;
try {
task = taskManager.getTask(taskOid, waitResult);
} catch (ObjectNotFoundException | SchemaException e) {
LOGGER.error("Exception during task refresh: {}", e, e);
}
OperationResult result = null;
if (task != null) {
result = task.getResult();
LOGGER.debug("Result of timed-out task:\n{}", result.debugDump());
}
assert false : "Timeout (" + timeout + ") while waiting for " + taskOid + " to close or suspend. Last result " + result;
}
};
IntegrationTestTools.waitFor("Waiting for " + taskOid + " close/suspend", checker, timeout, sleepTime);
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class TestDummy method testLiveSyncDeleteCorsairs.
public void testLiveSyncDeleteCorsairs(final String TEST_NAME, DummySyncStyle syncStyle, QName objectClass, boolean expectReaction) throws Exception {
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
syncServiceMock.reset();
dummyResource.setSyncStyle(syncStyle);
if (isNameUnique()) {
dummyResource.deleteGroupByName(GROUP_CORSAIRS_NAME);
} else {
dummyResource.deleteGroupById(corsairsIcfUid);
}
display("Resource before sync", dummyResource.debugDump());
ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, objectClass);
// WHEN
TestUtil.displayWhen(TEST_NAME);
provisioningService.synchronize(coords, syncTokenTask, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
display("Synchronization result", result);
TestUtil.assertSuccess("Synchronization result is not OK", result);
if (expectReaction) {
syncServiceMock.assertNotifyChange();
ResourceObjectShadowChangeDescription lastChange = syncServiceMock.getLastChange();
display("The change", lastChange);
PrismObject<? extends ShadowType> oldShadow = lastChange.getOldShadow();
assertNotNull("Old shadow missing", oldShadow);
assertNotNull("Old shadow does not have an OID", oldShadow.getOid());
PrismAsserts.assertClass("old shadow", ShadowType.class, oldShadow);
ShadowType oldShadowType = oldShadow.asObjectable();
ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(oldShadowType);
assertNotNull("No attributes container in old shadow", attributesContainer);
Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes();
assertFalse("Attributes container is empty", attributes.isEmpty());
assertEquals("Unexpected number of attributes", 2, attributes.size());
ResourceAttribute<?> icfsNameAttribute = attributesContainer.findAttribute(SchemaConstants.ICFS_NAME);
assertNotNull("No ICF name attribute in old shadow", icfsNameAttribute);
assertEquals("Wrong value of ICF name attribute in old shadow", GROUP_CORSAIRS_NAME, icfsNameAttribute.getRealValue());
ObjectDelta<? extends ShadowType> objectDelta = lastChange.getObjectDelta();
assertNotNull("Delta missing", objectDelta);
assertEquals("Wrong delta changetype", ChangeType.DELETE, objectDelta.getChangeType());
PrismAsserts.assertClass("delta", ShadowType.class, objectDelta);
assertNotNull("No OID in delta", objectDelta.getOid());
assertNull("Unexpected current shadow", lastChange.getCurrentShadow());
try {
// The shadow should be gone
PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, corsairsShadowOid, null, result);
AssertJUnit.fail("The shadow " + repoShadow + " is not gone from repo");
} catch (ObjectNotFoundException e) {
// This is expected
}
} else {
syncServiceMock.assertNoNotifyChange();
}
checkAllShadows();
assertSteadyResource();
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class TestDummy method test265DeleteAccountLeChuck.
/**
* LeChuck has both group and priv entitlement. If deleted it should be correctly removed from all
* the entitlements.
*/
@Test
public void test265DeleteAccountLeChuck() throws Exception {
final String TEST_NAME = "test265DeleteAccountLeChuck";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
syncServiceMock.reset();
// WHEN
provisioningService.deleteObject(ShadowType.class, ACCOUNT_LECHUCK_OID, null, null, task, result);
// THEN
result.computeStatus();
display("add object result", result);
TestUtil.assertSuccess("addObject has failed (result)", result);
syncServiceMock.assertNotifySuccessOnly();
// Check if the account is gone and that group membership is gone as well
DummyAccount dummyAccount = getDummyAccount(ACCOUNT_LECHUCK_NAME, leChuckIcfUid);
assertNull("Dummy account is NOT gone", dummyAccount);
// Make sure that privilege object is still there
DummyPrivilege priv = getDummyPrivilegeAssert(PRIVILEGE_PILLAGE_NAME, pillageIcfUid);
assertNotNull("Privilege object is gone!", priv);
DummyGroup group = getDummyGroupAssert(GROUP_PIRATES_NAME, piratesIcfUid);
assertNoMember(group, ACCOUNT_LECHUCK_NAME);
try {
repositoryService.getObject(ShadowType.class, ACCOUNT_LECHUCK_OID, null, result);
AssertJUnit.fail("Shadow (repo) is not gone");
} catch (ObjectNotFoundException e) {
// This is expected
}
try {
provisioningService.getObject(ShadowType.class, ACCOUNT_LECHUCK_OID, null, task, result);
AssertJUnit.fail("Shadow (provisioning) is not gone");
} catch (ObjectNotFoundException e) {
// This is expected
}
assertSteadyResource();
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class TestDummyNegative method test230GetAccountDeletedShadow.
/**
* Try to get an account when a shadow has been deleted (but the account exists).
* Proper ObjectNotFoundException is expected, compensation should not run.
*/
@Test
public void test230GetAccountDeletedShadow() throws Exception {
final String TEST_NAME = "test230GetAccountDeletedShadow";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestDummyNegative.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_MORGAN_FILE);
String shadowOid = provisioningService.addObject(account, null, null, task, result);
repositoryService.deleteObject(ShadowType.class, shadowOid, result);
// reset
task = taskManager.createTaskInstance(TestDummyNegative.class.getName() + "." + TEST_NAME);
result = task.getResult();
syncServiceMock.reset();
try {
// WHEN
provisioningService.getObject(ShadowType.class, shadowOid, null, task, result);
AssertJUnit.fail("Unexpected success");
} catch (ObjectNotFoundException e) {
// this is expected
display("Expected exception", e);
result.computeStatus();
display("Result", result);
TestUtil.assertFailure(result);
}
syncServiceMock.assertNoNotifyChange();
}
Aggregations