Search in sources :

Example 26 with FaultMessage

use of com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage in project midpoint by Evolveum.

the class TestSanityLegacy method modifyObjectViaModelWS.

private OperationResultType modifyObjectViaModelWS(ObjectDeltaType objectChange) throws FaultMessage {
    ObjectDeltaListType deltaList = new ObjectDeltaListType();
    deltaList.getDelta().add(objectChange);
    ObjectDeltaOperationListType list = modelWeb.executeChanges(deltaList, null);
    return getOdoFromDeltaOperationList(list, objectChange).getExecutionResult();
}
Also used : ObjectDeltaOperationListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType) ObjectDeltaListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)

Example 27 with FaultMessage

use of com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage in project midpoint by Evolveum.

the class TestSanityLegacy method test400ImportFromResource.

@Test
public void test400ImportFromResource() throws Exception {
    final String TEST_NAME = "test400ImportFromResource";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    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 CommonException {
            Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
            Holder<ObjectType> objectHolder = new Holder<ObjectType>();
            OperationResult opResult = new OperationResult("import check");
            assertNoRepoCache();
            SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
            try {
                modelWeb.getObject(ObjectTypes.TASK.getTypeQName(), taskOid, options, objectHolder, resultHolder);
            } catch (FaultMessage faultMessage) {
                throw new SystemException(faultMessage);
            }
            assertNoRepoCache();
            //				display("getObject result (wait loop)",resultHolder.value);
            TestUtil.assertSuccess("getObject has failed", resultHolder.value);
            Task task = taskManager.createTaskInstance((PrismObject<TaskType>) 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((PrismObject<TaskType>) 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);
        // This would be really strange ;-)
        assertNotEmpty("No OID in shadow", shadow.getOid());
        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, SchemaConstants.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);
        // This would be
        assertNotEmpty("No OID in user", user.getOid());
        // 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());
        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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GenericObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) Checker(com.evolveum.midpoint.test.Checker) ObjectChecker(com.evolveum.midpoint.test.ObjectChecker) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) Holder(javax.xml.ws.Holder) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) Date(java.util.Date) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) 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)

Example 28 with FaultMessage

use of com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage in project midpoint by Evolveum.

the class AbstractWebserviceTest method deleteObject.

protected <O extends ObjectType> void deleteObject(Class<O> type, String oid, ModelExecuteOptionsType options) throws FaultMessage {
    ObjectDeltaListType deltaList = new ObjectDeltaListType();
    ObjectDeltaType delta = new ObjectDeltaType();
    delta.setObjectType(getTypeQName(type));
    delta.setChangeType(ChangeTypeType.DELETE);
    delta.setOid(oid);
    deltaList.getDelta().add(delta);
    ObjectDeltaOperationListType deltaOpList = modelPort.executeChanges(deltaList, options);
    assertSuccess(deltaOpList);
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectDeltaOperationListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType) ObjectDeltaListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)

Example 29 with FaultMessage

use of com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage in project midpoint by Evolveum.

the class TestWSSanity method test032ResourceNonexistingTestConnection.

@Test
public void test032ResourceNonexistingTestConnection() throws Exception {
    final String TEST_NAME = "test032ResourceNonexistingTestConnection";
    displayTestTitle(TEST_NAME);
    try {
        // WHEN
        OperationResultType testResult = modelPort.testResource("56b53914-df90-11e4-8c8c-001e8c717e5b");
        AssertJUnit.fail("Unexpected success");
    } catch (FaultMessage f) {
        assertFaultMessage(f, ObjectNotFoundFaultType.class, "was not found");
    }
}
Also used : ObjectNotFoundFaultType(com.evolveum.midpoint.xml.ns._public.common.fault_3.ObjectNotFoundFaultType) FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Test(org.testng.annotations.Test)

Example 30 with FaultMessage

use of com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage in project midpoint by Evolveum.

the class ReportWebServiceRaw method invokeAllowingFaults.

