This is an automated email from the ASF dual-hosted git repository.

jianbin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git


The following commit(s) were added to refs/heads/2.x by this push:
     new b2d15dacb7 test: add some UT for saga compatible (#7442)
b2d15dacb7 is described below

commit b2d15dacb7923690c6eda0e27a03fceca05faa6e
Author: jimin <sliev...@163.com>
AuthorDate: Mon Jun 16 13:51:50 2025 +0800

    test: add some UT for saga compatible (#7442)
---
 changes/en-us/2.x.md                               |   1 +
 changes/zh-cn/2.x.md                               |   1 +
 .../saga/engine/config/DbStateMachineConfig.java   |  41 ++--
 .../engine/impl/DefaultStateMachineConfig.java     |  54 ++++-
 .../engine/config/DbStateMachineConfigTest.java    |  57 +++++
 .../engine/impl/DefaultStateMachineConfigTest.java | 240 +++++++++++++++++++++
 .../engine/config/AbstractStateMachineConfig.java  |   4 +-
 7 files changed, 378 insertions(+), 20 deletions(-)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index f32621d09f..f820edd1c8 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -93,6 +93,7 @@ Add changes here for all PR submitted to the 2.x branch.
 - [[#7433](https://github.com/apache/incubator-seata/pull/7433)] add UT for 
GlobalTransactionScanner class
 - [[#7436](https://github.com/apache/incubator-seata/pull/7436)] fix 
namingserver ut error
 - [[#7435](https://github.com/apache/incubator-seata/pull/7435)] Add common 
test config for dynamic server port assignment in tests
+- [[#7442](https://github.com/apache/incubator-seata/pull/7442)] add some UT 
for saga compatible
 
 ### refactor:
 
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index 0e5350ad4d..1136e75d42 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -94,6 +94,7 @@
 - [[#7436](https://github.com/apache/incubator-seata/pull/7436)]  
修复namingserver 单测错误
 - [[#7435](https://github.com/apache/incubator-seata/pull/7435)] 
为测试中的动态服务器端口分配添加通用测试配置
 - [[#7432](https://github.com/apache/incubator-seata/pull/7432)] 使用Maven 
Profile按条件引入Test模块
+- [[#7442](https://github.com/apache/incubator-seata/pull/7442)] 增加 saga 
compatible 模块单测
 
 
 ### refactor:
diff --git 
a/compatible/src/main/java/io/seata/saga/engine/config/DbStateMachineConfig.java
 
b/compatible/src/main/java/io/seata/saga/engine/config/DbStateMachineConfig.java
index 9c2480733a..284382792a 100644
--- 
a/compatible/src/main/java/io/seata/saga/engine/config/DbStateMachineConfig.java
+++ 
b/compatible/src/main/java/io/seata/saga/engine/config/DbStateMachineConfig.java
@@ -70,16 +70,21 @@ public class DbStateMachineConfig extends 
DefaultStateMachineConfig implements D
         try {
             Configuration configuration = ConfigurationFactory.getInstance();
             if (configuration != null) {
-                this.rmReportSuccessEnable = 
configuration.getBoolean(ConfigurationKeys.CLIENT_REPORT_SUCCESS_ENABLE, 
DEFAULT_CLIENT_REPORT_SUCCESS_ENABLE);
-                this.sagaBranchRegisterEnable = 
configuration.getBoolean(ConfigurationKeys.CLIENT_SAGA_BRANCH_REGISTER_ENABLE, 
DEFAULT_CLIENT_SAGA_BRANCH_REGISTER_ENABLE);
-                
setSagaJsonParser(configuration.getConfig(ConfigurationKeys.CLIENT_SAGA_JSON_PARSER,
 DEFAULT_SAGA_JSON_PARSER));
+                this.rmReportSuccessEnable = 
configuration.getBoolean(ConfigurationKeys.CLIENT_REPORT_SUCCESS_ENABLE,
+                    DEFAULT_CLIENT_REPORT_SUCCESS_ENABLE);
+                this.sagaBranchRegisterEnable = configuration.getBoolean(
+                    ConfigurationKeys.CLIENT_SAGA_BRANCH_REGISTER_ENABLE, 
DEFAULT_CLIENT_SAGA_BRANCH_REGISTER_ENABLE);
+                setSagaJsonParser(
+                    
configuration.getConfig(ConfigurationKeys.CLIENT_SAGA_JSON_PARSER, 
DEFAULT_SAGA_JSON_PARSER));
                 this.applicationId = 
configuration.getConfig(ConfigurationKeys.APPLICATION_ID);
                 this.txServiceGroup = 
configuration.getConfig(ConfigurationKeys.TX_SERVICE_GROUP);
                 this.accessKey = 
configuration.getConfig(ConfigurationKeys.ACCESS_KEY, null);
                 this.secretKey = 
configuration.getConfig(ConfigurationKeys.SECRET_KEY, null);
-                
setSagaRetryPersistModeUpdate(configuration.getBoolean(ConfigurationKeys.CLIENT_SAGA_RETRY_PERSIST_MODE_UPDATE,
+                setSagaRetryPersistModeUpdate(
+                    
configuration.getBoolean(ConfigurationKeys.CLIENT_SAGA_RETRY_PERSIST_MODE_UPDATE,
                         DEFAULT_CLIENT_SAGA_RETRY_PERSIST_MODE_UPDATE));
-                
setSagaCompensatePersistModeUpdate(configuration.getBoolean(ConfigurationKeys.CLIENT_SAGA_COMPENSATE_PERSIST_MODE_UPDATE,
+                setSagaCompensatePersistModeUpdate(
+                    
configuration.getBoolean(ConfigurationKeys.CLIENT_SAGA_COMPENSATE_PERSIST_MODE_UPDATE,
                         DEFAULT_CLIENT_SAGA_COMPENSATE_PERSIST_MODE_UPDATE));
             }
         } catch (Exception e) {
@@ -123,14 +128,7 @@ public class DbStateMachineConfig extends 
DefaultStateMachineConfig implements D
             }
 
             if (sagaTransactionalTemplate == null) {
-                DefaultSagaTransactionalTemplate 
defaultSagaTransactionalTemplate = new DefaultSagaTransactionalTemplate();
-                
defaultSagaTransactionalTemplate.setApplicationContext(getApplicationContext());
-                
defaultSagaTransactionalTemplate.setApplicationId(applicationId);
-                
defaultSagaTransactionalTemplate.setTxServiceGroup(txServiceGroup);
-                defaultSagaTransactionalTemplate.setAccessKey(accessKey);
-                defaultSagaTransactionalTemplate.setSecretKey(secretKey);
-                defaultSagaTransactionalTemplate.afterPropertiesSet();
-                sagaTransactionalTemplate = defaultSagaTransactionalTemplate;
+                sagaTransactionalTemplate = 
buildDefaultSagaTransactionalTemplate();
             }
 
             
dbStateLogStore.setSagaTransactionalTemplate(sagaTransactionalTemplate);
@@ -151,10 +149,25 @@ public class DbStateMachineConfig extends 
DefaultStateMachineConfig implements D
         super.afterPropertiesSet();
     }
 
+    public SagaTransactionalTemplate buildDefaultSagaTransactionalTemplate() {
+        DefaultSagaTransactionalTemplate defaultSagaTransactionalTemplate = 
new DefaultSagaTransactionalTemplate();
+        
defaultSagaTransactionalTemplate.setApplicationContext(getApplicationContext());
+        defaultSagaTransactionalTemplate.setApplicationId(applicationId);
+        defaultSagaTransactionalTemplate.setTxServiceGroup(txServiceGroup);
+        defaultSagaTransactionalTemplate.setAccessKey(accessKey);
+        defaultSagaTransactionalTemplate.setSecretKey(secretKey);
+        try {
+            defaultSagaTransactionalTemplate.afterPropertiesSet();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return defaultSagaTransactionalTemplate;
+    }
+
     @Override
     public void destroy() throws Exception {
         if ((sagaTransactionalTemplate != null) && (sagaTransactionalTemplate 
instanceof DisposableBean)) {
-            ((DisposableBean) sagaTransactionalTemplate).destroy();
+            ((DisposableBean)sagaTransactionalTemplate).destroy();
         }
     }
 
diff --git 
a/compatible/src/main/java/io/seata/saga/engine/impl/DefaultStateMachineConfig.java
 
b/compatible/src/main/java/io/seata/saga/engine/impl/DefaultStateMachineConfig.java
index 6ae50b303d..8a0f18ae30 100644
--- 
a/compatible/src/main/java/io/seata/saga/engine/impl/DefaultStateMachineConfig.java
+++ 
b/compatible/src/main/java/io/seata/saga/engine/impl/DefaultStateMachineConfig.java
@@ -98,6 +98,11 @@ public class DefaultStateMachineConfig implements 
StateMachineConfig, Applicatio
         actual.setStateLangStore(stateLangStore);
     }
 
+    /**
+     * this method will return a {@link ExpressionFactoryManager} which is 
wrapped from {@link 
org.apache.seata.saga.engine.expression.ExpressionFactoryManager}
+     * notice: This method cannot be referenced in the normal process of saga. 
The method here is only for
+     * compatibility interfaces {@link 
io.seata.saga.engine.StateMachineConfig} public methods.
+     */
     @Override
     public ExpressionFactoryManager getExpressionFactoryManager() {
         if (expressionFactoryManager == null) {
@@ -111,15 +116,30 @@ public class DefaultStateMachineConfig implements 
StateMachineConfig, Applicatio
         
this.expressionResolver.setExpressionFactoryManager(expressionFactoryManager.unwrap());
     }
 
+    /**
+     * fix setExpressionFactoryManager NPE issue
+     * @param expressionResolver
+     */
+    public void setExpressionResolver(ExpressionResolver expressionResolver) {
+        this.expressionResolver = expressionResolver;
+        this.actual.setExpressionResolver(expressionResolver);
+    }
+
+    /**
+     * this method will return a {@link ExpressionResolver} which is wrapped 
from {@link org.apache.seata.saga.engine.expression.ExpressionResolver}
+     * notice: This method cannot be referenced in the normal process of saga. 
The method here is only for
+     * compatibility interfaces {@link 
io.seata.saga.engine.StateMachineConfig} public methods.
+     */
     @Override
     public ExpressionResolver getExpressionResolver() {
         return actual.getExpressionResolver();
     }
 
-    public void setExpressionResolver(ExpressionResolver expressionResolver) {
-        actual.setExpressionResolver(expressionResolver);
-    }
-
+    /**
+     * this method will return a {@link ServiceInvokerManager} which is 
wrapped from {@link org.apache.seata.saga.engine.invoker.ServiceInvokerManager}
+     * notice: This method cannot be referenced in the normal process of saga. 
The method here is only for
+     * compatibility interfaces {@link 
io.seata.saga.engine.StateMachineConfig} public methods.
+     */
     @Override
     public String getCharset() {
         return actual.getCharset();
@@ -129,6 +149,11 @@ public class DefaultStateMachineConfig implements 
StateMachineConfig, Applicatio
         actual.setCharset(charset);
     }
 
+    /**
+     * this method will return a {@link StateMachineRepository} which is 
wrapped from {@link org.apache.seata.saga.engine.repo.StateMachineRepository}
+     * notice: This method cannot be referenced in the normal process of saga. 
The method here is only for
+     * compatibility interfaces {@link 
io.seata.saga.engine.StateMachineConfig} public methods.
+     */
     @Override
     public StateMachineRepository getStateMachineRepository() {
         org.apache.seata.saga.engine.repo.StateMachineRepository repository = 
actual.getStateMachineRepository();
@@ -173,6 +198,11 @@ public class DefaultStateMachineConfig implements 
StateMachineConfig, Applicatio
         actual.setStateMachineRepository(stateMachineRepository);
     }
 
+    /**
+     * this method will return a {@link StatusDecisionStrategy} which is 
wrapped from {@link 
org.apache.seata.saga.engine.strategy.StatusDecisionStrategy}
+     * notice: This method cannot be referenced in the normal process of saga. 
The method here is only for
+     * compatibility interfaces {@link 
io.seata.saga.engine.StateMachineConfig} public methods.
+     */
     @Override
     public StatusDecisionStrategy getStatusDecisionStrategy() {
         return actual.getStatusDecisionStrategy();
@@ -192,11 +222,21 @@ public class DefaultStateMachineConfig implements 
StateMachineConfig, Applicatio
         actual.setSeqGenerator(seqGenerator);
     }
 
+    /**
+     * this method will return a {@link ProcessCtrlEventPublisher} which is 
wrapped from {@link 
org.apache.seata.saga.proctrl.eventing.impl.ProcessCtrlEventPublisher}
+     * notice: This method cannot be referenced in the normal process of saga. 
The method here is only for
+     * compatibility interfaces {@link 
io.seata.saga.engine.StateMachineConfig} public methods.
+     */
     @Override
     public ProcessCtrlEventPublisher getProcessCtrlEventPublisher() {
         return actual.getProcessCtrlEventPublisher();
     }
 
+    /**
+     * this method will return a {@link ProcessCtrlEventPublisher} which is 
wrapped from {@link 
org.apache.seata.saga.proctrl.eventing.impl.ProcessCtrlEventPublisher}
+     * notice: This method cannot be referenced in the normal process of saga. 
The method here is only for
+     * compatibility interfaces {@link 
io.seata.saga.engine.StateMachineConfig} public methods.
+     */
     @Override
     public ProcessCtrlEventPublisher getAsyncProcessCtrlEventPublisher() {
         return actual.getAsyncProcessCtrlEventPublisher();
@@ -224,6 +264,7 @@ public class DefaultStateMachineConfig implements 
StateMachineConfig, Applicatio
         actual.setThreadPoolExecutor(threadPoolExecutor);
     }
 
+
     @Override
     public boolean isEnableAsync() {
         return actual.isEnableAsync();
@@ -233,6 +274,11 @@ public class DefaultStateMachineConfig implements 
StateMachineConfig, Applicatio
         actual.setEnableAsync(enableAsync);
     }
 
+    /**
+     * this method will return a {@link StateLogRepository} which is wrapped 
from {@link org.apache.seata.saga.engine.repo.StateLogRepository}
+     * notice: This method cannot be referenced in the normal process of saga. 
The method here is only for
+     * compatibility interfaces {@link 
io.seata.saga.engine.StateMachineConfig} public methods.
+     */
     @Override
     public StateLogRepository getStateLogRepository() {
         org.apache.seata.saga.engine.repo.StateLogRepository repository = 
actual.getStateLogRepository();
diff --git 
a/compatible/src/test/java/io/seata/saga/engine/config/DbStateMachineConfigTest.java
 
b/compatible/src/test/java/io/seata/saga/engine/config/DbStateMachineConfigTest.java
new file mode 100644
index 0000000000..c608a730e8
--- /dev/null
+++ 
b/compatible/src/test/java/io/seata/saga/engine/config/DbStateMachineConfigTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 io.seata.saga.engine.config;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class DbStateMachineConfigTest {
+
+    private static final String APPLICATION_ID = "test";
+    private static final String TX_SERVICE_GROUP = "testTxServiceGroup";
+    private static final String ACCESS_KEY = "fakeAccessKey";
+    private static final String SECRET_KEY = "fakeSecretKey";
+    private static final String DB_TYPE = "mysql";
+    private static final boolean RM_REPORT_SUCCESS_ENABLE = true;
+    private static final boolean SAGA_BRANCH_REGISTER_ENABLE = true;
+    private static final String TABLE_PREFIX = "test_";
+
+    @Test
+    public void testBuildDefaultSagaTransactionalTemplateThrowsException() {
+        DbStateMachineConfig config = new DbStateMachineConfig();
+        config.setApplicationId(APPLICATION_ID);
+        config.setTxServiceGroup(TX_SERVICE_GROUP);
+        config.setAccessKey(ACCESS_KEY);
+        config.setSecretKey(SECRET_KEY);
+        config.setDbType(DB_TYPE);
+        config.setRmReportSuccessEnable(RM_REPORT_SUCCESS_ENABLE);
+        config.setSagaBranchRegisterEnable(SAGA_BRANCH_REGISTER_ENABLE);
+        config.setTablePrefix(TABLE_PREFIX);
+
+        Assertions.assertEquals(APPLICATION_ID, config.getApplicationId());
+        Assertions.assertEquals(TX_SERVICE_GROUP, config.getTxServiceGroup());
+        Assertions.assertEquals(ACCESS_KEY, config.getAccessKey());
+        Assertions.assertEquals(SECRET_KEY, config.getSecretKey());
+        Assertions.assertEquals(DB_TYPE, config.getDbType());
+        Assertions.assertTrue(config.isRmReportSuccessEnable());
+        Assertions.assertTrue(config.isSagaBranchRegisterEnable());
+
+        //can not find seata-server address, so it should throw an exception
+        Assertions.assertThrows(RuntimeException.class, () -> 
config.buildDefaultSagaTransactionalTemplate());
+    }
+}
diff --git 
a/compatible/src/test/java/io/seata/saga/engine/impl/DefaultStateMachineConfigTest.java
 
b/compatible/src/test/java/io/seata/saga/engine/impl/DefaultStateMachineConfigTest.java
new file mode 100644
index 0000000000..aad1357c40
--- /dev/null
+++ 
b/compatible/src/test/java/io/seata/saga/engine/impl/DefaultStateMachineConfigTest.java
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 io.seata.saga.engine.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.script.ScriptEngineManager;
+
+import io.seata.saga.engine.expression.ExpressionFactory;
+import io.seata.saga.engine.expression.ExpressionFactoryManager;
+import io.seata.saga.engine.repo.StateLogRepository;
+import io.seata.saga.engine.repo.StateMachineRepository;
+import org.apache.seata.saga.engine.expression.Expression;
+import org.apache.seata.saga.engine.expression.ExpressionResolver;
+import org.apache.seata.saga.engine.strategy.StatusDecisionStrategy;
+import org.apache.seata.saga.proctrl.eventing.impl.ProcessCtrlEventPublisher;
+import org.apache.seata.saga.statelang.domain.StateInstance;
+import org.apache.seata.saga.statelang.domain.StateMachine;
+import org.apache.seata.saga.statelang.domain.StateMachineInstance;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static 
org.apache.seata.saga.engine.config.AbstractStateMachineConfig.DEFAULT_SERVICE_INVOKE_TIMEOUT;
+import static 
org.apache.seata.saga.engine.config.AbstractStateMachineConfig.DEFAULT_TRANS_OPERATION_TIMEOUT;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DefaultStateMachineConfigTest {
+    private DefaultStateMachineConfig defaultStateMachineConfig;
+
+    @BeforeEach
+    public void setUp() {
+        defaultStateMachineConfig = new DefaultStateMachineConfig();
+    }
+
+    @Test
+    public void testGetExpressionFactoryManager() {
+        defaultStateMachineConfig.getExpressionFactoryManager();
+        assertNotNull(defaultStateMachineConfig.getExpressionFactoryManager());
+
+        ExpressionFactoryManager expressionFactoryManager = new 
ExpressionFactoryManager();
+        ExpressionFactory factory = new ExpressionFactory() {
+            @Override
+            public Expression createExpression(String expression) {
+                return new io.seata.saga.engine.expression.Expression() {
+                    @Override
+                    public Object getValue(Object elContext) {
+                        return expression;
+                    }
+
+                    @Override
+                    public void setValue(Object value, Object elContext) {
+
+                    }
+
+                    @Override
+                    public String getExpressionString() {
+                        return expression;
+                    }
+                };
+            }
+        };
+        Map<String, ExpressionFactory> expressionFactoryMap = new HashMap<>();
+        expressionFactoryMap.put("type", factory);
+        defaultStateMachineConfig.setExpressionResolver(new 
ExpressionResolver() {
+            @Override
+            public Expression getExpression(String expressionStr) {
+                return null;
+            }
+
+            @Override
+            public 
org.apache.seata.saga.engine.expression.ExpressionFactoryManager 
getExpressionFactoryManager() {
+                return null;
+            }
+
+            @Override
+            public void setExpressionFactoryManager(
+                
org.apache.seata.saga.engine.expression.ExpressionFactoryManager 
expressionFactoryManager) {
+
+            }
+        });
+        
Assertions.assertNotNull(defaultStateMachineConfig.getExpressionResolver());
+        expressionFactoryManager.setExpressionFactoryMap(expressionFactoryMap);
+        
defaultStateMachineConfig.setExpressionFactoryManager(expressionFactoryManager);
+        ExpressionFactory retrievedFactory = 
defaultStateMachineConfig.getExpressionFactoryManager()
+            .getExpressionFactory("type");
+        String mockValue = "mock";
+        Assertions.assertEquals(mockValue, 
retrievedFactory.createExpression(mockValue).getExpressionString());
+
+    }
+
+    @Test
+    void testGetStateMachineRepository() {
+        defaultStateMachineConfig.setStateMachineRepository(null);
+        StateMachineRepository repository = 
defaultStateMachineConfig.getStateMachineRepository();
+        Assertions.assertNotNull(repository);
+
+        String mockStateMachineName = "mockStateMachine";
+        StateMachine mockStateMachine = mock(StateMachine.class);
+        when(mockStateMachine.getName()).thenReturn(mockStateMachineName);
+        org.apache.seata.saga.engine.repo.StateMachineRepository 
sateMachineRepository = mock(
+            org.apache.seata.saga.engine.repo.StateMachineRepository.class);
+        when(sateMachineRepository.getStateMachine(mockStateMachineName, "", 
"")).thenReturn(mockStateMachine);
+        when(sateMachineRepository.getStateMachine(mockStateMachineName, 
"")).thenReturn(mockStateMachine);
+        
when(sateMachineRepository.getStateMachineById(mockStateMachineName)).thenReturn(mockStateMachine);
+        
defaultStateMachineConfig.setStateMachineRepository(sateMachineRepository);
+        StateMachineRepository getRepository = 
defaultStateMachineConfig.getStateMachineRepository();
+        Assertions.assertNotNull(getRepository);
+        Assertions.assertEquals(mockStateMachineName,
+            getRepository.getStateMachineById(mockStateMachineName).getName());
+        Assertions.assertEquals(mockStateMachineName,
+            getRepository.getStateMachine(mockStateMachineName, "").getName());
+        Assertions.assertEquals(mockStateMachineName,
+            getRepository.getStateMachine(mockStateMachineName, "", 
"").getName());
+    }
+
+    @Test
+    public void testStateLogRepository() {
+        defaultStateMachineConfig.setStateLogRepository(null);
+        assertNotNull(defaultStateMachineConfig.getStateLogRepository());
+
+        org.apache.seata.saga.engine.repo.StateLogRepository 
mockStateLogRepository = mock(
+            org.apache.seata.saga.engine.repo.StateLogRepository.class);
+        
defaultStateMachineConfig.setStateLogRepository(mockStateLogRepository);
+        StateInstance mockStateInstance = mock(StateInstance.class);
+        StateMachineInstance mockStateMachineInstance = 
mock(StateMachineInstance.class);
+        String mockStateInstanceName = "mockStateInstance";
+        String mockMachineId = "mockMachineId";
+        
when(mockStateMachineInstance.getMachineId()).thenReturn(mockMachineId);
+        when(mockStateMachineInstance.getBusinessKey()).thenReturn("key");
+        String mockStateMachineInstanceName = "mockStateMachineInstanceId";
+        when(mockStateInstance.getName()).thenReturn(mockStateInstanceName);
+        
when(mockStateLogRepository.getStateInstance(mockStateMachineInstanceName, 
"")).thenReturn(mockStateInstance);
+        
when(mockStateLogRepository.getStateMachineInstance(mockStateMachineInstanceName)).thenReturn(
+            mockStateMachineInstance);
+        
when(mockStateLogRepository.getStateMachineInstanceByBusinessKey("key", 
"")).thenReturn(
+            mockStateMachineInstance);
+        StateLogRepository getStateLogRepository = 
defaultStateMachineConfig.getStateLogRepository();
+        Assertions.assertNotNull(getStateLogRepository);
+        Assertions.assertEquals(mockStateInstanceName,
+            
getStateLogRepository.getStateInstance(mockStateMachineInstanceName, 
"").getName());
+        Assertions.assertEquals(mockMachineId,
+            
getStateLogRepository.getStateMachineInstance(mockStateMachineInstanceName).getMachineId());
+        Assertions.assertEquals("key",
+            getStateLogRepository.getStateMachineInstanceByBusinessKey("key", 
"").getBusinessKey());
+    }
+
+    @Test
+    public void testCharset() {
+        String charset = defaultStateMachineConfig.getCharset();
+        Assertions.assertEquals("UTF-8", charset);
+
+        String newCharset = "ISO-8859-1";
+        defaultStateMachineConfig.setCharset(newCharset);
+        Assertions.assertEquals(newCharset, 
defaultStateMachineConfig.getCharset());
+    }
+
+    @Test
+    public void testAsyncProcessCtrlEventPublisher() {
+        ProcessCtrlEventPublisher asyncProcessCtrlEventPublisher
+            = defaultStateMachineConfig.getAsyncProcessCtrlEventPublisher();
+        Assertions.assertNull(asyncProcessCtrlEventPublisher);
+
+        defaultStateMachineConfig.setAsyncProcessCtrlEventPublisher(new 
ProcessCtrlEventPublisher());
+        
Assertions.assertNotNull(defaultStateMachineConfig.getAsyncProcessCtrlEventPublisher());
+    }
+
+    @Test
+    public void testGetExpressionResolver() {
+        
Assertions.assertNull(defaultStateMachineConfig.getExpressionResolver());
+
+        ExpressionResolver expressionResolver = mock(ExpressionResolver.class);
+        defaultStateMachineConfig.setExpressionResolver(expressionResolver);
+        Assertions.assertEquals(expressionResolver, 
defaultStateMachineConfig.getExpressionResolver());
+    }
+
+    @Test
+    public void testStatusDecisionStrategy() {
+        
Assertions.assertNull(defaultStateMachineConfig.getStatusDecisionStrategy());
+
+        StatusDecisionStrategy statusDecisionStrategy = 
mock(StatusDecisionStrategy.class);
+        
defaultStateMachineConfig.setStatusDecisionStrategy(statusDecisionStrategy);
+        Assertions.assertEquals(statusDecisionStrategy, 
defaultStateMachineConfig.getStatusDecisionStrategy());
+    }
+
+    @Test
+    public void testServiceInvokerManager() {
+        
Assertions.assertNull(defaultStateMachineConfig.getServiceInvokerManager());
+
+        org.apache.seata.saga.engine.invoker.ServiceInvokerManager 
serviceInvokerManager = mock(
+            org.apache.seata.saga.engine.invoker.ServiceInvokerManager.class);
+        
defaultStateMachineConfig.setServiceInvokerManager(serviceInvokerManager);
+        Assertions.assertEquals(serviceInvokerManager, 
defaultStateMachineConfig.getServiceInvokerManager());
+    }
+
+    @Test
+    public void testTransOperationTimeout() {
+        Assertions.assertEquals(DEFAULT_TRANS_OPERATION_TIMEOUT, 
defaultStateMachineConfig.getTransOperationTimeout());
+
+        int timeout = 1000;
+        defaultStateMachineConfig.setTransOperationTimeout(timeout);
+        Assertions.assertEquals(timeout, 
defaultStateMachineConfig.getTransOperationTimeout());
+    }
+
+    @Test
+    public void testServiceInvokeTimeout() {
+        Assertions.assertEquals(DEFAULT_SERVICE_INVOKE_TIMEOUT, 
defaultStateMachineConfig.getServiceInvokeTimeout());
+
+        int timeout = 2000;
+        defaultStateMachineConfig.setServiceInvokeTimeout(timeout);
+        Assertions.assertEquals(timeout, 
defaultStateMachineConfig.getServiceInvokeTimeout());
+    }
+
+    @Test
+    public void testScriptEngineManager() {
+        
Assertions.assertNull(defaultStateMachineConfig.getScriptEngineManager());
+
+        ScriptEngineManager scriptEngineManager = 
mock(ScriptEngineManager.class);
+        defaultStateMachineConfig.setScriptEngineManager(scriptEngineManager);
+        Assertions.assertEquals(scriptEngineManager, 
defaultStateMachineConfig.getScriptEngineManager());
+    }
+}
\ No newline at end of file
diff --git 
a/saga/seata-saga-engine/src/main/java/org/apache/seata/saga/engine/config/AbstractStateMachineConfig.java
 
b/saga/seata-saga-engine/src/main/java/org/apache/seata/saga/engine/config/AbstractStateMachineConfig.java
index 9644659477..0bedf7b986 100644
--- 
a/saga/seata-saga-engine/src/main/java/org/apache/seata/saga/engine/config/AbstractStateMachineConfig.java
+++ 
b/saga/seata-saga-engine/src/main/java/org/apache/seata/saga/engine/config/AbstractStateMachineConfig.java
@@ -74,8 +74,8 @@ import static 
org.apache.seata.common.DefaultValues.DEFAULT_SAGA_JSON_PARSER;
  */
 public abstract class AbstractStateMachineConfig implements StateMachineConfig 
{
 
-    private static final int DEFAULT_TRANS_OPERATION_TIMEOUT = 60000 * 30;
-    private static final int DEFAULT_SERVICE_INVOKE_TIMEOUT = 60000 * 5;
+    public static final int DEFAULT_TRANS_OPERATION_TIMEOUT = 60000 * 30;
+    public static final int DEFAULT_SERVICE_INVOKE_TIMEOUT = 60000 * 5;
 
     private ExpressionFactoryManager expressionFactoryManager;
     private ExpressionResolver expressionResolver;


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org
For additional commands, e-mail: notifications-h...@seata.apache.org

Reply via email to