From 235b587d1b244fe4bc38ff4506bfb2336c1af096 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 16 Jan 2025 11:59:24 +0800 Subject: [PATCH 1/5] Polish #33 : Exclude junit 4 on spring-cloud-hoxton --- microsphere-spring-cloud-commons/pom.xml | 6 ++++++ microsphere-spring-cloud-openfeign/pom.xml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/microsphere-spring-cloud-commons/pom.xml b/microsphere-spring-cloud-commons/pom.xml index a9e9c7f..b70148f 100644 --- a/microsphere-spring-cloud-commons/pom.xml +++ b/microsphere-spring-cloud-commons/pom.xml @@ -90,6 +90,12 @@ org.springframework.boot spring-boot-starter-test test + + + junit + junit + + diff --git a/microsphere-spring-cloud-openfeign/pom.xml b/microsphere-spring-cloud-openfeign/pom.xml index be05c2c..eaf4491 100644 --- a/microsphere-spring-cloud-openfeign/pom.xml +++ b/microsphere-spring-cloud-openfeign/pom.xml @@ -54,6 +54,12 @@ org.springframework.boot spring-boot-starter-test test + + + junit + junit + + From b5b16cacdf0237e37e19a8431dc736cfbb982a44 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 16 Jan 2025 12:02:26 +0800 Subject: [PATCH 2/5] Polish #33 : Add junit-jupiter --- microsphere-spring-cloud-commons/pom.xml | 8 +++++++- microsphere-spring-cloud-openfeign/pom.xml | 13 +++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/microsphere-spring-cloud-commons/pom.xml b/microsphere-spring-cloud-commons/pom.xml index b70148f..6dfd98a 100644 --- a/microsphere-spring-cloud-commons/pom.xml +++ b/microsphere-spring-cloud-commons/pom.xml @@ -84,8 +84,14 @@ microsphere-spring-webflux true - + + + org.junit.jupiter + junit-jupiter + test + + org.springframework.boot spring-boot-starter-test diff --git a/microsphere-spring-cloud-openfeign/pom.xml b/microsphere-spring-cloud-openfeign/pom.xml index eaf4491..3bc6e13 100644 --- a/microsphere-spring-cloud-openfeign/pom.xml +++ b/microsphere-spring-cloud-openfeign/pom.xml @@ -50,6 +50,13 @@ true + + + org.junit.jupiter + junit-jupiter + test + + org.springframework.boot spring-boot-starter-test @@ -62,12 +69,6 @@ - - org.springframework.cloud - spring-cloud-starter-loadbalancer - true - - \ No newline at end of file From c1f0a704e073e1c6db3d1faeb0cc4c366eff2c41 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 16 Jan 2025 12:07:45 +0800 Subject: [PATCH 3/5] Polish #33 : Exclude junit-vintage-engine --- microsphere-spring-cloud-commons/pom.xml | 6 +++--- microsphere-spring-cloud-openfeign/pom.xml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/microsphere-spring-cloud-commons/pom.xml b/microsphere-spring-cloud-commons/pom.xml index 6dfd98a..f4ce6fa 100644 --- a/microsphere-spring-cloud-commons/pom.xml +++ b/microsphere-spring-cloud-commons/pom.xml @@ -84,7 +84,7 @@ microsphere-spring-webflux true - + org.junit.jupiter @@ -98,8 +98,8 @@ test - junit - junit + org.junit.vintage + junit-vintage-engine diff --git a/microsphere-spring-cloud-openfeign/pom.xml b/microsphere-spring-cloud-openfeign/pom.xml index 3bc6e13..d750450 100644 --- a/microsphere-spring-cloud-openfeign/pom.xml +++ b/microsphere-spring-cloud-openfeign/pom.xml @@ -63,8 +63,8 @@ test - junit - junit + org.junit.vintage + junit-vintage-engine From 6a8e06dbe5fcd2cc5f1edc455e9e206a43bc40f6 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 16 Jan 2025 12:09:42 +0800 Subject: [PATCH 4/5] Polish #33 : Add ServiceInstancesChangedEvent test --- .../event/ServiceInstancesChangedEvent.java | 12 ++-- .../ServiceInstancesChangedEventTest.java | 68 +++++++++++++++++++ 2 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/event/ServiceInstancesChangedEventTest.java diff --git a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/event/ServiceInstancesChangedEvent.java b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/event/ServiceInstancesChangedEvent.java index e13600c..95e6c25 100644 --- a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/event/ServiceInstancesChangedEvent.java +++ b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/event/ServiceInstancesChangedEvent.java @@ -16,24 +16,19 @@ */ package io.microsphere.spring.cloud.client.event; -/** - * TODO Comment - * - * @author Mercy - * @since TODO - */ - import org.springframework.cloud.client.ServiceInstance; import org.springframework.context.ApplicationEvent; import org.springframework.context.event.ApplicationEventMulticaster; import org.springframework.context.event.SimpleApplicationEventMulticaster; +import org.springframework.util.Assert; import java.util.List; import static java.util.Collections.unmodifiableList; +import static org.springframework.util.Assert.notEmpty; /** - * An event raised after the {@link ServiceInstance instances} of one service has been + * An event raised when the {@link ServiceInstance instances} of one service has been * changed. * * @author Mercy @@ -58,6 +53,7 @@ public class ServiceInstancesChangedEvent extends ApplicationEvent { public ServiceInstancesChangedEvent(String serviceName, List serviceInstances) { super(serviceName); + notEmpty(serviceInstances, () -> "The arguments 'serviceInstances' must not be empty!"); this.serviceInstances = unmodifiableList(serviceInstances); } diff --git a/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/event/ServiceInstancesChangedEventTest.java b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/event/ServiceInstancesChangedEventTest.java new file mode 100644 index 0000000..63d6403 --- /dev/null +++ b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/event/ServiceInstancesChangedEventTest.java @@ -0,0 +1,68 @@ +package io.microsphere.spring.cloud.client.event; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.cloud.client.DefaultServiceInstance; +import org.springframework.cloud.client.ServiceInstance; + +import java.net.URI; +import java.util.Arrays; +import java.util.UUID; + + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * {@link ServiceInstancesChangedEvent} Test + * + * @author Mercy + * @see ServiceInstancesChangedEvent + * @since 1.0.0 + */ +public class ServiceInstancesChangedEventTest { + + private String serviceName = "testService"; + + private ServiceInstancesChangedEvent event; + + private ServiceInstance instance; + + @BeforeEach + public void init() { + this.instance = createInstance(serviceName); + this.event = new ServiceInstancesChangedEvent(serviceName, Arrays.asList(instance)); + } + + private ServiceInstance createInstance(String serviceName) { + DefaultServiceInstance instance = new DefaultServiceInstance(); + instance.setServiceId(serviceName); + instance.setServiceId(UUID.randomUUID().toString()); + instance.setHost("127.0.0.1"); + instance.setPort(8080); + instance.setUri(URI.create("http://127.0.0.1:8080/info")); + return instance; + } + + @Test + public void testGetServiceName() { + assertEquals(this.serviceName, this.event.getServiceName()); + assertEquals(this.serviceName, this.event.getSource()); + } + + @Test + public void testGetServiceInstances() { + assertEquals(Arrays.asList(this.instance), this.event.getServiceInstances()); + assertEquals(this.instance, this.event.getServiceInstances().get(0)); + assertSame(this.instance, this.event.getServiceInstances().get(0)); + } + + @Test + public void testProcessed() { + assertFalse(this.event.isProcessed()); + this.event.processed(); + assertTrue(this.event.isProcessed()); + } +} \ No newline at end of file From 2b80ef919219b67fc59bd37f2ca01f72721347fc Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 16 Jan 2025 18:42:57 +0800 Subject: [PATCH 5/5] Refactor --- .../ServiceRegistryAutoConfigurationTest.java | 14 ++++++++++++++ .../autoconfigure/EnableFeignAutoRefresh.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/ServiceRegistryAutoConfigurationTest.java diff --git a/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/ServiceRegistryAutoConfigurationTest.java b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/ServiceRegistryAutoConfigurationTest.java new file mode 100644 index 0000000..5b09845 --- /dev/null +++ b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/ServiceRegistryAutoConfigurationTest.java @@ -0,0 +1,14 @@ +package io.microsphere.spring.cloud.client.service.registry.autoconfigure; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * {@link ServiceRegistryAutoConfiguration} Test + * + * @author Mercy + * @see ServiceRegistryAutoConfiguration + * @since 1.0.0 + */ +public class ServiceRegistryAutoConfigurationTest { + +} \ No newline at end of file diff --git a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/EnableFeignAutoRefresh.java b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/EnableFeignAutoRefresh.java index 1587b12..7433fb0 100644 --- a/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/EnableFeignAutoRefresh.java +++ b/microsphere-spring-cloud-openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/autoconfigure/EnableFeignAutoRefresh.java @@ -19,7 +19,7 @@ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) @Documented -@Import(FeignClientAutoRefreshAutoConfiguration.class) +@Import(EnableFeignAutoRefresh.Marker.class) public @interface EnableFeignAutoRefresh { class Marker {