From 513f9e52d69b85aca7a409d887c979c9b935c7b7 Mon Sep 17 00:00:00 2001 From: weihu Date: Sat, 1 Jun 2024 22:16:22 +0800 Subject: [PATCH 1/4] :new: add spring-boot-test --- pom.xml | 395 +++++++++--------- spring-boot-nebula-dependencies/pom.xml | 2 + .../web/common/utils/ExpressionUtil.java | 15 +- .../web/common/utils/ExpressionUtilTest.java | 11 + spring-boot-nebula-web/pom.xml | 7 +- 5 files changed, 223 insertions(+), 207 deletions(-) create mode 100644 spring-boot-nebula-web-common/src/test/java/com/nebula/web/common/utils/ExpressionUtilTest.java diff --git a/pom.xml b/pom.xml index a1c4cce..5b52d2e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,201 +1,208 @@ - 4.0.0 - - io.github.weihubeats - spring-boot-nebula - pom - ${revision} - - - spring-boot-nebula-web - spring-boot-nebula-dependencies + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + io.github.weihubeats + spring-boot-nebula + pom + ${revision} + + + spring-boot-nebula-web + spring-boot-nebula-dependencies spring-boot-nebula-common - spring-boot-nebula-samples + spring-boot-nebula-samples spring-boot-nebula-aggregate - spring-boot-nebula-mybatis - spring-boot-nebula-aop-base - spring-boot-nebula-distribute-lock + spring-boot-nebula-mybatis + spring-boot-nebula-aop-base + spring-boot-nebula-distribute-lock spring-boot-nebula-web-common - spring-boot-nebula-all - - - spring-boot-nebula - spring-boot-common - https://github.com/weihubeats/spring-boot-common - - - - 0.0.01 - 1.2.7 - 3.0.1 - 11 - 11 - - - - - - - - io.github.weihubeats - spring-boot-nebula-dependencies - ${revision} - pom - import - - - - - - - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - - weihubeats - weihu@apche.org - https://weihubeats.blog.csdn.net/ - - - - - scm:git@github.com:weihubeats/spring-boot-common.git - scm:git@github.com:weihubeats/spring-boot-common.git - git@github.com:weihubeats/spring-boot-common.git - - - - Github Issue - https://github.com/weihubeats/spring-boot-common/issues - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - true - - ${maven.compiler.source} - ${maven.compiler.target} - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.18.1 - true - - 1 - false - - - - - org.apache.maven.plugins - maven-source-plugin - 2.4 - - true - - - - package - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-site-plugin - 3.7.1 - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.0.1 - - ${java.home}/bin/javadoc - - -Xdoclint:none - - - - - package - - jar - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin.version} - - - sign-artifacts - verify - - sign - - - - - - - org.codehaus.mojo - flatten-maven-plugin - ${flatten-maven-plugin.version} - - true - resolveCiFriendliesOnly - - - - flatten - process-resources - - flatten - - - - flatten.clean - clean - - clean - - - - - - - - - - sonatype - https://s01.oss.sonatype.org/content/repositories/snapshots/ - - - sonatype - https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ - - + spring-boot-nebula-all + + + spring-boot-nebula + spring-boot-common + https://github.com/weihubeats/spring-boot-common + + + + 0.0.01 + 1.2.7 + 3.0.1 + 11 + 11 + + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + + io.github.weihubeats + spring-boot-nebula-dependencies + ${revision} + pom + import + + + + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + weihubeats + weihu@apche.org + https://weihubeats.blog.csdn.net/ + + + + + scm:git@github.com:weihubeats/spring-boot-common.git + scm:git@github.com:weihubeats/spring-boot-common.git + git@github.com:weihubeats/spring-boot-common.git + + + + Github Issue + https://github.com/weihubeats/spring-boot-common/issues + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + true + + ${maven.compiler.source} + ${maven.compiler.target} + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18.1 + true + + 1 + false + + + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + true + + + + package + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.0.1 + + ${java.home}/bin/javadoc + + -Xdoclint:none + + + + + package + + jar + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + + org.codehaus.mojo + flatten-maven-plugin + ${flatten-maven-plugin.version} + + true + resolveCiFriendliesOnly + + + + flatten + process-resources + + flatten + + + + flatten.clean + clean + + clean + + + + + + + + + + sonatype + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + + sonatype + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + \ No newline at end of file diff --git a/spring-boot-nebula-dependencies/pom.xml b/spring-boot-nebula-dependencies/pom.xml index 91c7ee3..ad23041 100644 --- a/spring-boot-nebula-dependencies/pom.xml +++ b/spring-boot-nebula-dependencies/pom.xml @@ -30,6 +30,8 @@ 3.5.5 3.17.3 + + diff --git a/spring-boot-nebula-web-common/src/main/java/com/nebula/web/common/utils/ExpressionUtil.java b/spring-boot-nebula-web-common/src/main/java/com/nebula/web/common/utils/ExpressionUtil.java index 90c4faf..1d8904d 100644 --- a/spring-boot-nebula-web-common/src/main/java/com/nebula/web/common/utils/ExpressionUtil.java +++ b/spring-boot-nebula-web-common/src/main/java/com/nebula/web/common/utils/ExpressionUtil.java @@ -3,6 +3,7 @@ import com.nebula.base.utils.DataUtils; import java.lang.reflect.Method; import java.util.Objects; +import org.apache.commons.lang3.StringUtils; import org.springframework.core.LocalVariableTableParameterNameDiscoverer; import org.springframework.expression.ExpressionParser; import org.springframework.expression.spel.standard.SpelExpressionParser; @@ -29,20 +30,20 @@ public static Object parse(String expressionString, Method method, Object[] args } //获取被拦截方法参数名列表 LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer(); - String[] paramNameArr = discoverer.getParameterNames(method); + String[] paramNames = discoverer.getParameterNames(method); + if (paramNames == null || args == null || paramNames.length != args.length) { + throw new IllegalArgumentException("Method parameter names and argument values do not match."); + } //SPEL解析 ExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext context = new StandardEvaluationContext(); - for (int i = 0; i < Objects.requireNonNull(paramNameArr).length; i++) { - context.setVariable(paramNameArr[i], args[i]); + for (int i = 0; i < Objects.requireNonNull(paramNames).length; i++) { + context.setVariable(paramNames[i], args[i]); } return parser.parseExpression(expressionString).getValue(context); } public static boolean isEl(String param) { - if (DataUtils.isEmpty(param)) { - return false; - } - return Objects.equals(param.substring(0, 1), "#"); + return !StringUtils.isEmpty(param) && param.startsWith("#"); } } diff --git a/spring-boot-nebula-web-common/src/test/java/com/nebula/web/common/utils/ExpressionUtilTest.java b/spring-boot-nebula-web-common/src/test/java/com/nebula/web/common/utils/ExpressionUtilTest.java new file mode 100644 index 0000000..22dbba4 --- /dev/null +++ b/spring-boot-nebula-web-common/src/test/java/com/nebula/web/common/utils/ExpressionUtilTest.java @@ -0,0 +1,11 @@ +package com.nebula.web.common.utils; + +/** + * @author : wh + * @date : 2024/6/1 22:12 + * @description: + */ +public class ExpressionUtilTest { + + +} \ No newline at end of file diff --git a/spring-boot-nebula-web/pom.xml b/spring-boot-nebula-web/pom.xml index a7bb4f0..d32c3b0 100644 --- a/spring-boot-nebula-web/pom.xml +++ b/spring-boot-nebula-web/pom.xml @@ -28,12 +28,7 @@ org.springframework.boot spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-test - test - + org.projectlombok From 4840bb86ca93e303e562ce68d3fd50e77bbb4d6d Mon Sep 17 00:00:00 2001 From: weihu Date: Sat, 1 Jun 2024 22:20:56 +0800 Subject: [PATCH 2/4] :new: add spring-boot-test --- .../main/java/com/nebula/web/common/utils/ExpressionUtil.java | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-nebula-web-common/src/main/java/com/nebula/web/common/utils/ExpressionUtil.java b/spring-boot-nebula-web-common/src/main/java/com/nebula/web/common/utils/ExpressionUtil.java index 515e72f..7cee3f0 100644 --- a/spring-boot-nebula-web-common/src/main/java/com/nebula/web/common/utils/ExpressionUtil.java +++ b/spring-boot-nebula-web-common/src/main/java/com/nebula/web/common/utils/ExpressionUtil.java @@ -20,6 +20,7 @@ import com.nebula.base.utils.DataUtils; import java.lang.reflect.Method; import java.util.Objects; +import org.apache.commons.lang3.StringUtils; import org.springframework.core.LocalVariableTableParameterNameDiscoverer; import org.springframework.expression.ExpressionParser; import org.springframework.expression.spel.standard.SpelExpressionParser; From e8b9e9b9b764cc495d00354cb60c90001e26d437 Mon Sep 17 00:00:00 2001 From: weihu Date: Sat, 1 Jun 2024 22:31:55 +0800 Subject: [PATCH 3/4] :new: add spring-boot-test --- spring-boot-nebula-dependencies/pom.xml | 3 -- spring-boot-nebula-web-common/pom.xml | 3 +- .../web/common/utils/ExpressionUtil.java | 2 +- .../web/common/utils/ExpressionUtilTest.java | 11 ------ .../web/common/utils/SpringBeanUtilsTest.java | 38 ++++++++++++++----- spring-boot-nebula-web/pom.xml | 1 - 6 files changed, 30 insertions(+), 28 deletions(-) delete mode 100644 spring-boot-nebula-web-common/src/test/java/com/nebula/web/common/utils/ExpressionUtilTest.java diff --git a/spring-boot-nebula-dependencies/pom.xml b/spring-boot-nebula-dependencies/pom.xml index b5ef453..dfad62a 100644 --- a/spring-boot-nebula-dependencies/pom.xml +++ b/spring-boot-nebula-dependencies/pom.xml @@ -29,9 +29,6 @@ 2.43.0 - - - diff --git a/spring-boot-nebula-web-common/pom.xml b/spring-boot-nebula-web-common/pom.xml index 36d03c6..6218105 100644 --- a/spring-boot-nebula-web-common/pom.xml +++ b/spring-boot-nebula-web-common/pom.xml @@ -28,7 +28,6 @@ spring-boot-nebula-common - org.springframework.boot spring-boot-starter-test @@ -40,7 +39,7 @@ assertj-core test - + diff --git a/spring-boot-nebula-web-common/src/main/java/com/nebula/web/common/utils/ExpressionUtil.java b/spring-boot-nebula-web-common/src/main/java/com/nebula/web/common/utils/ExpressionUtil.java index 7cee3f0..9725055 100644 --- a/spring-boot-nebula-web-common/src/main/java/com/nebula/web/common/utils/ExpressionUtil.java +++ b/spring-boot-nebula-web-common/src/main/java/com/nebula/web/common/utils/ExpressionUtil.java @@ -52,7 +52,7 @@ public static Object parse(String expressionString, Method method, Object[] args if (paramNames == null || args == null || paramNames.length != args.length) { throw new IllegalArgumentException("Method parameter names and argument values do not match."); } - //SPEL解析 + // SPEL解析 ExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext context = new StandardEvaluationContext(); for (int i = 0; i < Objects.requireNonNull(paramNames).length; i++) { diff --git a/spring-boot-nebula-web-common/src/test/java/com/nebula/web/common/utils/ExpressionUtilTest.java b/spring-boot-nebula-web-common/src/test/java/com/nebula/web/common/utils/ExpressionUtilTest.java deleted file mode 100644 index 22dbba4..0000000 --- a/spring-boot-nebula-web-common/src/test/java/com/nebula/web/common/utils/ExpressionUtilTest.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.nebula.web.common.utils; - -/** - * @author : wh - * @date : 2024/6/1 22:12 - * @description: - */ -public class ExpressionUtilTest { - - -} \ No newline at end of file diff --git a/spring-boot-nebula-web-common/src/test/java/com/nebula/web/common/utils/SpringBeanUtilsTest.java b/spring-boot-nebula-web-common/src/test/java/com/nebula/web/common/utils/SpringBeanUtilsTest.java index 204caf8..d63adc2 100644 --- a/spring-boot-nebula-web-common/src/test/java/com/nebula/web/common/utils/SpringBeanUtilsTest.java +++ b/spring-boot-nebula-web-common/src/test/java/com/nebula/web/common/utils/SpringBeanUtilsTest.java @@ -1,3 +1,20 @@ +/* + * 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 com.nebula.web.common.utils; import com.nebula.web.common.autoconfigure.NebulaWebCommonAutoConfiguration; @@ -10,6 +27,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrowsExactly; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -20,34 +38,34 @@ */ @SpringBootTest(classes = SpringBeanUtilsTest.TestConfig.class) public class SpringBeanUtilsTest { - + @Test public void getBean() { Object bean = SpringBeanUtils.getBean("testBean"); - assertTrue(bean instanceof TestBean); + assertInstanceOf(TestBean.class, bean); TestBean bean1 = SpringBeanUtils.getBean(TestBean.class); assertTrue(Objects.nonNull(bean1)); assertThrowsExactly(NoSuchBeanDefinitionException.class, () -> SpringBeanUtils.getBean(NoTestBean.class)); - + } - + static final class TestBean { } - + static final class NoTestBean { } - + @Configuration @EnableAutoConfiguration @ImportAutoConfiguration({NebulaWebCommonAutoConfiguration.class}) public static class TestConfig { - + @Bean public TestBean testBean() { return new TestBean(); - + } - + } - + } \ No newline at end of file diff --git a/spring-boot-nebula-web/pom.xml b/spring-boot-nebula-web/pom.xml index 7dbd277..484a047 100644 --- a/spring-boot-nebula-web/pom.xml +++ b/spring-boot-nebula-web/pom.xml @@ -27,7 +27,6 @@ org.springframework.boot spring-boot-starter-actuator - org.projectlombok From 4f9c3c1db6eeebb53489e659c79a8af6cafb2486 Mon Sep 17 00:00:00 2001 From: weihu Date: Sat, 1 Jun 2024 22:35:40 +0800 Subject: [PATCH 4/4] :new: add spring-boot-test --- pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index f967217..3012972 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,14 @@ 11 2.43.0 + + + + org.springframework.boot + spring-boot-starter-test + test + +