Search in sources :

Example 26 with OrgType

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

the class OrgStructTest method test002modifyOrgStructAddRefIncorrect.

@Test
public void test002modifyOrgStructAddRefIncorrect() throws Exception {
    OperationResult opResult = new OperationResult("test002modifyOrgStructAddRefIncorrect");
    // test modification of org ref in another org type..
    ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(MODIFY_ORG_INCORRECT_ADD_REF_FILENAME), ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<OrgType> delta = DeltaConvertor.createObjectDelta(modification, OrgType.class, prismContext);
    repositoryService.modifyObject(OrgType.class, MODIFY_ORG_INCORRECT_ADD_REF_OID, delta.getModifications(), opResult);
    Session session = open();
    try {
        List<ROrgClosure> orgClosure = getOrgClosureByDescendant(MODIFY_ORG_INCORRECT_ADD_REF_OID, session);
        LOGGER.info("after modify incorrect - closure");
        for (ROrgClosure c : orgClosure) {
            LOGGER.info("{}\t{}", new Object[] { c.getAncestor().getOid(), c.getDescendant().getOid() });
        }
        AssertJUnit.assertEquals(5, orgClosure.size());
        List<String> ancestors = new ArrayList<String>();
        ancestors.add(MODIFY_ORG_INCORRECT_ADD_REF_OID);
        ancestors.add(ORG_F001_OID);
        ancestors.add(ORG_F002_OID);
        for (String ancestorOid : ancestors) {
            orgClosure = getOrgClosure(ancestorOid, MODIFY_ORG_INCORRECT_ADD_REF_OID, session);
            AssertJUnit.assertEquals(1, orgClosure.size());
            AssertJUnit.assertEquals(ancestorOid, orgClosure.get(0).getAncestor().getOid());
            AssertJUnit.assertEquals(MODIFY_ORG_INCORRECT_ADD_REF_OID, orgClosure.get(0).getDescendant().getOid());
        }
    } finally {
        close(session);
    }
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) ROrgClosure(com.evolveum.midpoint.repo.sql.data.common.ROrgClosure) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 27 with OrgType

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

the class OrgStructTest method test002modifyOrgStructAddRef.

@Test
public void test002modifyOrgStructAddRef() throws Exception {
    OperationResult opResult = new OperationResult("test002modifyOrgStructAddRef");
    // test modification of org ref in another org type..
    ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(MODIFY_ORG_ADD_REF_FILENAME), ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<OrgType> delta = DeltaConvertor.createObjectDelta(modification, OrgType.class, prismContext);
    Query query;
    List<ROrgClosure> orgClosure;
    Session session = open();
    try {
        orgClosure = getOrgClosureByDescendant(MODIFY_ORG_ADD_REF_OID, session);
        LOGGER.info("before modify");
        for (ROrgClosure c : orgClosure) {
            LOGGER.info("{}\t{}", new Object[] { c.getAncestor().getOid(), c.getDescendant().getOid() });
        }
        AssertJUnit.assertEquals(3, orgClosure.size());
    } finally {
        close(session);
    }
    repositoryService.modifyObject(OrgType.class, MODIFY_ORG_ADD_REF_OID, delta.getModifications(), opResult);
    session = open();
    try {
        orgClosure = getOrgClosureByDescendant(MODIFY_ORG_ADD_REF_OID, session);
        LOGGER.info("after modify");
        for (ROrgClosure c : orgClosure) {
            LOGGER.info("{}\t{}", new Object[] { c.getAncestor().getOid(), c.getDescendant().getOid() });
        }
        AssertJUnit.assertEquals(4, orgClosure.size());
        List<String> ancestors = new ArrayList<String>();
        ancestors.add(MODIFY_ORG_ADD_REF_OID);
        ancestors.add(ORG_F003_OID);
        ancestors.add(ORG_F001_OID);
        ancestors.add(ORG_F002_OID);
        for (String ancestorOid : ancestors) {
            orgClosure = getOrgClosure(ancestorOid, MODIFY_ORG_ADD_REF_OID, session);
            LOGGER.info("=> A: {}, D: {}", orgClosure.get(0).getAncestor(), orgClosure.get(0).getDescendant());
            AssertJUnit.assertEquals(1, orgClosure.size());
            AssertJUnit.assertEquals(ancestorOid, orgClosure.get(0).getAncestor().getOid());
            AssertJUnit.assertEquals(MODIFY_ORG_ADD_REF_OID, orgClosure.get(0).getDescendant().getOid());
        }
    } finally {
        close(session);
    }
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) Query(org.hibernate.Query) ROrgClosure(com.evolveum.midpoint.repo.sql.data.common.ROrgClosure) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 28 with OrgType

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

