From ce5a5e6ed13de1098207d746eb39b7e9b0a7745a Mon Sep 17 00:00:00 2001 From: Tassilo Weidner Date: Thu, 21 Mar 2019 13:18:21 +0100 Subject: [PATCH] fix(engine): fix task filter properties with nested structures related to CAM-9881 --- ...tancesBatchConfigurationJsonConverter.java | 4 +- ...stanceBatchConfigurationJsonConverter.java | 4 +- ...stanceBatchConfigurationJsonConverter.java | 4 +- ...etriesBatchConfigurationJsonConverter.java | 4 +- ...etriesBatchConfigurationJsonConverter.java | 4 +- ...dStateBatchConfigurationJsonConverter.java | 4 +- ...stanceBatchConfigurationJsonConverter.java | 4 +- ...rationBatchConfigurationJsonConverter.java | 4 +- ...cationBatchConfigurationJsonConverter.java | 4 +- .../bpm/engine/impl/util/JsonUtil.java | 115 ++++++++++---- .../test/api/filter/FilterPropertiesTest.java | 141 +++++++++++++++++- .../camunda/bpm/qa/upgrade/TestFixture.java | 2 + .../gson/TaskFilterPropertiesScenario.java | 73 +++++++++ .../gson/TaskFilterPropertiesTest.java | 91 +++++++++++ 14 files changed, 408 insertions(+), 50 deletions(-) create mode 100644 qa/test-db-instance-migration/test-fixture-710/src/main/java/org/camunda/bpm/qa/upgrade/gson/TaskFilterPropertiesScenario.java create mode 100644 qa/test-db-instance-migration/test-migration/src/test/java/org/camunda/bpm/qa/upgrade/scenarios7110/gson/TaskFilterPropertiesTest.java diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/RestartProcessInstancesBatchConfigurationJsonConverter.java b/engine/src/main/java/org/camunda/bpm/engine/impl/RestartProcessInstancesBatchConfigurationJsonConverter.java index 5ba6523306e..f73ad92da2c 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/RestartProcessInstancesBatchConfigurationJsonConverter.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/RestartProcessInstancesBatchConfigurationJsonConverter.java @@ -1,5 +1,5 @@ /* - * Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com) + * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,6 +60,6 @@ public RestartProcessInstancesBatchConfiguration toObject(JsonObject json) { } protected List readProcessInstanceIds(JsonObject jsonObject) { - return JsonUtil.asList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS)); + return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS)); } } diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/deletion/DeleteHistoricProcessInstanceBatchConfigurationJsonConverter.java b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/deletion/DeleteHistoricProcessInstanceBatchConfigurationJsonConverter.java index f50ed46baeb..31eccb4a44b 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/deletion/DeleteHistoricProcessInstanceBatchConfigurationJsonConverter.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/deletion/DeleteHistoricProcessInstanceBatchConfigurationJsonConverter.java @@ -1,5 +1,5 @@ /* - * Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com) + * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +44,6 @@ public BatchConfiguration toObject(JsonObject json) { } protected List readProcessInstanceIds(JsonObject jsonObject) { - return JsonUtil.asList(JsonUtil.getArray(jsonObject, HISTORIC_PROCESS_INSTANCE_IDS)); + return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, HISTORIC_PROCESS_INSTANCE_IDS)); } } diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/deletion/DeleteProcessInstanceBatchConfigurationJsonConverter.java b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/deletion/DeleteProcessInstanceBatchConfigurationJsonConverter.java index 844a6ff44c5..0d9f910f5e8 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/deletion/DeleteProcessInstanceBatchConfigurationJsonConverter.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/deletion/DeleteProcessInstanceBatchConfigurationJsonConverter.java @@ -1,5 +1,5 @@ /* - * Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com) + * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,6 +57,6 @@ public DeleteProcessInstanceBatchConfiguration toObject(JsonObject json) { } protected List readProcessInstanceIds(JsonObject jsonObject) { - return JsonUtil.asList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS)); + return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS)); } } diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/externaltask/SetExternalTaskRetriesBatchConfigurationJsonConverter.java b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/externaltask/SetExternalTaskRetriesBatchConfigurationJsonConverter.java index 5874ddd1771..6b34f3ac083 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/externaltask/SetExternalTaskRetriesBatchConfigurationJsonConverter.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/externaltask/SetExternalTaskRetriesBatchConfigurationJsonConverter.java @@ -1,5 +1,5 @@ /* - * Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com) + * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ public SetRetriesBatchConfiguration toObject(JsonObject json) { } protected List readExternalTaskIds(JsonObject json) { - return JsonUtil.asList(JsonUtil.getArray(json, EXTERNAL_TASK_IDS)); + return JsonUtil.asStringList(JsonUtil.getArray(json, EXTERNAL_TASK_IDS)); } } diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/job/SetJobRetriesBatchConfigurationJsonConverter.java b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/job/SetJobRetriesBatchConfigurationJsonConverter.java index 9933cc2f024..049948351a5 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/job/SetJobRetriesBatchConfigurationJsonConverter.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/job/SetJobRetriesBatchConfigurationJsonConverter.java @@ -1,5 +1,5 @@ /* - * Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com) + * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,6 +49,6 @@ public SetRetriesBatchConfiguration toObject(JsonObject json) { } protected List readJobIds(JsonObject jsonObject) { - return JsonUtil.asList(JsonUtil.getArray(jsonObject, JOB_IDS)); + return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, JOB_IDS)); } } diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/update/UpdateProcessInstancesSuspendStateBatchConfigurationJsonConverter.java b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/update/UpdateProcessInstancesSuspendStateBatchConfigurationJsonConverter.java index bd80ccad755..3099b5d8b5a 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/batch/update/UpdateProcessInstancesSuspendStateBatchConfigurationJsonConverter.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/batch/update/UpdateProcessInstancesSuspendStateBatchConfigurationJsonConverter.java @@ -1,5 +1,5 @@ /* - * Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com) + * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,6 +43,6 @@ public UpdateProcessInstancesSuspendStateBatchConfiguration toObject(JsonObject } protected List readProcessInstanceIds(JsonObject jsonObject) { - return JsonUtil.asList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS)); + return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS)); } } diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/dmn/batch/DeleteHistoricDecisionInstanceBatchConfigurationJsonConverter.java b/engine/src/main/java/org/camunda/bpm/engine/impl/dmn/batch/DeleteHistoricDecisionInstanceBatchConfigurationJsonConverter.java index 7b62a811c5e..44fe6ea21d0 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/dmn/batch/DeleteHistoricDecisionInstanceBatchConfigurationJsonConverter.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/dmn/batch/DeleteHistoricDecisionInstanceBatchConfigurationJsonConverter.java @@ -1,5 +1,5 @@ /* - * Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com) + * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ public BatchConfiguration toObject(JsonObject json) { } protected List readDecisionInstanceIds(JsonObject jsonNode) { - return JsonUtil.asList(JsonUtil.getArray(jsonNode, HISTORIC_DECISION_INSTANCE_IDS)); + return JsonUtil.asStringList(JsonUtil.getArray(jsonNode, HISTORIC_DECISION_INSTANCE_IDS)); } } diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/json/MigrationBatchConfigurationJsonConverter.java b/engine/src/main/java/org/camunda/bpm/engine/impl/json/MigrationBatchConfigurationJsonConverter.java index c8aaf236238..ea293dcea7a 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/json/MigrationBatchConfigurationJsonConverter.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/json/MigrationBatchConfigurationJsonConverter.java @@ -1,5 +1,5 @@ /* - * Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com) + * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,7 +52,7 @@ public MigrationBatchConfiguration toObject(JsonObject json) { } protected List readProcessInstanceIds(JsonObject jsonObject) { - return JsonUtil.asList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS)); + return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS)); } diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/json/ModificationBatchConfigurationJsonConverter.java b/engine/src/main/java/org/camunda/bpm/engine/impl/json/ModificationBatchConfigurationJsonConverter.java index 92cf60a07f0..a6ee73e0c03 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/json/ModificationBatchConfigurationJsonConverter.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/json/ModificationBatchConfigurationJsonConverter.java @@ -1,5 +1,5 @@ /* - * Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com) + * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,7 +63,7 @@ public ModificationBatchConfiguration toObject(JsonObject json) { } protected List readProcessInstanceIds(JsonObject jsonObject) { - return JsonUtil.asList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS)); + return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS)); } } diff --git a/engine/src/main/java/org/camunda/bpm/engine/impl/util/JsonUtil.java b/engine/src/main/java/org/camunda/bpm/engine/impl/util/JsonUtil.java index 104ea088239..ddc3fbbe8e4 100644 --- a/engine/src/main/java/org/camunda/bpm/engine/impl/util/JsonUtil.java +++ b/engine/src/main/java/org/camunda/bpm/engine/impl/util/JsonUtil.java @@ -1,5 +1,5 @@ /* - * Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com) + * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,6 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSyntaxException; import com.google.gson.internal.LazilyParsedNumber; -import com.google.gson.reflect.TypeToken; import org.camunda.bpm.engine.impl.ProcessEngineLogger; /** @@ -48,8 +47,6 @@ public final class JsonUtil { private static final EngineUtilLogger LOG = ProcessEngineLogger.UTIL_LOGGER; - protected static final Type MAP_TYPE_TOKEN = new TypeToken>() {}.getType(); - protected static Gson gsonMapper = createGsonMapper(); public static void addFieldRawValue(JsonObject jsonObject, String memberName, Object rawValue) { @@ -277,7 +274,7 @@ public static JsonObject asObject(Map properties) { } } - public static List asList(JsonElement jsonObject) { + public static List asStringList(JsonElement jsonObject) { JsonArray jsonArray = null; if (jsonObject != null) { @@ -341,40 +338,94 @@ public static List asList(JsonArray jsonArray, JsonObjectConverter con return list; } - public static Map asMap(JsonObject jsonObject) { - if (jsonObject != null) { - Map map = null; + public static List asList(JsonElement jsonElement) { + if (jsonElement == null) { + return Collections.emptyList(); + } - try { - map = getGsonMapper().fromJson(jsonObject, MAP_TYPE_TOKEN); + JsonArray jsonArray = null; - } catch (JsonParseException | ClassCastException e) { - LOG.logJsonException(e); - } + try { + jsonArray = jsonElement.getAsJsonArray(); - if (map != null) { + } catch (IllegalStateException | ClassCastException e) { + LOG.logJsonException(e); + } - for (Map.Entry entry : map.entrySet()) { - Object value = entry.getValue(); + if (jsonArray == null) { + return Collections.emptyList(); + } - if (value != null && value instanceof JsonPrimitive) { + List list = new ArrayList<>(); + for (JsonElement entry : jsonArray) { - Object rawObject = asPrimitiveObject((JsonPrimitive) value); - if (rawObject != null) { - map.put(entry.getKey(), rawObject); - } - } + if (entry.isJsonPrimitive()) { + + Object rawObject = asPrimitiveObject((JsonPrimitive) entry); + if (rawObject != null) { + list.add(rawObject); } - return map; + } else if (entry.isJsonNull()) { + list.add(null); - } else { - return Collections.emptyMap(); + } else if (entry.isJsonObject()) { + list.add(asMap(entry)); + + } else if (entry.isJsonArray()) { + list.add(asList(entry)); } - } else { + } + + return list; + } + + public static Map asMap(JsonElement jsonElement) { + if (jsonElement == null) { return Collections.emptyMap(); } + + JsonObject jsonObject = null; + + try { + jsonObject = jsonElement.getAsJsonObject(); + + } catch (IllegalStateException | ClassCastException e) { + LOG.logJsonException(e); + } + + if (jsonObject == null) { + return Collections.emptyMap(); + + } + + Map map = new HashMap<>(); + for (Map.Entry jsonEntry : jsonObject.entrySet()) { + + String key = jsonEntry.getKey(); + JsonElement value = jsonEntry.getValue(); + + if (value.isJsonPrimitive()) { + + Object rawObject = asPrimitiveObject((JsonPrimitive) value); + if (rawObject != null) { + map.put(key, rawObject); + } + + } else if (value.isJsonNull()) { + map.put(key, null); + + } else if (value.isJsonObject()) { + map.put(key, asMap(value)); + + } else if (value.isJsonArray()) { + map.put(key, asList(value)); + + } + } + + return map; } public static String asString(Map properties) { @@ -466,22 +517,24 @@ public static Object asPrimitiveObject(JsonPrimitive jsonValue) { Object rawObject = null; if (jsonValue.isNumber()) { - LazilyParsedNumber numberValue = null; + Object numberValue = null; try { - numberValue = (LazilyParsedNumber) jsonValue.getAsNumber(); + numberValue = jsonValue.getAsNumber(); - } catch (ClassCastException | NumberFormatException e) { + } catch (NumberFormatException e) { LOG.logJsonException(e); } - if (numberValue != null) { - + if (numberValue != null && numberValue instanceof LazilyParsedNumber) { String numberString = numberValue.toString(); if (numberString != null) { rawObject = parseNumber(numberString); } + } else { + rawObject = numberValue; + } } else { // string, boolean try { diff --git a/engine/src/test/java/org/camunda/bpm/engine/test/api/filter/FilterPropertiesTest.java b/engine/src/test/java/org/camunda/bpm/engine/test/api/filter/FilterPropertiesTest.java index 7dc223bf4a4..67ece6f5f14 100644 --- a/engine/src/test/java/org/camunda/bpm/engine/test/api/filter/FilterPropertiesTest.java +++ b/engine/src/test/java/org/camunda/bpm/engine/test/api/filter/FilterPropertiesTest.java @@ -1,5 +1,5 @@ /* - * Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com) + * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,11 +15,19 @@ */ package org.camunda.bpm.engine.test.api.filter; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.camunda.bpm.engine.filter.Filter; import org.camunda.bpm.engine.impl.test.PluggableProcessEngineTestCase; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + /** * @author Sebastian Menski */ @@ -93,4 +101,135 @@ public void testNullProperty() { } + public void testMapContainingListProperty() { + // given + Map properties = Collections.singletonMap("foo", Collections.singletonList("bar")); + + filter.setProperties(properties); + filterService.saveFilter(filter); + + // when + filter = filterService.getFilter(filter.getId()); + + Map deserialisedProperties = filter.getProperties(); + List list = (List) deserialisedProperties.get("foo"); + Object string = list.get(0); + + // then + assertThat(deserialisedProperties.size(), is(1)); + assertThat(string, instanceOf(String.class)); + assertThat(string.toString(), is("bar")); + } + + public void testMapContainingMapProperty() { + // given + Map properties = Collections.singletonMap("foo", Collections.singletonMap("bar", "foo")); + + filter.setProperties(properties); + filterService.saveFilter(filter); + + // when + filter = filterService.getFilter(filter.getId()); + + Map deserialisedProperties = filter.getProperties(); + + Map map = (Map) deserialisedProperties.get("foo"); + Object string = map.get("bar"); + + // then + assertThat(deserialisedProperties.size(), is(1)); + assertThat(string.toString(), is("foo")); + } + + public void testMapContainingMapContainingListProperty() { + // given + Map properties = Collections.singletonMap("foo", Collections.singletonMap("bar", Collections.singletonList("foo"))); + + filter.setProperties(properties); + filterService.saveFilter(filter); + + // when + filter = filterService.getFilter(filter.getId()); + + Map deserialisedProperties = filter.getProperties(); + + Map map = (Map) deserialisedProperties.get("foo"); + List list = (List) map.get("bar"); + Object string = list.get(0); + + // then + assertThat(deserialisedProperties.size(), is(1)); + assertThat(string.toString(), is("foo")); + } + + public void testMapContainingListContainingMapProperty_DeserializePrimitives() { + // given + Map primitives = new HashMap<>(); + primitives.put("string", "aStringValue"); + primitives.put("int", 47); + primitives.put("intOutOfRange", Integer.MAX_VALUE + 1L); + primitives.put("long", Long.MAX_VALUE); + primitives.put("double", 3.14159265359D); + primitives.put("boolean", true); + primitives.put("null", null); + + Map properties = Collections.singletonMap("foo", Collections.singletonList(primitives)); + + filter.setProperties(properties); + filterService.saveFilter(filter); + + // when + filter = filterService.getFilter(filter.getId()); + + Map deserialisedProperties = filter.getProperties(); + + List list = (List) deserialisedProperties.get("foo"); + Map map = (Map) list.get(0); + + // then + assertThat(deserialisedProperties.size(), is(1)); + assertThat((String) map.get("string"), is("aStringValue")); + assertThat((int) map.get("int"), is(47)); + assertThat((long) map.get("intOutOfRange"), is(Integer.MAX_VALUE + 1L)); + assertThat((long) map.get("long"), is(Long.MAX_VALUE)); + assertThat((double) map.get("double"), is(3.14159265359D)); + assertThat((boolean) map.get("boolean"), is(true)); + assertThat(map.get("null"), nullValue()); + } + + public void testMapContainingMapContainingListProperty_DeserializePrimitives() { + // given + List primitives = new ArrayList<>(); + primitives.add("aStringValue"); + primitives.add(47); + primitives.add(Integer.MAX_VALUE + 1L); + primitives.add(Long.MAX_VALUE); + primitives.add(3.14159265359D); + primitives.add(true); + primitives.add(null); + + Map properties = Collections.singletonMap("foo", Collections.singletonMap("bar", primitives)); + + filter.setProperties(properties); + filterService.saveFilter(filter); + + // when + filter = filterService.getFilter(filter.getId()); + + Map deserialisedProperties = filter.getProperties(); + + List list = (List) ((Map) deserialisedProperties.get("foo")).get("bar"); + + // then + assertThat(deserialisedProperties.size(), is(1)); + + assertThat((String) list.get(0), is("aStringValue")); + assertThat((int) list.get(1), is(47)); + assertThat((long) list.get(2), is(Integer.MAX_VALUE + 1L)); + assertThat((long) list.get(3), is(Long.MAX_VALUE)); + assertThat((double) list.get(4), is(3.14159265359D)); + assertThat((boolean) list.get(5), is(true)); + assertThat(list.get(6), nullValue()); + } + } diff --git a/qa/test-db-instance-migration/test-fixture-710/src/main/java/org/camunda/bpm/qa/upgrade/TestFixture.java b/qa/test-db-instance-migration/test-fixture-710/src/main/java/org/camunda/bpm/qa/upgrade/TestFixture.java index 66c6c0ace1c..7ec2bfec914 100644 --- a/qa/test-db-instance-migration/test-fixture-710/src/main/java/org/camunda/bpm/qa/upgrade/TestFixture.java +++ b/qa/test-db-instance-migration/test-fixture-710/src/main/java/org/camunda/bpm/qa/upgrade/TestFixture.java @@ -19,6 +19,7 @@ import org.camunda.bpm.engine.ProcessEngineConfiguration; import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; import org.camunda.bpm.qa.upgrade.gson.ProcessInstanceModificationScenario; +import org.camunda.bpm.qa.upgrade.gson.TaskFilterPropertiesScenario; import org.camunda.bpm.qa.upgrade.gson.TaskFilterScenario; import org.camunda.bpm.qa.upgrade.gson.TaskFilterVariablesScenario; import org.camunda.bpm.qa.upgrade.gson.TimerChangeJobDefinitionScenario; @@ -73,6 +74,7 @@ public static void main(String[] args) { runner.setupScenarios(MigrationBatchScenario.class); runner.setupScenarios(TaskFilterScenario.class); runner.setupScenarios(TaskFilterVariablesScenario.class); + runner.setupScenarios(TaskFilterPropertiesScenario.class); runner.setupScenarios(DeploymentDeployTimeScenario.class); runner.setupScenarios(JobTimestampsScenario.class); runner.setupScenarios(IncidentTimestampScenario.class); diff --git a/qa/test-db-instance-migration/test-fixture-710/src/main/java/org/camunda/bpm/qa/upgrade/gson/TaskFilterPropertiesScenario.java b/qa/test-db-instance-migration/test-fixture-710/src/main/java/org/camunda/bpm/qa/upgrade/gson/TaskFilterPropertiesScenario.java new file mode 100644 index 00000000000..1eb5216077a --- /dev/null +++ b/qa/test-db-instance-migration/test-fixture-710/src/main/java/org/camunda/bpm/qa/upgrade/gson/TaskFilterPropertiesScenario.java @@ -0,0 +1,73 @@ +/* + * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.camunda.bpm.qa.upgrade.gson; + +import org.camunda.bpm.engine.FilterService; +import org.camunda.bpm.engine.ProcessEngine; +import org.camunda.bpm.engine.filter.Filter; +import org.camunda.bpm.qa.upgrade.DescribesScenario; +import org.camunda.bpm.qa.upgrade.ScenarioSetup; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Tassilo Weidner + */ +public class TaskFilterPropertiesScenario { + + @DescribesScenario("initTaskFilterProperties") + public static ScenarioSetup initTaskFilterProperties() { + return new ScenarioSetup() { + public void execute(ProcessEngine engine, String scenarioName) { + FilterService filterService = engine.getFilterService(); + + Filter filterOne = filterService + .newTaskFilter("taskFilterOne"); + + Map primitivesMap = new HashMap<>(); + primitivesMap.put("string", "aStringValue"); + primitivesMap.put("int", 47); + primitivesMap.put("intOutOfRange", Integer.MAX_VALUE + 1L); + primitivesMap.put("long", Long.MAX_VALUE); + primitivesMap.put("double", 3.14159265359D); + primitivesMap.put("boolean", true); + primitivesMap.put("null", null); + + filterOne.setProperties(Collections.singletonMap("foo", Collections.singletonList(primitivesMap))); + filterService.saveFilter(filterOne); + + Filter filterTwo = engine.getFilterService() + .newTaskFilter("taskFilterTwo"); + + List primitivesList = new ArrayList<>(); + primitivesList.add("aStringValue"); + primitivesList.add(47); + primitivesList.add(Integer.MAX_VALUE + 1L); + primitivesList.add(Long.MAX_VALUE); + primitivesList.add(3.14159265359D); + primitivesList.add(true); + primitivesList.add(null); + + filterTwo.setProperties(Collections.singletonMap("foo", Collections.singletonMap("bar", primitivesList))); + filterService.saveFilter(filterTwo); + } + }; + } +} diff --git a/qa/test-db-instance-migration/test-migration/src/test/java/org/camunda/bpm/qa/upgrade/scenarios7110/gson/TaskFilterPropertiesTest.java b/qa/test-db-instance-migration/test-migration/src/test/java/org/camunda/bpm/qa/upgrade/scenarios7110/gson/TaskFilterPropertiesTest.java new file mode 100644 index 00000000000..3e84030565f --- /dev/null +++ b/qa/test-db-instance-migration/test-migration/src/test/java/org/camunda/bpm/qa/upgrade/scenarios7110/gson/TaskFilterPropertiesTest.java @@ -0,0 +1,91 @@ +/* + * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.camunda.bpm.qa.upgrade.scenarios7110.gson; + +import org.camunda.bpm.engine.FilterService; +import org.camunda.bpm.engine.filter.Filter; +import org.camunda.bpm.engine.test.ProcessEngineRule; +import org.camunda.bpm.qa.upgrade.Origin; +import org.camunda.bpm.qa.upgrade.ScenarioUnderTest; +import org.junit.Rule; +import org.junit.Test; + +import java.util.List; +import java.util.Map; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * @author Tassilo Weidner + */ +@ScenarioUnderTest("TaskFilterPropertiesScenario") +@Origin("7.11.0") +public class TaskFilterPropertiesTest { + + @Rule + public ProcessEngineRule engineRule = new ProcessEngineRule("camunda.cfg.xml"); + + @ScenarioUnderTest("initTaskFilterProperties.1") + @Test + public void testMapContainingListContainingMapProperty_DeserializePrimitives() { + FilterService filterService = engineRule.getFilterService(); + + // when + Filter filterOne = filterService.createFilterQuery().filterName("taskFilterOne").singleResult(); + + Map deserialisedProperties = filterOne.getProperties(); + + List list = (List) deserialisedProperties.get("foo"); + Map map = (Map) list.get(0); + + // then + assertThat(deserialisedProperties.size(), is(1)); + assertThat((String) map.get("string"), is("aStringValue")); + assertThat((int) map.get("int"), is(47)); + assertThat((long) map.get("intOutOfRange"), is(Integer.MAX_VALUE + 1L)); + assertThat((long) map.get("long"), is(Long.MAX_VALUE)); + assertThat((double) map.get("double"), is(3.14159265359D)); + assertThat((boolean) map.get("boolean"), is(true)); + assertThat(map.get("null"), nullValue()); + } + + @ScenarioUnderTest("initTaskFilterProperties.1") + @Test + public void testMapContainingMapContainingListProperty_DeserializePrimitives() { + FilterService filterService = engineRule.getFilterService(); + + // when + Filter filterTwo = filterService.createFilterQuery().filterName("taskFilterTwo").singleResult(); + + Map deserialisedProperties = filterTwo.getProperties(); + + List list = (List) ((Map) deserialisedProperties.get("foo")).get("bar"); + + // then + assertThat(deserialisedProperties.size(), is(1)); + + assertThat((String) list.get(0), is("aStringValue")); + assertThat((int) list.get(1), is(47)); + assertThat((long) list.get(2), is(Integer.MAX_VALUE + 1L)); + assertThat((long) list.get(3), is(Long.MAX_VALUE)); + assertThat((double) list.get(4), is(3.14159265359D)); + assertThat((boolean) list.get(5), is(true)); + assertThat(list.get(6), nullValue()); + } + +} \ No newline at end of file