Search in sources :

Example 31 with OperationResultType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType in project midpoint by Evolveum.

the class TestSanity method test109UnassignRoleCaptainAgain.

/**
     * Captain role was assigned twice. It has to also be unassigned twice.
     */
@Test
public void test109UnassignRoleCaptainAgain() throws Exception {
    final String TEST_NAME = "test109UnassignRoleCaptainAgain";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResultType result = new OperationResultType();
    assertNoRepoCache();
    ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_USER_MODIFY_DELETE_ROLE_CAPTAIN_2_FILENAME, ObjectDeltaType.class);
    // WHEN ObjectTypes.USER.getTypeQName(), 
    result = modifyObjectViaModelWS(objectChange);
    // THEN
    assertNoRepoCache();
    displayJaxb("modifyObject result", result, SchemaConstants.C_RESULT);
    //TODO TODO TODO TODO operation result from repostiory.getObject is unknown...find out why..
    //        assertSuccess("modifyObject has failed", result);
    // Check if user object was modified in the repo
    OperationResult repoResult = new OperationResult("getObject");
    PropertyReferenceListType resolve = new PropertyReferenceListType();
    PrismObject<UserType> repoUser = repositoryService.getObject(UserType.class, USER_GUYBRUSH_OID, null, repoResult);
    UserType repoUserType = repoUser.asObjectable();
    repoResult.computeStatus();
    display("User (repository)", repoUserType);
    List<ObjectReferenceType> accountRefs = repoUserType.getLinkRef();
    assertEquals(0, accountRefs.size());
    // Check if shadow was deleted from the repo
    repoResult = new OperationResult("getObject");
    try {
        PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidGuybrushOpendj, null, repoResult);
        AssertJUnit.fail("Account shadow was not deleted from repo");
    } catch (ObjectNotFoundException ex) {
    // This is expected
    }
    // check if account was deleted from LDAP
    Entry entry = openDJController.searchByEntryUuid(accountGuybrushOpendjEntryUuuid);
    display("LDAP account", entry);
    assertNull("LDAP account was not deleted", entry);
// TODO: Derby
}
Also used : PropertyReferenceListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.PropertyReferenceListType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 32 with OperationResultType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType in project midpoint by Evolveum.

the class TestSanity method test040UnlinkDerbyAccountFromUser.

/**
     * Unlink account by removing the accountRef from the user.
     * The account will not be deleted, just the association to user will be broken.
     */
@Test
public void test040UnlinkDerbyAccountFromUser() throws FileNotFoundException, JAXBException, FaultMessage, ObjectNotFoundException, SchemaException, DirectoryException, SQLException {
    TestUtil.displayTestTile("test040UnlinkDerbyAccountFromUser");
    // GIVEN
    ObjectDeltaType objectChange = new ObjectDeltaType();
    objectChange.setOid(USER_JACK_OID);
    ItemDeltaType modificationDeleteAccountRef = new ItemDeltaType();
    modificationDeleteAccountRef.setModificationType(ModificationTypeType.DELETE);
    ObjectReferenceType accountRefToDelete = new ObjectReferenceType();
    accountRefToDelete.setOid(accountShadowOidDerby);
    RawType modificationValue = new RawType(((PrismContextImpl) prismContext).getBeanMarshaller().marshall(accountRefToDelete), prismContext);
    modificationDeleteAccountRef.getValue().add(modificationValue);
    modificationDeleteAccountRef.setPath(new ItemPathType(new ItemPath(UserType.F_LINK_REF)));
    objectChange.getItemDelta().add(modificationDeleteAccountRef);
    objectChange.setChangeType(ChangeTypeType.MODIFY);
    objectChange.setObjectType(UserType.COMPLEX_TYPE);
    displayJaxb("modifyObject input", objectChange, new QName(SchemaConstants.NS_C, "change"));
    assertNoRepoCache();
    // WHEN ObjectTypes.USER.getTypeQName(), 
    OperationResultType result = modifyObjectViaModelWS(objectChange);
    // THEN
    assertNoRepoCache();
    displayJaxb("modifyObject result", result, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("modifyObject has failed", result);
    // Check if user object was modified in the repo
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<UserType> uObject = repositoryService.getObject(UserType.class, USER_JACK_OID, null, repoResult);
    UserType repoUser = uObject.asObjectable();
    repoResult.computeStatus();
    display("User (repository)", repoUser);
    List<ObjectReferenceType> accountRefs = repoUser.getLinkRef();
    // only OpenDJ account should be left now
    assertEquals(1, accountRefs.size());
    ObjectReferenceType ref = accountRefs.get(0);
    assertEquals("Wrong OID in accountRef in " + repoUser, accountShadowOidOpendj, ref.getOid());
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 33 with OperationResultType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType in project midpoint by Evolveum.

the class TestSanity method test006reimportResourceDummy.

@Test
public void test006reimportResourceDummy() throws Exception {
    TestUtil.displayTestTile("test006reimportResourceDummy");
    //get object from repo (with version set and try to add it - it should be re-added, without error)
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<ResourceType> resource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, repoResult);
    assertNotNull(resource);
    ModelExecuteOptionsType options = new ModelExecuteOptionsType();
    options.setOverwrite(Boolean.TRUE);
    options.setIsImport(Boolean.TRUE);
    addObjectViaModelWS(resource.asObjectable(), options, new Holder<String>(), new Holder<OperationResultType>());
    //TODO: add some asserts
    //parse object from file again and try to add it - this should fail, becasue the same object already exists)
    resource = PrismTestUtil.parseObject(new File(RESOURCE_DUMMY_FILENAME));
    try {
        Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
        options = new ModelExecuteOptionsType();
        options.setIsImport(Boolean.TRUE);
        addObjectViaModelWS(resource.asObjectable(), options, new Holder<String>(), resultHolder);
        OperationResultType result = resultHolder.value;
        TestUtil.assertFailure(result);
        fail("Expected object already exists exception, but haven't got one.");
    } catch (FaultMessage ex) {
        LOGGER.info("fault {}", ex.getFaultInfo());
        LOGGER.info("fault {}", ex.getCause());
        if (ex.getFaultInfo() instanceof ObjectAlreadyExistsFaultType) {
        // this is OK, we expect this
        } else {
            fail("Expected object already exists exception, but haven't got one.");
        }
    }
//         ResourceType resourceType = uObject.asObjectable();
//         assertNotNull("Reference on the connector must not be null in resource.",resourceType.getConnectorRef());
//         assertNotNull("Missing oid reference on the connector",resourceType.getConnectorRef().getOid());
}
Also used : FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) ModelExecuteOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectAlreadyExistsFaultType(com.evolveum.midpoint.xml.ns._public.common.fault_3.ObjectAlreadyExistsFaultType) File(java.io.File) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 34 with OperationResultType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType in project midpoint by Evolveum.

