use of org.camunda.bpm.model.bpmn.instance.BpmnModelElementInstance in project camunda-bpmn-model by camunda.
the class CamundaExtensionsTest method testCamundaListInputParameter.
@Test
public void testCamundaListInputParameter() {
CamundaInputParameter inputParameter = findInputParameterByName(serviceTask, "shouldBeList");
assertThat(inputParameter.getCamundaName()).isEqualTo("shouldBeList");
assertThat(inputParameter.getTextContent()).isNotEmpty();
assertThat(inputParameter.getUniqueChildElementByNameNs(CAMUNDA_NS, "list")).isNotNull();
CamundaList list = inputParameter.getValue();
assertThat(list.getValues()).hasSize(3);
for (BpmnModelElementInstance values : list.getValues()) {
assertThat(values.getTextContent()).isIn("a", "b", "c");
}
list = modelInstance.newInstance(CamundaList.class);
for (int i = 0; i < 4; i++) {
CamundaValue value = modelInstance.newInstance(CamundaValue.class);
value.setTextContent("test");
list.getValues().add(value);
}
Collection<CamundaValue> testValues = Arrays.asList(modelInstance.newInstance(CamundaValue.class), modelInstance.newInstance(CamundaValue.class));
list.getValues().addAll(testValues);
inputParameter.setValue(list);
list = inputParameter.getValue();
assertThat(list.getValues()).hasSize(6);
list.getValues().removeAll(testValues);
ArrayList<BpmnModelElementInstance> camundaValues = new ArrayList<BpmnModelElementInstance>(list.getValues());
assertThat(camundaValues).hasSize(4);
for (BpmnModelElementInstance value : camundaValues) {
assertThat(value.getTextContent()).isEqualTo("test");
}
list.getValues().remove(camundaValues.get(1));
assertThat(list.getValues()).hasSize(3);
list.getValues().removeAll(Arrays.asList(camundaValues.get(0), camundaValues.get(3)));
assertThat(list.getValues()).hasSize(1);
list.getValues().clear();
assertThat(list.getValues()).isEmpty();
// test standard list interactions
Collection<BpmnModelElementInstance> elements = list.getValues();
CamundaValue value = modelInstance.newInstance(CamundaValue.class);
elements.add(value);
List<CamundaValue> newValues = new ArrayList<CamundaValue>();
newValues.add(modelInstance.newInstance(CamundaValue.class));
newValues.add(modelInstance.newInstance(CamundaValue.class));
elements.addAll(newValues);
assertThat(elements).hasSize(3);
assertThat(elements).doesNotContain(modelInstance.newInstance(CamundaValue.class));
assertThat(elements.containsAll(Arrays.asList(modelInstance.newInstance(CamundaValue.class)))).isFalse();
assertThat(elements.remove(modelInstance.newInstance(CamundaValue.class))).isFalse();
assertThat(elements).hasSize(3);
assertThat(elements.remove(value)).isTrue();
assertThat(elements).hasSize(2);
assertThat(elements.removeAll(newValues)).isTrue();
assertThat(elements).isEmpty();
elements.add(modelInstance.newInstance(CamundaValue.class));
elements.clear();
assertThat(elements).isEmpty();
inputParameter.removeValue();
assertThat(inputParameter.getValue()).isNull();
}
use of org.camunda.bpm.model.bpmn.instance.BpmnModelElementInstance 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");
}
Aggregations