Search in sources :

Example 1 with CamundaScript

use of org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript in project camunda-bpmn-model by camunda.

the class CamundaExtensionsTest method testCamundaScriptInputParameter.

@Test
public void testCamundaScriptInputParameter() {
    CamundaInputParameter inputParameter = findInputParameterByName(serviceTask, "shouldBeScript");
    assertThat(inputParameter.getCamundaName()).isEqualTo("shouldBeScript");
    assertThat(inputParameter.getTextContent()).isNotEmpty();
    assertThat(inputParameter.getUniqueChildElementByNameNs(CAMUNDA_NS, "script")).isNotNull();
    assertThat(inputParameter.getUniqueChildElementByType(CamundaScript.class)).isNotNull();
    CamundaScript script = inputParameter.getValue();
    assertThat(script.getCamundaScriptFormat()).isEqualTo("groovy");
    assertThat(script.getCamundaResource()).isNull();
    assertThat(script.getTextContent()).isEqualTo("1 + 1");
    script = modelInstance.newInstance(CamundaScript.class);
    script.setCamundaScriptFormat("python");
    script.setCamundaResource("script.py");
    inputParameter.setValue(script);
    script = inputParameter.getValue();
    assertThat(script.getCamundaScriptFormat()).isEqualTo("python");
    assertThat(script.getCamundaResource()).isEqualTo("script.py");
    assertThat(script.getTextContent()).isEmpty();
    inputParameter.removeValue();
    assertThat(inputParameter.getValue()).isNull();
}
Also used : CamundaInputParameter(org.camunda.bpm.model.bpmn.instance.camunda.CamundaInputParameter) CamundaScript(org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript) Test(org.junit.Test)

Example 2 with CamundaScript

use of org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript in project camunda-bpmn-model by camunda.

the class CamundaScriptImpl method registerType.

public static void registerType(ModelBuilder modelBuilder) {
    ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(CamundaScript.class, CAMUNDA_ELEMENT_SCRIPT).namespaceUri(CAMUNDA_NS).instanceProvider(new ModelTypeInstanceProvider<CamundaScript>() {

        public CamundaScript newInstance(ModelTypeInstanceContext instanceContext) {
            return new CamundaScriptImpl(instanceContext);
        }
    });
    camundaScriptFormatAttribute = typeBuilder.stringAttribute(CAMUNDA_ATTRIBUTE_SCRIPT_FORMAT).required().build();
    camundaResourceAttribute = typeBuilder.stringAttribute(CAMUNDA_ATTRIBUTE_RESOURCE).build();
    typeBuilder.build();
}
Also used : ModelElementTypeBuilder(org.camunda.bpm.model.xml.type.ModelElementTypeBuilder) ModelTypeInstanceContext(org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext) CamundaScript(org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript)

Example 3 with CamundaScript

use of org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript in project camunda-bpmn-model by camunda.

the class CamundaExtensionsTest method testCamundaScriptExecutionListener.

@Test
public void testCamundaScriptExecutionListener() {
    CamundaExecutionListener sequenceFlowListener = sequenceFlow.getExtensionElements().getElementsQuery().filterByType(CamundaExecutionListener.class).singleResult();
    CamundaScript script = sequenceFlowListener.getCamundaScript();
    assertThat(script.getCamundaScriptFormat()).isEqualTo("groovy");
    assertThat(script.getCamundaResource()).isNull();
    assertThat(script.getTextContent()).isEqualTo("println 'Hello World'");
    CamundaScript newScript = modelInstance.newInstance(CamundaScript.class);
    newScript.setCamundaScriptFormat("groovy");
    newScript.setCamundaResource("test.groovy");
    sequenceFlowListener.setCamundaScript(newScript);
    script = sequenceFlowListener.getCamundaScript();
    assertThat(script.getCamundaScriptFormat()).isEqualTo("groovy");
    assertThat(script.getCamundaResource()).isEqualTo("test.groovy");
    assertThat(script.getTextContent()).isEmpty();
}
Also used : CamundaExecutionListener(org.camunda.bpm.model.bpmn.instance.camunda.CamundaExecutionListener) CamundaScript(org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript) Test(org.junit.Test)

Example 4 with CamundaScript

use of org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript in project camunda-bpmn-model by camunda.

the class CamundaExtensionsTest method testCamundaScriptTaskListener.

@Test
public void testCamundaScriptTaskListener() {
    CamundaTaskListener taskListener = userTask.getExtensionElements().getElementsQuery().filterByType(CamundaTaskListener.class).list().get(1);
    CamundaScript script = taskListener.getCamundaScript();
    assertThat(script.getCamundaScriptFormat()).isEqualTo("groovy");
    assertThat(script.getCamundaResource()).isEqualTo("test.groovy");
    assertThat(script.getTextContent()).isEmpty();
    CamundaScript newScript = modelInstance.newInstance(CamundaScript.class);
    newScript.setCamundaScriptFormat("groovy");
    newScript.setTextContent("println 'Hello World'");
    taskListener.setCamundaScript(newScript);
    script = taskListener.getCamundaScript();
    assertThat(script.getCamundaScriptFormat()).isEqualTo("groovy");
    assertThat(script.getCamundaResource()).isNull();
    assertThat(script.getTextContent()).isEqualTo("println 'Hello World'");
}
Also used : CamundaTaskListener(org.camunda.bpm.model.bpmn.instance.camunda.CamundaTaskListener) CamundaScript(org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript) Test(org.junit.Test)

Aggregations

CamundaScript (org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript)4 Test (org.junit.Test)3 CamundaExecutionListener (org.camunda.bpm.model.bpmn.instance.camunda.CamundaExecutionListener)1 CamundaInputParameter (org.camunda.bpm.model.bpmn.instance.camunda.CamundaInputParameter)1 CamundaTaskListener (org.camunda.bpm.model.bpmn.instance.camunda.CamundaTaskListener)1 ModelTypeInstanceContext (org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext)1 ModelElementTypeBuilder (org.camunda.bpm.model.xml.type.ModelElementTypeBuilder)1