Search in sources :

Example 11 with DummyResourceContoller

use of com.evolveum.midpoint.test.DummyResourceContoller in project midpoint by Evolveum.

the class TestNotifyChange method initSystem.

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
    super.initSystem(initTask, initResult);
    // Resources
    DummyResourceContoller dummyResourceCtlGrouper = DummyResourceContoller.create(RESOURCE_GROUPER_ID, resourceDummyGrouper);
    DummyResource dummyResourceGrouper = dummyResourceCtlGrouper.getDummyResource();
    dummyResourceGrouper.setSyncStyle(DummySyncStyle.SMART);
    dummyResourceGrouper.populateWithDefaultSchema();
    resourceDummyGrouper = importAndGetObjectFromFile(ResourceType.class, RESOURCE_GROUPER_FILE, RESOURCE_GROUPER_OID, initTask, initResult);
    dummyResourceCtlGrouper.setResource(resourceDummyGrouper);
}
Also used : DummyResource(com.evolveum.icf.dummy.resource.DummyResource) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) DummyResourceContoller(com.evolveum.midpoint.test.DummyResourceContoller)

Example 12 with DummyResourceContoller

use of com.evolveum.midpoint.test.DummyResourceContoller in project midpoint by Evolveum.

the class TestDummyNegative method test240GetBrokenAccounts.

/**
 * Checks the behaviour when getting broken accounts, i.e. accounts that cannot be retrieved
 * because of e.g.
 *
 * - inability to convert from ConnId to resource object (`ShadowType`)
 * - inability to create or update midPoint shadow
 *
 * The current behavior is that `getObject` throws an exception in these cases.
 * This may or may not be ideal. We can consider changing that (to signalling via `fetchResult`)
 * later. But that would mean adapting the clients so that they would check the `fetchResult`
 * and use the resulting shadow only if it's OK.
 *
 * Because the `getObject` operation requires a shadow to exists, we have to create these objects
 * in a good shape, retrieve them, and break them afterwards.
 */
@Test
public void test240GetBrokenAccounts() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    DummyResourceContoller controller = RESOURCE_DUMMY_BROKEN_ACCOUNTS.controller;
    DummyResource resource = controller.getDummyResource();
    // create good accounts
    createAccount(GOOD_ACCOUNT, 1, null);
    createAccount(INCONVERTIBLE_ACCOUNT, 2, null);
    createAccount(UNSTORABLE_ACCOUNT, 3, null);
    // here we create the shadows
    SearchResultList<PrismObject<ShadowType>> accounts = provisioningService.searchObjects(ShadowType.class, getAllAccountsQuery(RESOURCE_DUMMY_BROKEN_ACCOUNTS), null, task, result);
    String goodOid = selectAccountByName(accounts, GOOD_ACCOUNT).getOid();
    String inconvertibleOid = selectAccountByName(accounts, INCONVERTIBLE_ACCOUNT).getOid();
    String unstorableOid = selectAccountByName(accounts, UNSTORABLE_ACCOUNT).getOid();
    // break the accounts
    resource.getAccountByUsername(INCONVERTIBLE_ACCOUNT).replaceAttributeValue(ENABLE_DATE_NAME, "WRONG");
    resource.getAccountByUsername(UNSTORABLE_ACCOUNT).replaceAttributeValue(ATTR_NUMBER, "WRONG");
    when(GOOD_ACCOUNT);
    PrismObject<ShadowType> goodReloaded = provisioningService.getObject(ShadowType.class, goodOid, null, task, result);
    then(GOOD_ACCOUNT);
    assertShadow(goodReloaded, GOOD_ACCOUNT).assertSuccessOrNoFetchResult();
    when(INCONVERTIBLE_ACCOUNT);
    try {
        provisioningService.getObject(ShadowType.class, inconvertibleOid, null, task, result);
        assertNotReached();
    } catch (SchemaException e) {
        then(INCONVERTIBLE_ACCOUNT);
        displayExpectedException(e);
    // Note: this is the current implementation. We might change it to return something,
    // and fill-in fetchResult appropriately.
    }
    when(UNSTORABLE_ACCOUNT);
    try {
        provisioningService.getObject(ShadowType.class, unstorableOid, null, task, result);
        assertNotReached();
    } catch (Exception e) {
        then(UNSTORABLE_ACCOUNT);
        displayExpectedException(e);
    // Note: this is the current implementation. We might change it to return something,
    // and fill-in fetchResult appropriately.
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) DummyResourceContoller(com.evolveum.midpoint.test.DummyResourceContoller) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectException(java.net.ConnectException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) FileNotFoundException(java.io.FileNotFoundException) Test(org.testng.annotations.Test)

Aggregations

DummyResourceContoller (com.evolveum.midpoint.test.DummyResourceContoller)12 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 Task (com.evolveum.midpoint.task.api.Task)2 Test (org.testng.annotations.Test)2 DummyResource (com.evolveum.icf.dummy.resource.DummyResource)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 FileNotFoundException (java.io.FileNotFoundException)1 ConnectException (java.net.ConnectException)1