|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. |
| 3 | + * This file is a part of the ModelEngine Project. |
| 4 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 5 | + *--------------------------------------------------------------------------------------------*/ |
| 6 | + |
| 7 | +package modelengine.fit.jade.aipp.variable.updater; |
| 8 | + |
| 9 | +import modelengine.fitframework.util.MapBuilder; |
| 10 | +import modelengine.fitframework.util.ObjectUtils; |
| 11 | + |
| 12 | +import org.junit.jupiter.api.Assertions; |
| 13 | +import org.junit.jupiter.api.DisplayName; |
| 14 | +import org.junit.jupiter.api.Test; |
| 15 | + |
| 16 | +import java.util.HashMap; |
| 17 | +import java.util.List; |
| 18 | +import java.util.Map; |
| 19 | + |
| 20 | +/** |
| 21 | + * {@link AippVariableUpdater}的测试方法。 |
| 22 | + * |
| 23 | + * @author 鲁为 |
| 24 | + * @since 2025-09-28 |
| 25 | + */ |
| 26 | +@DisplayName("变量更新节点测试") |
| 27 | +public class AippVariableUpdaterTest { |
| 28 | + public static final String UPDATE_VARIABLES = "updateVariables"; |
| 29 | + public static final String INTERNAL = "_internal"; |
| 30 | + public static final String OUTPUT_SCOPE = "outputScope"; |
| 31 | + public static final String KEY = "key"; |
| 32 | + public static final String VALUE = "value"; |
| 33 | + |
| 34 | + private final AippVariableUpdater aippVariableUpdater = new AippVariableUpdater(); |
| 35 | + |
| 36 | + @Test |
| 37 | + @DisplayName("修改 businessData 中指定路径的值") |
| 38 | + void shouldModifySpecificPathValue() { |
| 39 | + Map<String, Object> flowDataInner = |
| 40 | + this.getFlowData(this.getContextData(List.of("trace1"), "contextId"), this.buildBusinessData()); |
| 41 | + List<Map<String, Object>> flowData = List.of(flowDataInner); |
| 42 | + this.aippVariableUpdater.handleTask(flowData); |
| 43 | + Assertions.assertEquals(ObjectUtils.<String>cast(ObjectUtils.<Map<String, Object>>cast(ObjectUtils.<Map<String, Object>>cast( |
| 44 | + ObjectUtils.<Map<String, Object>>cast(ObjectUtils.<Map<String, Object>>cast(ObjectUtils.<Map<String, Object>>cast( |
| 45 | + flowData.get(0).get("businessData")).get(INTERNAL)).get(OUTPUT_SCOPE)).get( |
| 46 | + "jade8xvdq4")) |
| 47 | + .get("output")).get("a")), "after"); |
| 48 | + } |
| 49 | + |
| 50 | + private Map<String, Object> getFlowData(Map<String, Object> contextData, Map<String, Object> businessData) { |
| 51 | + return MapBuilder.get(() -> new HashMap<String, Object>()) |
| 52 | + .put("contextData", contextData) |
| 53 | + .put("businessData", businessData) |
| 54 | + .build(); |
| 55 | + } |
| 56 | + |
| 57 | + private Map<String, Object> getContextData(List<String> traceIds, String contextId) { |
| 58 | + return MapBuilder.get(() -> new HashMap<String, Object>()) |
| 59 | + .put("flowTraceIds", traceIds) |
| 60 | + .put("contextId", contextId) |
| 61 | + .build(); |
| 62 | + } |
| 63 | + |
| 64 | + private Map<String, Object> buildBusinessData() { |
| 65 | + return MapBuilder.<String, Object>get() |
| 66 | + .put(UPDATE_VARIABLES, |
| 67 | + List.of(MapBuilder.get() |
| 68 | + .put(KEY, List.of("jade8xvdq4", "output", "a")) |
| 69 | + .put(VALUE, "after") |
| 70 | + .build())) |
| 71 | + .put(INTERNAL, |
| 72 | + MapBuilder.get() |
| 73 | + .put(OUTPUT_SCOPE, |
| 74 | + MapBuilder.get() |
| 75 | + .put("jade8xvdq4", |
| 76 | + MapBuilder.get() |
| 77 | + .put("output", |
| 78 | + MapBuilder.get().put("a", "before").build()) |
| 79 | + .build()) |
| 80 | + .build()) |
| 81 | + .build()) |
| 82 | + .build(); |
| 83 | + } |
| 84 | +} |
0 commit comments