Example usage for javax.xml.ws Holder Holder

List of usage examples for javax.xml.ws Holder Holder

Introduction

In this page you can find the example usage for javax.xml.ws Holder Holder.

Prototype

public Holder() 

Source Link

Document

Creates a new holder with a null value.

Usage

From source file:com.evolveum.midpoint.testing.model.client.sample.TestExchangeConnector.java

private RoleType searchRoleByName(String roleName)
        throws SAXException, IOException, FaultMessage, JAXBException {
    // WARNING: in a real case make sure that the role name is properly escaped before putting it in XML
    SearchFilterType filter = ModelClientUtil.parseSearchFilterType(
            "<equal xmlns='http://prism.evolveum.com/xml/ns/public/query-3' xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3' >"
                    + "<path>c:name</path>" + "<value>" + roleName + "</value>" + "</equal>");
    QueryType query = new QueryType();
    query.setFilter(filter);//from  www .ja va 2s  . co  m
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    Holder<ObjectListType> objectListHolder = new Holder<ObjectListType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();

    modelPort.searchObjects(ModelClientUtil.getTypeQName(RoleType.class), query, options, objectListHolder,
            resultHolder);

    ObjectListType objectList = objectListHolder.value;
    List<ObjectType> objects = objectList.getObject();
    if (objects.isEmpty()) {
        return null;
    }
    if (objects.size() == 1) {
        return (RoleType) objects.get(0);
    }
    throw new IllegalStateException("Expected to find a single role with name '" + roleName + "' but found "
            + objects.size() + " users instead");
}

From source file:com.evolveum.midpoint.testing.model.client.sample.TestExchangeConnector.java

private Collection<RoleType> listRequestableRoles()
        throws SAXException, IOException, FaultMessage, JAXBException {
    SearchFilterType filter = ModelClientUtil.parseSearchFilterType(
            "<equal xmlns='http://prism.evolveum.com/xml/ns/public/query-3' xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3' >"
                    + "<path>c:requestable</path>" + "<value>true</value>" + "</equal>");
    QueryType query = new QueryType();
    query.setFilter(filter);/* ww  w .  j  av  a2  s  .c  o  m*/
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    Holder<ObjectListType> objectListHolder = new Holder<ObjectListType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();

    modelPort.searchObjects(ModelClientUtil.getTypeQName(RoleType.class), query, options, objectListHolder,
            resultHolder);

    ObjectListType objectList = objectListHolder.value;
    return (Collection) objectList.getObject();
}

From source file:com.evolveum.midpoint.testing.sanity.TestSanityLegacy.java

License:asdf

/**
 * Try to disable user. As the user has an account, the account should be disabled as well.
 *//*from  w w w.j a va  2s  .  co m*/
@Test
public void test030DisableUser() throws Exception {
    final String TEST_NAME = "test030DisableUser";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN

    ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_USER_MODIFY_ACTIVATION_DISABLE_FILENAME,
            ObjectDeltaType.class);

    Entry entry = openDJController.searchByUid("jack");
    assertOpenDJAccountJack(entry, "jack");

    String pwpAccountDisabled = OpenDJController.getAttributeValue(entry, "ds-pwp-account-disabled");
    display("ds-pwp-account-disabled before change", pwpAccountDisabled);
    assertTrue("LDAP account is not enabled (precondition)", openDJController.isAccountEnabled(entry));

    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> repoUser = repositoryService.getObject(UserType.class, USER_JACK_OID, null,
            repoResult);
    display("repository user", repoUser);
    UserType repoUserType = repoUser.asObjectable();

    // Check if nothing else was modified
    assertEqualsPolyString("wrong repo fullName", "Cpt. Jack Sparrow", repoUserType.getFullName());
    assertEqualsPolyString("wrong repo locality", "somewhere", repoUserType.getLocality());

    // Check if appropriate accountRef is still there
    List<ObjectReferenceType> accountRefs = repoUserType.getLinkRef();
    assertEquals(1, accountRefs.size());
    for (ObjectReferenceType accountRef : accountRefs) {
        assertTrue("No OID in " + accountRef + " in " + repoUserType,
                accountRef.getOid().equals(accountShadowOidOpendj));
    }

    // Check if shadow is still in the repo and that it is untouched
    repoResult = new OperationResult("getObject");

    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidOpendj,
            null, repoResult);
    display("repo shadow", repoShadow);
    ShadowType repoShadowType = repoShadow.asObjectable();

    repoResult.computeStatus();
    TestUtil.assertSuccess("getObject(repo) has failed", repoResult);
    AssertJUnit.assertNotNull(repoShadowType);
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());

    // check attributes in the shadow: should be only identifiers (ICF UID)
    String uid = checkRepoShadow(repoShadow);

    // Use getObject to test fetch of complete shadow

    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    assertNoRepoCache();

    // WHEN
    modelWeb.getObject(ObjectTypes.SHADOW.getTypeQName(), accountShadowOidOpendj, 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_OPENDJ_OID, modelShadow.getResourceRef().getOid());

    assertAttributeNotNull(modelShadow, ConnectorFactoryIcfImpl.ICFS_UID);
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "uid", "jack");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "givenName", "Jack");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "sn", "Sparrow");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "cn", "Cpt. Jack Sparrow");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "displayName", "Cpt. Jack Sparrow");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "l", "somewhere");

    assertNotNull("The account activation is null in the shadow", modelShadow.getActivation());
    assertNotNull("The account activation status was not present in shadow",
            modelShadow.getActivation().getAdministrativeStatus());
    assertEquals("The account was not disabled in the shadow", ActivationStatusType.DISABLED,
            modelShadow.getActivation().getAdministrativeStatus());

    // Check if LDAP account was updated

    entry = openDJController.searchAndAssertByEntryUuid(uid);
    assertOpenDJAccountJack(entry, "jack");

    pwpAccountDisabled = OpenDJController.getAttributeValue(entry, "ds-pwp-account-disabled");
    display("ds-pwp-account-disabled after change", pwpAccountDisabled);
    assertFalse("LDAP account was not disabled", openDJController.isAccountEnabled(entry));
}

