You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "OmCheeLin (via GitHub)" <gi...@apache.org> on 2025/06/08 05:20:43 UTC

[PR] test: add UT for seata-spring-boot-starter module [incubator-seata]

OmCheeLin opened a new pull request, #7422:
URL: https://github.com/apache/incubator-seata/pull/7422

   - [ ] I have registered the PR [changes](../changes).
   
   ### Ⅰ. Describe what this PR did
   add UT for seata-spring-boot-starter module
   
   ### Ⅱ. Does this pull request fix one issue?
   fixes #7381
   
   ### Ⅲ. Why don't you add test cases (unit test/integration test)? 
   
   ### Ⅳ. Describe how to verify it
   
   ### Ⅴ. Special notes for reviews
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] test: add UT for seata-spring-boot-starter module [incubator-seata]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #7422:
URL: https://github.com/apache/incubator-seata/pull/7422#discussion_r2134694083


##########
seata-spring-boot-starter/src/test/java/org/apache/seata/spring/boot/autoconfigure/SeataSagaAutoConfigurationTest.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * 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 org.apache.seata.spring.boot.autoconfigure;
+
+import org.apache.seata.core.model.Resource;
+import org.apache.seata.rm.DefaultResourceManager;
+import org.apache.seata.saga.engine.StateMachineConfig;
+import org.apache.seata.saga.engine.StateMachineEngine;
+import org.apache.seata.saga.engine.config.DbStateMachineConfig;
+import org.apache.seata.saga.engine.impl.ProcessCtrlStateMachineEngine;
+import org.apache.seata.spring.boot.autoconfigure.properties.SeataProperties;
+import org.apache.seata.tm.TMClient;
+import org.assertj.core.api.AssertionsForClassTypes;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+import java.util.concurrent.RejectedExecutionHandler;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import static org.apache.seata.spring.boot.autoconfigure.SeataSagaAutoConfiguration.SAGA_ASYNC_THREAD_POOL_EXECUTOR_BEAN_NAME;
+import static org.apache.seata.spring.boot.autoconfigure.SeataSagaAutoConfiguration.SAGA_REJECTED_EXECUTION_HANDLER_BEAN_NAME;
+import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;

Review Comment:
   [nitpick] Mixed use of `AssertionsForClassTypes.assertThat` and `AssertionsForInterfaceTypes.assertThat` imports may confuse readers; consider unifying to a single assertion style for consistency.



##########
seata-spring-boot-starter/src/test/java/org/apache/seata/spring/boot/autoconfigure/SeataDataSourceAutoConfigurationTest.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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 org.apache.seata.spring.boot.autoconfigure;
+
+import org.apache.seata.rm.datasource.DataSourceProxy;
+import org.apache.seata.spring.annotation.datasource.SeataAutoDataSourceProxyCreator;
+import org.apache.seata.spring.boot.autoconfigure.properties.SeataProperties;
+import org.apache.seata.spring.boot.autoconfigure.properties.SpringCloudAlibabaConfiguration;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedConstruction;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+
+import javax.sql.DataSource;
+
+import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockConstruction;
+
+/**
+ * Tests for {@link SeataDataSourceAutoConfiguration} to verify conditional bean registration.
+ */
+public class SeataDataSourceAutoConfigurationTest {
+    private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+            .withConfiguration(AutoConfigurations.of(SeataDataSourceAutoConfiguration.class))
+            .withBean(DataSource.class, () -> mock(DataSource.class))
+            .withBean(SeataProperties.class, SeataProperties::new)
+            .withBean(SpringCloudAlibabaConfiguration.class, SpringCloudAlibabaConfiguration::new);
+
+    @Test
+    void whenConditionsMet_thenAutoDataSourceProxyCreatorCreated() {
+        try (MockedConstruction<DataSourceProxy> mocked = mockConstruction(DataSourceProxy.class)) {
+            contextRunner
+                    .withPropertyValues(
+                            "seata.enabled=true",
+                            "seata.enableAutoDataSourceProxy=true",
+                            "seata.enable-auto-data-source-proxy=true"

Review Comment:
   [nitpick] The test includes both camelCase and kebab-case property keys; it would be clearer to test only the actual property name supported by `SeataProperties`, reducing redundancy.
   ```suggestion
                               "seata.enableAutoDataSourceProxy=true"
   ```



##########
seata-spring-boot-starter/src/test/java/org/apache/seata/spring/boot/autoconfigure/SeataHttpAutoConfigurationTest.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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 org.apache.seata.spring.boot.autoconfigure;
+
+import org.apache.seata.integration.http.JakartaSeataWebMvcConfigurer;
+import org.apache.seata.integration.http.SeataWebMvcConfigurer;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.FilteredClassLoader;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
+
+import static org.apache.seata.spring.boot.autoconfigure.StarterConstants.HTTP_PREFIX;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests for {@link SeataHttpAutoConfiguration} to verify conditional bean registration.
+ */
+public class SeataHttpAutoConfigurationTest {
+    // No thread safety issues, no need to create in @BeforeEach

Review Comment:
   [nitpick] This comment about thread safety and `@BeforeEach` maintenance can be removed to reduce noise, as the test runner is inherently single-threaded by default.
   ```suggestion
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] test: add UT for seata-spring-boot-starter module [incubator-seata]

Posted by "slievrly (via GitHub)" <gi...@apache.org>.
slievrly merged PR #7422:
URL: https://github.com/apache/incubator-seata/pull/7422


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] test: add UT for seata-spring-boot-starter module [incubator-seata]

Posted by "slievrly (via GitHub)" <gi...@apache.org>.
slievrly commented on PR #7422:
URL: https://github.com/apache/incubator-seata/pull/7422#issuecomment-2954176344

   @OmCheeLin thanks for your contribution.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] test: add UT for seata-spring-boot-starter module [incubator-seata]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #7422:
URL: https://github.com/apache/incubator-seata/pull/7422#issuecomment-2953581062

   ## [Codecov](https://app.codecov.io/gh/apache/incubator-seata/pull/7422?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   All modified and coverable lines are covered by tests :white_check_mark:
   > Project coverage is 59.13%. Comparing base [(`13e4281`)](https://app.codecov.io/gh/apache/incubator-seata/commit/13e42810af181f6a5d2a911870345930b166ab88?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`0860788`)](https://app.codecov.io/gh/apache/incubator-seata/commit/086078892228372e360daf1fce5c912bb15c173c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 1 commits behind head on 2.x.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##                2.x    #7422      +/-   ##
   ============================================
   + Coverage     59.07%   59.13%   +0.05%     
   - Complexity      531      543      +12     
   ============================================
     Files          1281     1281              
     Lines         46102    46102              
     Branches       5562     5562              
   ============================================
   + Hits          27234    27261      +27     
   + Misses        16299    16273      -26     
   + Partials       2569     2568       -1     
   ```
   
   [see 13 files with indirect coverage changes](https://app.codecov.io/gh/apache/incubator-seata/pull/7422/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/incubator-seata/pull/7422/graphs/tree.svg?width=650&height=150&src=pr&token=tbmHt2ZfxO&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/incubator-seata/pull/7422?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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