提交 4420b00c 编写于 作者: F Frederik Heremans

ACT-1023: Retain order of enum-formproperty values as defined in xml

上级 1fde43c9
......@@ -14,6 +14,7 @@
package org.activiti.engine.impl.form;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.activiti.engine.impl.bpmn.parser.BpmnParse;
......@@ -42,7 +43,8 @@ public class FormTypes {
formType = new DateFormType(datePatternText);
} else if ("enum".equals(typeText)) {
Map<String, String> values = new HashMap<String, String>();
// ACT-1023: Using linked hashmap to preserve the order in which the entries are defined
Map<String, String> values = new LinkedHashMap<String, String>();
for (Element valueElement: formPropertyElement.elementsNS(BpmnParser.ACTIVITI_BPMN_EXTENSIONS_NS,"value")) {
String valueId = valueElement.attribute("id");
String valueName = valueElement.attribute("name");
......
......@@ -15,8 +15,11 @@ package org.activiti.engine.test.api.form;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.form.FormProperty;
......@@ -267,11 +270,19 @@ public class FormServiceTest extends PluggableActivitiTestCase {
assertEquals("enum", property.getType().getName());
Map<String, String> values = (Map<String, String>) property.getType().getInformation("values");
Map<String, String> expectedValues = new HashMap<String, String>();
Map<String, String> expectedValues = new LinkedHashMap<String, String>();
expectedValues.put("left", "Go Left");
expectedValues.put("right", "Go Right");
expectedValues.put("up", "Go Up");
expectedValues.put("down", "Go Down");
// ACT-1023: check if ordering is retained
Iterator<Entry<String, String>> expectedValuesIterator = expectedValues.entrySet().iterator();
for(Entry<String, String> entry : values.entrySet()) {
Entry<String, String> expectedEntryAtLocation = expectedValuesIterator.next();
assertEquals(expectedEntryAtLocation.getKey(), entry.getKey());
assertEquals(expectedEntryAtLocation.getValue(), entry.getValue());
}
assertEquals(expectedValues, values);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册