diff --git a/microsphere-spring-cloud-commons/pom.xml b/microsphere-spring-cloud-commons/pom.xml index a9e9c7f..f4ce6fa 100644 --- a/microsphere-spring-cloud-commons/pom.xml +++ b/microsphere-spring-cloud-commons/pom.xml @@ -86,10 +86,22 @@ + + org.junit.jupiter + junit-jupiter + test + + org.springframework.boot spring-boot-starter-test test + + + org.junit.vintage + junit-vintage-engine + + 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 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/pom.xml b/microsphere-spring-cloud-openfeign/pom.xml index be05c2c..d750450 100644 --- a/microsphere-spring-cloud-openfeign/pom.xml +++ b/microsphere-spring-cloud-openfeign/pom.xml @@ -50,16 +50,23 @@ true + - org.springframework.boot - spring-boot-starter-test + org.junit.jupiter + junit-jupiter test - org.springframework.cloud - spring-cloud-starter-loadbalancer - true + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + 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 {