From source file:com.evolveum.midpoint.testing.sanity.TestSanityLegacy.java

License:asdf

/**
 * Try to enable user after it has been disabled. As the user has an account, the account should be enabled as well.
 *//*from   w w  w .j  a va2 s  . co  m*/
@Test
public void test031EnableUser() throws Exception {
    final String TEST_NAME = "test031EnableUser";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN

    ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_USER_MODIFY_ACTIVATION_ENABLE_FILENAME,
            ObjectDeltaType.class);
    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();
    display("repo user", repoUser);

    // Check if nothing else was modified
    PrismAsserts.assertEqualsPolyString("wrong repo fullName", "Cpt. Jack Sparrow", repoUser.getFullName());
    PrismAsserts.assertEqualsPolyString("wrong repo locality", "somewhere", repoUser.getLocality());

    // Check if appropriate accountRef is still there
    List<ObjectReferenceType> accountRefs = repoUser.getLinkRef();
    assertEquals(1, accountRefs.size());
    for (ObjectReferenceType accountRef : accountRefs) {
        assertTrue("No OID in " + accountRef + " in " + repoUser,
                accountRef.getOid().equals(accountShadowOidOpendj));
    }

    // Check if shadow is still in the repo and that it is untouched
    repoResult = new OperationResult("getObject");

    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidOpendj,
            null, repoResult);
    ShadowType repoShadowType = repoShadow.asObjectable();

    repoResult.computeStatus();
    TestUtil.assertSuccess("getObject(repo) has failed", repoResult);
    display("repo shadow", repoShadowType);
    AssertJUnit.assertNotNull(repoShadowType);
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());

    // check attributes in the shadow: should be only identifiers (ICF UID)
    String uid = checkRepoShadow(repoShadow);

    // Use getObject to test fetch of complete shadow

    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    assertNoRepoCache();

    // WHEN
    modelWeb.getObject(ObjectTypes.SHADOW.getTypeQName(), accountShadowOidOpendj, 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_OPENDJ_OID, modelShadow.getResourceRef().getOid());

    assertAttributeNotNull(modelShadow, ConnectorFactoryIcfImpl.ICFS_UID);
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "uid", "jack");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "givenName", "Jack");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "sn", "Sparrow");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "cn", "Cpt. Jack Sparrow");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "displayName", "Cpt. Jack Sparrow");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "l", "somewhere");

    assertNotNull("The account activation is null in the shadow", modelShadow.getActivation());
    assertNotNull("The account activation status was not present in shadow",
            modelShadow.getActivation().getAdministrativeStatus());
    assertEquals("The account was not enabled in the shadow", ActivationStatusType.ENABLED,
            modelShadow.getActivation().getAdministrativeStatus());

    // Check if LDAP account was updated

    Entry entry = openDJController.searchAndAssertByEntryUuid(uid);
    assertOpenDJAccountJack(entry, "jack");

    // The value of ds-pwp-account-disabled should have been removed
    String pwpAccountDisabled = OpenDJController.getAttributeValue(entry, "ds-pwp-account-disabled");
    System.out.println("ds-pwp-account-disabled after change: " + pwpAccountDisabled);
    assertTrue("LDAP account was not enabled", openDJController.isAccountEnabled(entry));
}

From source file:com.evolveum.midpoint.testing.sanity.TestSanity.java

License:asdf

/**
 * Try to disable user. As the user has an account, the account should be disabled as well.
 *///from  www  .  j ava  2s  .  c o m
