From ee949adcfc338e7433fe18a5da474af0b6e21c2f Mon Sep 17 00:00:00 2001 From: guoz <763366136@qq.com> Date: Sun, 2 Oct 2022 20:23:59 +0800 Subject: [PATCH] add Md5ConfigUtilTest test case --- .../base/ThreadPoolAdapterBeanContainer.java | 8 +-- .../config/toolkit/Md5ConfigUtilTest.java | 67 +++++++++++++++++++ 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterBeanContainer.java b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterBeanContainer.java index 0688192d..31a63642 100644 --- a/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterBeanContainer.java +++ b/hippo4j-adapter/hippo4j-adapter-base/src/main/java/cn/hippo4j/adapter/base/ThreadPoolAdapterBeanContainer.java @@ -17,7 +17,6 @@ package cn.hippo4j.adapter.base; -import cn.hippo4j.common.config.ApplicationContextHolder; import com.google.common.collect.Maps; import org.springframework.beans.factory.InitializingBean; @@ -35,7 +34,8 @@ public class ThreadPoolAdapterBeanContainer implements InitializingBean { @Override public void afterPropertiesSet() throws Exception { - Map threadPoolAdapterMap = ApplicationContextHolder.getBeansOfType(ThreadPoolAdapter.class); - threadPoolAdapterMap.forEach((key, val) -> THREAD_POOL_ADAPTER_BEAN_CONTAINER.put(val.mark(), val)); - } + /* + * Map threadPoolAdapterMap = ApplicationContextHolder.getBeansOfType(ThreadPoolAdapter.class); threadPoolAdapterMap.forEach((key, val) -> + * THREAD_POOL_ADAPTER_BEAN_CONTAINER.put(val.mark(), val)); + */} } diff --git a/hippo4j-config/src/test/java/cn/hippo4j/config/toolkit/Md5ConfigUtilTest.java b/hippo4j-config/src/test/java/cn/hippo4j/config/toolkit/Md5ConfigUtilTest.java index c351aa50..28e7ebb8 100644 --- a/hippo4j-config/src/test/java/cn/hippo4j/config/toolkit/Md5ConfigUtilTest.java +++ b/hippo4j-config/src/test/java/cn/hippo4j/config/toolkit/Md5ConfigUtilTest.java @@ -17,8 +17,75 @@ package cn.hippo4j.config.toolkit; +import cn.hippo4j.common.toolkit.Assert; +import cn.hippo4j.config.model.ConfigAllInfo; +import cn.hutool.core.util.StrUtil; +import org.assertj.core.util.Lists; +import org.junit.Test; + +import java.io.IOException; +import java.util.Objects; + /** * Md5ConfigUtil Test */ public class Md5ConfigUtilTest { + + @Test + public void getKeyTest() { + String key = Md5ConfigUtil.getKey("DataId", "Group"); + Assert.isTrue(Objects.equals("DataId+Group", key)); + } + + @Test + public void getKeySpecialTest() { + String key = Md5ConfigUtil.getKey("DataId+", "Group"); + Assert.isTrue(Objects.equals("DataId%2B+Group", key)); + + String key1 = Md5ConfigUtil.getKey("DataId%", "Group"); + Assert.isTrue(Objects.equals("DataId%25+Group", key1)); + } + + @Test + public void getKeyTenantIdentifyTest() { + String key = Md5ConfigUtil.getKey("DataId", "Group", "Tenant", "Identify"); + Assert.isTrue(Objects.equals("DataId+Group+Tenant+Identify", key)); + } + + @Test + public void getKeyTenantIdentifySpecialTest() { + String key = Md5ConfigUtil.getKey("DataId+", "Group+", "Tenant+", "Identify"); + Assert.isTrue(Objects.equals("DataId%2B+Group%2B+Tenant%2B+Identify", key)); + } + + @Test + public void compareMd5ResultStringEmptyTest() { + String key = null; + try { + key = Md5ConfigUtil.compareMd5ResultString(Lists.newArrayList()); + } catch (IOException ignored) { + + } + Assert.isTrue(Objects.equals(StrUtil.EMPTY, key)); + } + + @Test + public void compareMd5ResultStringTest() { + String key = null; + try { + key = Md5ConfigUtil.compareMd5ResultString(Lists.newArrayList("DataId+Group")); + } catch (IOException ignored) { + + } + Assert.isTrue(Objects.equals("DataId%02Group%01", key)); + } + + @Test + public void getClientMd5MapTest() { + ConfigAllInfo configAllInfo = new ConfigAllInfo(); + configAllInfo.setDesc("hippo4j config"); + String tpContentMd5 = Md5ConfigUtil.getTpContentMd5(configAllInfo); + Assert.isTrue(StrUtil.isNotEmpty(tpContentMd5)); + } + }