public DOMSource invokeAllowingFaults(DOMSource request) throws FaultMessage {
    Node rootNode = request.getNode();
    Element rootElement;
    if (rootNode instanceof Document) {
        rootElement = ((Document) rootNode).getDocumentElement();
    } else if (rootNode instanceof Element) {
        rootElement = (Element) rootNode;
    } else {
        //	            throw ws.createIllegalArgumentFault("Unexpected DOM node type: " + rootNode);
        throw new FaultMessage("Unexpected DOM node type: " + rootNode);
    }
    Object requestObject;
    try {
        requestObject = prismContext.parserFor(rootElement).parseRealValue();
    } catch (SchemaException e) {
        throw new FaultMessage("Couldn't parse SOAP request body because of schema exception: " + e.getMessage());
    //	            throw ws.createIllegalArgumentFault("Couldn't parse SOAP request body because of schema exception: " + e.getMessage());
    }
    Node response;
    Holder<OperationResultType> operationResultTypeHolder = new Holder<>();
    SerializationContext ctx = new SerializationContext(SerializationOptions.createSerializeReferenceNames());
    try {
        if (requestObject instanceof EvaluateScriptType) {
            EvaluateScriptType s = (EvaluateScriptType) requestObject;
            ObjectListType olt = reportService.evaluateScript(s.getScript(), s.getParameters());
            EvaluateScriptResponseType sr = new EvaluateScriptResponseType();
            sr.setObjectList(olt);
            response = prismContext.domSerializer().context(ctx).serializeAnyData(sr, ReportPort.EVALUATE_SCRIPT_RESPONSE);
        } else if (requestObject instanceof EvaluateAuditScriptType) {
            EvaluateAuditScriptType s = (EvaluateAuditScriptType) requestObject;
            AuditEventRecordListType olt = reportService.evaluateAuditScript(s.getScript(), s.getParameters());
            EvaluateAuditScriptResponseType sr = new EvaluateAuditScriptResponseType();
            sr.setObjectList(olt);
            response = prismContext.domSerializer().context(ctx).serializeAnyData(sr, ReportPort.EVALUATE_AUDIT_SCRIPT_RESPONSE);
        } else if (requestObject instanceof ProcessReportType) {
            ProcessReportType p = (ProcessReportType) requestObject;
            ObjectListType olt = reportService.processReport(p.getQuery(), p.getParameters(), p.getOptions());
            ProcessReportResponseType pr = new ProcessReportResponseType();
            pr.setObjectList(olt);
            response = prismContext.domSerializer().context(ctx).serializeAnyData(pr, ReportPort.PROCESS_REPORT_RESPONSE);
        } else {
            throw new FaultMessage("Unsupported request type: " + requestObject);
        }
    } catch (SchemaException e) {
        throwFault(e, operationResultTypeHolder.value);
        // not reached
        return null;
    }
    return new DOMSource(response);
}
Also used : SerializationContext(com.evolveum.midpoint.prism.SerializationContext) ProcessReportType(com.evolveum.midpoint.xml.ns._public.report.report_3.ProcessReportType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) DOMSource(javax.xml.transform.dom.DOMSource) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Holder(javax.xml.ws.Holder) EvaluateScriptType(com.evolveum.midpoint.xml.ns._public.report.report_3.EvaluateScriptType) EvaluateAuditScriptType(com.evolveum.midpoint.xml.ns._public.report.report_3.EvaluateAuditScriptType) Document(org.w3c.dom.Document) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) EvaluateAuditScriptResponseType(com.evolveum.midpoint.xml.ns._public.report.report_3.EvaluateAuditScriptResponseType) FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) AuditEventRecordListType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordListType) EvaluateScriptResponseType(com.evolveum.midpoint.xml.ns._public.report.report_3.EvaluateScriptResponseType) ProcessReportResponseType(com.evolveum.midpoint.xml.ns._public.report.report_3.ProcessReportResponseType)

Aggregations

OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)46 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)36 ObjectDeltaListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)33 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)32 Holder (javax.xml.ws.Holder)32 SelectorQualifiedGetOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)25 ObjectDeltaOperationListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)22 FaultMessage (com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage)22 Test (org.testng.annotations.Test)22 ObjectListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType)21 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)16 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)16 QName (javax.xml.namespace.QName)15 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)13 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)13 Document (org.w3c.dom.Document)13 ModelExecuteOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType)10 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)10 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)10