@Test
public void test030DisableUser() throws Exception {
    final String TEST_NAME = "test030DisableUser";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN

    ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_USER_MODIFY_ACTIVATION_DISABLE_FILENAME,
            ObjectDeltaType.class);

    Entry entry = openDJController.searchByUid("jack");
    assertOpenDJAccountJack(entry, "jack");

    String pwpAccountDisabled = OpenDJController.getAttributeValue(entry, "ds-pwp-account-disabled");
    display("ds-pwp-account-disabled before change", pwpAccountDisabled);
    assertTrue("LDAP account is not enabled (precondition)", openDJController.isAccountEnabled(entry));

    assertNoRepoCache();

    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    OperationResultType result = modifyObjectViaModelWS(objectChange);

    // THEN
    TestUtil.displayThen(TEST_NAME);
    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> repoUser = repositoryService.getObject(UserType.class, USER_JACK_OID, null,
            repoResult);
    display("repository user", repoUser);
    UserType repoUserType = repoUser.asObjectable();

    // Check if nothing else was modified
    assertEqualsPolyString("wrong repo fullName", "Cpt. Jack Sparrow", repoUserType.getFullName());
    assertEqualsPolyString("wrong repo locality", "somewhere", repoUserType.getLocality());

    // Check if appropriate accountRef is still there
    List<ObjectReferenceType> accountRefs = repoUserType.getLinkRef();
    assertEquals(2, accountRefs.size());
    for (ObjectReferenceType accountRef : accountRefs) {
        assertTrue("No OID in " + accountRef + " in " + repoUserType,
                accountRef.getOid().equals(accountShadowOidOpendj)
                        || accountRef.getOid().equals(accountShadowOidDerby));
    }

    // Check if shadow is still in the repo and that it is untouched
    repoResult = new OperationResult("getObject");

    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidOpendj,
            null, repoResult);
    display("repo shadow", repoShadow);
    ShadowType repoShadowType = repoShadow.asObjectable();

    repoResult.computeStatus();
    TestUtil.assertSuccess("getObject(repo) has failed", repoResult);
    AssertJUnit.assertNotNull(repoShadowType);
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());

    // check attributes in the shadow: should be only identifiers (ICF UID)
    String uid = checkRepoShadow(repoShadow);

    // Check if LDAP account was updated

    entry = openDJController.searchAndAssertByEntryUuid(uid);
    assertOpenDJAccountJack(entry, "jack");

    pwpAccountDisabled = OpenDJController.getAttributeValue(entry, "ds-pwp-account-disabled");
    display("ds-pwp-account-disabled after change", pwpAccountDisabled);
    assertFalse("LDAP account was not disabled", openDJController.isAccountEnabled(entry));

    // Use getObject to test fetch of complete shadow

    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    assertNoRepoCache();

    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelWeb.getObject(ObjectTypes.SHADOW.getTypeQName(), accountShadowOidOpendj, options, objectHolder,
            resultHolder);

    // THEN
    TestUtil.displayThen(TEST_NAME);
    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_OPENDJ_OID, modelShadow.getResourceRef().getOid());

    assertAttributeNotNull(modelShadow, getOpenDjPrimaryIdentifierQName());
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "uid", "jack");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "givenName", "Jack");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "sn", "Sparrow");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "cn", "Cpt. Jack Sparrow");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "displayName", "Cpt. Jack Sparrow");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "l", "somewhere");

    assertNotNull("The account activation is null in the shadow", modelShadow.getActivation());
    assertNotNull("The account activation status was not present in shadow",
            modelShadow.getActivation().getAdministrativeStatus());
    assertEquals("The account was not disabled in the shadow", ActivationStatusType.DISABLED,
            modelShadow.getActivation().getAdministrativeStatus());

}

From source file:com.evolveum.midpoint.testing.sanity.TestSanity.java

License:asdf

/**
 * Try to enable user after it has been disabled. As the user has an account, the account should be enabled as well.
 *///w w  w.jav a 2  s  . co  m
@Test
public void test031EnableUser() throws Exception {
    final String TEST_NAME = "test031EnableUser";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN

    ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_USER_MODIFY_ACTIVATION_ENABLE_FILENAME,
            ObjectDeltaType.class);
    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();
    display("repo user", repoUser);

    // Check if nothing else was modified
    PrismAsserts.assertEqualsPolyString("wrong repo fullName", "Cpt. Jack Sparrow", repoUser.getFullName());
    PrismAsserts.assertEqualsPolyString("wrong repo locality", "somewhere", repoUser.getLocality());

    // Check if appropriate accountRef is still there
    List<ObjectReferenceType> accountRefs = repoUser.getLinkRef();
    assertEquals(2, accountRefs.size());
    for (ObjectReferenceType accountRef : accountRefs) {
        assertTrue("No OID in " + accountRef + " in " + repoUser,
                accountRef.getOid().equals(accountShadowOidOpendj)
                        || accountRef.getOid().equals(accountShadowOidDerby));
    }

    // Check if shadow is still in the repo and that it is untouched
    repoResult = new OperationResult("getObject");

    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidOpendj,
            null, repoResult);
    ShadowType repoShadowType = repoShadow.asObjectable();

    repoResult.computeStatus();
    TestUtil.assertSuccess("getObject(repo) has failed", repoResult);
    display("repo shadow", repoShadowType);
    AssertJUnit.assertNotNull(repoShadowType);
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());

    // check attributes in the shadow: should be only identifiers (ICF UID)
    String uid = checkRepoShadow(repoShadow);

    // Use getObject to test fetch of complete shadow

    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    assertNoRepoCache();

    // WHEN
    modelWeb.getObject(ObjectTypes.SHADOW.getTypeQName(), accountShadowOidOpendj, 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_OPENDJ_OID, modelShadow.getResourceRef().getOid());

    assertAttributeNotNull(modelShadow, getOpenDjPrimaryIdentifierQName());
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "uid", "jack");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "givenName", "Jack");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "sn", "Sparrow");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "cn", "Cpt. Jack Sparrow");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "displayName", "Cpt. Jack Sparrow");
    assertAttribute(modelShadow, resourceTypeOpenDjrepo, "l", "somewhere");

    assertNotNull("The account activation is null in the shadow", modelShadow.getActivation());
    assertNotNull("The account activation status was not present in shadow",
            modelShadow.getActivation().getAdministrativeStatus());
    assertEquals("The account was not enabled in the shadow", ActivationStatusType.ENABLED,
            modelShadow.getActivation().getAdministrativeStatus());

    // Check if LDAP account was updated

    Entry entry = openDJController.searchAndAssertByEntryUuid(uid);
    assertOpenDJAccountJack(entry, "jack");

    // The value of ds-pwp-account-disabled should have been removed
    String pwpAccountDisabled = OpenDJController.getAttributeValue(entry, "ds-pwp-account-disabled");
    System.out.println("ds-pwp-account-disabled after change: " + pwpAccountDisabled);
    assertTrue("LDAP account was not enabled", openDJController.isAccountEnabled(entry));
}

