kcode-pi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +358 -0
- package/dist/cli/kcode.d.ts +15 -0
- package/dist/cli/kcode.js +153 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +7 -0
- package/docs/KCODE_DISTRIBUTION.md +91 -0
- package/extensions/kingdee-harness.ts +180 -0
- package/extensions/kingdee-header.ts +122 -0
- package/extensions/kingdee-tools.ts +379 -0
- package/knowledge/.backup/v1.0.0/version.json +10 -0
- package/knowledge/cangqiong/product-notes.md +15 -0
- package/knowledge/common/business-flows.md +115 -0
- package/knowledge/common/config-guides.md +110 -0
- package/knowledge/common/error-patterns.md +170 -0
- package/knowledge/common/implementation.md +144 -0
- package/knowledge/cosmic/hard-constraints.md +38 -0
- package/knowledge/cosmic/ksql-datafix.md +34 -0
- package/knowledge/cosmic/platform-baseline.md +32 -0
- package/knowledge/cosmic/plugin-decision-matrix.md +40 -0
- package/knowledge/cosmic/review-checklist.md +40 -0
- package/knowledge/cosmic/unittest.md +35 -0
- package/knowledge/enterprise/api-reference.md +186 -0
- package/knowledge/enterprise/code-patterns.md +217 -0
- package/knowledge/enterprise/plugin-lifecycle.md +188 -0
- package/knowledge/enterprise/tables.json +159 -0
- package/knowledge/flagship/api-reference.md +237 -0
- package/knowledge/flagship/code-patterns.md +246 -0
- package/knowledge/flagship/cosmic-platform-note.md +15 -0
- package/knowledge/flagship/plugin-lifecycle.md +248 -0
- package/knowledge/flagship/tables.json +159 -0
- package/knowledge/version.json +10 -0
- package/knowledge/xinghan/product-notes.md +15 -0
- package/package.json +71 -0
- package/prompts/kd-discuss.md +11 -0
- package/prompts/kd-execute.md +12 -0
- package/prompts/kd-plan.md +12 -0
- package/prompts/kd-ship.md +12 -0
- package/prompts/kd-spec.md +12 -0
- package/prompts/kd-verify.md +12 -0
- package/skills/kd-check/SKILL.md +26 -0
- package/skills/kd-cosmic-dev/SKILL.md +82 -0
- package/skills/kd-cosmic-review/SKILL.md +90 -0
- package/skills/kd-cosmic-unittest/SKILL.md +92 -0
- package/skills/kd-debug/SKILL.md +30 -0
- package/skills/kd-discuss/SKILL.md +24 -0
- package/skills/kd-execute/SKILL.md +22 -0
- package/skills/kd-gen/SKILL.md +34 -0
- package/skills/kd-ksql/SKILL.md +86 -0
- package/skills/kd-plan/SKILL.md +24 -0
- package/skills/kd-ship/SKILL.md +22 -0
- package/skills/kd-spec/SKILL.md +24 -0
- package/skills/kd-verify/SKILL.md +22 -0
- package/themes/kcode-dark.json +81 -0
- package/vendor/kingdee-skills/cosmic-unittest/SKILL.md +788 -0
- package/vendor/kingdee-skills/cosmic-unittest/author-cache.json +5 -0
- package/vendor/kingdee-skills/cosmic-unittest/cosmic-unittest-skill-overview.html +746 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/business-test.md +205 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/common-test.md +257 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/formplugin-test.md +560 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/op-plugin-test.md +231 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/validator-test.md +232 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/business-helper.md +184 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/common-module.md +355 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/convert-plugin.md +130 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/formplugin.md +235 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/op-plugin.md +226 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/validator.md +206 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/SKILL.md +674 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/advanced-scenario-checklist.md +307 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/algox-performance-checklist.md +129 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/coding-standard-checklist.md +491 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/cosmic-api-checklist.md +285 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/data-access-checklist.md +261 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/data-transaction-checklist.md +390 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/domain-logic-checklist.md +295 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/form-plugin-checklist.md +508 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/infra-checklist.md +254 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/ksql-checklist.md +305 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/lifecycle-checklist.md +298 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/operation-plugin-checklist.md +442 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/test-mock-checklist.md +120 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/ui-performance-checklist.md +320 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/pattern-matcher.py +336 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/review-score-calculator.py +121 -0
- package/vendor/kingdee-skills/ok-cosmic/CHANGELOG.md +295 -0
- package/vendor/kingdee-skills/ok-cosmic/README.md +460 -0
- package/vendor/kingdee-skills/ok-cosmic/SKILL.md +287 -0
- package/vendor/kingdee-skills/ok-cosmic/agents/openai.yaml +17 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/BatchImportPluginTemplate.java +93 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/BillPlugInTemplate.java +156 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ConvertPlugInTemplate.java +255 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/FormPluginTemplate.java +597 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/IWorkflowPluginTemplate.java +91 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ListPluginTemplate.java +194 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/OpPluginTemplate.java +201 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/OpenApiControllerTemplate.java +103 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/PrintPluginTemplate.java +95 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ReportFormPluginTemplate.java +257 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ReportListDataPluginTemplate.java +70 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/StandardTreeListPluginTemplate.java +130 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/TaskTemplate.java +80 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/TreeListPluginTemplate.java +152 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/WriteBackPlugInTemplate.java +286 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/attachment/AttachmentUploadBindSample.java +93 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/botp/BotpTracePushSample.java +168 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/botp/SampleConvertPlugin.java +223 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/cache/SampleCacheUsage.java +218 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/concurrent/SampleThreadPoolBatch.java +156 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/data/DynamicObjectCrudSample.java +205 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/data/DynamicObjectOpsSample.java +100 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/BeforeOperationConfirmSample.java +217 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ConfirmDialogSample.java +131 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/EntryRowCalculateSample.java +116 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/F7FilterSample.java +134 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/GetAndSetValueSample.java +176 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/HyperlinkJumpSample.java +124 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/OpenBillModalSample.java +253 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ReturnParentDataSample.java +295 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/TreeControlSample.java +140 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ViewControlOpsSample.java +132 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/list/ListPluginBasicSample.java +170 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/list/ListPreOpenFilterSample.java +68 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/message/MessageNotifySample.java +95 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/mq/SampleMQConsumer.java +198 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/mq/sample_mq.xml +15 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/operation/OpAddValidatorsSample.java +137 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/operation/OperationOptionBridgeSample.java +228 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/package-info.java +19 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/BaseDataQuerySample.java +194 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/BatchQuerySample.java +368 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/DataSetQueryStatSample.java +131 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/report/SampleReportFormPlugin.java +179 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/report/SampleReportListDataPlugin.java +616 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/snippets-guide.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/task/ScheduleTaskSample.java +160 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/workflow/SampleWorkflowPlugin.java +302 -0
- package/vendor/kingdee-skills/ok-cosmic/manifest.json +78 -0
- package/vendor/kingdee-skills/ok-cosmic/ok-cosmic-intro.html +903 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/attachment-api.md +114 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/botp-convert.md +98 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/dynamic-object.md +113 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/entity-metadata.md +123 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/event-lifecycle.md +184 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/flex-prop.md +114 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/form-utils.md +133 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/operate-chain.md +159 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/plugin-base.md +218 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/query-dataset.md +149 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/request-context.md +88 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/view-handler.md +157 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-bill.md +76 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-botp.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-form.md +165 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-import.md +69 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-list.md +227 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-openapi.md +112 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-operation.md +135 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-print.md +65 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-report-data.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-report-form.md +90 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-task.md +62 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-tree-list.md +71 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-workflow.md +82 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-writeback.md +71 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-algo.md +67 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-cache.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-dynamic-model-svc.md +82 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-dynamic-object.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-entity-model.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-exception.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-file.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-id.md +47 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-lock.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-log.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-network-control.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-orm-access.md +78 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-request-context.md +62 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-threadpool.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-tx.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-utils.md +67 -0
- package/vendor/kingdee-skills/ok-cosmic/requirements.txt +2 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/a-layer-rules.json +24 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/anti-patterns.md +48 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/cheat-sheet.md +256 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/coding-preferences.md +140 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/constraints.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/decision-matrix.md +222 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/intent-routing.md +94 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/platform-baseline.md +69 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/post-check.md +109 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/config_loader.py +204 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-api-knowledge.py +910 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-basedata-query.py +359 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-config-check.py +181 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-extpoints-query.py +389 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-form-metadata.py +856 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-check.py +262 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-lint.py +293 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/__init__.py +2 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/base.py +393 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/resource_check.py +176 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/scene_check.py +375 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/style_check.py +434 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/verify_check.py +36 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/route_client.py +186 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/script_utils.py +40 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/sqlite_cache.py +142 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-commons.jar +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-features.jar +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/ok-cosmic-docs.db +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/ok-cosmic.json +13 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup-mac.sh +18 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup-windows.bat +53 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup.jar +0 -0
- package/vendor/kingdee-skills/ok-ksql/SKILL.md +81 -0
- package/vendor/kingdee-skills/ok-ksql/agents/openai.yaml +7 -0
- package/vendor/kingdee-skills/ok-ksql/manifest.json +14 -0
- package/vendor/kingdee-skills/ok-ksql/references/ksql-datafix.md +452 -0
- package/vendor/kingdee-skills/ok-ksql/scripts/ksql_lint.py +363 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Business Helper 测试完整示例
|
|
2
|
+
|
|
3
|
+
> 以 `AutoCompleteWorkHelper` 为例,展示 business 帮助类的完整测试写法。
|
|
4
|
+
|
|
5
|
+
```java
|
|
6
|
+
package kd.mmc.sfc.business;
|
|
7
|
+
|
|
8
|
+
import kd.bd.mpdm.common.sfc.assist.ProcessStatus;
|
|
9
|
+
import kd.bd.sbd.enums.sfc.SequenceTypeEnum;
|
|
10
|
+
import kd.bos.dataentity.OperateOption;
|
|
11
|
+
import kd.bos.dataentity.entity.DynamicObject;
|
|
12
|
+
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
13
|
+
import kd.bos.entity.operate.result.OperationResult;
|
|
14
|
+
import kd.bos.org.utils.Consts;
|
|
15
|
+
import kd.bos.servicehelper.operation.OperationServiceHelper;
|
|
16
|
+
import kd.bos.test.ext.annotaions.UnittestCaseInfo;
|
|
17
|
+
import kd.bos.unittest.AbstractJunitNoDependenciesResManagerTest;
|
|
18
|
+
import kd.bos.unittest.mock.DynamicObjectMocker;
|
|
19
|
+
import kd.bos.unittest.mock.ReflectHelper;
|
|
20
|
+
import kd.mmc.sfc.common.consts.SendWorkConst;
|
|
21
|
+
import kd.mmc.sfc.common.outsourcesend.OutsourceSendConsts;
|
|
22
|
+
import kd.mmc.sfc.common.processplan.ProcessPlanConsts;
|
|
23
|
+
import org.junit.After;
|
|
24
|
+
import org.junit.Before;
|
|
25
|
+
import org.junit.Test;
|
|
26
|
+
import org.mockito.MockedStatic;
|
|
27
|
+
|
|
28
|
+
import java.math.BigDecimal;
|
|
29
|
+
import java.util.*;
|
|
30
|
+
|
|
31
|
+
import static org.mockito.ArgumentMatchers.*;
|
|
32
|
+
import static org.mockito.Mockito.*;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 自动完工帮助类单测
|
|
36
|
+
* @author zhang_san
|
|
37
|
+
* @version 1.0
|
|
38
|
+
* @date 2025/4/14 9:18
|
|
39
|
+
*/
|
|
40
|
+
public class AutoCompleteWorkHelperTest extends AbstractJunitNoDependenciesResManagerTest {
|
|
41
|
+
|
|
42
|
+
// ========== 1. 声明 MockedStatic ==========
|
|
43
|
+
MockedStatic<OperationServiceHelper> operationServiceHelper;
|
|
44
|
+
MockedStatic<ProcessPlanHelper> processPlanHelper;
|
|
45
|
+
private MockedStatic<ProcessReviewHelper> processReviewHelper;
|
|
46
|
+
|
|
47
|
+
// ========== 2. @Before 初始化 ==========
|
|
48
|
+
@Before
|
|
49
|
+
public void before() {
|
|
50
|
+
operationServiceHelper = mockStatic(OperationServiceHelper.class);
|
|
51
|
+
processPlanHelper = mockStatic(ProcessPlanHelper.class);
|
|
52
|
+
processReviewHelper = mockStatic(ProcessReviewHelper.class);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ========== 3. @After 关闭 ==========
|
|
56
|
+
@After
|
|
57
|
+
public void after() {
|
|
58
|
+
operationServiceHelper.close();
|
|
59
|
+
processPlanHelper.close();
|
|
60
|
+
processReviewHelper.close();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ========== 4. reset 方法 ==========
|
|
64
|
+
public void reset() {
|
|
65
|
+
operationServiceHelper.reset();
|
|
66
|
+
processPlanHelper.reset();
|
|
67
|
+
processReviewHelper.reset();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ========== 5. 测试 public static 方法 ==========
|
|
71
|
+
|
|
72
|
+
@UnittestCaseInfo(
|
|
73
|
+
author = "zhang_san <zhang_san@kingdee.com>",
|
|
74
|
+
title = "Invoke bill operate success",
|
|
75
|
+
targetClass = "kd.mmc.sfc.business.AutoCompleteWorkHelper",
|
|
76
|
+
targetMethod = "invokebilloperate",
|
|
77
|
+
lastUpdateTime = "2025-04-14 09:27:03",
|
|
78
|
+
lastUpdateAuthor = "zhang_san <zhang_san@kingdee.com>",
|
|
79
|
+
methodSignature = "protected static OperationResult invokeBillOperate(...)",
|
|
80
|
+
testPoints = {"Functionality"},
|
|
81
|
+
description = "Invoke bill operate success"
|
|
82
|
+
)
|
|
83
|
+
@Test
|
|
84
|
+
public void invokeBillOperate_Success() {
|
|
85
|
+
//step 构建查询返回数据
|
|
86
|
+
Set<String> billIds = new HashSet<>(Arrays.asList("1", "2"));
|
|
87
|
+
Set<String> entryIds = new HashSet<>(Collections.singletonList("1"));
|
|
88
|
+
Map<String, Date> dateMap = new HashMap<>();
|
|
89
|
+
dateMap.put("1", new Date());
|
|
90
|
+
|
|
91
|
+
OperationResult opResult = new OperationResult();
|
|
92
|
+
opResult.setSuccess(true);
|
|
93
|
+
operationServiceHelper.when(() -> OperationServiceHelper.executeOperate(
|
|
94
|
+
anyString(), anyString(), any(Object[].class), any(OperateOption.class)))
|
|
95
|
+
.thenReturn(opResult);
|
|
96
|
+
|
|
97
|
+
//step 执行被测方法
|
|
98
|
+
OperationResult result = AutoCompleteWorkHelper.invokeBillOperate(
|
|
99
|
+
"operation", billIds, entryIds, dateMap, "formId");
|
|
100
|
+
|
|
101
|
+
//assert 断言返回结果
|
|
102
|
+
assertTrue(result.isSuccess());
|
|
103
|
+
reset();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Test
|
|
107
|
+
public void invokeBillOperate_Exception() {
|
|
108
|
+
//step 构建异常场景
|
|
109
|
+
Set<String> billIds = new HashSet<>(Arrays.asList("1", "2"));
|
|
110
|
+
Set<String> entryIds = new HashSet<>(Collections.singletonList("1"));
|
|
111
|
+
Map<String, Date> dateMap = new HashMap<>();
|
|
112
|
+
dateMap.put("1", new Date());
|
|
113
|
+
|
|
114
|
+
operationServiceHelper.when(() -> OperationServiceHelper.executeOperate(
|
|
115
|
+
anyString(), anyString(), any(Object[].class), any(OperateOption.class)))
|
|
116
|
+
.thenThrow(new RuntimeException("Exception"));
|
|
117
|
+
|
|
118
|
+
//step 执行被测方法(异常被内部捕获)
|
|
119
|
+
OperationResult result = AutoCompleteWorkHelper.invokeBillOperate(
|
|
120
|
+
"operation", billIds, entryIds, dateMap, "formId");
|
|
121
|
+
|
|
122
|
+
//assert 异常被捕获后仍返回成功
|
|
123
|
+
assertTrue(result.isSuccess());
|
|
124
|
+
reset();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ========== 6. 测试 private static 方法(用 ReflectHelper)==========
|
|
128
|
+
|
|
129
|
+
@Test
|
|
130
|
+
public void testAutoProcessPlanCompleteWork_WhenProPlanBillsIsEmpty() {
|
|
131
|
+
//step 模拟 proPlanBills 为空
|
|
132
|
+
Set<Long> proPlanEntryIds = new HashSet<>();
|
|
133
|
+
proPlanEntryIds.add(1001L);
|
|
134
|
+
Map<Long, Date> allEndTimeMap = new HashMap<>();
|
|
135
|
+
allEndTimeMap.put(1001L, new Date());
|
|
136
|
+
|
|
137
|
+
//mock getProPlanBillsByEntryIds 返回空数组
|
|
138
|
+
processPlanHelper.when(() -> ProcessPlanHelper.getProPlanBillsByEntryIds(
|
|
139
|
+
proPlanEntryIds, Arrays.asList(ProcessStatus.STARTWORKER, ProcessStatus.SENDORDER)))
|
|
140
|
+
.thenReturn(new DynamicObject[0]);
|
|
141
|
+
|
|
142
|
+
//step 通过反射调用 private static 方法
|
|
143
|
+
ReflectHelper.invokeStaticMethod(AutoCompleteWorkHelper.class,
|
|
144
|
+
"autoProcessPlanCompleteWork", proPlanEntryIds, allEndTimeMap);
|
|
145
|
+
|
|
146
|
+
//assert 不应调用 invokeBillOperate
|
|
147
|
+
operationServiceHelper.verify(() -> OperationServiceHelper.executeOperate(
|
|
148
|
+
anyString(), anyString(), any(Object[].class), any(OperateOption.class)), never());
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ========== 7. 复杂数据构造示例 ==========
|
|
152
|
+
|
|
153
|
+
@Test
|
|
154
|
+
public void testAutoProcessPlanCompleteWork_MeetConditions() {
|
|
155
|
+
//step 构建满足条件的工序计划数据
|
|
156
|
+
Set<Long> proPlanEntryIds = new HashSet<>();
|
|
157
|
+
proPlanEntryIds.add(1001L);
|
|
158
|
+
Map<Long, Date> allEndTimeMap = new HashMap<>();
|
|
159
|
+
allEndTimeMap.put(1001L, new Date());
|
|
160
|
+
|
|
161
|
+
// 构建分录集合
|
|
162
|
+
DynamicObjectCollection entrys = new DynamicObjectCollection();
|
|
163
|
+
entrys.add(new DynamicObjectMocker()
|
|
164
|
+
.add(ProcessPlanConsts.ENTRY.PROCESSTATUS, ProcessStatus.STARTWORKER)
|
|
165
|
+
.add(ProcessPlanConsts.ENTRY.TOBEINSPECTQTY, new BigDecimal("0"))
|
|
166
|
+
.add(ProcessPlanConsts.ENTRY.TOBEREWORKEDQTY, new BigDecimal("0"))
|
|
167
|
+
.add(ProcessPlanConsts.ENTRY.COMPLETEQTY, new BigDecimal("10"))
|
|
168
|
+
.add(ProcessPlanConsts.ENTRY.PROCESSQTY, new BigDecimal("10"))
|
|
169
|
+
.add(OutsourceSendConsts.ENTRY.ID, 1001L)
|
|
170
|
+
.add(ProcessPlanConsts.ENTRY.PROCESSSEQUENCE, "1")
|
|
171
|
+
.add(ProcessPlanConsts.ENTRY.PROCESSNUMBER, "1001")
|
|
172
|
+
.add(ProcessPlanConsts.ENTRY.SEQUENCETYPE, SequenceTypeEnum.MAIN.getType())
|
|
173
|
+
.getObject());
|
|
174
|
+
|
|
175
|
+
// 构建单据(包含分录)
|
|
176
|
+
DynamicObject proPlanBill = new DynamicObjectMocker()
|
|
177
|
+
.add(Consts.ID, 1L)
|
|
178
|
+
.add(ProcessPlanConsts.BILLTYPE_ID, 100L)
|
|
179
|
+
.add(ProcessPlanConsts.ENTRY.ENTRYENTITY_ENTITY, entrys)
|
|
180
|
+
.getObject();
|
|
181
|
+
|
|
182
|
+
//mock
|
|
183
|
+
processPlanHelper.when(() -> ProcessPlanHelper.getProPlanBillsByEntryIds(
|
|
184
|
+
proPlanEntryIds, Arrays.asList(ProcessStatus.STARTWORKER, ProcessStatus.SENDORDER)))
|
|
185
|
+
.thenReturn(new DynamicObject[]{proPlanBill});
|
|
186
|
+
|
|
187
|
+
//step 执行
|
|
188
|
+
ReflectHelper.invokeStaticMethod(AutoCompleteWorkHelper.class,
|
|
189
|
+
"autoProcessPlanCompleteWork", proPlanEntryIds, allEndTimeMap);
|
|
190
|
+
|
|
191
|
+
//assert 应调用 executeOperate 2次
|
|
192
|
+
operationServiceHelper.verify(() -> OperationServiceHelper.executeOperate(
|
|
193
|
+
anyString(), anyString(), any(Object[].class), any(OperateOption.class)), times(2));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## 要点总结
|
|
199
|
+
|
|
200
|
+
1. **MockedStatic 三板斧**:声明 → @Before 初始化 → @After 关闭
|
|
201
|
+
2. **reset()** 方法在每个 @Test 末尾调用,防止状态污染
|
|
202
|
+
3. **private/protected 方法**用 `ReflectHelper` 反射调用
|
|
203
|
+
4. **DynamicObjectMocker** 链式构造单据 + 分录的嵌套结构
|
|
204
|
+
5. **@UnittestCaseInfo** 注解记录完整的测试元信息
|
|
205
|
+
6. **断言方式**:assertEquals / assertTrue / assertFalse / assertNotNull + verify 验证调用次数
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# Common Module 测试完整示例
|
|
2
|
+
|
|
3
|
+
> 展示 mmc-sfc-common 工程中三种测试类型的完整示例。
|
|
4
|
+
|
|
5
|
+
## 1. POJO 测试示例(InvokeResultTest)
|
|
6
|
+
|
|
7
|
+
```java
|
|
8
|
+
package kd.mmc.sfc.common.pojo;
|
|
9
|
+
|
|
10
|
+
import kd.bos.test.ext.annotaions.UnittestCaseInfo;
|
|
11
|
+
import org.junit.Test;
|
|
12
|
+
|
|
13
|
+
import static org.junit.Assert.*;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* InvokeResult 单元测试
|
|
17
|
+
* @author zhang_san
|
|
18
|
+
* @date 2026/02/05
|
|
19
|
+
*/
|
|
20
|
+
public class InvokeResultTest {
|
|
21
|
+
|
|
22
|
+
@UnittestCaseInfo(
|
|
23
|
+
author = "zhang_san <zhang_san@kingdee.com>",
|
|
24
|
+
title = "Test success with data",
|
|
25
|
+
targetClass = "kd.mmc.sfc.common.pojo.InvokeResult",
|
|
26
|
+
targetMethod = "successwithdata",
|
|
27
|
+
lastUpdateTime = "2026-02-05 15:58:24",
|
|
28
|
+
lastUpdateAuthor = "zhang_san <zhang_san@kingdee.com>",
|
|
29
|
+
methodSignature = "null",
|
|
30
|
+
testPoints = {"Functionality"},
|
|
31
|
+
description = "Test success with data"
|
|
32
|
+
)
|
|
33
|
+
@Test
|
|
34
|
+
public void testSuccessWithData() {
|
|
35
|
+
// step 准备测试数据
|
|
36
|
+
String testData = "test data";
|
|
37
|
+
|
|
38
|
+
// 执行被测方法
|
|
39
|
+
InvokeResult result = InvokeResult.success(testData);
|
|
40
|
+
|
|
41
|
+
// assert 验证结果
|
|
42
|
+
assertTrue(result.isSuccess());
|
|
43
|
+
assertEquals(testData, result.getData());
|
|
44
|
+
assertNull(result.getMessage());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Test
|
|
48
|
+
public void testSuccessWithoutParams() {
|
|
49
|
+
//step 执行被测方法
|
|
50
|
+
InvokeResult result = InvokeResult.success();
|
|
51
|
+
|
|
52
|
+
//assert 验证结果
|
|
53
|
+
assertTrue(result.isSuccess());
|
|
54
|
+
assertNull(result.getData());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Test
|
|
58
|
+
public void testFailureWithMessage() {
|
|
59
|
+
// step
|
|
60
|
+
InvokeResult result = InvokeResult.failure("error message");
|
|
61
|
+
|
|
62
|
+
// assert
|
|
63
|
+
assertFalse(result.isSuccess());
|
|
64
|
+
assertEquals("error message", result.getMessage());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Test
|
|
68
|
+
public void testGetSetMessage() {
|
|
69
|
+
// step
|
|
70
|
+
InvokeResult result = new InvokeResult();
|
|
71
|
+
result.setMessage("test message");
|
|
72
|
+
|
|
73
|
+
// assert
|
|
74
|
+
assertEquals("test message", result.getMessage());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@Test
|
|
78
|
+
public void testToString() {
|
|
79
|
+
// step
|
|
80
|
+
InvokeResult result = new InvokeResult();
|
|
81
|
+
result.setSuccess(true);
|
|
82
|
+
result.setMessage("test message");
|
|
83
|
+
result.setData("test data");
|
|
84
|
+
|
|
85
|
+
String str = result.toString();
|
|
86
|
+
|
|
87
|
+
// assert
|
|
88
|
+
assertTrue(str.contains("success=true"));
|
|
89
|
+
assertTrue(str.contains("message=test message"));
|
|
90
|
+
assertTrue(str.contains("data=test data"));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## 2. 枚举测试示例(PushOperationCodeEnumTest)
|
|
96
|
+
|
|
97
|
+
```java
|
|
98
|
+
package kd.mmc.sfc.common.enums;
|
|
99
|
+
|
|
100
|
+
import kd.bos.test.ext.annotaions.UnittestCaseInfo;
|
|
101
|
+
import kd.bos.unittest.AbstractJunitNoDependenciesTest;
|
|
102
|
+
import kd.mmc.sfc.common.processmaterial.ProcessMaterialConsts.OPERATION_CONST;
|
|
103
|
+
import org.junit.Test;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* PushOperationCodeEnum 单元测试
|
|
107
|
+
* @author zhang_san
|
|
108
|
+
* @date 2025/6/24
|
|
109
|
+
*/
|
|
110
|
+
public class PushOperationCodeEnumTest extends AbstractJunitNoDependenciesTest {
|
|
111
|
+
|
|
112
|
+
@UnittestCaseInfo(
|
|
113
|
+
author = "zhang_san <zhang_san@kingdee.com>",
|
|
114
|
+
title = "Match push target bill empty operation key returns empty string",
|
|
115
|
+
targetClass = "kd.mmc.sfc.common.enums.PushOperationCodeEnum",
|
|
116
|
+
targetMethod = "matchpushtargetbill",
|
|
117
|
+
lastUpdateTime = "2025-06-24 10:55:45",
|
|
118
|
+
lastUpdateAuthor = "zhang_san <zhang_san@kingdee.com>",
|
|
119
|
+
methodSignature = "public static String matchPushTargetBill(String operationKey)",
|
|
120
|
+
testPoints = {"Functionality"},
|
|
121
|
+
description = "Match push target bill empty operation key returns empty string"
|
|
122
|
+
)
|
|
123
|
+
@Test
|
|
124
|
+
public void matchPushTargetBill_EmptyOperationKey_ReturnsEmptyString() {
|
|
125
|
+
// step 空操作标识
|
|
126
|
+
String result = PushOperationCodeEnum.matchPushTargetBill("");
|
|
127
|
+
|
|
128
|
+
// assert
|
|
129
|
+
assertEquals("", result);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@Test
|
|
133
|
+
public void matchPushTargetBill_ValidOperationKey_ReturnsTargetBill() {
|
|
134
|
+
// step 有效操作标识
|
|
135
|
+
String result = PushOperationCodeEnum.matchPushTargetBill(
|
|
136
|
+
OPERATION_CONST.RETURNAPPLYORDER);
|
|
137
|
+
|
|
138
|
+
// assert 返回目标单据标识
|
|
139
|
+
assertEquals("qcpp_manuinspecapply", result);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## 3. 工具类测试示例(BillPushUtilTest)
|
|
145
|
+
|
|
146
|
+
```java
|
|
147
|
+
package kd.mmc.sfc.common.utils;
|
|
148
|
+
|
|
149
|
+
import kd.bos.dataentity.OperateOption;
|
|
150
|
+
import kd.bos.entity.botp.runtime.ConvertOperationResult;
|
|
151
|
+
import kd.bos.entity.botp.runtime.PushArgs;
|
|
152
|
+
import kd.bos.entity.botp.runtime.SourceBillReport;
|
|
153
|
+
import kd.bos.entity.datamodel.ListSelectedRow;
|
|
154
|
+
import kd.bos.servicehelper.botp.ConvertServiceHelper;
|
|
155
|
+
import kd.bos.test.ext.annotaions.UnittestCaseInfo;
|
|
156
|
+
import kd.mmc.sfc.common.BaseTest; // common 包自带的 BaseTest
|
|
157
|
+
import org.junit.Test;
|
|
158
|
+
import org.mockito.MockedConstruction;
|
|
159
|
+
import org.mockito.MockedStatic;
|
|
160
|
+
import org.mockito.Mockito;
|
|
161
|
+
|
|
162
|
+
import java.util.*;
|
|
163
|
+
import java.util.stream.*;
|
|
164
|
+
|
|
165
|
+
import static org.mockito.ArgumentMatchers.*;
|
|
166
|
+
import static org.mockito.Mockito.*;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* BillPushUtil 单元测试
|
|
170
|
+
* @author zhang_san
|
|
171
|
+
* @date 2025/4/21
|
|
172
|
+
*/
|
|
173
|
+
public class BillPushUtilTest extends BaseTest {
|
|
174
|
+
|
|
175
|
+
// ========== 继承 BaseTest,自动拥有常用 Mock ==========
|
|
176
|
+
// 无需自行声明 queryServiceHelper、businessDataServiceHelper 等
|
|
177
|
+
|
|
178
|
+
@UnittestCaseInfo(
|
|
179
|
+
author = "zhang_san <zhang_san@kingdee.com>",
|
|
180
|
+
title = "Test do push",
|
|
181
|
+
targetClass = "kd.mmc.sfc.common.utils.BillPushUtil",
|
|
182
|
+
targetMethod = "dopush",
|
|
183
|
+
lastUpdateTime = "2025-04-21 15:58:57",
|
|
184
|
+
lastUpdateAuthor = "zhang_san <zhang_san@kingdee.com>",
|
|
185
|
+
methodSignature = "public static ConvertOperationResult doPush(...)",
|
|
186
|
+
testPoints = {"Functionality"},
|
|
187
|
+
description = "Test do push"
|
|
188
|
+
)
|
|
189
|
+
@Test
|
|
190
|
+
public void testDoPush() {
|
|
191
|
+
// 使用 try-with-resources 管理方法级 Mock
|
|
192
|
+
try (MockedStatic<ConvertServiceHelper> convertServiceHelper =
|
|
193
|
+
mockStatic(ConvertServiceHelper.class);
|
|
194
|
+
// MockedConstruction:Mock 构造函数
|
|
195
|
+
MockedConstruction<PushArgs> pushArgsMock =
|
|
196
|
+
Mockito.mockConstruction(PushArgs.class)) {
|
|
197
|
+
|
|
198
|
+
//step 准备数据
|
|
199
|
+
ListSelectedRow row = mock(ListSelectedRow.class);
|
|
200
|
+
|
|
201
|
+
//step 执行
|
|
202
|
+
BillPushUtil.doPush("sourcebill", "targetbill", "ruleid",
|
|
203
|
+
new HashMap<>(), Stream.of(row).collect(Collectors.toList()));
|
|
204
|
+
|
|
205
|
+
//assert 正常执行
|
|
206
|
+
convertServiceHelper.when(() -> ConvertServiceHelper.push(any()))
|
|
207
|
+
.thenReturn(null);
|
|
208
|
+
|
|
209
|
+
//step 空列表返回 null
|
|
210
|
+
ConvertOperationResult result = BillPushUtil.doPush(
|
|
211
|
+
"sourcebill", "targetbill", "ruleid",
|
|
212
|
+
new HashMap<>(), new ArrayList<>());
|
|
213
|
+
|
|
214
|
+
//assert
|
|
215
|
+
assertNull(result);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
@Test
|
|
220
|
+
public void testGetErrorMessageFromConverResult() {
|
|
221
|
+
//step 构建失败的转换结果
|
|
222
|
+
ConvertOperationResult mockResult = mock(ConvertOperationResult.class);
|
|
223
|
+
when(mockResult.isSuccess()).thenReturn(false);
|
|
224
|
+
when(mockResult.getMessage()).thenReturn("Initial Error");
|
|
225
|
+
|
|
226
|
+
SourceBillReport mockReport = mock(SourceBillReport.class);
|
|
227
|
+
when(mockReport.isFullSuccess()).thenReturn(false);
|
|
228
|
+
when(mockReport.getFailMessage()).thenReturn("Bill Error");
|
|
229
|
+
when(mockResult.getBillReports()).thenReturn(
|
|
230
|
+
new ArrayList<SourceBillReport>() {{ add(mockReport); }});
|
|
231
|
+
|
|
232
|
+
//step 执行
|
|
233
|
+
String errorMsg = BillPushUtil.getErrorMessageFromConverResult(mockResult);
|
|
234
|
+
|
|
235
|
+
//assert 包含错误信息
|
|
236
|
+
assertTrue(errorMsg.contains("Bill Error"));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## 要点总结
|
|
242
|
+
|
|
243
|
+
### POJO 测试
|
|
244
|
+
- **零 Mock**,纯 Java 对象操作
|
|
245
|
+
- 覆盖 getter/setter、工厂方法、toString、Builder 模式
|
|
246
|
+
- 无需基类,测试最简洁
|
|
247
|
+
|
|
248
|
+
### 枚举测试
|
|
249
|
+
- 继承 `AbstractJunitNoDependenciesTest`
|
|
250
|
+
- 测试匹配方法的有效值 / 无效值 / 边界值
|
|
251
|
+
- 代码量最少的测试类型
|
|
252
|
+
|
|
253
|
+
### 工具类测试
|
|
254
|
+
- 继承 common 包 `BaseTest`(预置 10 个 MockedStatic)
|
|
255
|
+
- 额外 Mock 用 try-with-resources 管理
|
|
256
|
+
- `MockedConstruction` 可 Mock 类的构造函数(`new Xxx()` 内部创建的对象)
|
|
257
|
+
- 与 business 工程 BaseTest 的区别:common 的 BaseTest 多了 `EntityMetadataCache` Mock
|