Search in sources :

Example 26 with ExecutionContext

use of com.evolveum.midpoint.model.impl.scripting.ExecutionContext in project midpoint by Evolveum.

the class TestScriptingBasic method test400PurgeSchema.

@Test
public void test400PurgeSchema() throws Exception {
    final String TEST_NAME = "test400PurgeSchema";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(DOT_CLASS + TEST_NAME);
    OperationResult result = task.getResult();
    PrismProperty<ScriptingExpressionType> expression = parseAnyData(PURGE_DUMMY_BLACK_SCHEMA_FILE);
    //        ResourceType dummy = modelService.getObject(ResourceType.class, RESOURCE_DUMMY_BLACK_OID, null, task, result).asObjectable();
    //        IntegrationTestTools.display("dummy resource before purge schema", dummy.asPrismObject());
    //        IntegrationTestTools.display("elements: " + dummy.getSchema().getDefinition().getAny().get(0).getElementsByTagName("*").getLength());
    //        IntegrationTestTools.display("schema as XML: " + DOMUtil.printDom(dummy.getSchema().getDefinition().getAny().get(0)));
    // WHEN
    ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(expression.getAnyValue().getValue(), task, result);
    // THEN
    dumpOutput(output, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals(1, output.getFinalOutput().getData().size());
    //        dummy = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_BLACK_OID, null, result).asObjectable();
    //        IntegrationTestTools.display("dummy resource from repo", dummy.asPrismObject());
    //        IntegrationTestTools.display("elements: " + dummy.getSchema().getDefinition().getAny().get(0).getElementsByTagName("*").getLength());
    //        IntegrationTestTools.display("schema as XML: " + DOMUtil.printDom(dummy.getSchema().getDefinition().getAny().get(0)));
    //AssertJUnit.assertNull("Schema is still present", dummy.getSchema());
    // actually, schema gets downloaded just after purging it
    assertEquals("Purged schema information from resource:10000000-0000-0000-0000-000000000305(Dummy Resource Black)\n", output.getConsoleOutput());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 27 with ExecutionContext

use of com.evolveum.midpoint.model.impl.scripting.ExecutionContext in project midpoint by Evolveum.

the class TestScriptingBasic method test215SearchForShadowsNoFetch.

@Test
public void test215SearchForShadowsNoFetch() throws Exception {
    final String TEST_NAME = "test215SearchForShadowsNoFetch";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(DOT_CLASS + TEST_NAME);
    OperationResult result = task.getResult();
    PrismProperty<SearchExpressionType> expression = parseAnyData(SEARCH_FOR_SHADOWS_NOFETCH_FILE);
    // WHEN
    ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(expression.getAnyValue().getValue(), task, result);
    // THEN
    dumpOutput(output, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals(5, output.getFinalOutput().getData().size());
    assertAttributesNotFetched(output.getFinalOutput().getData());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 28 with ExecutionContext

use of com.evolveum.midpoint.model.impl.scripting.ExecutionContext in project midpoint by Evolveum.

the class TestScriptingBasic method test340ModifyJackBack.

@Test
public void test340ModifyJackBack() throws Exception {
    final String TEST_NAME = "test340ModifyJackBack";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(DOT_CLASS + TEST_NAME);
    OperationResult result = task.getResult();
    PrismProperty<ScriptingExpressionType> expression = parseAnyData(MODIFY_JACK_BACK_FILE);
    // WHEN
    ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(expression.getAnyValue().getValue(), task, result);
    // THEN
    dumpOutput(output, result);
    assertOutputData(output, 1, OperationResultStatus.SUCCESS);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals("Modified user:c0c010c0-d34d-b33f-f00d-111111111111(jack)\n", output.getConsoleOutput());
    assertEquals("Caribbean", searchObjectByName(UserType.class, "jack").asObjectable().getLocality().getOrig());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 29 with ExecutionContext

use of com.evolveum.midpoint.model.impl.scripting.ExecutionContext in project midpoint by Evolveum.

the class TestScriptingBasic method test112Echo.

@Test
public void test112Echo() throws Exception {
    final String TEST_NAME = "test112Echo";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(DOT_CLASS + TEST_NAME);
    OperationResult result = task.getResult();
    ExecuteScriptType executeScript = parseRealValue(ECHO_FILE);
    // WHEN
    ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(executeScript, task, result);
    // THEN
    dumpOutput(output, result);
    result.computeStatus();
    PipelineData data = output.getFinalOutput();
    assertEquals("Unexpected # of items in output", 4, data.getData().size());
// TODO check correct serialization (MID-
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 30 with ExecutionContext

use of com.evolveum.midpoint.model.impl.scripting.ExecutionContext in project midpoint by Evolveum.

the class ModelController method evaluateExpression.

@Override
public ScriptExecutionResult evaluateExpression(ExecuteScriptType scriptExecutionCommand, Task task, OperationResult result) throws ScriptExecutionException, SchemaException, SecurityViolationException {
    checkScriptingAuthorization(result);
    ExecutionContext executionContext = scriptingExpressionEvaluator.evaluateExpression(scriptExecutionCommand, task, result);
    return executionContext.toExecutionResult();
}
Also used : ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext)

Aggregations

ExecutionContext (com.evolveum.midpoint.model.impl.scripting.ExecutionContext)31 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)29 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)28 Task (com.evolveum.midpoint.task.api.Task)28 Test (org.testng.annotations.Test)28 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)6 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)6 Message (com.evolveum.midpoint.notifications.api.transports.Message)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 HashSet (java.util.HashSet)2 ScriptExecutionException (com.evolveum.midpoint.model.api.ScriptExecutionException)1 ExpressionHelper (com.evolveum.midpoint.model.impl.scripting.helpers.ExpressionHelper)1 OperationsHelper (com.evolveum.midpoint.model.impl.scripting.helpers.OperationsHelper)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 QueryConvertor (com.evolveum.midpoint.prism.marshaller.QueryConvertor)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 QueryJaxbConvertor (com.evolveum.midpoint.prism.query.QueryJaxbConvertor)1 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)1 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)1