This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 97cb883bfd [type:refactor] refactor shenyu admin listener module
(#5347)
97cb883bfd is described below
commit 97cb883bfd022aa926fd1e2521eb3bf9a90afe32
Author: moremind <[email protected]>
AuthorDate: Sat Dec 9 13:30:33 2023 +0800
[type:refactor] refactor shenyu admin listener module (#5347)
* [type:refactor] refactor shenyu admin listener module
* [type:refactor] refactor shenyu admin listener module
* [type:refactor] refactor shenyu admin listener module
* [type:refactor] refactor shenyu admin listener module
* [type:refactor] refactor shenyu admin listener module
* [type:refactor] refactor shenyu admin listener module
* [type:refactor] refactor shenyu admin listener module
* [type:refactor] refactor shenyu admin listener module
---
.../admin/listener/AbstractConfigurationTest.java | 69 ++++++
.../admin/config/ConsulSyncConfigurationTest.java | 50 ++++
.../config/properties/ConsulPropertiesTest.java | 0
.../admin/config/EtcdSyncConfigurationTest.java | 28 ++-
.../config/properties/EtcdPropertiesTest.java | 0
.../shenyu-admin-listener-nacos/pom.xml | 11 +-
.../admin/config/NacosSyncConfigurationTest.java | 71 ++++++
.../properties/AbstractConfigurationTest.java | 69 ++++++
.../config/properties}/NacosPropertiesTest.java | 15 +-
.../admin/config/PolarisSyncConfigurationTest.java | 56 +++++
.../config/properties/PolarisPropertiesTest.java | 0
.../shenyu-admin-listener-zookeeper/pom.xml | 24 +-
.../admin/config/ZookeeperSyncConfiguration.java | 4 +-
.../admin/config/properties/ZookeeperConfig.java | 199 +++++++++++++++
.../admin/listener/zookeeper/ZookeeperClient.java | 254 +++++++++++++++++++
.../zookeeper/ZookeeperDataChangedInit.java | 1 -
.../zookeeper/ZookeeperDataChangedListener.java | 1 -
.../config/ZookeeperSyncConfigurationTest.java | 66 +++++
.../properties/AbstractConfigurationTest.java | 69 ++++++
.../properties}/ZookeeperPropertiesTest.java | 8 +-
.../listener/zookeeper/ZookeeperClientTest.java | 208 ++++++++++++++++
.../zookeeper/ZookeeperDataChangedInitTest.java | 1 -
.../ZookeeperDataChangedListenerTest.java | 1 -
shenyu-admin/pom.xml | 1 -
.../admin/config/DataSyncConfigurationTest.java | 269 ---------------------
...a => HttpLongPollingSyncConfigurationTest.java} | 19 +-
...st.java => WebSocketSyncConfigurationTest.java} | 29 ++-
.../{ => properties}/HttpSyncPropertiesTest.java | 3 +-
.../WebsocketSyncPropertiesTest.java | 3 +-
.../org/apache/shenyu/web/logo/ShenyuLogo.java | 66 -----
.../org/apache/shenyu/web/logo/ShenyuLogoTest.java | 61 -----
31 files changed, 1199 insertions(+), 457 deletions(-)
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-api/src/test/java/org/apache/shenyu/admin/listener/AbstractConfigurationTest.java
b/shenyu-admin-listener/shenyu-admin-listener-api/src/test/java/org/apache/shenyu/admin/listener/AbstractConfigurationTest.java
new file mode 100644
index 0000000000..6565e80fa2
--- /dev/null
+++
b/shenyu-admin-listener/shenyu-admin-listener-api/src/test/java/org/apache/shenyu/admin/listener/AbstractConfigurationTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.shenyu.admin.listener;
+
+import org.junit.jupiter.api.AfterEach;
+import
org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.test.context.support.TestPropertySourceUtils;
+
+/**
+ * AbstractConfigurationTest for Configuration or Properties.
+ */
+public abstract class AbstractConfigurationTest {
+
+ private final AnnotationConfigApplicationContext context = new
AnnotationConfigApplicationContext();
+
+ /**
+ * Get the current mock context.
+ *
+ * @return AnnotationConfigApplicationContext
+ */
+ public AnnotationConfigApplicationContext getContext() {
+ return context;
+ }
+
+ /**
+ * clear context.
+ */
+ @AfterEach
+ public void clear() {
+ context.close();
+ }
+
+ /**
+ * Add properties to Environment and register configuration into spring
context.
+ *
+ * @param configuration the configuration class
+ * @param inlinedProperties the config properties
+ */
+ public void load(final Class<?> configuration, final String...
inlinedProperties) {
+ load(new Class<?>[]{configuration}, inlinedProperties);
+ }
+
+ /**
+ * Add properties to Environment and register configuration into spring
context.
+ *
+ * @param configuration the configuration class array
+ * @param inlinedProperties the config properties
+ */
+ public void load(final Class<?>[] configuration, final String...
inlinedProperties) {
+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
inlinedProperties);
+ this.context.register(configuration);
+ this.context.refresh();
+ }
+}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-consul/src/test/java/org/apache/shenyu/admin/config/ConsulSyncConfigurationTest.java
b/shenyu-admin-listener/shenyu-admin-listener-consul/src/test/java/org/apache/shenyu/admin/config/ConsulSyncConfigurationTest.java
new file mode 100644
index 0000000000..6d3b55ec4e
--- /dev/null
+++
b/shenyu-admin-listener/shenyu-admin-listener-consul/src/test/java/org/apache/shenyu/admin/config/ConsulSyncConfigurationTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.shenyu.admin.config;
+
+import com.ecwid.consul.v1.ConsulClient;
+import org.apache.shenyu.admin.config.properties.ConsulProperties;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ConsulSyncConfigurationTest {
+ @Test
+ public void testConsulClient() {
+ ConsulSyncConfiguration consulListener = new ConsulSyncConfiguration();
+ ConsulProperties consulProperties = mock(ConsulProperties.class);
+ when(consulProperties.getUrl()).thenReturn("http://127.0.0.1:8500");
+ assertNotNull(consulListener.consulClient(consulProperties));
+ }
+
+ @Test
+ public void testConsulDataChangedListener() {
+ ConsulSyncConfiguration consulListener = new ConsulSyncConfiguration();
+ ConsulClient consulClient = mock(ConsulClient.class);
+ assertNotNull(consulListener.consulDataChangedListener(consulClient));
+ }
+
+ @Test
+ public void testConsulDataInit() {
+ ConsulSyncConfiguration consulListener = new ConsulSyncConfiguration();
+ ConsulClient consulClient = mock(ConsulClient.class);
+ assertNotNull(consulListener.consulDataChangedInit(consulClient));
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/ConsulPropertiesTest.java
b/shenyu-admin-listener/shenyu-admin-listener-consul/src/test/java/org/apache/shenyu/admin/config/properties/ConsulPropertiesTest.java
similarity index 100%
copy from
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/ConsulPropertiesTest.java
copy to
shenyu-admin-listener/shenyu-admin-listener-consul/src/test/java/org/apache/shenyu/admin/config/properties/ConsulPropertiesTest.java
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/ConsulPropertiesTest.java
b/shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/config/EtcdSyncConfigurationTest.java
similarity index 53%
copy from
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/ConsulPropertiesTest.java
copy to
shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/config/EtcdSyncConfigurationTest.java
index 6f1e673260..2a2b98943d 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/ConsulPropertiesTest.java
+++
b/shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/config/EtcdSyncConfigurationTest.java
@@ -15,20 +15,28 @@
* limitations under the License.
*/
-package org.apache.shenyu.admin.config.properties;
+package org.apache.shenyu.admin.config;
-import org.junit.jupiter.api.Assertions;
+import org.apache.shenyu.admin.listener.etcd.EtcdClient;
import org.junit.jupiter.api.Test;
-/**
- * Test cases for {@link ConsulProperties}.
- */
-public class ConsulPropertiesTest {
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.Mockito.mock;
+
+public class EtcdSyncConfigurationTest {
+
+ @Test
+ public void testEtcdDataChangedListener() {
+ EtcdSyncConfiguration etcdListener = new EtcdSyncConfiguration();
+ EtcdClient client = mock(EtcdClient.class);
+ assertNotNull(etcdListener.etcdDataChangedListener(client));
+ }
@Test
- public void consulPropertiesTest() {
- final ConsulProperties consulProperties = new ConsulProperties();
- consulProperties.setUrl("url");
- Assertions.assertEquals(consulProperties.getUrl(), "url");
+ public void testEtcdDataInit() {
+ EtcdSyncConfiguration etcdListener = new EtcdSyncConfiguration();
+ EtcdClient client = mock(EtcdClient.class);
+ assertNotNull(etcdListener.etcdDataChangedInit(client));
}
+
}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/EtcdPropertiesTest.java
b/shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/config/properties/EtcdPropertiesTest.java
similarity index 100%
rename from
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/EtcdPropertiesTest.java
rename to
shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/config/properties/EtcdPropertiesTest.java
diff --git a/shenyu-admin-listener/shenyu-admin-listener-nacos/pom.xml
b/shenyu-admin-listener/shenyu-admin-listener-nacos/pom.xml
index 7d3e0523b7..9935ce9d57 100644
--- a/shenyu-admin-listener/shenyu-admin-listener-nacos/pom.xml
+++ b/shenyu-admin-listener/shenyu-admin-listener-nacos/pom.xml
@@ -42,9 +42,14 @@
</dependency>
<dependency>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-discovery-nacos</artifactId>
- <version>${project.version}</version>
+ <groupId>com.alibaba.nacos</groupId>
+ <artifactId>nacos-client</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
</dependency>
</dependencies>
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-nacos/src/test/java/org/apache/shenyu/admin/config/NacosSyncConfigurationTest.java
b/shenyu-admin-listener/shenyu-admin-listener-nacos/src/test/java/org/apache/shenyu/admin/config/NacosSyncConfigurationTest.java
new file mode 100644
index 0000000000..9bf77fdc81
--- /dev/null
+++
b/shenyu-admin-listener/shenyu-admin-listener-nacos/src/test/java/org/apache/shenyu/admin/config/NacosSyncConfigurationTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.shenyu.admin.config;
+
+import com.alibaba.nacos.api.NacosFactory;
+import com.alibaba.nacos.api.config.ConfigService;
+import com.alibaba.nacos.client.config.NacosConfigService;
+import org.apache.shenyu.admin.config.properties.NacosProperties;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+
+import java.util.Properties;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+
+public class NacosSyncConfigurationTest {
+ @Test
+ public void testNacosDataChangedListener() {
+ NacosSyncConfiguration nacosListener = new NacosSyncConfiguration();
+ NacosConfigService configService = mock(NacosConfigService.class);
+ assertNotNull(nacosListener.nacosDataChangedListener(configService));
+ }
+
+ @Test
+ public void testNacosDataInit() {
+ NacosSyncConfiguration nacosListener = new NacosSyncConfiguration();
+ NacosConfigService configService = mock(NacosConfigService.class);
+ assertNotNull(nacosListener.nacosDataChangedInit(configService));
+ }
+
+ @Test
+ public void nacosConfigServiceTest() {
+ try (MockedStatic<NacosFactory> nacosFactoryMockedStatic =
mockStatic(NacosFactory.class)) {
+ final NacosProperties nacosProperties = new NacosProperties();
+ final NacosProperties.NacosACMProperties nacosACMProperties = new
NacosProperties.NacosACMProperties();
+ nacosProperties.setAcm(nacosACMProperties);
+ nacosFactoryMockedStatic.when(() ->
NacosFactory.createConfigService(any(Properties.class))).thenReturn(mock(ConfigService.class));
+ NacosSyncConfiguration nacosListener = new
NacosSyncConfiguration();
+ nacosProperties.setUrl("url");
+ Assertions.assertDoesNotThrow(() ->
nacosListener.nacosConfigService(nacosProperties));
+ nacosProperties.setNamespace("url");
+ nacosProperties.setUsername("username");
+ nacosProperties.setPassword("password");
+ Assertions.assertDoesNotThrow(() ->
nacosListener.nacosConfigService(nacosProperties));
+ nacosACMProperties.setEnabled(true);
+ nacosACMProperties.setEndpoint("acm.aliyun.com");
+ nacosACMProperties.setAccessKey("accessKey");
+ nacosACMProperties.setNamespace("namespace");
+ nacosACMProperties.setSecretKey("secretKey");
+ Assertions.assertDoesNotThrow(() ->
nacosListener.nacosConfigService(nacosProperties));
+ }
+ }
+}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-nacos/src/test/java/org/apache/shenyu/admin/config/properties/AbstractConfigurationTest.java
b/shenyu-admin-listener/shenyu-admin-listener-nacos/src/test/java/org/apache/shenyu/admin/config/properties/AbstractConfigurationTest.java
new file mode 100644
index 0000000000..77582635c7
--- /dev/null
+++
b/shenyu-admin-listener/shenyu-admin-listener-nacos/src/test/java/org/apache/shenyu/admin/config/properties/AbstractConfigurationTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.shenyu.admin.config.properties;
+
+import org.junit.jupiter.api.AfterEach;
+import
org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.test.context.support.TestPropertySourceUtils;
+
+/**
+ * AbstractConfigurationTest for Configuration or Properties.
+ */
+public abstract class AbstractConfigurationTest {
+
+ private final AnnotationConfigApplicationContext context = new
AnnotationConfigApplicationContext();
+
+ /**
+ * Get the current mock context.
+ *
+ * @return AnnotationConfigApplicationContext
+ */
+ public AnnotationConfigApplicationContext getContext() {
+ return context;
+ }
+
+ /**
+ * clear context.
+ */
+ @AfterEach
+ public void clear() {
+ context.close();
+ }
+
+ /**
+ * Add properties to Environment and register configuration into spring
context.
+ *
+ * @param configuration the configuration class
+ * @param inlinedProperties the config properties
+ */
+ public void load(final Class<?> configuration, final String...
inlinedProperties) {
+ load(new Class<?>[]{configuration}, inlinedProperties);
+ }
+
+ /**
+ * Add properties to Environment and register configuration into spring
context.
+ *
+ * @param configuration the configuration class array
+ * @param inlinedProperties the config properties
+ */
+ public void load(final Class<?>[] configuration, final String...
inlinedProperties) {
+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
inlinedProperties);
+ this.context.register(configuration);
+ this.context.refresh();
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/NacosPropertiesTest.java
b/shenyu-admin-listener/shenyu-admin-listener-nacos/src/test/java/org/apache/shenyu/admin/config/properties/NacosPropertiesTest.java
similarity index 93%
rename from
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/NacosPropertiesTest.java
rename to
shenyu-admin-listener/shenyu-admin-listener-nacos/src/test/java/org/apache/shenyu/admin/config/properties/NacosPropertiesTest.java
index c4bad1a4ce..8360a8cdac 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/NacosPropertiesTest.java
+++
b/shenyu-admin-listener/shenyu-admin-listener-nacos/src/test/java/org/apache/shenyu/admin/config/properties/NacosPropertiesTest.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.shenyu.admin.config;
+package org.apache.shenyu.admin.config.properties;
-import org.apache.shenyu.admin.AbstractConfigurationTest;
-
-import org.apache.shenyu.admin.config.properties.NacosProperties;
import org.junit.jupiter.api.Test;
+
import
org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@@ -31,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
* Test cases for NacosProperties.
*/
public final class NacosPropertiesTest extends AbstractConfigurationTest {
-
+
@Test
public void testNacosPropertiesDefault() {
load(NacosPropertiesTest.NacosPropertiesConfiguration.class);
@@ -44,7 +42,7 @@ public final class NacosPropertiesTest extends
AbstractConfigurationTest {
assertEquals(nacosProperties.getPassword(), "password");
assertEquals(nacosProperties.getUsername(), "username");
}
-
+
@Test
public void testNacosPropertiesSpecified() {
final String url = "localhost:8848";
@@ -58,7 +56,8 @@ public final class NacosPropertiesTest extends
AbstractConfigurationTest {
assertEquals(acm.getAccessKey(), "accessKey");
assertEquals(acm.getNamespace(), "namespace");
assertEquals(acm.getSecretKey(), "secretKey");
- load(NacosPropertiesTest.NacosPropertiesConfiguration.class,
"shenyu.sync.nacos.url=localhost:8848",
+ load(NacosPropertiesTest.NacosPropertiesConfiguration.class,
+ "shenyu.sync.nacos.url=localhost:8848",
"shenyu.sync.nacos.namespace=1c10d748-af86-43b9-8265-75f487d20c6c",
"shenyu.sync.nacos.acm.enabled=false",
"shenyu.sync.nacos.acm.endpoint=acm.aliyun.com");
@@ -68,7 +67,7 @@ public final class NacosPropertiesTest extends
AbstractConfigurationTest {
assertEquals(nacosProperties.getAcm().isEnabled(), acm.isEnabled());
assertEquals(nacosProperties.getAcm().getEndpoint(),
acm.getEndpoint());
}
-
+
@Configuration
@EnableConfigurationProperties(NacosProperties.class)
static class NacosPropertiesConfiguration {
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/config/PolarisSyncConfigurationTest.java
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/config/PolarisSyncConfigurationTest.java
new file mode 100644
index 0000000000..5831f586af
--- /dev/null
+++
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/config/PolarisSyncConfigurationTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.shenyu.admin.config;
+
+import com.tencent.polaris.configuration.api.core.ConfigFilePublishService;
+import com.tencent.polaris.configuration.api.core.ConfigFileService;
+import org.apache.shenyu.admin.config.properties.PolarisProperties;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.Mockito.mock;
+
+public class PolarisSyncConfigurationTest {
+
+ @Test
+ public void testPolarisDataChangedListener() {
+ PolarisSyncConfiguration polarisListener = new
PolarisSyncConfiguration();
+ PolarisProperties polarisProperties = mock(PolarisProperties.class);
+ ConfigFileService polarisConfigFileService =
mock(ConfigFileService.class);
+ ConfigFilePublishService polarisConfigFilePublishService =
mock(ConfigFilePublishService.class);
+
assertNotNull(polarisListener.polarisDataChangedListener(polarisProperties,
polarisConfigFileService, polarisConfigFilePublishService));
+ }
+
+ @Test
+ public void testPolarisDataInit() {
+ PolarisSyncConfiguration polarisListener = new
PolarisSyncConfiguration();
+ PolarisProperties polarisProperties = mock(PolarisProperties.class);
+ ConfigFileService polarisConfigFileService =
mock(ConfigFileService.class);
+
assertNotNull(polarisListener.polarisDataChangedInit(polarisProperties,
polarisConfigFileService));
+ }
+
+ @Test
+ public void polarisConfigServiceTest() {
+ final PolarisProperties polarisProperties = new PolarisProperties();
+ polarisProperties.setUrl("127.0.0.1:8093");
+ polarisProperties.setNamespace("namespace");
+ PolarisSyncConfiguration polarisListener = new
PolarisSyncConfiguration();
+
assertNotNull(polarisListener.polarisConfigFileService(polarisProperties));
+
assertNotNull(polarisListener.polarisConfigFilePublishService(polarisProperties));
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/PolarisPropertiesTest.java
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/config/properties/PolarisPropertiesTest.java
similarity index 100%
rename from
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/PolarisPropertiesTest.java
rename to
shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/config/properties/PolarisPropertiesTest.java
diff --git a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/pom.xml
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/pom.xml
index 3aafdcb924..347783c6b9 100644
--- a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/pom.xml
+++ b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/pom.xml
@@ -32,14 +32,18 @@
<dependency>
<groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-register-client-server-zookeeper</artifactId>
+ <artifactId>shenyu-admin-listener-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-admin-listener-api</artifactId>
- <version>${project.version}</version>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-framework</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-recipes</artifactId>
</dependency>
<dependency>
@@ -47,6 +51,18 @@
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-test</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/config/ZookeeperSyncConfiguration.java
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/config/ZookeeperSyncConfiguration.java
index 739b7da371..86e04a6d04 100644
---
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/config/ZookeeperSyncConfiguration.java
+++
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/config/ZookeeperSyncConfiguration.java
@@ -17,13 +17,13 @@
package org.apache.shenyu.admin.config;
+import org.apache.shenyu.admin.config.properties.ZookeeperConfig;
import org.apache.shenyu.admin.config.properties.ZookeeperProperties;
import org.apache.shenyu.admin.listener.DataChangedInit;
import org.apache.shenyu.admin.listener.DataChangedListener;
+import org.apache.shenyu.admin.listener.zookeeper.ZookeeperClient;
import org.apache.shenyu.admin.listener.zookeeper.ZookeeperDataChangedInit;
import org.apache.shenyu.admin.listener.zookeeper.ZookeeperDataChangedListener;
-import org.apache.shenyu.register.client.server.zookeeper.ZookeeperClient;
-import org.apache.shenyu.register.client.server.zookeeper.ZookeeperConfig;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import
org.springframework.boot.context.properties.EnableConfigurationProperties;
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/config/properties/ZookeeperConfig.java
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/config/properties/ZookeeperConfig.java
new file mode 100644
index 0000000000..be488846e6
--- /dev/null
+++
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/config/properties/ZookeeperConfig.java
@@ -0,0 +1,199 @@
+/*
+ * 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.shenyu.admin.config.properties;
+
+public class ZookeeperConfig {
+ /**
+ * zookeeper server list.
+ * e.g. host1:2181,host2:2181
+ */
+ private final String serverLists;
+
+ /**
+ * zookeeper namespace.
+ */
+ private String namespace = "";
+
+ /**
+ * initial amount of time to wait between retries.
+ */
+ private int baseSleepTimeMilliseconds = 1000;
+
+ /**
+ * max time in ms to sleep on each retry.
+ */
+ private int maxSleepTimeMilliseconds = Integer.MAX_VALUE;
+
+ /**
+ * max number of times to retry.
+ */
+ private int maxRetries = 3;
+
+ /**
+ * session timeout.
+ */
+ private int sessionTimeoutMilliseconds = 60 * 1000;
+
+ /**
+ * connection timeout.
+ */
+ private int connectionTimeoutMilliseconds = 15 * 1000;
+
+ /**
+ * auth token digest. no auth by default.
+ */
+ private String digest;
+
+ public ZookeeperConfig(final String serverLists) {
+ this.serverLists = serverLists;
+ }
+
+ /**
+ * get zookeeper server list.
+ * @return server list.
+ */
+ public String getServerLists() {
+ return serverLists;
+ }
+
+ /**
+ * set namespace.
+ * @param namespace zk namespace
+ * @return zk config
+ */
+ public ZookeeperConfig setNamespace(final String namespace) {
+ this.namespace = namespace;
+ return this;
+ }
+
+ /**
+ * get namespace.
+ * @return namespace
+ */
+ public String getNamespace() {
+ return namespace;
+ }
+
+ /**
+ * get base sleep time.
+ * @return base sleep time.
+ */
+ public int getBaseSleepTimeMilliseconds() {
+ return baseSleepTimeMilliseconds;
+ }
+
+ /**
+ * set base sleep time.
+ * @param baseSleepTimeMilliseconds base sleep time in milliseconds.
+ * @return zk config.
+ */
+ public ZookeeperConfig setBaseSleepTimeMilliseconds(final int
baseSleepTimeMilliseconds) {
+ this.baseSleepTimeMilliseconds = baseSleepTimeMilliseconds;
+ return this;
+ }
+
+ /**
+ * get max sleep time.
+ * @return max sleep time
+ */
+ public int getMaxSleepTimeMilliseconds() {
+ return maxSleepTimeMilliseconds;
+ }
+
+ /**
+ * set max sleep time.
+ * @param maxSleepTimeMilliseconds max sleep time.
+ * @return zk config.
+ */
+ public ZookeeperConfig setMaxSleepTimeMilliseconds(final int
maxSleepTimeMilliseconds) {
+ this.maxSleepTimeMilliseconds = maxSleepTimeMilliseconds;
+ return this;
+ }
+
+ /**
+ * get max retries.
+ * @return max retries
+ */
+ public int getMaxRetries() {
+ return maxRetries;
+ }
+
+ /**
+ * set max retries count.
+ * @param maxRetries max retries
+ * @return zk config.
+ */
+ public ZookeeperConfig setMaxRetries(final int maxRetries) {
+ this.maxRetries = maxRetries;
+ return this;
+ }
+
+ /**
+ * get session timeout in milliseconds.
+ * @return session timeout.
+ */
+ public int getSessionTimeoutMilliseconds() {
+ return sessionTimeoutMilliseconds;
+ }
+
+ /**
+ * set session timeout in milliseconds.
+ * @param sessionTimeoutMilliseconds session timeout
+ * @return zk config.
+ */
+ public ZookeeperConfig setSessionTimeoutMilliseconds(final int
sessionTimeoutMilliseconds) {
+ this.sessionTimeoutMilliseconds = sessionTimeoutMilliseconds;
+ return this;
+ }
+
+ /**
+ * get connection timeout in milliseconds.
+ * @return connection timeout.
+ */
+ public int getConnectionTimeoutMilliseconds() {
+ return connectionTimeoutMilliseconds;
+ }
+
+ /**
+ * set connection timeout in milliseconds.
+ * @param connectionTimeoutMilliseconds connection timeout.
+ * @return zk config.
+ */
+ public ZookeeperConfig setConnectionTimeoutMilliseconds(final int
connectionTimeoutMilliseconds) {
+ this.connectionTimeoutMilliseconds = connectionTimeoutMilliseconds;
+ return this;
+ }
+
+ /**
+ * get digest.
+ * @return digest.
+ */
+ public String getDigest() {
+ return digest;
+ }
+
+ /**
+ * set digest.
+ * @param digest digest
+ * @return zk config.
+ */
+ public ZookeeperConfig setDigest(final String digest) {
+ this.digest = digest;
+ return this;
+ }
+}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperClient.java
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperClient.java
new file mode 100644
index 0000000000..00a54e11da
--- /dev/null
+++
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperClient.java
@@ -0,0 +1,254 @@
+/*
+ * 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.shenyu.admin.listener.zookeeper;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.recipes.cache.ChildData;
+import org.apache.curator.framework.recipes.cache.TreeCache;
+import org.apache.curator.framework.recipes.cache.TreeCacheListener;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.curator.utils.CloseableUtils;
+import org.apache.shenyu.admin.config.properties.ZookeeperConfig;
+import org.apache.shenyu.common.exception.ShenyuException;
+import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.zookeeper.CreateMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class ZookeeperClient {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(ZookeeperClient.class);
+
+ private final ZookeeperConfig config;
+
+ private final CuratorFramework client;
+
+ private final Map<String, TreeCache> caches = new ConcurrentHashMap<>();
+
+ public ZookeeperClient(final ZookeeperConfig zookeeperConfig) {
+ this.config = zookeeperConfig;
+ ExponentialBackoffRetry retryPolicy = new
ExponentialBackoffRetry(config.getBaseSleepTimeMilliseconds(),
config.getMaxRetries(), config.getMaxSleepTimeMilliseconds());
+
+ CuratorFrameworkFactory.Builder builder =
CuratorFrameworkFactory.builder()
+ .connectString(config.getServerLists())
+ .retryPolicy(retryPolicy)
+ .connectionTimeoutMs(config.getConnectionTimeoutMilliseconds())
+ .sessionTimeoutMs(config.getSessionTimeoutMilliseconds())
+ .namespace(config.getNamespace());
+
+ if (!StringUtils.isEmpty(config.getDigest())) {
+ builder.authorization("digest",
config.getDigest().getBytes(StandardCharsets.UTF_8));
+ }
+
+ this.client = builder.build();
+ }
+
+ /**
+ * start.
+ */
+ public void start() {
+ this.client.start();
+ try {
+ this.client.blockUntilConnected();
+ } catch (InterruptedException e) {
+ LOGGER.warn("Interrupted during zookeeper client starting.");
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ /**
+ * start.
+ */
+ public void close() {
+ // close all caches
+ for (Map.Entry<String, TreeCache> cache : caches.entrySet()) {
+ CloseableUtils.closeQuietly(cache.getValue());
+ }
+ // close client
+ CloseableUtils.closeQuietly(client);
+ }
+
+ /**
+ * get curator framework.
+ *
+ * @return curator framework client.
+ */
+ public CuratorFramework getClient() {
+ return client;
+ }
+
+ /**
+ * check if key exist.
+ *
+ * @param key zookeeper path
+ * @return if exist.
+ */
+ public boolean isExist(final String key) {
+ try {
+ return null != client.checkExists().forPath(key);
+ } catch (Exception e) {
+ throw new ShenyuException(e);
+ }
+ }
+
+ /**
+ * get from zk directly.
+ *
+ * @param key zookeeper path
+ * @return value.
+ */
+ public String getDirectly(final String key) {
+ try {
+ byte[] ret = client.getData().forPath(key);
+ return Objects.isNull(ret) ? null : new String(ret,
StandardCharsets.UTF_8);
+ } catch (Exception e) {
+ throw new ShenyuException(e);
+ }
+ }
+
+ /**
+ * get value for specific key.
+ *
+ * @param key zookeeper path
+ * @return value.
+ */
+ public String get(final String key) {
+ TreeCache cache = findFromcache(key);
+ if (Objects.isNull(cache)) {
+ return getDirectly(key);
+ }
+ ChildData data = cache.getCurrentData(key);
+ if (Objects.isNull(data)) {
+ return getDirectly(key);
+ }
+ return Objects.isNull(data.getData()) ? null : new
String(data.getData(), StandardCharsets.UTF_8);
+ }
+
+ /**
+ * create or update key with value.
+ *
+ * @param key zookeeper path key.
+ * @param value string value.
+ * @param mode creation mode.
+ */
+ public void createOrUpdate(final String key, final String value, final
CreateMode mode) {
+ String val = StringUtils.isEmpty(value) ? "" : value;
+ try {
+
client.create().orSetData().creatingParentsIfNeeded().withMode(mode).forPath(key,
val.getBytes(StandardCharsets.UTF_8));
+ } catch (Exception e) {
+ throw new ShenyuException(e);
+ }
+ }
+
+ /**
+ * create or update key with value.
+ *
+ * @param key zookeeper path key.
+ * @param value object value.
+ * @param mode creation mode.
+ */
+ public void createOrUpdate(final String key, final Object value, final
CreateMode mode) {
+ if (value != null) {
+ String val = GsonUtils.getInstance().toJson(value);
+ createOrUpdate(key, val, mode);
+ } else {
+ createOrUpdate(key, "", mode);
+ }
+ }
+
+ /**
+ * delete a node with specific key.
+ *
+ * @param key zookeeper path key.
+ */
+ public void delete(final String key) {
+ try {
+
client.delete().guaranteed().deletingChildrenIfNeeded().forPath(key);
+ } catch (Exception e) {
+ throw new ShenyuException(e);
+ }
+ }
+
+ /**
+ * get children with specific key.
+ *
+ * @param key zookeeper key.
+ * @return children node name.
+ */
+ public List<String> getChildren(final String key) {
+ try {
+ return client.getChildren().forPath(key);
+ } catch (Exception e) {
+ throw new ShenyuException(e);
+ }
+ }
+
+ /**
+ * get created cache.
+ * @param path path.
+ * @return cache.
+ */
+ public TreeCache getCache(final String path) {
+ return caches.get(path);
+ }
+
+ /**
+ * add new curator cache.
+ * @param path path.
+ * @param listeners listeners.
+ * @return cache.
+ */
+ public TreeCache addCache(final String path, final TreeCacheListener...
listeners) {
+ TreeCache cache = TreeCache.newBuilder(client, path).build();
+ caches.put(path, cache);
+ if (ArrayUtils.isNotEmpty(listeners)) {
+ for (TreeCacheListener listener : listeners) {
+ cache.getListenable().addListener(listener);
+ }
+ }
+ try {
+ cache.start();
+ } catch (Exception e) {
+ throw new ShenyuException("failed to add curator cache.", e);
+ }
+ return cache;
+ }
+
+ /**
+ * find cache with key.
+ * @param key key.
+ * @return cache.
+ */
+ private TreeCache findFromcache(final String key) {
+ for (Map.Entry<String, TreeCache> cache : caches.entrySet()) {
+ if (key.startsWith(cache.getKey())) {
+ return cache.getValue();
+ }
+ }
+ return null;
+ }
+}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedInit.java
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedInit.java
index f31bedd9c5..f0a8d45333 100644
---
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedInit.java
+++
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedInit.java
@@ -19,7 +19,6 @@ package org.apache.shenyu.admin.listener.zookeeper;
import org.apache.shenyu.admin.listener.AbstractDataChangedInit;
import org.apache.shenyu.common.constant.DefaultPathConstants;
-import org.apache.shenyu.register.client.server.zookeeper.ZookeeperClient;
import java.util.stream.Stream;
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedListener.java
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedListener.java
index 4777808946..4b81511390 100644
---
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedListener.java
+++
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/main/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedListener.java
@@ -18,7 +18,6 @@
package org.apache.shenyu.admin.listener.zookeeper;
import org.apache.shenyu.admin.listener.AbstractPathDataChangedListener;
-import org.apache.shenyu.register.client.server.zookeeper.ZookeeperClient;
import org.apache.zookeeper.CreateMode;
/**
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/config/ZookeeperSyncConfigurationTest.java
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/config/ZookeeperSyncConfigurationTest.java
new file mode 100644
index 0000000000..2ff220d545
--- /dev/null
+++
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/config/ZookeeperSyncConfigurationTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.shenyu.admin.config;
+
+import org.apache.curator.test.TestingServer;
+import org.apache.shenyu.admin.config.properties.ZookeeperConfig;
+import org.apache.shenyu.admin.listener.zookeeper.ZookeeperClient;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class ZookeeperSyncConfigurationTest {
+
+ private static TestingServer zkServer;
+
+ private static ZookeeperClient zkClient;
+
+ @BeforeAll
+ public static void setUpBeforeClass() throws Exception {
+ zkServer = new TestingServer();
+ ZookeeperConfig config = new
ZookeeperConfig(zkServer.getConnectString());
+ zkClient = new ZookeeperClient(config);
+ }
+
+ @AfterAll
+ public static void tearDown() throws Exception {
+ zkClient.close();
+ zkServer.stop();
+ }
+
+ @Test
+ public void testZookeeperDataChangedListener() {
+ ZookeeperSyncConfiguration zookeeperListener = new
ZookeeperSyncConfiguration();
+
assertNotNull(zookeeperListener.zookeeperDataChangedListener(zkClient));
+ }
+
+ @Test
+ public void testZookeeperDataInit() {
+ ZookeeperSyncConfiguration zookeeperListener = new
ZookeeperSyncConfiguration();
+ assertNotNull(zookeeperListener.zookeeperDataChangedInit(zkClient));
+ }
+
+ @AfterEach
+ public void after() {
+ zkClient.close();
+ }
+
+}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/config/properties/AbstractConfigurationTest.java
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/config/properties/AbstractConfigurationTest.java
new file mode 100644
index 0000000000..77582635c7
--- /dev/null
+++
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/config/properties/AbstractConfigurationTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.shenyu.admin.config.properties;
+
+import org.junit.jupiter.api.AfterEach;
+import
org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.test.context.support.TestPropertySourceUtils;
+
+/**
+ * AbstractConfigurationTest for Configuration or Properties.
+ */
+public abstract class AbstractConfigurationTest {
+
+ private final AnnotationConfigApplicationContext context = new
AnnotationConfigApplicationContext();
+
+ /**
+ * Get the current mock context.
+ *
+ * @return AnnotationConfigApplicationContext
+ */
+ public AnnotationConfigApplicationContext getContext() {
+ return context;
+ }
+
+ /**
+ * clear context.
+ */
+ @AfterEach
+ public void clear() {
+ context.close();
+ }
+
+ /**
+ * Add properties to Environment and register configuration into spring
context.
+ *
+ * @param configuration the configuration class
+ * @param inlinedProperties the config properties
+ */
+ public void load(final Class<?> configuration, final String...
inlinedProperties) {
+ load(new Class<?>[]{configuration}, inlinedProperties);
+ }
+
+ /**
+ * Add properties to Environment and register configuration into spring
context.
+ *
+ * @param configuration the configuration class array
+ * @param inlinedProperties the config properties
+ */
+ public void load(final Class<?>[] configuration, final String...
inlinedProperties) {
+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
inlinedProperties);
+ this.context.register(configuration);
+ this.context.refresh();
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/ZookeeperPropertiesTest.java
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/config/properties/ZookeeperPropertiesTest.java
similarity index 92%
rename from
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/ZookeeperPropertiesTest.java
rename to
shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/config/properties/ZookeeperPropertiesTest.java
index 6b127a942f..432b477356 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/ZookeeperPropertiesTest.java
+++
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/config/properties/ZookeeperPropertiesTest.java
@@ -15,10 +15,8 @@
* limitations under the License.
*/
-package org.apache.shenyu.admin.config;
+package org.apache.shenyu.admin.config.properties;
-import org.apache.shenyu.admin.AbstractConfigurationTest;
-import org.apache.shenyu.admin.config.properties.ZookeeperProperties;
import
org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.junit.jupiter.api.Test;
@@ -30,7 +28,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
* Test case for ZookeeperProperties.
*/
public final class ZookeeperPropertiesTest extends AbstractConfigurationTest {
-
+
@Test
public void testLoadPropertiesBySpringContext() {
final String url = "127.0.0.1:2181";
@@ -47,7 +45,7 @@ public final class ZookeeperPropertiesTest extends
AbstractConfigurationTest {
assertThat(properties.getSessionTimeout(), is(sessionTimeOut));
assertThat(properties.getConnectionTimeout(), is(connectionTimeout));
}
-
+
@Configuration
@EnableConfigurationProperties(ZookeeperProperties.class)
static class ZookeeperPropertiesConfiguration {
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperClientTest.java
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperClientTest.java
new file mode 100644
index 0000000000..c637459c8e
--- /dev/null
+++
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperClientTest.java
@@ -0,0 +1,208 @@
+/*
+ * 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.shenyu.admin.listener.zookeeper;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.api.ACLBackgroundPathAndBytesable;
+import org.apache.curator.framework.api.BackgroundVersionable;
+import org.apache.curator.framework.api.ChildrenDeletable;
+import org.apache.curator.framework.api.CreateBuilder;
+import org.apache.curator.framework.api.CreateBuilder2;
+import org.apache.curator.framework.api.DeleteBuilder;
+import org.apache.curator.framework.api.GetChildrenBuilder;
+import org.apache.curator.framework.api.GetDataBuilder;
+import
org.apache.curator.framework.api.ProtectACLCreateModeStatPathAndBytesable;
+import org.apache.curator.framework.imps.ExistsBuilderImpl;
+import org.apache.curator.framework.recipes.cache.TreeCache;
+import org.apache.curator.framework.recipes.cache.TreeCacheListener;
+import org.apache.shenyu.admin.config.ZookeeperSyncConfiguration;
+import org.apache.shenyu.admin.config.properties.ZookeeperConfig;
+import org.apache.shenyu.admin.config.properties.ZookeeperProperties;
+import org.apache.shenyu.common.exception.ShenyuException;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.data.Stat;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+
+import java.lang.reflect.Field;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockConstruction;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+class ZookeeperClientTest {
+
+ private ZookeeperClient client;
+
+ private CuratorFramework curatorFramework;
+
+ @BeforeEach
+ public void setup() {
+ curatorFramework = mock(CuratorFramework.class);
+ try (MockedStatic<CuratorFrameworkFactory>
frameworkFactoryMockedStatic = mockStatic(CuratorFrameworkFactory.class)) {
+ CuratorFrameworkFactory.Builder builder =
mock(CuratorFrameworkFactory.Builder.class);
+
frameworkFactoryMockedStatic.when(CuratorFrameworkFactory::builder).thenReturn(builder);
+ when(builder.connectString(anyString())).thenReturn(builder);
+ when(builder.retryPolicy(any())).thenReturn(builder);
+ when(builder.connectionTimeoutMs(anyInt())).thenReturn(builder);
+ when(builder.sessionTimeoutMs(anyInt())).thenReturn(builder);
+ when(builder.namespace(anyString())).thenReturn(builder);
+ when(builder.build()).thenReturn(curatorFramework);
+ ZookeeperConfig config = new ZookeeperConfig("services");
+ config.setNamespace("namespace");
+ config.setDigest("digest");
+ client = new ZookeeperClient(config);
+ client.start();
+
doThrow(InterruptedException.class).when(curatorFramework).blockUntilConnected();
+ assertDoesNotThrow(() -> client.start());
+ } catch (Exception e) {
+ throw new ShenyuException(e);
+ }
+ }
+
+ @AfterEach
+ public void cleanup() {
+ client.close();
+ }
+
+ @Test
+ public void zookeeperClientTest() {
+ try (MockedConstruction<ZookeeperClient>
zookeeperClientMockedConstruction = mockConstruction(ZookeeperClient.class)) {
+ final ZookeeperProperties zookeeperProperties = new
ZookeeperProperties();
+ ZookeeperSyncConfiguration zookeeperListener = new
ZookeeperSyncConfiguration();
+
assertNotNull(zookeeperListener.zookeeperClient(zookeeperProperties));
+ zookeeperProperties.setSessionTimeout(3000);
+ zookeeperProperties.setConnectionTimeout(3000);
+
assertNotNull(zookeeperListener.zookeeperClient(zookeeperProperties));
+ }
+ }
+
+ @Test
+ void getClient() {
+ CuratorFramework curatorFramework = client.getClient();
+ assertNotNull(curatorFramework);
+ }
+
+ @Test
+ void isExist() throws Exception {
+ assertThrows(ShenyuException.class, () -> client.isExist("/test"));
+ ExistsBuilderImpl existsBuilder = mock(ExistsBuilderImpl.class);
+ when(curatorFramework.checkExists()).thenReturn(existsBuilder);
+ when(existsBuilder.forPath(anyString())).thenReturn(new Stat());
+ boolean exist = client.isExist("/test");
+ assertTrue(exist);
+ }
+
+ @Test
+ void getDirectly() throws Exception {
+ assertThrows(ShenyuException.class, () -> client.getDirectly("/test"));
+ GetDataBuilder getDataBuilder = mock(GetDataBuilder.class);
+ when(curatorFramework.getData()).thenReturn(getDataBuilder);
+
when(getDataBuilder.forPath(anyString())).thenReturn("hello".getBytes());
+ String val = client.getDirectly("/test");
+ assertEquals("hello", val);
+ when(getDataBuilder.forPath(anyString())).thenReturn(null);
+ String val2 = client.getDirectly("/test");
+ assertNull(val2);
+ }
+
+ @Test
+ void delete() throws Exception {
+ assertThrows(ShenyuException.class, () -> client.delete("/test"));
+ DeleteBuilder deleteBuilder = mock(DeleteBuilder.class);
+ when(curatorFramework.delete()).thenReturn(deleteBuilder);
+ ChildrenDeletable childrenDeletable = mock(ChildrenDeletable.class);
+ when(deleteBuilder.guaranteed()).thenReturn(childrenDeletable);
+ BackgroundVersionable backgroundVersionable =
mock(BackgroundVersionable.class);
+
when(childrenDeletable.deletingChildrenIfNeeded()).thenReturn(backgroundVersionable);
+ doNothing().when(backgroundVersionable).forPath(anyString());
+ assertDoesNotThrow(() -> client.delete("/test"));
+ }
+
+ @Test
+ void getChildren() throws Exception {
+ assertThrows(ShenyuException.class, () -> client.getChildren("/test"));
+ GetChildrenBuilder getChildrenBuilder = mock(GetChildrenBuilder.class);
+ when(curatorFramework.getChildren()).thenReturn(getChildrenBuilder);
+ when(getChildrenBuilder.forPath(anyString())).thenReturn(new
ArrayList<>());
+ List<String> children = client.getChildren("/test");
+ assertEquals(0, children.size());
+ }
+
+ @Test
+ void createOrUpdate() throws Exception {
+ assertThrows(ShenyuException.class, () ->
+ client.createOrUpdate("/test", "hello",
CreateMode.PERSISTENT));
+ CreateBuilder createBuilder = mock(CreateBuilder.class);
+ when(curatorFramework.create()).thenReturn(createBuilder);
+ CreateBuilder2 createBuilder2 = mock(CreateBuilder2.class);
+ when(createBuilder.orSetData()).thenReturn(createBuilder2);
+ ProtectACLCreateModeStatPathAndBytesable
protectACLCreateModeStatPathAndBytesable =
mock(ProtectACLCreateModeStatPathAndBytesable.class);
+
when(createBuilder2.creatingParentsIfNeeded()).thenReturn(protectACLCreateModeStatPathAndBytesable);
+ ACLBackgroundPathAndBytesable pathAndBytesable =
mock(ACLBackgroundPathAndBytesable.class);
+
when(protectACLCreateModeStatPathAndBytesable.withMode(any())).thenReturn(pathAndBytesable);
+ when(pathAndBytesable.forPath(anyString(),
any(byte[].class))).thenReturn(null);
+ client.createOrUpdate("/test", "hello", CreateMode.PERSISTENT);
+ client.createOrUpdate("", "hello", CreateMode.PERSISTENT);
+ client.createOrUpdate("", (Object) null, CreateMode.PERSISTENT);
+ client.createOrUpdate("", new Object(), CreateMode.PERSISTENT);
+ }
+
+ @Test
+ void cacheTest() throws Exception {
+ assertThrows(ShenyuException.class, () -> client.addCache("/path",
mock(TreeCacheListener.class), mock(TreeCacheListener.class)));
+ Field clientField = ZookeeperClient.class.getDeclaredField("client");
+ clientField.setAccessible(true);
+ CuratorFramework curatorFramework = mock(CuratorFramework.class);
+ clientField.set(client, curatorFramework);
+
+ GetDataBuilder getDataBuilder = mock(GetDataBuilder.class);
+ when(curatorFramework.getData()).thenReturn(getDataBuilder);
+
when(getDataBuilder.forPath(any())).thenReturn("path".getBytes(StandardCharsets.UTF_8));
+ client.get("/path");
+ client.get("/test");
+ client.getCache("/test");
+ MockedStatic<TreeCache> treeCacheMockedStatic =
mockStatic(TreeCache.class);
+ TreeCache.Builder treeCacheBuilder = mock(TreeCache.Builder.class);
+ treeCacheMockedStatic.when(() -> TreeCache.newBuilder(any(),
any())).thenReturn(treeCacheBuilder);
+ TreeCache treeCache = mock(TreeCache.class);
+ when(treeCacheBuilder.build()).thenReturn(treeCache);
+ when(treeCache.start()).thenThrow(ShenyuException.class);
+ Assertions.assertThrows(ShenyuException.class, () ->
client.addCache("/path"));
+ treeCacheMockedStatic.close();
+ }
+}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedInitTest.java
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedInitTest.java
index d804b544c4..ef9b49ad9c 100644
---
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedInitTest.java
+++
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedInitTest.java
@@ -18,7 +18,6 @@
package org.apache.shenyu.admin.listener.zookeeper;
import org.apache.shenyu.common.constant.DefaultPathConstants;
-import org.apache.shenyu.register.client.server.zookeeper.ZookeeperClient;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedListenerTest.java
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedListenerTest.java
index d9c3d94c77..e3a640256a 100644
---
a/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedListenerTest.java
+++
b/shenyu-admin-listener/shenyu-admin-listener-zookeeper/src/test/java/org/apache/shenyu/admin/listener/zookeeper/ZookeeperDataChangedListenerTest.java
@@ -25,7 +25,6 @@ import org.apache.shenyu.common.dto.PluginData;
import org.apache.shenyu.common.dto.RuleData;
import org.apache.shenyu.common.dto.SelectorData;
import org.apache.shenyu.common.enums.DataEventTypeEnum;
-import org.apache.shenyu.register.client.server.zookeeper.ZookeeperClient;
import org.apache.zookeeper.CreateMode;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
diff --git a/shenyu-admin/pom.xml b/shenyu-admin/pom.xml
index eea81af418..8983006bca 100644
--- a/shenyu-admin/pom.xml
+++ b/shenyu-admin/pom.xml
@@ -26,7 +26,6 @@
<artifactId>shenyu-admin</artifactId>
<properties>
- <commons-io.version>2.11.0</commons-io.version>
<orai18n.version>19.7.0.0</orai18n.version>
</properties>
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/DataSyncConfigurationTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/DataSyncConfigurationTest.java
deleted file mode 100644
index 7115ed7999..0000000000
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/DataSyncConfigurationTest.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * 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.shenyu.admin.config;
-
-import com.alibaba.nacos.api.NacosFactory;
-import com.alibaba.nacos.api.config.ConfigService;
-import com.alibaba.nacos.client.config.NacosConfigService;
-import com.ecwid.consul.v1.ConsulClient;
-import com.tencent.polaris.configuration.api.core.ConfigFilePublishService;
-import com.tencent.polaris.configuration.api.core.ConfigFileService;
-import org.apache.curator.test.TestingServer;
-import org.apache.shenyu.admin.AbstractConfigurationTest;
-import org.apache.shenyu.admin.config.properties.ConsulProperties;
-import org.apache.shenyu.admin.config.properties.HttpSyncProperties;
-import org.apache.shenyu.admin.config.properties.NacosProperties;
-import org.apache.shenyu.admin.config.properties.PolarisProperties;
-import org.apache.shenyu.admin.config.properties.ZookeeperProperties;
-import org.apache.shenyu.admin.listener.etcd.EtcdClient;
-import org.apache.shenyu.admin.service.DiscoveryService;
-import org.apache.shenyu.admin.service.MetaDataService;
-import org.apache.shenyu.admin.service.PluginService;
-import org.apache.shenyu.admin.service.RuleService;
-import org.apache.shenyu.admin.service.SelectorService;
-import org.apache.shenyu.admin.service.SyncDataService;
-import org.apache.shenyu.admin.service.impl.AppAuthServiceImpl;
-import org.apache.shenyu.admin.service.impl.SyncDataServiceImpl;
-import org.apache.shenyu.register.client.server.zookeeper.ZookeeperClient;
-import org.apache.shenyu.register.client.server.zookeeper.ZookeeperConfig;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockedConstruction;
-import org.mockito.MockedStatic;
-import org.mockito.junit.jupiter.MockitoExtension;
-import
org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.ApplicationEventPublisher;
-
-import java.util.Properties;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.mockConstruction;
-import static org.mockito.Mockito.mockStatic;
-import static org.mockito.Mockito.when;
-
-/**
- * The TestCase for {@link DataSyncConfiguration}.
- */
-@ExtendWith(MockitoExtension.class)
-@EnableConfigurationProperties(HttpSyncProperties.class)
-public final class DataSyncConfigurationTest extends AbstractConfigurationTest
{
-
- private static TestingServer zkServer;
-
- private static ZookeeperClient zkClient;
-
- @InjectMocks
- private AppAuthServiceImpl appAuthService;
-
- @Mock
- private PluginService pluginService;
-
- @Mock
- private SelectorService selectorService;
-
- @Mock
- private RuleService ruleService;
-
- @Mock
- private ApplicationEventPublisher eventPublisher;
-
- @Mock
- private MetaDataService metaDataService;
-
- @Mock
- private DiscoveryService discoveryService;
-
- @BeforeAll
- public static void setUpBeforeClass() throws Exception {
- zkServer = new TestingServer();
- ZookeeperConfig config = new
ZookeeperConfig(zkServer.getConnectString());
- zkClient = new ZookeeperClient(config);
- }
-
- @AfterAll
- public static void tearDown() throws Exception {
- zkClient.close();
- zkServer.stop();
- }
-
- @Test
- public void testHttpLongPollingDataChangedListener() {
- final HttpSyncProperties httpSyncProperties = new HttpSyncProperties();
- HttpLongPollingSyncConfiguration httpLongPollingListener = new
HttpLongPollingSyncConfiguration();
-
assertNotNull(httpLongPollingListener.httpLongPollingDataChangedListener(httpSyncProperties));
- }
-
- @Test
- public void zookeeperClientTest() {
- try (MockedConstruction<ZookeeperClient>
zookeeperClientMockedConstruction = mockConstruction(ZookeeperClient.class)) {
- final ZookeeperProperties zookeeperProperties = new
ZookeeperProperties();
- ZookeeperSyncConfiguration zookeeperListener = new
ZookeeperSyncConfiguration();
-
assertNotNull(zookeeperListener.zookeeperClient(zookeeperProperties));
- zookeeperProperties.setSessionTimeout(3000);
- zookeeperProperties.setConnectionTimeout(3000);
-
assertNotNull(zookeeperListener.zookeeperClient(zookeeperProperties));
- }
- }
-
- @Test
- public void testZookeeperDataChangedListener() {
- ZookeeperSyncConfiguration zookeeperListener = new
ZookeeperSyncConfiguration();
-
assertNotNull(zookeeperListener.zookeeperDataChangedListener(zkClient));
- }
-
- @Test
- public void testZookeeperDataInit() {
- final SyncDataService syncDataService = new
SyncDataServiceImpl(appAuthService, pluginService, selectorService,
- ruleService, eventPublisher, metaDataService,
discoveryService);
- ZookeeperSyncConfiguration zookeeperListener = new
ZookeeperSyncConfiguration();
- assertNotNull(zookeeperListener.zookeeperDataChangedInit(zkClient));
- }
-
- @Test
- public void testWebsocketDataChangedListener() {
- WebSocketSyncConfiguration websocketListener = new
WebSocketSyncConfiguration();
- assertNotNull(websocketListener.websocketDataChangedListener());
- }
-
- @Test
- public void testWebsocketCollector() {
- WebSocketSyncConfiguration websocketListener = new
WebSocketSyncConfiguration();
- assertNotNull(websocketListener.websocketCollector());
- }
-
- @Test
- public void testServerEndpointExporter() {
- WebSocketSyncConfiguration websocketListener = new
WebSocketSyncConfiguration();
- assertNotNull(websocketListener.serverEndpointExporter());
- }
-
- @Test
- public void testNacosDataChangedListener() {
- NacosSyncConfiguration nacosListener = new NacosSyncConfiguration();
- NacosConfigService configService = mock(NacosConfigService.class);
- assertNotNull(nacosListener.nacosDataChangedListener(configService));
- }
-
- @Test
- public void testNacosDataInit() {
- NacosSyncConfiguration nacosListener = new NacosSyncConfiguration();
- NacosConfigService configService = mock(NacosConfigService.class);
- assertNotNull(nacosListener.nacosDataChangedInit(configService));
- }
-
- @Test
- public void nacosConfigServiceTest() {
- try (MockedStatic<NacosFactory> nacosFactoryMockedStatic =
mockStatic(NacosFactory.class)) {
- final NacosProperties nacosProperties = new NacosProperties();
- final NacosProperties.NacosACMProperties nacosACMProperties = new
NacosProperties.NacosACMProperties();
- nacosProperties.setAcm(nacosACMProperties);
- nacosFactoryMockedStatic.when(() ->
NacosFactory.createConfigService(any(Properties.class))).thenReturn(mock(ConfigService.class));
- NacosSyncConfiguration nacosListener = new
NacosSyncConfiguration();
- nacosProperties.setUrl("url");
- Assertions.assertDoesNotThrow(() ->
nacosListener.nacosConfigService(nacosProperties));
- nacosProperties.setNamespace("url");
- nacosProperties.setUsername("username");
- nacosProperties.setPassword("password");
- Assertions.assertDoesNotThrow(() ->
nacosListener.nacosConfigService(nacosProperties));
- nacosACMProperties.setEnabled(true);
- nacosACMProperties.setEndpoint("acm.aliyun.com");
- nacosACMProperties.setAccessKey("accessKey");
- nacosACMProperties.setNamespace("namespace");
- nacosACMProperties.setSecretKey("secretKey");
- Assertions.assertDoesNotThrow(() ->
nacosListener.nacosConfigService(nacosProperties));
- }
- }
-
- @Test
- public void testPolarisDataChangedListener() {
- PolarisSyncConfiguration polarisListener = new
PolarisSyncConfiguration();
- PolarisProperties polarisProperties = mock(PolarisProperties.class);
- ConfigFileService polarisConfigFileService =
mock(ConfigFileService.class);
- ConfigFilePublishService polarisConfigFilePublishService =
mock(ConfigFilePublishService.class);
-
assertNotNull(polarisListener.polarisDataChangedListener(polarisProperties,
polarisConfigFileService, polarisConfigFilePublishService));
- }
-
- @Test
- public void testPolarisDataInit() {
- PolarisSyncConfiguration polarisListener = new
PolarisSyncConfiguration();
- PolarisProperties polarisProperties = mock(PolarisProperties.class);
- ConfigFileService polarisConfigFileService =
mock(ConfigFileService.class);
-
assertNotNull(polarisListener.polarisDataChangedInit(polarisProperties,
polarisConfigFileService));
- }
-
- @Test
- public void polarisConfigServiceTest() {
- final PolarisProperties polarisProperties = new PolarisProperties();
- polarisProperties.setUrl("127.0.0.1:8093");
- polarisProperties.setNamespace("namespace");
- PolarisSyncConfiguration polarisListener = new
PolarisSyncConfiguration();
-
assertNotNull(polarisListener.polarisConfigFileService(polarisProperties));
-
assertNotNull(polarisListener.polarisConfigFilePublishService(polarisProperties));
- }
-
- @Test
- public void testEtcdDataChangedListener() {
- EtcdSyncConfiguration etcdListener = new EtcdSyncConfiguration();
- EtcdClient client = mock(EtcdClient.class);
- assertNotNull(etcdListener.etcdDataChangedListener(client));
- }
-
- @Test
- public void testEtcdDataInit() {
- EtcdSyncConfiguration etcdListener = new EtcdSyncConfiguration();
- EtcdClient client = mock(EtcdClient.class);
- SyncDataService syncDataService = mock(SyncDataService.class);
- assertNotNull(etcdListener.etcdDataChangedInit(client));
- }
-
- @Test
- public void testConsulClient() {
- ConsulSyncConfiguration consulListener = new ConsulSyncConfiguration();
- ConsulProperties consulProperties = mock(ConsulProperties.class);
- when(consulProperties.getUrl()).thenReturn("http://127.0.0.1:8500");
- assertNotNull(consulListener.consulClient(consulProperties));
- }
-
- @Test
- public void testConsulDataChangedListener() {
- ConsulSyncConfiguration consulListener = new ConsulSyncConfiguration();
- ConsulClient consulClient = mock(ConsulClient.class);
- assertNotNull(consulListener.consulDataChangedListener(consulClient));
- }
-
- @Test
- public void testConsulDataInit() {
- ConsulSyncConfiguration consulListener = new ConsulSyncConfiguration();
- ConsulClient consulClient = mock(ConsulClient.class);
- SyncDataService syncDataService = mock(SyncDataService.class);
- assertNotNull(consulListener.consulDataChangedInit(consulClient));
- }
-
- @AfterEach
- public void after() {
- zkClient.close();
- }
-}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/ConsulPropertiesTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/HttpLongPollingSyncConfigurationTest.java
similarity index 60%
copy from
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/ConsulPropertiesTest.java
copy to
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/HttpLongPollingSyncConfigurationTest.java
index 6f1e673260..8959f75e64 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/ConsulPropertiesTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/HttpLongPollingSyncConfigurationTest.java
@@ -15,20 +15,19 @@
* limitations under the License.
*/
-package org.apache.shenyu.admin.config.properties;
+package org.apache.shenyu.admin.config;
-import org.junit.jupiter.api.Assertions;
+import org.apache.shenyu.admin.config.properties.HttpSyncProperties;
import org.junit.jupiter.api.Test;
-/**
- * Test cases for {@link ConsulProperties}.
- */
-public class ConsulPropertiesTest {
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class HttpLongPollingSyncConfigurationTest {
@Test
- public void consulPropertiesTest() {
- final ConsulProperties consulProperties = new ConsulProperties();
- consulProperties.setUrl("url");
- Assertions.assertEquals(consulProperties.getUrl(), "url");
+ public void testHttpLongPollingDataChangedListener() {
+ final HttpSyncProperties httpSyncProperties = new HttpSyncProperties();
+ HttpLongPollingSyncConfiguration httpLongPollingListener = new
HttpLongPollingSyncConfiguration();
+
assertNotNull(httpLongPollingListener.httpLongPollingDataChangedListener(httpSyncProperties));
}
}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/ConsulPropertiesTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/WebSocketSyncConfigurationTest.java
similarity index 51%
rename from
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/ConsulPropertiesTest.java
rename to
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/WebSocketSyncConfigurationTest.java
index 6f1e673260..0ef0be9f58 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/ConsulPropertiesTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/WebSocketSyncConfigurationTest.java
@@ -15,20 +15,29 @@
* limitations under the License.
*/
-package org.apache.shenyu.admin.config.properties;
+package org.apache.shenyu.admin.config;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-/**
- * Test cases for {@link ConsulProperties}.
- */
-public class ConsulPropertiesTest {
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class WebSocketSyncConfigurationTest {
+
+ @Test
+ public void testWebsocketDataChangedListener() {
+ WebSocketSyncConfiguration websocketListener = new
WebSocketSyncConfiguration();
+ assertNotNull(websocketListener.websocketDataChangedListener());
+ }
+
+ @Test
+ public void testWebsocketCollector() {
+ WebSocketSyncConfiguration websocketListener = new
WebSocketSyncConfiguration();
+ assertNotNull(websocketListener.websocketCollector());
+ }
@Test
- public void consulPropertiesTest() {
- final ConsulProperties consulProperties = new ConsulProperties();
- consulProperties.setUrl("url");
- Assertions.assertEquals(consulProperties.getUrl(), "url");
+ public void testServerEndpointExporter() {
+ WebSocketSyncConfiguration websocketListener = new
WebSocketSyncConfiguration();
+ assertNotNull(websocketListener.serverEndpointExporter());
}
}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/HttpSyncPropertiesTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/HttpSyncPropertiesTest.java
similarity index 95%
rename from
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/HttpSyncPropertiesTest.java
rename to
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/HttpSyncPropertiesTest.java
index 2e096306fa..4205574ad2 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/HttpSyncPropertiesTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/HttpSyncPropertiesTest.java
@@ -15,10 +15,9 @@
* limitations under the License.
*/
-package org.apache.shenyu.admin.config;
+package org.apache.shenyu.admin.config.properties;
import org.apache.shenyu.admin.AbstractConfigurationTest;
-import org.apache.shenyu.admin.config.properties.HttpSyncProperties;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/WebsocketSyncPropertiesTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/WebsocketSyncPropertiesTest.java
similarity index 95%
rename from
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/WebsocketSyncPropertiesTest.java
rename to
shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/WebsocketSyncPropertiesTest.java
index 68b18fd404..14abcceaa1 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/WebsocketSyncPropertiesTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/WebsocketSyncPropertiesTest.java
@@ -15,10 +15,9 @@
* limitations under the License.
*/
-package org.apache.shenyu.admin.config;
+package org.apache.shenyu.admin.config.properties;
import org.apache.shenyu.admin.AbstractConfigurationTest;
-import org.apache.shenyu.admin.config.properties.WebsocketSyncProperties;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import
org.springframework.boot.context.properties.EnableConfigurationProperties;
diff --git
a/shenyu-web/src/main/java/org/apache/shenyu/web/logo/ShenyuLogo.java
b/shenyu-web/src/main/java/org/apache/shenyu/web/logo/ShenyuLogo.java
deleted file mode 100644
index 6e1fd16221..0000000000
--- a/shenyu-web/src/main/java/org/apache/shenyu/web/logo/ShenyuLogo.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.shenyu.web.logo;
-
-import org.apache.shenyu.common.constant.Constants;
-import org.apache.shenyu.common.utils.VersionUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import
org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
-import org.springframework.boot.context.logging.LoggingApplicationListener;
-import org.springframework.context.ApplicationListener;
-import org.springframework.core.annotation.Order;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * the shenyu logo.
- */
-@Order(LoggingApplicationListener.DEFAULT_ORDER + 1)
-public class ShenyuLogo implements
ApplicationListener<ApplicationEnvironmentPreparedEvent> {
-
- private static final Logger LOG =
LoggerFactory.getLogger(ShenyuLogo.class);
-
- private static final String SHENYU_LOGO = "\n"
- + " _____ _ \n"
- + " / ____| | \n"
- + " | (___ | |__ ___ _ __ _ _ _ _ \n"
- + " \\___ \\| '_ \\ / _ \\ '_ \\| | | | | | |\n"
- + " ____) | | | | __/ | | | |_| | |_| |\n"
- + " |_____/|_| |_|\\___|_| |_|\\__, |\\__,_|\n"
- + " __/ | \n"
- + " |___/ ";
-
- private static final AtomicBoolean ALREADY_LOG = new AtomicBoolean(false);
-
- @Override
- public void onApplicationEvent(final ApplicationEnvironmentPreparedEvent
event) {
- if (!ALREADY_LOG.compareAndSet(false, true)) {
- return;
- }
- LOG.info(buildBannerText());
- }
-
- private String buildBannerText() {
- return Constants.LINE_SEPARATOR
- + Constants.LINE_SEPARATOR
- + SHENYU_LOGO
- + Constants.LINE_SEPARATOR
- + " :: Shenyu :: (v" + VersionUtils.getVersion(getClass(),
"2.3.0") + ")"
- + Constants.LINE_SEPARATOR;
- }
-}
diff --git
a/shenyu-web/src/test/java/org/apache/shenyu/web/logo/ShenyuLogoTest.java
b/shenyu-web/src/test/java/org/apache/shenyu/web/logo/ShenyuLogoTest.java
deleted file mode 100644
index d72463c96a..0000000000
--- a/shenyu-web/src/test/java/org/apache/shenyu/web/logo/ShenyuLogoTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.shenyu.web.logo;
-
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.SpringApplication;
-import
org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
-import org.springframework.core.env.ConfigurableEnvironment;
-import org.springframework.mock.env.MockEnvironment;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-/**
- * The TestCase for ShenyuLogo.
- */
-public final class ShenyuLogoTest {
-
- private final ShenyuLogo shenyuLogo = new ShenyuLogo();
-
- @Test
- public void testBuildBannerText() throws NoSuchMethodException,
InvocationTargetException, IllegalAccessException {
- Method method =
shenyuLogo.getClass().getDeclaredMethod("buildBannerText", (Class<?>[]) null);
- method.setAccessible(true);
- Object logInfo = method.invoke(shenyuLogo);
- assertTrue(logInfo instanceof String);
- }
-
- @Test
- public void testOnApplicationEvent() throws NoSuchFieldException,
IllegalAccessException {
- SpringApplication application = new SpringApplication();
- ConfigurableEnvironment environment = new MockEnvironment();
- ApplicationEnvironmentPreparedEvent event = new
ApplicationEnvironmentPreparedEvent(null, application, null, environment);
- shenyuLogo.onApplicationEvent(event);
- shenyuLogo.onApplicationEvent(event);
- Field field = shenyuLogo.getClass().getDeclaredField("ALREADY_LOG");
- field.setAccessible(true);
- AtomicBoolean atomicBoolean = (AtomicBoolean) field.get(shenyuLogo);
- assertTrue(atomicBoolean.get());
- }
-
-}