From source file:com.evolveum.midpoint.testing.sanity.TestSanity.java

License:asdf

@Test
public void test101AccountOwnerAfterRole() throws Exception {
    final String TEST_NAME = "test101AccountOwnerAfterRole";
    TestUtil.displayTestTile(TEST_NAME);

    // GIVEN//from w w  w  .j ava 2s. c om

    assertNoRepoCache();

    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    Holder<UserType> userHolder = new Holder<UserType>();

    // WHEN

    modelWeb.findShadowOwner(accountShadowOidGuybrushOpendj, userHolder, resultHolder);

    // THEN

    TestUtil.assertSuccess("listAccountShadowOwner has failed (result)", resultHolder.value);
    UserType user = userHolder.value;
    assertNotNull("No owner", user);
    assertEquals(USER_GUYBRUSH_OID, user.getOid());

    System.out.println(
            "Account " + accountShadowOidGuybrushOpendj + " has owner " + ObjectTypeUtil.toShortString(user));
}

From source file:com.evolveum.midpoint.testing.sanity.TestSanityLegacy.java

License:asdf

@Test
public void test400ImportFromResource() throws Exception {
    final String TEST_NAME = "test400ImportFromResource";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN//from w w  w.  j  a  va 2 s .  c o  m
    checkAllShadows();
    assertNoRepoCache();

    OperationResult result = new OperationResult(TestSanityLegacy.class.getName() + "." + TEST_NAME);

    // Make sure Mr. Gibbs has "l" attribute set to the same value as an outbound expression is setting
    ChangeRecordEntry entry = openDJController.executeLdifChange(LDIF_GIBBS_MODIFY_FILE);
    display("Entry from LDIF", entry);

    // Let's add an entry with multiple uids.
    Entry addEntry = openDJController.addEntryFromLdifFile(LDIF_HERMAN_FILENAME);
    display("Entry from LDIF", addEntry);

    // WHEN
    TaskType taskType = modelWeb.importFromResource(RESOURCE_OPENDJ_OID, IMPORT_OBJECTCLASS);

    // THEN

    assertNoRepoCache();
    displayJaxb("importFromResource result", taskType.getResult(), SchemaConstants.C_RESULT);
    AssertJUnit.assertEquals("importFromResource has failed", OperationResultStatusType.IN_PROGRESS,
            taskType.getResult().getStatus());
    // Convert the returned TaskType to a more usable Task
    Task task = taskManager.createTaskInstance(taskType.asPrismObject(), result);
    AssertJUnit.assertNotNull(task);
    assertNotNull(task.getOid());
    AssertJUnit.assertTrue(task.isAsynchronous());
    AssertJUnit.assertEquals(TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
    //        AssertJUnit.assertEquals(TaskExclusivityStatus.CLAIMED, task.getExclusivityStatus());

    display("Import task after launch", task);

    PrismObject<TaskType> tObject = repositoryService.getObject(TaskType.class, task.getOid(), null, result);
    TaskType taskAfter = tObject.asObjectable();
    display("Import task in repo after launch", taskAfter);

    result.computeStatus();
    TestUtil.assertSuccess("getObject has failed", result);

    final String taskOid = task.getOid();

    waitFor("Waiting for import to complete", new Checker() {
        @Override
        public boolean check() throws Exception {
            Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
            Holder<ObjectType> objectHolder = new Holder<ObjectType>();
            OperationResult opResult = new OperationResult("import check");
            assertNoRepoCache();
            SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
            modelWeb.getObject(ObjectTypes.TASK.getTypeQName(), taskOid, options, objectHolder, resultHolder);
            assertNoRepoCache();
            //            display("getObject result (wait loop)",resultHolder.value);
            TestUtil.assertSuccess("getObject has failed", resultHolder.value);
            Task task = taskManager.createTaskInstance(objectHolder.value.asPrismObject(), opResult);
            System.out.println(new Date() + ": Import task status: " + task.getExecutionStatus()
                    + ", progress: " + task.getProgress());
            if (task.getExecutionStatus() == TaskExecutionStatus.CLOSED) {
                // Task closed, wait finished
                return true;
            }
            //            IntegrationTestTools.display("Task result while waiting: ", task.getResult());
            return false;
        }

        @Override
        public void timeout() {
            // No reaction, the test will fail right after return from this
        }
    }, 180000);

    // wait a second until the task will be definitely saved
    Thread.sleep(1000);

    //### Check task state after the task is finished ###

    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    assertNoRepoCache();

    modelWeb.getObject(ObjectTypes.TASK.getTypeQName(), task.getOid(), options, objectHolder, resultHolder);

    assertNoRepoCache();
    TestUtil.assertSuccess("getObject has failed", resultHolder.value);
    task = taskManager.createTaskInstance(objectHolder.value.asPrismObject(), result);

    display("Import task after finish (fetched from model)", task);

    AssertJUnit.assertEquals(TaskExecutionStatus.CLOSED, task.getExecutionStatus());

    assertNotNull("Null lastRunStartTimestamp in " + task, task.getLastRunStartTimestamp());
    assertNotNull("Null lastRunFinishTimestamp in " + task, task.getLastRunFinishTimestamp());

    long importDuration = task.getLastRunFinishTimestamp() - task.getLastRunStartTimestamp();
    double usersPerSec = (task.getProgress() * 1000) / importDuration;
    display("Imported " + task.getProgress() + " users in " + importDuration + " milliseconds (" + usersPerSec
            + " users/sec)");

    OperationResult taskResult = task.getResult();
    AssertJUnit.assertNotNull("Task has no result", taskResult);
    TestUtil.assertSuccess("Import task result is not success", taskResult);
    AssertJUnit.assertTrue("Task failed", taskResult.isSuccess());

    AssertJUnit.assertTrue("No progress", task.getProgress() > 0);

    //### Check if the import created users and shadows ###

    // Listing of shadows is not supported by the provisioning. So we need
    // to look directly into repository
    List<PrismObject<ShadowType>> sobjects = repositoryService.searchObjects(ShadowType.class, null, null,
            result);
    result.computeStatus();
    TestUtil.assertSuccess("listObjects has failed", result);
    AssertJUnit.assertFalse("No shadows created", sobjects.isEmpty());

    for (PrismObject<ShadowType> aObject : sobjects) {
        ShadowType shadow = aObject.asObjectable();
        display("Shadow object after import (repo)", shadow);
        assertNotEmpty("No OID in shadow", shadow.getOid()); // This would be really strange ;-)
        assertNotEmpty("No name in shadow", shadow.getName());
        AssertJUnit.assertNotNull("No objectclass in shadow", shadow.getObjectClass());
        AssertJUnit.assertNotNull("Null attributes in shadow", shadow.getAttributes());
        assertAttributeNotNull("No UID in shadow", shadow, ConnectorFactoryIcfImpl.ICFS_UID);
    }

    Holder<ObjectListType> listHolder = new Holder<ObjectListType>();
    assertNoRepoCache();

    modelWeb.searchObjects(ObjectTypes.USER.getTypeQName(), null, null, listHolder, resultHolder);

    assertNoRepoCache();
    ObjectListType uobjects = listHolder.value;
    TestUtil.assertSuccess("listObjects has failed", resultHolder.value);
    AssertJUnit.assertFalse("No users created", uobjects.getObject().isEmpty());

    // TODO: use another account, not guybrush

    display("Users after import " + uobjects.getObject().size());

    for (ObjectType oo : uobjects.getObject()) {
        UserType user = (UserType) oo;
        if (SystemObjectsType.USER_ADMINISTRATOR.value().equals(user.getOid())) {
            //skip administrator check
            continue;
        }
        display("User after import (repo)", user);
        assertNotEmpty("No OID in user", user.getOid()); // This would be
        // really
        // strange ;-)
        assertNotEmpty("No name in user", user.getName());
        assertNotNull("No fullName in user", user.getFullName());
        assertNotEmpty("No fullName in user", user.getFullName().getOrig());
        assertNotEmpty("No familyName in user", user.getFamilyName().getOrig());
        // givenName is not mandatory in LDAP, therefore givenName may not
        // be present on user

        if (user.getName().getOrig().equals(USER_GUYBRUSH_USERNAME)) {
            // skip the rest of checks for guybrush, he does not have LDAP account now
            continue;
        }

        assertTrue(
                "User " + user.getName() + " is disabled (" + user.getActivation().getAdministrativeStatus()
                        + ")",
                user.getActivation() == null
                        || user.getActivation().getAdministrativeStatus() == ActivationStatusType.ENABLED);

        List<ObjectReferenceType> accountRefs = user.getLinkRef();
        AssertJUnit.assertEquals("Wrong accountRef for user " + user.getName(), 1, accountRefs.size());
        ObjectReferenceType accountRef = accountRefs.get(0);

        boolean found = false;
        for (PrismObject<ShadowType> aObject : sobjects) {
            ShadowType acc = aObject.asObjectable();
            if (accountRef.getOid().equals(acc.getOid())) {
                found = true;
                break;
            }
        }
        if (!found) {
            AssertJUnit.fail("accountRef does not point to existing account " + accountRef.getOid());
        }

        PrismObject<ShadowType> aObject = modelService.getObject(ShadowType.class, accountRef.getOid(), null,
                task, result);
        ShadowType account = aObject.asObjectable();

        display("Account after import ", account);

        String attributeValueL = ShadowUtil.getMultiStringAttributeValueAsSingle(account,
                new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "l"));
        //            assertEquals("Unexcpected value of l", "middle of nowhere", attributeValueL);
        assertEquals("Unexcpected value of l", getUserLocality(user), attributeValueL);
    }

    // This also includes "idm" user imported from LDAP. Later we need to ignore that one.
    assertEquals("Wrong number of users after import", 10, uobjects.getObject().size());

    checkAllShadows();

}