the class TestOrgStructCaribbean method test104RecomputeGovernor.

/**
     * MID-3448
     */
@Test
public void test104RecomputeGovernor() throws Exception {
    final String TEST_NAME = "test104RecomputeGovernor";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TestOrgStructCaribbean.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.recompute(OrgType.class, ORG_GOVERNOR_OFFICE_OID, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismObject<OrgType> orgJamaica = getObject(OrgType.class, ORG_CARIBBEAN_JAMAICA_OID);
    display("Jamaica", orgJamaica);
    assertAssignedOrgs(orgJamaica, ORG_CARIBBEAN_THE_CROWN_OID);
    assertHasOrgs(orgJamaica, ORG_CARIBBEAN_THE_CROWN_OID);
    assertHasNoOrg(orgJamaica, ORG_GOVERNOR_OFFICE_OID);
    PrismObject<OrgType> orgMonkeyGovernor = getObject(OrgType.class, ORG_GOVERNOR_OFFICE_OID);
    display("Monkey Governor", orgMonkeyGovernor);
    assertHasNoOrg(orgMonkeyGovernor, ORG_CARIBBEAN_JAMAICA_OID);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 29 with OrgType

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

the class TestOrgStructCaribbean method test102RecomputeJamaica.

/**
     * MID-3448
     */
@Test
public void test102RecomputeJamaica() throws Exception {
    final String TEST_NAME = "test102RecomputeJamaica";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TestOrgStructCaribbean.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.recompute(OrgType.class, ORG_CARIBBEAN_JAMAICA_OID, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismObject<OrgType> orgJamaica = getObject(OrgType.class, ORG_CARIBBEAN_JAMAICA_OID);
    display("Jamaica", orgJamaica);
    assertAssignedOrgs(orgJamaica, ORG_CARIBBEAN_THE_CROWN_OID);
    assertHasOrgs(orgJamaica, ORG_CARIBBEAN_THE_CROWN_OID);
    assertHasNoOrg(orgJamaica, ORG_GOVERNOR_OFFICE_OID);
    PrismObject<OrgType> orgMonkeyGovernor = getObject(OrgType.class, ORG_GOVERNOR_OFFICE_OID);
    display("Monkey Governor", orgMonkeyGovernor);
    assertHasNoOrg(orgMonkeyGovernor, ORG_CARIBBEAN_JAMAICA_OID);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 30 with OrgType

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

the class TestOrgStruct method assertManager.

private void assertManager(String userOid, String managerOid, String orgType, boolean allowSelf, OperationResult result) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    PrismObject<UserType> user = getUser(userOid);
    ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(null, result));
    Collection<UserType> managers = libraryMidpointFunctions.getManagers(user.asObjectable(), orgType, allowSelf);
    ModelExpressionThreadLocalHolder.popExpressionEnvironment();
    if (managerOid == null) {
        if (managers == null || managers.isEmpty()) {
            return;
        } else {
            AssertJUnit.fail("Expected no manager for " + user + ", but got " + managers);
        }
    } else {
        if (managers == null) {
            AssertJUnit.fail("Expected manager for " + user + ", but got no manager");
        }
        if (managers.size() != 1) {
            AssertJUnit.fail("Expected one manager for " + user + ", but got: " + managers);
        } else {
            UserType manager = managers.iterator().next();
            if (manager.getOid().equals(managerOid)) {
                return;
            } else {
                AssertJUnit.fail("Expected manager with OID " + managerOid + " for " + user + ", but got " + manager);
            }
        }
    }
}
Also used : UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)123 Test (org.testng.annotations.Test)70 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)69 Task (com.evolveum.midpoint.task.api.Task)69 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)31 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)26 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)23 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)22 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)15 PrismObject (com.evolveum.midpoint.prism.PrismObject)13 ArrayList (java.util.ArrayList)13 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)11 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)11 Entry (org.opends.server.types.Entry)10 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)9 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)8 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)8 QName (javax.xml.namespace.QName)8 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)7