From eeb7f9c2c10235d5a588b27836b1cc4dbe235a2e Mon Sep 17 00:00:00 2001 From: jiangw <39796328+b6688c@users.noreply.github.com> Date: Fri, 24 Nov 2023 12:03:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:1.=E5=8D=87=E7=BA=A7springboot=20->=203.2.?= =?UTF-8?q?0=20mybatis=20->=203.0.3...=20=E5=85=A8=E9=9D=A2=E6=94=AF?= =?UTF-8?q?=E6=8C=81jdk21=E3=80=822.=E4=BC=98=E5=8C=96uno-test=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 49 +++++++++- uno-bom/pom.xml | 36 +------- .../http/openapi/OpenApiV3Assembly.java | 2 +- uno-core/pom.xml | 1 - .../datastructure/tree/ComparableElement.java | 24 +++++ .../datastructure/tree/DefaultElement.java | 8 +- .../core/datastructure/tree/TreeSupport.java | 51 +++++++---- .../datastructure/tree/TreeSupportTest.java | 42 ++++++++- .../cc/allio/uno/gis/type/VillageTest.java | 4 +- .../uno/rule/api/vistor/GroupElement.java | 2 - .../redis/ReactiveRedisTemplateTest.java | 45 ---------- .../cc/allio/uno/test/BaseSpringTest.java | 17 +--- .../main/java/cc/allio/uno/test/CoreTest.java | 89 +++++++++---------- .../main/java/cc/allio/uno/test/RunAfter.java | 18 ---- .../java/cc/allio/uno/test/RunBefore.java | 18 ---- .../java/cc/allio/uno/test/RunMapperTest.java | 33 ------- .../cc/allio/uno/test/RunServiceTest.java | 39 -------- .../main/java/cc/allio/uno/test/RunTest.java | 34 ------- .../cc/allio/uno/test/RunTestAttributes.java | 49 +++------- .../java/cc/allio/uno/test/TestManager.java | 2 + .../cc/allio/uno/test/TestPropertyValues.java | 1 - .../allio/uno/test/env/EnvironmentFacade.java | 13 ++- .../test/env/annotation/DynamicConfigure.java | 14 +-- .../test/env/annotation/MybatisConfigure.java | 5 +- .../env/annotation/MybatisPlusConfigure.java | 2 +- .../uno/test/runner/AnnoMetadataRunner.java | 19 ++-- .../uno/test/runner/ContextCloseRunner.java | 29 ------ .../test/runner/ContextCompleteRunner.java | 32 ------- .../allio/uno/test/ConfigDataLoaderTest.java | 14 +-- .../uno/test/DataSourceEnvironmentTest.java | 52 ----------- .../allio/uno/test/RunMapperTestWithTest.java | 20 ----- .../cc/allio/uno/test/RunServiceWithTest.java | 25 ------ .../cc/allio/uno/test/RunTestWithTest.java | 4 +- .../env/DatasourceTestEnvironmentTest.java | 39 -------- .../env/MybatisPlusTestEnvironmentTest.java | 24 ----- uno-test/src/test/resources/uno.yaml | 3 + 36 files changed, 241 insertions(+), 618 deletions(-) create mode 100644 uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/ComparableElement.java delete mode 100644 uno-test/src/main/java/cc/allio/uno/test/RunAfter.java delete mode 100644 uno-test/src/main/java/cc/allio/uno/test/RunBefore.java delete mode 100644 uno-test/src/main/java/cc/allio/uno/test/RunMapperTest.java delete mode 100644 uno-test/src/main/java/cc/allio/uno/test/RunServiceTest.java delete mode 100644 uno-test/src/main/java/cc/allio/uno/test/runner/ContextCloseRunner.java delete mode 100644 uno-test/src/main/java/cc/allio/uno/test/runner/ContextCompleteRunner.java delete mode 100644 uno-test/src/test/java/cc/allio/uno/test/DataSourceEnvironmentTest.java delete mode 100644 uno-test/src/test/java/cc/allio/uno/test/RunMapperTestWithTest.java delete mode 100644 uno-test/src/test/java/cc/allio/uno/test/RunServiceWithTest.java delete mode 100644 uno-test/src/test/java/cc/allio/uno/test/env/DatasourceTestEnvironmentTest.java delete mode 100644 uno-test/src/test/java/cc/allio/uno/test/env/MybatisPlusTestEnvironmentTest.java diff --git a/pom.xml b/pom.xml index d2bc20de..853c4747 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 21 2020.0.12 - 3.1.5 + 3.2.0 3.2.1 3.8.1 3.1.0 @@ -199,4 +199,51 @@ https://packages.aliyun.com/maven/repository/2300285-snapshot-JAW5GT/ + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + true + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + true + + + true + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + true + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + \ No newline at end of file diff --git a/uno-bom/pom.xml b/uno-bom/pom.xml index 88ca1c6d..f75aa6af 100644 --- a/uno-bom/pom.xml +++ b/uno-bom/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.5 + 3.2.0 @@ -22,8 +22,6 @@ 1.5.9 1.0.1 - - 2.11.4 1.12.2 3.3.0 @@ -36,7 +34,8 @@ 2.2.17 1.6.2 3.0.0 - 3.0.2 + + 3.0.3-SNAPSHOT 3.5.3 1.2.20 @@ -176,35 +175,6 @@ cglib ${cglib.version} - - - net.bytebuddy - byte-buddy - ${byte-buddy.version} - - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-core - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-annotations - ${jackson.version} - - - - org.projectlombok - lombok - ${lombok.version} - provided - diff --git a/uno-components/uno-component-http/src/main/java/cc/allio/uno/component/http/openapi/OpenApiV3Assembly.java b/uno-components/uno-component-http/src/main/java/cc/allio/uno/component/http/openapi/OpenApiV3Assembly.java index 52052d02..2b66f208 100644 --- a/uno-components/uno-component-http/src/main/java/cc/allio/uno/component/http/openapi/OpenApiV3Assembly.java +++ b/uno-components/uno-component-http/src/main/java/cc/allio/uno/component/http/openapi/OpenApiV3Assembly.java @@ -131,7 +131,7 @@ private Mono>> buildMultiValueSwapper(Map.Entry */ private Flux buildSwappers(String path, PathItem pathItem) { return Flux.fromIterable(pathItem.readOperationsMap().entrySet()) - .map(operation -> HttpSwapper.build(host.concat(path), HttpMethod.resolve(operation.getKey().name()))); + .map(operation -> HttpSwapper.build(host.concat(path), HttpMethod.valueOf(operation.getKey().name()))); } /** diff --git a/uno-core/pom.xml b/uno-core/pom.xml index 2b49b033..dd1ef514 100644 --- a/uno-core/pom.xml +++ b/uno-core/pom.xml @@ -32,7 +32,6 @@ org.aspectj aspectjweaver - org.projectlombok lombok diff --git a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/ComparableElement.java b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/ComparableElement.java new file mode 100644 index 00000000..8e72420c --- /dev/null +++ b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/ComparableElement.java @@ -0,0 +1,24 @@ +package cc.allio.uno.core.datastructure.tree; + +import lombok.NonNull; + +import java.io.Serializable; +import java.util.Comparator; + +public class ComparableElement> extends DefaultElement { + + private final Comparator comparator; + + public ComparableElement(@NonNull Serializable id, Comparator comparator) { + super(id); + this.comparator = comparator; + } + + @Override + public void addChildren(Element element) { + super.addChildren(element); + if (comparator != null) { + getChildren().sort((o1, o2) -> comparator.compare((T) o1, (T) o2)); + } + } +} diff --git a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/DefaultElement.java b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/DefaultElement.java index c4f17b86..952006c1 100644 --- a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/DefaultElement.java +++ b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/DefaultElement.java @@ -6,6 +6,7 @@ import lombok.Setter; import java.io.Serializable; +import java.util.Collections; import java.util.List; /** @@ -25,7 +26,7 @@ public class DefaultElement extends TraversalElement { @Setter private Element parent; - private final List children; + private List children; public DefaultElement(@NonNull Serializable id) { this.id = id; @@ -45,13 +46,12 @@ public boolean isLeaf() { @Override public void setChildren(List children) { - clearChildren(); - this.children.addAll(children); + this.children = Collections.singletonList(children); } @Override public void addChildren(Element element) { - children.add(element); + this.children.add(element); } @Override diff --git a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TreeSupport.java b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TreeSupport.java index 9b9385bd..22d19303 100644 --- a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TreeSupport.java +++ b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TreeSupport.java @@ -1,10 +1,10 @@ package cc.allio.uno.core.datastructure.tree; +import cc.allio.uno.core.util.CollectionUtils; import com.google.common.collect.Lists; import java.io.Serializable; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -15,14 +15,16 @@ * @date 2023/11/9 11:34 * @since 1.1.5 */ -public class TreeSupport { +public final class TreeSupport { + private TreeSupport() { + } /** * @see #treeify(List, Function) */ - public static List treeify(List expandTrees) { - return (List) treeify(expandTrees, e -> new DefaultElement(e.getId())); + public static List treeify(List expandTrees) { + return treeify(expandTrees, e -> new DefaultElement(e.getId())); } /** @@ -40,7 +42,10 @@ public static List treeify(List expa * @param 继承于{@link Element}的泛型 * @return hierarchy filter expand tree depth == 0的结点 */ - public static List treeify(List expandTrees, Function treeFunc) { + public static synchronized List treeify(List expandTrees, Function treeFunc) { + if (CollectionUtils.isEmpty(expandTrees)) { + return Collections.emptyList(); + } // transfer expand id must not null Map idElement = expandTrees.stream() @@ -59,19 +64,27 @@ public static List treeify(List expa } } - // 返回根结点数据 - return idElement.values() - .stream() - .filter(e -> e.getDepth() == Element.ROOT_NODE) - .toList(); - } + T fake = expandTrees.getFirst(); + + R sentinel = treeFunc.apply(fake); + for (R virtual : idElement.values()) { + if (virtual.getDepth() == Element.ROOT_NODE) { + // 触发Element添加结点的特性,如排序 + sentinel.addChildren(virtual); + } + } + return sentinel.getChildren(); + } /** - * @see #expand(List, Function) + * @see #expand(List, Function, Comparator) */ - public static List expand(List forest) { - return (List) expand(forest, (r) -> new DefaultExpand(r.getId(), r.getParent() != null ? r.getParent().getId() : null)); + public static List expand(List forest) { + return expand( + forest, + r -> new DefaultExpand(r.getId(), r.getParent() != null ? r.getParent().getId() : null), + null); } /** @@ -80,14 +93,15 @@ public static List expand(List fores * * @param forest 树 * @param expandFunc 树结构展缓为平展结构 + * @param comparator 用于平展结构的排序,可以为null * @param 继承于{@link Expand}的泛型 * @param 继承于{@link Element}的泛型 * @return expand */ - public static List expand(List forest, Function expandFunc) { + public static synchronized List expand(List forest, Function expandFunc, Comparator comparator) { List expands = Lists.newArrayList(); try { - Element.ROOT_SENTINEL.setChildren(forest); + Element.ROOT_SENTINEL.setChildren(Lists.newArrayList(forest)); Element.ROOT_SENTINEL.accept(e -> { // 忽略哨兵结点 if (!Element.ROOT_SENTINEL.equals(e)) { @@ -97,6 +111,9 @@ public static List expand(List fores } finally { Element.ROOT_SENTINEL.clearChildren(); } + if (comparator != null) { + expands.sort(comparator); + } return expands; } } diff --git a/uno-core/src/test/java/cc/allio/uno/core/datastructure/tree/TreeSupportTest.java b/uno-core/src/test/java/cc/allio/uno/core/datastructure/tree/TreeSupportTest.java index d6f68795..716fffee 100644 --- a/uno-core/src/test/java/cc/allio/uno/core/datastructure/tree/TreeSupportTest.java +++ b/uno-core/src/test/java/cc/allio/uno/core/datastructure/tree/TreeSupportTest.java @@ -2,28 +2,62 @@ import cc.allio.uno.core.BaseTestCase; import com.google.common.collect.Lists; +import lombok.Getter; +import lombok.NonNull; import org.junit.jupiter.api.Test; +import java.io.Serializable; +import java.util.Comparator; import java.util.List; +import java.util.Set; +import java.util.function.Function; public class TreeSupportTest extends BaseTestCase { - static List testData = Lists.newArrayList( + List testData = Lists.newArrayList( new DefaultExpand(1, 0), - new DefaultExpand(2, 0), new DefaultExpand(3, 0), + new DefaultExpand(2, 0), new DefaultExpand(4, 1), + new DefaultExpand(6, 2), new DefaultExpand(5, 2) ); @Test void testTreeifyAndExpand() { - List treeify = TreeSupport.treeify(testData); + List treeify = TreeSupport.treeify(testData); assertEquals(3, treeify.size()); - List expands = TreeSupport.expand(treeify); + List expands = TreeSupport.expand(Lists.newArrayList(treeify)); assertEquals(testData.size(), expands.size()); } + + @Test + void testComparatorTreeify() { + List treeify = + TreeSupport.treeify( + testData, + expand -> new Role(expand.getId(), Comparator.comparingInt(Role::getSort)) + ); + assertEquals(3, treeify.size()); + Element element = treeify.get(1); + assertNotNull(element); + Element sort = element.getChildren().get(0); + assertNotNull(sort); + assertEquals(5, sort.getId()); + } + + + @Getter + public static class Role extends ComparableElement { + + private final int sort; + + public Role(@NonNull Serializable id, Comparator comparator) { + super(id, comparator); + this.sort = (int) id; + } + } } diff --git a/uno-gis/src/test/java/cc/allio/uno/gis/type/VillageTest.java b/uno-gis/src/test/java/cc/allio/uno/gis/type/VillageTest.java index 2f19f50d..1024211f 100644 --- a/uno-gis/src/test/java/cc/allio/uno/gis/type/VillageTest.java +++ b/uno-gis/src/test/java/cc/allio/uno/gis/type/VillageTest.java @@ -2,18 +2,18 @@ import cc.allio.uno.test.CoreTest; import cc.allio.uno.test.Inject; -import cc.allio.uno.test.RunMapperTest; import cc.allio.uno.test.RunTest; import cc.allio.uno.gis.config.UnoGisMybatisAutoConfiguration; import cc.allio.uno.gis.type.entity.Village; import cc.allio.uno.gis.type.mapper.VillageMapper; +import cc.allio.uno.test.env.annotation.MybatisPlusEnv; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import org.junit.jupiter.api.Test; import java.util.List; -@RunMapperTest(mapperScan = TestScan.class) @RunTest(components = UnoGisMybatisAutoConfiguration.class) +@MybatisPlusEnv(basePackages = "cc.allio.uno.gis.type.mapper.**") public class VillageTest extends CoreTest { @Inject diff --git a/uno-rule/src/main/java/cc/allio/uno/rule/api/vistor/GroupElement.java b/uno-rule/src/main/java/cc/allio/uno/rule/api/vistor/GroupElement.java index 02ddffd6..86fa9ccf 100644 --- a/uno-rule/src/main/java/cc/allio/uno/rule/api/vistor/GroupElement.java +++ b/uno-rule/src/main/java/cc/allio/uno/rule/api/vistor/GroupElement.java @@ -1,7 +1,5 @@ package cc.allio.uno.rule.api.vistor; -import cc.allio.uno.core.datastructure.tree.Element; - import java.util.List; /** diff --git a/uno-starters/uno-starter-redis/src/test/java/cc/allio/uno/starter/redis/ReactiveRedisTemplateTest.java b/uno-starters/uno-starter-redis/src/test/java/cc/allio/uno/starter/redis/ReactiveRedisTemplateTest.java index f47fff60..0bf078f1 100644 --- a/uno-starters/uno-starter-redis/src/test/java/cc/allio/uno/starter/redis/ReactiveRedisTemplateTest.java +++ b/uno-starters/uno-starter-redis/src/test/java/cc/allio/uno/starter/redis/ReactiveRedisTemplateTest.java @@ -1,13 +1,6 @@ package cc.allio.uno.starter.redis; -import cc.allio.uno.core.util.DateUtil; -import cc.allio.uno.starter.redis.config.ReactiveRedisAutoConfiguration; import cc.allio.uno.test.CoreTest; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.json.JsonReadFeature; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -15,40 +8,7 @@ import org.springframework.data.redis.core.ReactiveRedisTemplate; import reactor.test.StepVerifier; -import java.text.SimpleDateFormat; -import java.time.ZoneId; -import java.util.Locale; -import java.util.TimeZone; - class ReactiveRedisTemplateTest extends CoreTest { - @Override - protected void onEnvBuild() { - registerComponent( - ReactiveRedisAutoConfiguration.class); - - ObjectMapper mapper = new ObjectMapper(); - // 设置地点为中国 - mapper.setLocale(Locale.CHINA); - // 设置为中国上海时区 - mapper.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault())); - //序列化时,日期的统一格式 - mapper.setDateFormat(new SimpleDateFormat(DateUtil.PATTERN_DATETIME, Locale.CHINA)); - mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); - mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); - // 单引号 - mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); - // 允许JSON字符串包含非引号控制字符(值小于32的ASCII字符,包含制表符和换行符) - mapper.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true); - mapper.configure(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER.mappedFeature(), true); - // 失败处理 - mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - // 反序列化时,属性不存在的兼容处理s - mapper.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - // 单引号处理 - mapper.configure(JsonReadFeature.ALLOW_SINGLE_QUOTES.mappedFeature(), true); - register(ObjectMapper.class, mapper); - } @Test void testValueOperation() { @@ -75,11 +35,6 @@ void testListOperation() { .verifyComplete(); } - @Override - protected void onRefreshComplete() throws Throwable { - - } - @Data @NoArgsConstructor @AllArgsConstructor diff --git a/uno-test/src/main/java/cc/allio/uno/test/BaseSpringTest.java b/uno-test/src/main/java/cc/allio/uno/test/BaseSpringTest.java index c962d0b0..99fd53fa 100644 --- a/uno-test/src/main/java/cc/allio/uno/test/BaseSpringTest.java +++ b/uno-test/src/main/java/cc/allio/uno/test/BaseSpringTest.java @@ -10,6 +10,7 @@ import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigRegistry; @@ -63,14 +64,7 @@ protected void onInit() throws Throwable { if (runTestAttributes != null) { runTestAttributes.apply(this); } - -// addPropertySources(context.getEnvironment()); -// new ConfigFileApplicationListener() { -// public void apply() { -// addPostProcessors(context); -// } -// }.apply(); -// registerDefaultComponent(); + ConfigDataEnvironmentPostProcessor.applyTo(context.getEnvironment()); // spring环境初始化,回调接口 onInitSpringEnv(); @@ -249,13 +243,6 @@ public void register(Class beanType, T bean) { beanFactory.registerBeanDefinition(beanType.getName(), beanDefinitionBuilder.getRawBeanDefinition()); } -// /** -// * spring环境中注册默认的bean -// */ -// public void registerDefaultComponent() { -// registerComponent(ConfigurationBeanFactoryMetadata.class); -// } - /** * spring环境添加默认的配置属性 */ diff --git a/uno-test/src/main/java/cc/allio/uno/test/CoreTest.java b/uno-test/src/main/java/cc/allio/uno/test/CoreTest.java index 10b76d2b..d98cbb5b 100644 --- a/uno-test/src/main/java/cc/allio/uno/test/CoreTest.java +++ b/uno-test/src/main/java/cc/allio/uno/test/CoreTest.java @@ -1,6 +1,5 @@ package cc.allio.uno.test; -import cc.allio.uno.test.env.Environment; import cc.allio.uno.test.env.EnvironmentFacade; import cc.allio.uno.test.env.Visitor; import cc.allio.uno.test.runner.CoreRunner; @@ -51,48 +50,46 @@ public CoreTest(Class testClass) { @Override protected void onInitSpringEnv() throws Throwable { - Collection registerRunner = getCoreRunner().getRegisterRunner(); - for (Runner runner : registerRunner) { - try { - runner.run(this); - } catch (Throwable ex) { - // ignore Exception - log.error("run is failed", ex); + CoreRunner coreRunner = getCoreRunner(); + if (coreRunner != null) { + Collection registerRunner = getCoreRunner().getRegisterRunner(); + for (Runner runner : registerRunner) { + try { + runner.run(this); + } catch (Throwable ex) { + // ignore Exception + log.error("run is failed", ex); + } } } } @Override protected void onRefreshComplete() throws Throwable { - for (Runner runner : getCoreRunner().getRefreshCompleteRunner()) { - try { - runner.run(this); - } catch (Throwable ex) { - // ignore Exception - log.error("runner: {} run is failed", runner, ex); + CoreRunner coreRunner = getCoreRunner(); + if (coreRunner != null) { + for (Runner runner : getCoreRunner().getRefreshCompleteRunner()) { + try { + runner.run(this); + } catch (Throwable ex) { + // ignore Exception + log.error("runner: {} run is failed", runner, ex); + } } } } - /** - * 触发uno-core环境构建事件,子类实现。 - * 模板方法 - * - * @deprecated 1.1.4版本之后删除 - */ - @Deprecated - protected void onEnvBuild() { - - } - @Override protected void onContextClose() throws Throwable { - for (Runner runner : getCoreRunner().getCloseRunner()) { - try { - runner.run(this); - } catch (Throwable ex) { - // ignore Exception - log.error("runner: {} run is failed", runner, ex); + CoreRunner coreRunner = getCoreRunner(); + if (coreRunner != null) { + for (Runner runner : getCoreRunner().getCloseRunner()) { + try { + runner.run(this); + } catch (Throwable ex) { + // ignore Exception + log.error("runner: {} run is failed", runner, ex); + } } } } @@ -102,18 +99,6 @@ public RunTestAttributes getRunTestAttributes() { return new RunTestAttributes(getTestClass()); } - /** - * 子类提供Spring环境类 - * 模板方法 - * - * @return 环境类实例 - * @deprecated 1.1.4版本之后删除 - */ - @Deprecated - public Environment supportEnv() { - return null; - } - // ----------------- get/set ----------------- public void setEnv(EnvironmentFacade env) { @@ -199,7 +184,15 @@ public MergedAnnotation getMergedAnnotation(Class a } // 从components中寻找 MergedAnnotation runAnno = testClassAnnos.get(RunTest.class); - Class[] components = runAnno.getClassArray("components"); + Class[] components = null; + try { + components = runAnno.getClassArray("components"); + } catch (NoSuchElementException ex) { + // ignore + } + if (components == null) { + return null; + } for (Class component : components) { testClassAnnos = MergedAnnotations.from(component); if (testClassAnnos.isPresent(annoType)) { @@ -262,9 +255,11 @@ public AnnotationMetadata getCoreTestAnnotations() { public Set getComponentAnnotations() { Set annotationMetadatas = Sets.newHashSet(); MergedAnnotation annotation = getMergedAnnotation(RunTest.class); - Class[] components = annotation.getClassArray("components"); - for (Class component : components) { - annotationMetadatas.add(AnnotationMetadata.introspect(component)); + if (annotation != null) { + Class[] components = annotation.getClassArray("components"); + for (Class component : components) { + annotationMetadatas.add(AnnotationMetadata.introspect(component)); + } } return annotationMetadatas; } diff --git a/uno-test/src/main/java/cc/allio/uno/test/RunAfter.java b/uno-test/src/main/java/cc/allio/uno/test/RunAfter.java deleted file mode 100644 index b831f516..00000000 --- a/uno-test/src/main/java/cc/allio/uno/test/RunAfter.java +++ /dev/null @@ -1,18 +0,0 @@ -package cc.allio.uno.test; - -import java.lang.annotation.*; - -/** - * 单元测试执行完成之后触发 - * - * @author jiangwei - * @date 2022/9/19 16:00 - * @since 1.1.0 - * @deprecated 自1.1.4版本后废弃,使用{@link org.junit.jupiter.api.AfterEach}代理 - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -@Deprecated -public @interface RunAfter { -} diff --git a/uno-test/src/main/java/cc/allio/uno/test/RunBefore.java b/uno-test/src/main/java/cc/allio/uno/test/RunBefore.java deleted file mode 100644 index b8610ea2..00000000 --- a/uno-test/src/main/java/cc/allio/uno/test/RunBefore.java +++ /dev/null @@ -1,18 +0,0 @@ -package cc.allio.uno.test; - -import java.lang.annotation.*; - -/** - * 单元测试执行之前触发该注解标识的方法 - * - * @author jiangwei - * @date 2022/9/19 16:00 - * @since 1.1.0 - * @deprecated 自1.1.4版本后废弃,使用{@link org.junit.jupiter.api.BeforeEach}代替 - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -@Deprecated -public @interface RunBefore { -} diff --git a/uno-test/src/main/java/cc/allio/uno/test/RunMapperTest.java b/uno-test/src/main/java/cc/allio/uno/test/RunMapperTest.java deleted file mode 100644 index a1f8100b..00000000 --- a/uno-test/src/main/java/cc/allio/uno/test/RunMapperTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package cc.allio.uno.test; - -import cc.allio.uno.test.env.DataSourceEnvironment; -import cc.allio.uno.test.env.MybatisEnvironment; -import cc.allio.uno.test.env.MybatisPlusEnvironment; - -import java.lang.annotation.*; - -/** - * 给予测试类中,扫描那些Mapper的类 - * - * @author jiangwei - * @date 2022/10/28 16:30 - * @since 1.1.0 - * @deprecated 自1.1.4版本之后删除,使用cc.allio.uno.test.env.anno包下的注解构建环境 - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@RunTest(envs = { - @RunTest.Environment(env = DataSourceEnvironment.class), - @RunTest.Environment(env = MybatisPlusEnvironment.class), - @RunTest.Environment(env = MybatisEnvironment.class)}) -@Deprecated -public @interface RunMapperTest { - - /** - * 提供用于扫描MapperScan的配置类Class对象 - * - * @return class对象 - */ - Class mapperScan(); -} diff --git a/uno-test/src/main/java/cc/allio/uno/test/RunServiceTest.java b/uno-test/src/main/java/cc/allio/uno/test/RunServiceTest.java deleted file mode 100644 index 60d11945..00000000 --- a/uno-test/src/main/java/cc/allio/uno/test/RunServiceTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package cc.allio.uno.test; - -import cc.allio.uno.test.env.DataSourceEnvironment; -import cc.allio.uno.test.env.MybatisPlusEnvironment; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.FilterType; -import org.springframework.stereotype.Service; - -import java.lang.annotation.*; - -/** - * 给予测试类上,扫描那些被{@link Service}标识的类注册进入Spring中 - * - * @author jiangwei - * @date 2022/10/28 16:28 - * @since 1.1.0 - * @deprecated 自1.1.4版本之后删除,使用cc.allio.uno.test.env.anno包下的注解构建环境 - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@RunTest(envs = { - @RunTest.Environment(env = DataSourceEnvironment.class), - @RunTest.Environment(env = MybatisPlusEnvironment.class)}, components = RunServiceTest.Scan.class) -@Deprecated -public @interface RunServiceTest { - - /** - * 提供用于扫描MapperScan的配置类Class对象 - * - * @return class对象 - */ - Class mapperScan(); - - @ComponentScan(basePackages = "cc.allio.**.service.**", includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, value = Service.class)) - class Scan { - - } -} diff --git a/uno-test/src/main/java/cc/allio/uno/test/RunTest.java b/uno-test/src/main/java/cc/allio/uno/test/RunTest.java index 8d772ae0..5f2341ac 100644 --- a/uno-test/src/main/java/cc/allio/uno/test/RunTest.java +++ b/uno-test/src/main/java/cc/allio/uno/test/RunTest.java @@ -41,16 +41,6 @@ */ String active() default "test"; - /** - * 提供测试运行的环境 - * - * @return Environment数组 - * @see Environment - * @deprecated 1.1.4版本后启用,使用cc.allio.uno.test.anno包下后缀为Env的注解 - */ - @Deprecated - Environment[] envs() default {}; - /** * 提供spring的组件,使其注册为Spring-Bean * @@ -138,28 +128,4 @@ public boolean isEmbedded() { } } - /** - * 注解以获取当前测试所需要的环境 - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.TYPE) - @Deprecated - @interface Environment { - - /** - * {@link Environment}的Class对象,用于进行实例化 - * - * @return - */ - Class env(); - - /** - * 用于实例化{@link Environment}的Class对象时构造器器的参数列表的全限定类名,根据该参数进行传参数 - * - * @return - */ - Class[] classArgs() default {}; - } - } diff --git a/uno-test/src/main/java/cc/allio/uno/test/RunTestAttributes.java b/uno-test/src/main/java/cc/allio/uno/test/RunTestAttributes.java index 8f9e9f70..fcd5fc1d 100644 --- a/uno-test/src/main/java/cc/allio/uno/test/RunTestAttributes.java +++ b/uno-test/src/main/java/cc/allio/uno/test/RunTestAttributes.java @@ -3,7 +3,6 @@ import cc.allio.uno.core.util.ClassUtils; import cc.allio.uno.core.util.ObjectUtils; import cc.allio.uno.core.util.StringUtils; -import cc.allio.uno.test.env.Environment; import cc.allio.uno.test.env.Visitor; import cc.allio.uno.test.runner.CoreRunner; import cc.allio.uno.test.runner.Runner; @@ -37,8 +36,6 @@ public class RunTestAttributes { // 配置文件对应环境 @Getter private String active = "test"; - @Getter - private final Set envs = Sets.newHashSet(); // spring bean集合 @Getter private final Set> componentsClasses = Sets.newHashSet(); @@ -74,34 +71,17 @@ public RunTestAttributes(Class testClass) { .get(RunTest.class) .synthesize(MergedAnnotation::isPresent) .orElse(null); - if (runTest == null) { - throw new IllegalArgumentException(String.format("present test class %s nonexistence @RunTest", testClass.getName())); + if (runTest != null) { + this.profile = runTest.profile(); + this.active = runTest.active(); + this.webEnvironment = runTest.webEnvironment(); + addComponents(runTest.components()); + addInlineProperties(runTest.properties()); + addRunnerClasses(runTest.runner()); + addVisitorClasses(runTest.visitor()); + addListenerClasses(runTest.listeners()); + initInstance(); } - this.profile = runTest.profile(); - this.active = runTest.active(); - this.webEnvironment = runTest.webEnvironment(); - addEnvs(runTest.envs()); - addComponents(runTest.components()); - addInlineProperties(runTest.properties()); - addRunnerClasses(runTest.runner()); - addVisitorClasses(runTest.visitor()); - addListenerClasses(runTest.listeners()); - initInstance(); - } - - public RunTestAttributes(String profile, String active, RunTest.Environment[] envs, - Class[] components, String[] properties, RunTest.WebEnvironment webEnvironment, - Class[] runner, Class[] visitor, Class[] listeners) { - this.profile = profile; - this.active = active; - this.webEnvironment = webEnvironment; - addEnvs(envs); - addComponents(components); - addInlineProperties(properties); - addRunnerClasses(runner); - addVisitorClasses(visitor); - addListenerClasses(listeners); - initInstance(); } /** @@ -113,15 +93,6 @@ private void initInstance() { this.testListeners.addAll(create(listenersClasses)); } - /** - * 添加{@link Environment} - * - * @param envs envs - */ - public void addEnvs(RunTest.Environment... envs) { - this.envs.addAll(Lists.newArrayList(envs)); - } - public void addComponents(Class... componentClasses) { this.componentsClasses.addAll(Lists.newArrayList(componentClasses)); addAutoConfigurationClasses(componentClasses); diff --git a/uno-test/src/main/java/cc/allio/uno/test/TestManager.java b/uno-test/src/main/java/cc/allio/uno/test/TestManager.java index d6ae0857..5d9e1d82 100644 --- a/uno-test/src/main/java/cc/allio/uno/test/TestManager.java +++ b/uno-test/src/main/java/cc/allio/uno/test/TestManager.java @@ -55,6 +55,8 @@ private void registerExtensionObject() { getTestContext().getRunTestAttributes().addListenerClasses(CoreTestListener.class, PrintTimingListener.class, WebListener.class); // 注册默认Visitor getTestContext().getRunTestAttributes().addVisitorClasses(PropertiesVisitor.class); + // 注册默认Runner + getTestContext().getRunTestAttributes().addRunnerClasses(InjectRunner.class, AnnoMetadataRunner.class); } diff --git a/uno-test/src/main/java/cc/allio/uno/test/TestPropertyValues.java b/uno-test/src/main/java/cc/allio/uno/test/TestPropertyValues.java index c4ec7cf1..4f051faa 100644 --- a/uno-test/src/main/java/cc/allio/uno/test/TestPropertyValues.java +++ b/uno-test/src/main/java/cc/allio/uno/test/TestPropertyValues.java @@ -307,7 +307,6 @@ private String setOrClear(String name, String value) { } return (String) System.getProperties().setProperty(name, value); } - } } diff --git a/uno-test/src/main/java/cc/allio/uno/test/env/EnvironmentFacade.java b/uno-test/src/main/java/cc/allio/uno/test/env/EnvironmentFacade.java index ddb0a327..26cf9ff6 100644 --- a/uno-test/src/main/java/cc/allio/uno/test/env/EnvironmentFacade.java +++ b/uno-test/src/main/java/cc/allio/uno/test/env/EnvironmentFacade.java @@ -8,7 +8,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -45,7 +44,7 @@ public void support(CoreTest coreTest) throws Throwable { @Override public Class[] getPropertiesAnnotation() { - return null; + return new Class[0]; } /** @@ -71,8 +70,8 @@ public EnvironmentFacade concat(Collection environments) { public int size() { return environments.stream() .reduce(0, (c1, c2) -> { - if (c2 instanceof EnvironmentFacade) { - return c1 + ((EnvironmentFacade) c2).size(); + if (c2 instanceof EnvironmentFacade facade) { + return c1 + facade.size(); } return c1 + 1; }, Integer::sum); @@ -86,11 +85,11 @@ public int size() { public Collection getEnvironments() { return environments.stream() .flatMap(env -> { - if (env instanceof EnvironmentFacade) { - return ((EnvironmentFacade) env).getEnvironments().stream(); + if (env instanceof EnvironmentFacade facade) { + return facade.getEnvironments().stream(); } return Stream.of(env); }) - .collect(Collectors.toList()); + .toList(); } } diff --git a/uno-test/src/main/java/cc/allio/uno/test/env/annotation/DynamicConfigure.java b/uno-test/src/main/java/cc/allio/uno/test/env/annotation/DynamicConfigure.java index 02ca07bf..af153d16 100644 --- a/uno-test/src/main/java/cc/allio/uno/test/env/annotation/DynamicConfigure.java +++ b/uno-test/src/main/java/cc/allio/uno/test/env/annotation/DynamicConfigure.java @@ -29,19 +29,21 @@ public abstract class DynamicConfigure implements EnvConfigure { public BeanDefinition extract(CoreTest coreTest, MergedAnnotation annotation) { // 保存文件 try { - URL resource = getClass().getResource(StringPool.SLASH); + URL resource = ClassLoader.getSystemResource("./"); if (resource == null) { throw new NullPointerException("the class can't get '/' resource"); } String currentClassPath = resource.getPath(); // 动态生成一个配置类 + String newConfigurationClassName = + getClass().getPackage().getName() + + StringPool.ORIGIN_DOT + + getClass().getSimpleName() + + StringPool.DOLLAR + + IdGenerator.defaultGenerator().getNextIdAsString(); DynamicType.Unloaded dynamicType = new ByteBuddy().subclass(Object.class) - .name(getClass().getPackage().getName() - + StringPool.ORIGIN_DOT - + getClass().getSimpleName() - + StringPool.DOLLAR - + IdGenerator.defaultGenerator().getNextIdAsString()) + .name(newConfigurationClassName) .annotateType(buildAnnoDesc(coreTest, annotation)) .make(); Class configureClass = dynamicType.load(getClass().getClassLoader()).getLoaded(); diff --git a/uno-test/src/main/java/cc/allio/uno/test/env/annotation/MybatisConfigure.java b/uno-test/src/main/java/cc/allio/uno/test/env/annotation/MybatisConfigure.java index dd0c0b1e..51512105 100644 --- a/uno-test/src/main/java/cc/allio/uno/test/env/annotation/MybatisConfigure.java +++ b/uno-test/src/main/java/cc/allio/uno/test/env/annotation/MybatisConfigure.java @@ -23,10 +23,7 @@ protected AnnotationDescription[] buildAnnoDesc(CoreTest coreTest, MergedAnnotat String[] values = annotation.getStringArray("value"); String[] basePackages = annotation.getStringArray("basePackages"); // values and basePackages mutual alias for - if ((values != null && values.length == 0) && basePackages != null && basePackages.length == 0) { - basePackages = new String[]{coreTestPackageName}; - } - if (values == null && basePackages == null){ + if (values.length == 0 && basePackages.length == 0) { basePackages = new String[]{coreTestPackageName}; } annoBuilder = annoBuilder.defineArray("value", values) diff --git a/uno-test/src/main/java/cc/allio/uno/test/env/annotation/MybatisPlusConfigure.java b/uno-test/src/main/java/cc/allio/uno/test/env/annotation/MybatisPlusConfigure.java index 407bfb25..b494aa3d 100644 --- a/uno-test/src/main/java/cc/allio/uno/test/env/annotation/MybatisPlusConfigure.java +++ b/uno-test/src/main/java/cc/allio/uno/test/env/annotation/MybatisPlusConfigure.java @@ -20,7 +20,7 @@ public class MybatisPlusConfigure extends DynamicConfigure { protected AnnotationDescription[] buildAnnoDesc(CoreTest coreTest, MergedAnnotation annotation) { AnnotationDescription.Builder annoBuilder = AnnotationDescription.Builder.ofType(MapperScan.class); String[] basePackages = annotation.getStringArray("basePackages"); - if (basePackages == null || basePackages.length == 0) { + if (basePackages.length == 0) { String packageName = coreTest.getTestClass().getPackage().getName(); basePackages = new String[]{packageName}; } diff --git a/uno-test/src/main/java/cc/allio/uno/test/runner/AnnoMetadataRunner.java b/uno-test/src/main/java/cc/allio/uno/test/runner/AnnoMetadataRunner.java index da35bb8c..41ab8e96 100644 --- a/uno-test/src/main/java/cc/allio/uno/test/runner/AnnoMetadataRunner.java +++ b/uno-test/src/main/java/cc/allio/uno/test/runner/AnnoMetadataRunner.java @@ -47,7 +47,9 @@ public void onRegister(CoreTest coreTest) throws Throwable { // 解析当前注解上的Env注解 if (AnnotatedElementUtils.hasAnnotation(anno.getType(), Env.class)) { Env env = AnnotatedElementUtils.findMergedAnnotation(anno.getType(), Env.class); - resolveEnv(coreTest, env); + if (env != null) { + resolveEnv(coreTest, env); + } } } for (MergedAnnotation anno : mergedAnnotations) { @@ -55,7 +57,9 @@ public void onRegister(CoreTest coreTest) throws Throwable { if (AnnotatedElementUtils.hasAnnotation(anno.getType(), AnnoConfigure.class) && AnnotatedElementUtils.hasAnnotation(anno.getType(), Extractor.class)) { Extractor extractor = AnnotatedElementUtils.findMergedAnnotation(anno.getType(), Extractor.class); - extractEnv(anno, extractor, coreTest); + if (extractor != null) { + extractEnv(anno, extractor, coreTest); + } } } @@ -64,7 +68,7 @@ public void onRegister(CoreTest coreTest) throws Throwable { /** * 构建Environment实例,解析 * - * @param envClasses Environment + * @param env Environment */ public void resolveEnv(CoreTest coreTest, Env env) throws Throwable { Class[] envClasses = env.value(); @@ -72,10 +76,7 @@ public void resolveEnv(CoreTest coreTest, Env env) throws Throwable { Class[] allowEnv = Stream.of(envClasses).filter(c -> !parsedEnvCaches.contains(c)).toArray(Class[]::new); if (ObjectUtils.isNotEmpty(allowEnv)) { ClassUtils.Instantiation instantiation = - ClassUtils.instantiationBuilder() - .addMultiForInstanceClasses(allowEnv) - .setExcludeNull(true) - .build(); + ClassUtils.instantiationBuilder().addMultiForInstanceClasses(allowEnv).setExcludeNull(true).build(); instantiation.addFeature(new ClassUtils.DeDuplicationFeature<>()); instantiation.addFeature(new ClassUtils.SortFeature<>()); List environments = instantiation.create(); @@ -106,8 +107,8 @@ private void extractEnv(MergedAnnotation anno, Extractor extractor, if (configureExtractor != null) { // 动态生成bean 配置类 BeanDefinition beanDefinition = configureExtractor.extract(coreTest, anno); - if (beanDefinition != null) { - GenericApplicationContext context = coreTest.getContext(); + GenericApplicationContext context = coreTest.getContext(); + if (beanDefinition != null && context != null) { context.registerBeanDefinition(anno.getType().getName(), beanDefinition); } envConfigureCaches.add(extractorClazz); diff --git a/uno-test/src/main/java/cc/allio/uno/test/runner/ContextCloseRunner.java b/uno-test/src/main/java/cc/allio/uno/test/runner/ContextCloseRunner.java deleted file mode 100644 index 29256543..00000000 --- a/uno-test/src/main/java/cc/allio/uno/test/runner/ContextCloseRunner.java +++ /dev/null @@ -1,29 +0,0 @@ -package cc.allio.uno.test.runner; - -import cc.allio.uno.test.RunAfter; -import cc.allio.uno.test.CoreTest; -import org.springframework.util.ReflectionUtils; - -import java.util.Arrays; - -/** - * 当Spring上下文关闭时调用 - * - * @author jiangwei - * @date 2022/11/1 18:20 - * @since 1.1.0 - */ -@Deprecated -public class ContextCloseRunner implements CloseRunner { - - @Override - public void onClose(CoreTest coreTest) throws Throwable { - Class testClass = coreTest.getTestClass(); - Arrays.stream(ReflectionUtils.getDeclaredMethods(testClass)) - .filter(method -> method.isAnnotationPresent(RunAfter.class)) - .forEach(method -> { - ReflectionUtils.makeAccessible(method); - ReflectionUtils.invokeMethod(method, this); - }); - } -} diff --git a/uno-test/src/main/java/cc/allio/uno/test/runner/ContextCompleteRunner.java b/uno-test/src/main/java/cc/allio/uno/test/runner/ContextCompleteRunner.java deleted file mode 100644 index c2bc1eee..00000000 --- a/uno-test/src/main/java/cc/allio/uno/test/runner/ContextCompleteRunner.java +++ /dev/null @@ -1,32 +0,0 @@ -package cc.allio.uno.test.runner; - -import cc.allio.uno.test.CoreTest; -import cc.allio.uno.test.RunBefore; -import org.springframework.util.ReflectionUtils; - -import java.util.Arrays; - -/** - * 上下文刷新完成后回调 - *
- *     调用该测试类中被{@link RunBefore}标识的方法
- * 
- * - * @author jiangwei - * @date 2022/10/29 12:44 - * @since 1.1.0 - */ -@Deprecated -public class ContextCompleteRunner implements RefreshCompleteRunner { - - @Override - public void onRefreshComplete(CoreTest coreTest) throws Throwable { - Class testClass = coreTest.getTestClass(); - Arrays.stream(ReflectionUtils.getDeclaredMethods(testClass)) - .filter(method -> method.isAnnotationPresent(RunBefore.class)) - .forEach(method -> { - ReflectionUtils.makeAccessible(method); - ReflectionUtils.invokeMethod(method, this); - }); - } -} diff --git a/uno-test/src/test/java/cc/allio/uno/test/ConfigDataLoaderTest.java b/uno-test/src/test/java/cc/allio/uno/test/ConfigDataLoaderTest.java index d77914f7..efcdff72 100644 --- a/uno-test/src/test/java/cc/allio/uno/test/ConfigDataLoaderTest.java +++ b/uno-test/src/test/java/cc/allio/uno/test/ConfigDataLoaderTest.java @@ -1,6 +1,5 @@ package cc.allio.uno.test; -import cc.allio.uno.test.env.Environment; import org.junit.jupiter.api.Test; /** @@ -8,24 +7,13 @@ * * @author jiangwei * @date 2022/2/26 14:11 - * @see org.springframework.boot.test.context.ConfigFileApplicationContextInitializer - * @see org.springframework.boot.context.config.ConfigFileApplicationListener * @since 1.0 */ public class ConfigDataLoaderTest extends CoreTest { - @Override - protected void onEnvBuild() { - - } @Test void testLoad() { - assertEquals("test", getProperty("allio.uno")); - } - - @Override - public Environment supportEnv() { - return null; + assertEquals("uno", getProperty("allio")); } @Override diff --git a/uno-test/src/test/java/cc/allio/uno/test/DataSourceEnvironmentTest.java b/uno-test/src/test/java/cc/allio/uno/test/DataSourceEnvironmentTest.java deleted file mode 100644 index 352ab0e5..00000000 --- a/uno-test/src/test/java/cc/allio/uno/test/DataSourceEnvironmentTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package cc.allio.uno.test; - -import cc.allio.uno.test.env.DataSourceEnvironment; -import cc.allio.uno.test.env.Environment; -import cc.allio.uno.test.env.EnvironmentFacade; -import org.junit.jupiter.api.Test; -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; - -import javax.sql.DataSource; -import java.util.Map; - -/** - * 数据源环境测试 - * - * @author jiangwei - * @date 2022/8/29 11:30 - * @since 1.0.9 - */ -public class DataSourceEnvironmentTest extends CoreTest { - - - @Override - protected void onEnvBuild() { - - } - - @Override - public Environment supportEnv() { - DataSourceProperties dataSourceProperties = new DataSourceProperties(); - dataSourceProperties.setDriverClassName("com.mysql.cj.jdbc.Driver"); - dataSourceProperties.setUrl("jdbc:mysql://192.168.2.29:3306/migration?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true"); - dataSourceProperties.setUsername("root"); - dataSourceProperties.setPassword("123456"); - return new EnvironmentFacade(new DataSourceEnvironment()); - } - - @Override - protected void onRefreshComplete() throws Throwable { - - } - - @Override - protected void onContextClose() throws Throwable { - - } - - @Test - void testDatasource() { - Map beansOfType = getContext().getBeansOfType(DataSource.class); - assertEquals(beansOfType.size(), 1); - } -} diff --git a/uno-test/src/test/java/cc/allio/uno/test/RunMapperTestWithTest.java b/uno-test/src/test/java/cc/allio/uno/test/RunMapperTestWithTest.java deleted file mode 100644 index 0dd96dab..00000000 --- a/uno-test/src/test/java/cc/allio/uno/test/RunMapperTestWithTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package cc.allio.uno.test; - -import cc.allio.uno.test.env.EnvironmentFacade; -import org.junit.jupiter.api.Test; -import org.mybatis.spring.annotation.MapperScan; - -@RunMapperTest(mapperScan = RunMapperTestWithTest.TestMapperScan.class) -class RunMapperTestWithTest extends CoreTest { - - @Test - void testEnvCount() { - EnvironmentFacade env = getEnv(); - assertEquals(2, env.size()); - } - - @MapperScan("xxx") - public static class TestMapperScan { - - } -} diff --git a/uno-test/src/test/java/cc/allio/uno/test/RunServiceWithTest.java b/uno-test/src/test/java/cc/allio/uno/test/RunServiceWithTest.java deleted file mode 100644 index 0e90dd30..00000000 --- a/uno-test/src/test/java/cc/allio/uno/test/RunServiceWithTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package cc.allio.uno.test; - -import org.junit.jupiter.api.Test; -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.stereotype.Service; - -@RunServiceTest(mapperScan = RunServiceWithTest.TestMapperScan.class) -@RunTest(profile = "application") -class RunServiceWithTest extends CoreTest { - - @Test - void testGetTestService() { - assertDoesNotThrow(() -> getBean(TestService.class)); - } - - @Service - static class TestService { - - } - - @MapperScan("xxx") - static class TestMapperScan { - - } -} diff --git a/uno-test/src/test/java/cc/allio/uno/test/RunTestWithTest.java b/uno-test/src/test/java/cc/allio/uno/test/RunTestWithTest.java index 86a7620a..3780515b 100644 --- a/uno-test/src/test/java/cc/allio/uno/test/RunTestWithTest.java +++ b/uno-test/src/test/java/cc/allio/uno/test/RunTestWithTest.java @@ -7,9 +7,7 @@ import org.junit.jupiter.api.Test; import org.mybatis.spring.SqlSessionTemplate; -@RunTest(envs = { - @RunTest.Environment(env = DataSourceEnvironment.class), - @RunTest.Environment(env = MybatisPlusEnvironment.class)}, +@RunTest( components = {RunTestWithTest.TestBean.class}, profile = "whatever", active = "") diff --git a/uno-test/src/test/java/cc/allio/uno/test/env/DatasourceTestEnvironmentTest.java b/uno-test/src/test/java/cc/allio/uno/test/env/DatasourceTestEnvironmentTest.java deleted file mode 100644 index 96862de3..00000000 --- a/uno-test/src/test/java/cc/allio/uno/test/env/DatasourceTestEnvironmentTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package cc.allio.uno.test.env; - -import cc.allio.uno.test.CoreTest; -import cc.allio.uno.test.RunTest; -import org.junit.jupiter.api.Test; -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; - -import javax.sql.DataSource; - -@RunTest(envs = @RunTest.Environment(env = DataSourceEnvironment.class), active = "") -public class DatasourceTestEnvironmentTest extends CoreTest { - @Override - protected void onRefreshComplete() throws Throwable { - - } - - @Override - protected void onContextClose() throws Throwable { - - } - - @Test - void testDataSourceProperties() { - assertDoesNotThrow(() -> { - DataSourceProperties properties = getBean(DataSourceProperties.class); - assertEquals("jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true", properties.getUrl()); - assertEquals("root", properties.getUsername()); - assertEquals("123456", properties.getPassword()); - assertEquals("com.mysql.cj.jdbc.Driver", properties.getDriverClassName()); - }); - } - - @Test - void testDataSource() { - assertDoesNotThrow(() -> { - getBean(DataSource.class); - }); - } -} diff --git a/uno-test/src/test/java/cc/allio/uno/test/env/MybatisPlusTestEnvironmentTest.java b/uno-test/src/test/java/cc/allio/uno/test/env/MybatisPlusTestEnvironmentTest.java deleted file mode 100644 index 85d77d3d..00000000 --- a/uno-test/src/test/java/cc/allio/uno/test/env/MybatisPlusTestEnvironmentTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package cc.allio.uno.test.env; - -import cc.allio.uno.test.CoreTest; -import cc.allio.uno.test.RunTest; -import org.junit.jupiter.api.Test; -import org.mybatis.spring.SqlSessionTemplate; -import org.mybatis.spring.annotation.MapperScan; - -@RunTest(envs = { - @RunTest.Environment(env = MybatisPlusEnvironment.class, classArgs = MybatisPlusTestEnvironmentTest.TestMapper.class)}) -public class MybatisPlusTestEnvironmentTest extends CoreTest { - - @Test - void testGetSqlSessionTemplate() { - SqlSessionTemplate sqlSessionTemplate = getBean(SqlSessionTemplate.class); - assertNotNull(sqlSessionTemplate); - } - - - @MapperScan - static class TestMapper { - - } -} diff --git a/uno-test/src/test/resources/uno.yaml b/uno-test/src/test/resources/uno.yaml index 7228ad93..dab42a54 100644 --- a/uno-test/src/test/resources/uno.yaml +++ b/uno-test/src/test/resources/uno.yaml @@ -4,3 +4,6 @@ spring: username: postgres password: postgres driver-class-name: org.postgresql.Driver + + +allio: uno \ No newline at end of file