From source file:com.evolveum.midpoint.testing.sanity.TestSanity.java

License:asdf

@Test
public void test400ImportFromResource() throws Exception {
    final String TEST_NAME = "test400ImportFromResource";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN/*from www .  j  a v a2 s. co m*/
    checkAllShadows();
    assertNoRepoCache();

    OperationResult result = new OperationResult(TestSanity.class.getName() + "." + TEST_NAME);

    // Make sure Mr. Gibbs has "l" attribute set to the same value as an outbound expression is setting
    ChangeRecordEntry entry = openDJController.executeLdifChange(LDIF_GIBBS_MODIFY_FILE);
    display("Entry from LDIF", entry);

    // Let's add an entry with multiple uids.
    Entry addEntry = openDJController.addEntryFromLdifFile(LDIF_HERMAN_FILENAME);
    display("Entry from LDIF", addEntry);

    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    TaskType taskType = modelWeb.importFromResource(RESOURCE_OPENDJ_OID, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);

    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertNoRepoCache();
    displayJaxb("importFromResource result", taskType.getResult(), SchemaConstants.C_RESULT);
    AssertJUnit.assertEquals("importFromResource has failed", OperationResultStatusType.IN_PROGRESS,
            taskType.getResult().getStatus());
    // Convert the returned TaskType to a more usable Task
    Task task = taskManager.createTaskInstance(taskType.asPrismObject(), result);
    AssertJUnit.assertNotNull(task);
    assertNotNull(task.getOid());
    AssertJUnit.assertTrue(task.isAsynchronous());
    AssertJUnit.assertEquals(TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
    //        AssertJUnit.assertEquals(TaskExclusivityStatus.CLAIMED, task.getExclusivityStatus());

    display("Import task after launch", task);

    PrismObject<TaskType> tObject = repositoryService.getObject(TaskType.class, task.getOid(), null, result);
    TaskType taskAfter = tObject.asObjectable();
    display("Import task in repo after launch", taskAfter);

    result.computeStatus();
    TestUtil.assertSuccess("getObject has failed", result);

    final String taskOid = task.getOid();

    waitFor("Waiting for import to complete", new Checker() {
        @Override
        public boolean check() throws Exception {
            Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
            Holder<ObjectType> objectHolder = new Holder<ObjectType>();
            OperationResult opResult = new OperationResult("import check");
            assertNoRepoCache();
            SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
            modelWeb.getObject(ObjectTypes.TASK.getTypeQName(), taskOid, options, objectHolder, resultHolder);
            assertNoRepoCache();
            //            display("getObject result (wait loop)",resultHolder.value);
            TestUtil.assertSuccess("getObject has failed", resultHolder.value);
            Task task = taskManager.createTaskInstance(objectHolder.value.asPrismObject(), opResult);
            System.out.println(new Date() + ": Import task status: " + task.getExecutionStatus()
                    + ", progress: " + task.getProgress());
            if (task.getExecutionStatus() == TaskExecutionStatus.CLOSED) {
                // Task closed, wait finished
                return true;
            }
            //            IntegrationTestTools.display("Task result while waiting: ", task.getResult());
            return false;
        }

        @Override
        public void timeout() {
            // No reaction, the test will fail right after return from this
        }
    }, 180000);

    // wait a second until the task will be definitely saved
    Thread.sleep(1000);

    //### Check task state after the task is finished ###

    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    assertNoRepoCache();

    modelWeb.getObject(ObjectTypes.TASK.getTypeQName(), task.getOid(), options, objectHolder, resultHolder);

    assertNoRepoCache();
    TestUtil.assertSuccess("getObject has failed", resultHolder.value);
    task = taskManager.createTaskInstance(objectHolder.value.asPrismObject(), result);

    display("Import task after finish (fetched from model)", task);

    AssertJUnit.assertEquals(TaskExecutionStatus.CLOSED, task.getExecutionStatus());

    assertNotNull("Null lastRunStartTimestamp in " + task, task.getLastRunStartTimestamp());
    assertNotNull("Null lastRunFinishTimestamp in " + task, task.getLastRunFinishTimestamp());

    long importDuration = task.getLastRunFinishTimestamp() - task.getLastRunStartTimestamp();
    double usersPerSec = (task.getProgress() * 1000) / importDuration;
    display("Imported " + task.getProgress() + " users in " + importDuration + " milliseconds (" + usersPerSec
            + " users/sec)");

    OperationResult taskResult = task.getResult();
    AssertJUnit.assertNotNull("Task has no result", taskResult);
    TestUtil.assertSuccess("Import task result is not success", taskResult);
    AssertJUnit.assertTrue("Task failed", taskResult.isSuccess());

    AssertJUnit.assertTrue("No progress", task.getProgress() > 0);

    //### Check if the import created users and shadows ###

    // Listing of shadows is not supported by the provisioning. So we need
    // to look directly into repository
    List<PrismObject<ShadowType>> sobjects = repositoryService.searchObjects(ShadowType.class, null, null,
            result);
    result.computeStatus();
    TestUtil.assertSuccess("listObjects has failed", result);
    AssertJUnit.assertFalse("No shadows created", sobjects.isEmpty());

    for (PrismObject<ShadowType> aObject : sobjects) {
        ShadowType shadow = aObject.asObjectable();
        display("Shadow object after import (repo)", shadow);
        assertNotEmpty("No OID in shadow", shadow.getOid()); // This would be really strange ;-)
        assertNotEmpty("No name in shadow", shadow.getName());
        AssertJUnit.assertNotNull("No objectclass in shadow", shadow.getObjectClass());
        AssertJUnit.assertNotNull("Null attributes in shadow", shadow.getAttributes());
        String resourceOid = shadow.getResourceRef().getOid();
        if (resourceOid.equals(RESOURCE_OPENDJ_OID)) {
            assertAttributeNotNull("No identifier in shadow", shadow, getOpenDjPrimaryIdentifierQName());
        } else {
            assertAttributeNotNull("No UID in shadow", shadow, ConnectorFactoryIcfImpl.ICFS_UID);
        }
    }

    Holder<ObjectListType> listHolder = new Holder<ObjectListType>();
    assertNoRepoCache();

    modelWeb.searchObjects(ObjectTypes.USER.getTypeQName(), null, null, listHolder, resultHolder);

    assertNoRepoCache();
    ObjectListType uobjects = listHolder.value;
    TestUtil.assertSuccess("listObjects has failed", resultHolder.value);
    AssertJUnit.assertFalse("No users created", uobjects.getObject().isEmpty());

    // TODO: use another account, not guybrush

    display("Users after import " + uobjects.getObject().size());

    for (ObjectType oo : uobjects.getObject()) {
        UserType user = (UserType) oo;
        if (SystemObjectsType.USER_ADMINISTRATOR.value().equals(user.getOid())) {
            //skip administrator check
            continue;
        }
        display("User after import (repo)", user);
        assertNotEmpty("No OID in user", user.getOid()); // This would be
        // really
        // strange ;-)
        assertNotEmpty("No name in user", user.getName());
        assertNotNull("No fullName in user", user.getFullName());
        assertNotEmpty("No fullName in user", user.getFullName().getOrig());
        assertNotEmpty("No familyName in user", user.getFamilyName().getOrig());
        // givenName is not mandatory in LDAP, therefore givenName may not
        // be present on user

        if (user.getName().getOrig().equals(USER_GUYBRUSH_USERNAME)) {
            // skip the rest of checks for guybrush, he does not have LDAP account now
            continue;
        }

        assertTrue(
                "User " + user.getName() + " is disabled (" + user.getActivation().getAdministrativeStatus()
                        + ")",
                user.getActivation() == null
                        || user.getActivation().getAdministrativeStatus() == ActivationStatusType.ENABLED);

        List<ObjectReferenceType> accountRefs = user.getLinkRef();
        AssertJUnit.assertEquals("Wrong accountRef for user " + user.getName(), 1, accountRefs.size());
        ObjectReferenceType accountRef = accountRefs.get(0);

        boolean found = false;
        for (PrismObject<ShadowType> aObject : sobjects) {
            ShadowType acc = aObject.asObjectable();
            if (accountRef.getOid().equals(acc.getOid())) {
                found = true;
                break;
            }
        }
        if (!found) {
            AssertJUnit.fail("accountRef does not point to existing account " + accountRef.getOid());
        }

        PrismObject<ShadowType> aObject = modelService.getObject(ShadowType.class, accountRef.getOid(), null,
                task, result);
        ShadowType account = aObject.asObjectable();

        display("Account after import ", account);

        String attributeValueL = ShadowUtil.getMultiStringAttributeValueAsSingle(account,
                new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "l"));
        //            assertEquals("Unexcpected value of l", "middle of nowhere", attributeValueL);
        assertEquals("Unexcpected value of l", getUserLocality(user), attributeValueL);
    }

    // This also includes "idm" user imported from LDAP. Later we need to ignore that one.
    assertEquals("Wrong number of users after import", 10, uobjects.getObject().size());

    checkAllShadows();

}

