Search in sources :

Example 1 with CamundaMap

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

the class CamundaExtensionsTest method testCamundaMapInputParameter.

@Test
public void testCamundaMapInputParameter() {
    CamundaInputParameter inputParameter = findInputParameterByName(serviceTask, "shouldBeMap");
    assertThat(inputParameter.getCamundaName()).isEqualTo("shouldBeMap");
    assertThat(inputParameter.getTextContent()).isNotEmpty();
    assertThat(inputParameter.getUniqueChildElementByNameNs(CAMUNDA_NS, "map")).isNotNull();
    CamundaMap map = inputParameter.getValue();
    assertThat(map.getCamundaEntries()).hasSize(2);
    for (CamundaEntry entry : map.getCamundaEntries()) {
        if (entry.getCamundaKey().equals("foo")) {
            assertThat(entry.getTextContent()).isEqualTo("bar");
        } else {
            assertThat(entry.getCamundaKey()).isEqualTo("hello");
            assertThat(entry.getTextContent()).isEqualTo("world");
        }
    }
    map = modelInstance.newInstance(CamundaMap.class);
    CamundaEntry entry = modelInstance.newInstance(CamundaEntry.class);
    entry.setCamundaKey("test");
    entry.setTextContent("value");
    map.getCamundaEntries().add(entry);
    inputParameter.setValue(map);
    map = inputParameter.getValue();
    assertThat(map.getCamundaEntries()).hasSize(1);
    entry = map.getCamundaEntries().iterator().next();
    assertThat(entry.getCamundaKey()).isEqualTo("test");
    assertThat(entry.getTextContent()).isEqualTo("value");
    Collection<CamundaEntry> entries = map.getCamundaEntries();
    entries.add(modelInstance.newInstance(CamundaEntry.class));
    assertThat(entries).hasSize(2);
    inputParameter.removeValue();
    assertThat(inputParameter.getValue()).isNull();
}
Also used : CamundaMap(org.camunda.bpm.model.bpmn.instance.camunda.CamundaMap) CamundaEntry(org.camunda.bpm.model.bpmn.instance.camunda.CamundaEntry) CamundaInputParameter(org.camunda.bpm.model.bpmn.instance.camunda.CamundaInputParameter) Test(org.junit.Test)

Example 2 with CamundaMap

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

the class CamundaMapImpl method registerType.

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

        public CamundaMap newInstance(ModelTypeInstanceContext instanceContext) {
            return new CamundaMapImpl(instanceContext);
        }
    });
    SequenceBuilder sequenceBuilder = typeBuilder.sequence();
    camundaEntryCollection = sequenceBuilder.elementCollection(CamundaEntry.class).build();
    typeBuilder.build();
}
Also used : CamundaMap(org.camunda.bpm.model.bpmn.instance.camunda.CamundaMap) SequenceBuilder(org.camunda.bpm.model.xml.type.child.SequenceBuilder) ModelElementTypeBuilder(org.camunda.bpm.model.xml.type.ModelElementTypeBuilder) ModelTypeInstanceContext(org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext)

Example 3 with CamundaMap

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

the class CamundaExtensionsTest method testCamundaNestedOutputParameter.

@Test
public void testCamundaNestedOutputParameter() {
    CamundaOutputParameter camundaOutputParameter = serviceTask.getExtensionElements().getElementsQuery().filterByType(CamundaInputOutput.class).singleResult().getCamundaOutputParameters().iterator().next();
    assertThat(camundaOutputParameter).isNotNull();
    assertThat(camundaOutputParameter.getCamundaName()).isEqualTo("nested");
    CamundaList list = camundaOutputParameter.getValue();
    assertThat(list).isNotNull();
    assertThat(list.getValues()).hasSize(2);
    Iterator<BpmnModelElementInstance> iterator = list.getValues().iterator();
    // nested list
    CamundaList nestedList = (CamundaList) iterator.next().getUniqueChildElementByType(CamundaList.class);
    assertThat(nestedList).isNotNull();
    assertThat(nestedList.getValues()).hasSize(2);
    for (BpmnModelElementInstance value : nestedList.getValues()) {
        assertThat(value.getTextContent()).isEqualTo("list");
    }
    // nested map
    CamundaMap nestedMap = (CamundaMap) iterator.next().getUniqueChildElementByType(CamundaMap.class);
    assertThat(nestedMap).isNotNull();
    assertThat(nestedMap.getCamundaEntries()).hasSize(2);
    Iterator<CamundaEntry> mapIterator = nestedMap.getCamundaEntries().iterator();
    // nested list in nested map
    CamundaEntry nestedListEntry = mapIterator.next();
    assertThat(nestedListEntry).isNotNull();
    assertThat(nestedListEntry.getCamundaKey()).isEqualTo("list");
    CamundaList nestedNestedList = nestedListEntry.getValue();
    for (BpmnModelElementInstance value : nestedNestedList.getValues()) {
        assertThat(value.getTextContent()).isEqualTo("map");
    }
    // nested map in nested map
    CamundaEntry nestedMapEntry = mapIterator.next();
    assertThat(nestedMapEntry).isNotNull();
    assertThat(nestedMapEntry.getCamundaKey()).isEqualTo("map");
    CamundaMap nestedNestedMap = nestedMapEntry.getValue();
    CamundaEntry entry = nestedNestedMap.getCamundaEntries().iterator().next();
    assertThat(entry.getCamundaKey()).isEqualTo("so");
    assertThat(entry.getTextContent()).isEqualTo("nested");
}
Also used : CamundaOutputParameter(org.camunda.bpm.model.bpmn.instance.camunda.CamundaOutputParameter) CamundaMap(org.camunda.bpm.model.bpmn.instance.camunda.CamundaMap) BpmnModelElementInstance(org.camunda.bpm.model.bpmn.instance.BpmnModelElementInstance) CamundaEntry(org.camunda.bpm.model.bpmn.instance.camunda.CamundaEntry) CamundaList(org.camunda.bpm.model.bpmn.instance.camunda.CamundaList) Test(org.junit.Test)

Aggregations

CamundaMap (org.camunda.bpm.model.bpmn.instance.camunda.CamundaMap)3 CamundaEntry (org.camunda.bpm.model.bpmn.instance.camunda.CamundaEntry)2 Test (org.junit.Test)2 BpmnModelElementInstance (org.camunda.bpm.model.bpmn.instance.BpmnModelElementInstance)1 CamundaInputParameter (org.camunda.bpm.model.bpmn.instance.camunda.CamundaInputParameter)1 CamundaList (org.camunda.bpm.model.bpmn.instance.camunda.CamundaList)1 CamundaOutputParameter (org.camunda.bpm.model.bpmn.instance.camunda.CamundaOutputParameter)1 ModelTypeInstanceContext (org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext)1 ModelElementTypeBuilder (org.camunda.bpm.model.xml.type.ModelElementTypeBuilder)1 SequenceBuilder (org.camunda.bpm.model.xml.type.child.SequenceBuilder)1