the class TestSanity method test303LiveSyncLink.

@Test
public void test303LiveSyncLink() throws Exception {
    final String TEST_NAME = "test303LiveSyncLink";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    assertNoRepoCache();
    PrismObject<UserType> user = PrismTestUtil.parseObject(USER_E_LINK_ACTION_FILE);
    UserType userType = user.asObjectable();
    final String userOid = userType.getOid();
    // Encrypt e's password
    protector.encrypt(userType.getCredentials().getPassword().getValue());
    // create user in repository
    OperationResultType resultType = new OperationResultType();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>(resultType);
    Holder<String> oidHolder = new Holder<String>();
    display("Adding user object", userType);
    addObjectViaModelWS(userType, null, oidHolder, resultHolder);
    //check results
    assertNoRepoCache();
    displayJaxb("addObject result:", resultHolder.value, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("addObject has failed", resultHolder.value);
    //        AssertJUnit.assertEquals(userOid, oidHolder.value);
    //WHEN
    //create account for e which should be correlated
    final OperationResult result = new OperationResult(TestSanity.class.getName() + "." + TEST_NAME);
    final Task syncCycle = taskManager.getTask(TASK_OPENDJ_SYNC_OID, result);
    AssertJUnit.assertNotNull(syncCycle);
    int tokenBefore = findSyncToken(syncCycle);
    display("Sync token before", tokenBefore);
    Entry entry = openDJController.addEntryFromLdifFile(LDIF_E_FILENAME_LINK);
    display("Entry from LDIF", entry);
    // THEN
    // Wait a bit to give the sync cycle time to detect the change
    basicWaitForSyncChangeDetection(syncCycle, tokenBefore, 4, result);
    //check user and account ref
    userType = searchUserByName("e");
    List<ObjectReferenceType> accountRefs = userType.getLinkRef();
    assertEquals("Account ref not found, or found too many", 1, accountRefs.size());
    //check account defined by account ref
    String accountOid = accountRefs.get(0).getOid();
    ShadowType account = searchAccountByOid(accountOid);
    assertEqualsPolyString("Name doesn't match", "uid=e,ou=People,dc=example,dc=com", account.getName());
    assertAndStoreSyncTokenIncrement(syncCycle, 4);
    checkAllShadows();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Holder(javax.xml.ws.Holder) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 35 with OperationResultType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType in project midpoint by Evolveum.

the class TestSanity method test014AddDerbyAccountToUser.

/**
     * Add Derby account to user. This should result in account provisioning. Check if
     * that happens in repo and in Derby.
     */
@Test
public void test014AddDerbyAccountToUser() throws IOException, JAXBException, FaultMessage, ObjectNotFoundException, SchemaException, DirectoryException, SQLException {
    TestUtil.displayTestTile("test014AddDerbyAccountToUser");
    // GIVEN
    checkRepoDerbyResource();
    assertNoRepoCache();
    ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_USER_MODIFY_ADD_ACCOUNT_DERBY_FILENAME, ObjectDeltaType.class);
    // WHEN ObjectTypes.USER.getTypeQName(), 
    OperationResultType result = modifyObjectViaModelWS(objectChange);
    // THEN
    assertNoRepoCache();
    displayJaxb("modifyObject result", result, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("modifyObject has failed", result);
    // Check if user object was modified in the repo
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<UserType> uObject = repositoryService.getObject(UserType.class, USER_JACK_OID, null, repoResult);
    UserType repoUser = uObject.asObjectable();
    repoResult.computeStatus();
    display("User (repository)", repoUser);
    List<ObjectReferenceType> accountRefs = repoUser.getLinkRef();
    // OpenDJ account was added in previous test, hence 2 accounts
    assertEquals(2, accountRefs.size());
    ObjectReferenceType accountRef = null;
    for (ObjectReferenceType ref : accountRefs) {
        if (!ref.getOid().equals(accountShadowOidOpendj)) {
            accountRef = ref;
        }
    }
    accountShadowOidDerby = accountRef.getOid();
    assertFalse(accountShadowOidDerby.isEmpty());
    // Check if shadow was created in the repo
    repoResult = new OperationResult("getObject");
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidDerby, null, repoResult);
    ShadowType repoShadowType = repoShadow.asObjectable();
    repoResult.computeStatus();
    TestUtil.assertSuccess("addObject has failed", repoResult);
    display("Shadow (repository)", repoShadowType);
    assertNotNull(repoShadowType);
    assertEquals(RESOURCE_DERBY_OID, repoShadowType.getResourceRef().getOid());
    // Check the "name" property, it should be set to DN, not entryUUID
    assertEquals("Wrong name property", PrismTestUtil.createPolyStringType(USER_JACK_DERBY_LOGIN), repoShadowType.getName());
    // check attributes in the shadow: should be only identifiers (ICF UID)
    String uid = checkRepoShadow(repoShadow);
    // check if account was created in DB Table
    Statement stmt = derbyController.getExecutedStatementWhereLoginName(uid);
    ResultSet rs = stmt.getResultSet();
    System.out.println("RS: " + rs);
    assertTrue("No records found for login name " + uid, rs.next());
    assertEquals(USER_JACK_DERBY_LOGIN, rs.getString(DerbyController.COLUMN_LOGIN));
    assertEquals("Cpt. Jack Sparrow", rs.getString(DerbyController.COLUMN_FULL_NAME));
    // TODO: check password
    //assertEquals("3lizab3th",rs.getString(DerbyController.COLUMN_PASSWORD));
    System.out.println("Password: " + rs.getString(DerbyController.COLUMN_PASSWORD));
    assertFalse("Too many records found for login name " + uid, rs.next());
    rs.close();
    stmt.close();
    // Use getObject to test fetch of complete shadow
    assertNoRepoCache();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    // WHEN
    modelWeb.getObject(ObjectTypes.SHADOW.getTypeQName(), accountShadowOidDerby, options, objectHolder, resultHolder);
    // THEN
    assertNoRepoCache();
    displayJaxb("getObject result", resultHolder.value, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("getObject has failed", resultHolder.value);
    ShadowType modelShadow = (ShadowType) objectHolder.value;
    display("Shadow (model)", modelShadow);
    AssertJUnit.assertNotNull(modelShadow);
    AssertJUnit.assertEquals(RESOURCE_DERBY_OID, modelShadow.getResourceRef().getOid());
    assertAttribute(modelShadow, SchemaConstants.ICFS_UID, USER_JACK_DERBY_LOGIN);
    assertAttribute(modelShadow, SchemaConstants.ICFS_NAME, USER_JACK_DERBY_LOGIN);
    assertAttribute(resourceDerby, modelShadow, "FULL_NAME", "Cpt. Jack Sparrow");
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Statement(java.sql.Statement) Holder(javax.xml.ws.Holder) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GenericObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ResultSet(java.sql.ResultSet) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Aggregations

OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)172 Test (org.testng.annotations.Test)106 Holder (javax.xml.ws.Holder)78 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)75 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)63 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)57 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)56 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)53 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)49 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)47 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)34 SelectorQualifiedGetOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)34 ChangeRecordEntry (org.opends.server.util.ChangeRecordEntry)32 ObjectListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType)26 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)23 LogfileTestTailer (com.evolveum.midpoint.test.util.LogfileTestTailer)21 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)18 FaultMessage (com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage)18 QName (javax.xml.namespace.QName)18 GenericObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType)17