From source file:org.alfresco.filesys.repo.ContentDiskDriverTest.java

public void testFileInformationUpdatingByEditorUserForAlf8808() throws Exception {
    final Holder<org.alfresco.service.cmr.model.FileInfo> editorFolder = new Holder<org.alfresco.service.cmr.model.FileInfo>();
    final Holder<org.alfresco.service.cmr.model.FileInfo> testFile = new Holder<org.alfresco.service.cmr.model.FileInfo>();

    // Configuring test server with test server configuration and getting test tree connection for test shared device
    ServerConfiguration config = new ServerConfiguration(ContentDiskDriverTest.TEST_SERVER_NAME);
    TestServer server = new TestServer(ContentDiskDriverTest.TEST_SERVER_NAME, config);
    DiskSharedDevice device = getDiskSharedDevice();
    final TreeConnection treeConnection = server.getTreeConnection(device);

    // Getting target entity for testing - ContentDiskDriver
    final ExtendedDiskInterface deviceInterface = (ExtendedDiskInterface) treeConnection.getInterface();
    // Creating mock-session
    final SrvSession session = new TestSrvSession(13, server, ContentDiskDriverTest.TEST_PROTOTYPE_NAME,
            ContentDiskDriverTest.TEST_REMOTE_NAME);

    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
        @Override/*from www .  j a va  2 s  .  c om*/
        public Void execute() throws Throwable {
            try {
                NodeRef rootNode = repositoryHelper.getCompanyHome();
                // Creating test user to invite him as Editor for test content. This user will be created correctly (with person and authentication options)
                createUser(ContentDiskDriverTest.TEST_USER_AUTHORITY, ContentDiskDriverTest.TEST_USER_AUTHORITY,
                        rootNode);
                // Safely creating folder for test content
                editorFolder.value = getOrCreateNode(rootNode, PermissionService.EDITOR,
                        ContentModel.TYPE_FOLDER).getFirst();
                // Creating test content which will be editable by user created above
                testFile.value = getOrCreateNode(rootNode, "Test.txt", ContentModel.TYPE_CONTENT).getFirst();

                // Applying 'Editor' role for test user to test file
                permissionService.setPermission(testFile.value.getNodeRef(),
                        ContentDiskDriverTest.TEST_USER_AUTHORITY, PermissionService.EDITOR, true);

                try {
                    // Creating data for target method invocation
                    final FileInfo updatedInfo = new FileInfo();
                    updatedInfo.setFileName(testFile.value.getName());
                    updatedInfo.setFileId(DefaultTypeConverter.INSTANCE
                            .intValue(testFile.value.getProperties().get(ContentModel.PROP_NODE_DBID)));

                    // Testing ContentDiskDriver.setFileInformation() with test user authenticated who has 'Editor' role for test content.
                    // This method should fail if check on 'DELETE' permission was not moved to 'DeleteOnClose' context
                    AuthenticationUtil.runAs(new RunAsWork<Void>() {
                        @Override
                        public Void doWork() throws Exception {
                            deviceInterface.setFileInformation(session, treeConnection,
                                    testFile.value.getName(), updatedInfo);
                            return null;
                        }
                    }, ContentDiskDriverTest.TEST_USER_AUTHORITY);
                } catch (Exception e) {
                    // Informing about test failure. Expected exception is 'org.alfresco.jlan.server.filesys.AccessDeniedException'
                    if (e.getCause() instanceof AccessDeniedException) {
                        fail("For user='" + TEST_USER_AUTHORITY + "' " + e.getCause().toString());
                    } else {
                        fail("Unexpected exception was caught: " + e.toString());
                    }
                }
            } finally {
                // Cleaning all test data and rolling back transaction to revert all introduced changes during testing

                if (authenticationService.authenticationExists(ContentDiskDriverTest.TEST_USER_AUTHORITY)) {
                    authenticationService.deleteAuthentication(ContentDiskDriverTest.TEST_USER_AUTHORITY);
                }

                if (personService.personExists(ContentDiskDriverTest.TEST_USER_AUTHORITY)) {
                    personService.deletePerson(ContentDiskDriverTest.TEST_USER_AUTHORITY);
                }

                try {
                    if (null != testFile.value) {
                        nodeService.deleteNode(testFile.value.getNodeRef());
                    }
                } catch (Exception e) {
                    // Doing nothing
                }

                try {
                    if (null != editorFolder.value) {
                        nodeService.deleteNode(editorFolder.value.getNodeRef());
                    }
                } catch (Exception e) {
                    // Doing nothing
                }
            }

            return null;
        }
    }, false, true);
}