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 95e6c25..805706a 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 @@ -20,7 +20,6 @@ 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; diff --git a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/SimpleAutoServiceRegistrationAutoConfiguration.java b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/SimpleAutoServiceRegistrationAutoConfiguration.java index 7115ef0..81b4661 100644 --- a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/SimpleAutoServiceRegistrationAutoConfiguration.java +++ b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/SimpleAutoServiceRegistrationAutoConfiguration.java @@ -63,9 +63,9 @@ public class SimpleAutoServiceRegistrationAutoConfiguration { /** - * The property name prefix + * The property name prefix : "microsphere.spring.cloud.service-registry.auto-registration.simple." */ - public static final String PROPERTY_NAME_PREFIX = MICROSPHERE_SPRING_CLOUD_PROPERTY_NAME_PREFIX + "simple."; + public static final String PROPERTY_NAME_PREFIX = MICROSPHERE_SPRING_CLOUD_PROPERTY_NAME_PREFIX + "service-registry.auto-registration.simple."; @Bean public Registration registration( @@ -85,7 +85,6 @@ public Registration registration( return registration; } - @Bean @ConditionalOnMissingBean public ServiceRegistry serviceRegistry() { diff --git a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/condition/ConditionalOnAutoServiceRegistrationEnabled.java b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/condition/ConditionalOnAutoServiceRegistrationEnabled.java index 9da6d95..0db565e 100644 --- a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/condition/ConditionalOnAutoServiceRegistrationEnabled.java +++ b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/condition/ConditionalOnAutoServiceRegistrationEnabled.java @@ -40,7 +40,7 @@ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) @Documented -@ConditionalOnProperty(name = SERVICE_REGISTRY_AUTO_REGISTRATION_ENABLED_PROPERTY_NAME) +@ConditionalOnProperty(name = SERVICE_REGISTRY_AUTO_REGISTRATION_ENABLED_PROPERTY_NAME, matchIfMissing = true) public @interface ConditionalOnAutoServiceRegistrationEnabled { /** diff --git a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationDeregisteredEvent.java b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationDeregisteredEvent.java index 294583c..898b039 100644 --- a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationDeregisteredEvent.java +++ b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationDeregisteredEvent.java @@ -19,6 +19,8 @@ import org.springframework.cloud.client.serviceregistry.Registration; import org.springframework.cloud.client.serviceregistry.ServiceRegistry; +import static io.microsphere.spring.cloud.client.service.registry.event.RegistrationEvent.Type.DEREGISTERED; + /** * The after-{@link ServiceRegistry#deregister(Registration) deregister} event. * @@ -33,12 +35,8 @@ public RegistrationDeregisteredEvent(ServiceRegistry registry, Reg } @Override - public boolean isRegistered() { - return false; + public Type getType() { + return DEREGISTERED; } - @Override - public boolean isDeregistered() { - return true; - } } diff --git a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationEvent.java b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationEvent.java index d51d26a..b8e1b26 100644 --- a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationEvent.java +++ b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationEvent.java @@ -22,6 +22,11 @@ import org.springframework.lang.NonNull; import org.springframework.util.Assert; +import static io.microsphere.spring.cloud.client.service.registry.event.RegistrationEvent.Type.DEREGISTERED; +import static io.microsphere.spring.cloud.client.service.registry.event.RegistrationEvent.Type.PRE_DEREGISTERED; +import static io.microsphere.spring.cloud.client.service.registry.event.RegistrationEvent.Type.PRE_REGISTERED; +import static io.microsphere.spring.cloud.client.service.registry.event.RegistrationEvent.Type.REGISTERED; + /** * The Spring event for {@link ServiceRegistry} * @@ -80,7 +85,7 @@ public ServiceRegistry getRegistry() { * @return true if pre-registered */ public final boolean isPreRegistered() { - return !isRegistered(); + return getType() == PRE_REGISTERED; } /** @@ -89,7 +94,9 @@ public final boolean isPreRegistered() { * * @return true if registered */ - public abstract boolean isRegistered(); + public final boolean isRegistered() { + return getType() == REGISTERED; + } /** * Current event is raised before the {@link #getRegistration() registration} is @@ -98,7 +105,7 @@ public final boolean isPreRegistered() { * @return true if pre-deregistered */ public final boolean isPreDeregistered() { - return !isDeregistered(); + return getType() == PRE_DEREGISTERED; } /** @@ -107,6 +114,40 @@ public final boolean isPreDeregistered() { * * @return true if deregistered */ - public abstract boolean isDeregistered(); + public final boolean isDeregistered() { + return getType() == DEREGISTERED; + } + + /** + * Get the {@link Type} of the {@link RegistrationEvent} + * + * @return non-null + */ + public abstract Type getType(); + /** + * The {@link Type} of the {@link RegistrationEvent} + */ + public static enum Type { + + /** + * The {@link RegistrationPreRegisteredEvent} + */ + PRE_REGISTERED, + + /** + * The {@link RegistrationRegisteredEvent} + */ + REGISTERED, + + /** + * The {@link RegistrationPreDeregisteredEvent} + */ + PRE_DEREGISTERED, + + /** + * The {@link RegistrationDeregisteredEvent} + */ + DEREGISTERED + } } diff --git a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationPreDeregisteredEvent.java b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationPreDeregisteredEvent.java index 6e19475..3ef61b6 100644 --- a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationPreDeregisteredEvent.java +++ b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationPreDeregisteredEvent.java @@ -19,6 +19,8 @@ import org.springframework.cloud.client.serviceregistry.Registration; import org.springframework.cloud.client.serviceregistry.ServiceRegistry; +import static io.microsphere.spring.cloud.client.service.registry.event.RegistrationEvent.Type.PRE_DEREGISTERED; + /** * The before-{@link ServiceRegistry#deregister(Registration) deregister} event. * @@ -33,12 +35,7 @@ public RegistrationPreDeregisteredEvent(ServiceRegistry registry, } @Override - public boolean isRegistered() { - return false; - } - - @Override - public boolean isDeregistered() { - return false; + public Type getType() { + return PRE_DEREGISTERED; } } \ No newline at end of file diff --git a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationPreRegisteredEvent.java b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationPreRegisteredEvent.java index 2e0d192..ccceec1 100644 --- a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationPreRegisteredEvent.java +++ b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationPreRegisteredEvent.java @@ -19,6 +19,8 @@ import org.springframework.cloud.client.serviceregistry.Registration; import org.springframework.cloud.client.serviceregistry.ServiceRegistry; +import static io.microsphere.spring.cloud.client.service.registry.event.RegistrationEvent.Type.PRE_REGISTERED; + /** * The before-{@link ServiceRegistry#register(Registration) register} event. * @@ -33,12 +35,7 @@ public RegistrationPreRegisteredEvent(ServiceRegistry registry, Re } @Override - public boolean isRegistered() { - return false; - } - - @Override - public boolean isDeregistered() { - return false; + public Type getType() { + return PRE_REGISTERED; } } diff --git a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationRegisteredEvent.java b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationRegisteredEvent.java index cc20ed1..06306ac 100644 --- a/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationRegisteredEvent.java +++ b/microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/event/RegistrationRegisteredEvent.java @@ -19,6 +19,8 @@ import org.springframework.cloud.client.serviceregistry.Registration; import org.springframework.cloud.client.serviceregistry.ServiceRegistry; +import static io.microsphere.spring.cloud.client.service.registry.event.RegistrationEvent.Type.REGISTERED; + /** * The after-{@link ServiceRegistry#register(Registration) register} event. * @@ -33,12 +35,7 @@ public RegistrationRegisteredEvent(ServiceRegistry registry, Regis } @Override - public boolean isRegistered() { - return true; - } - - @Override - public boolean isDeregistered() { - return false; + public Type getType() { + return REGISTERED; } } \ No newline at end of file diff --git a/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/discovery/UnionDiscoveryClientTest.java b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/discovery/UnionDiscoveryClientTest.java index 064bf06..513a4a3 100644 --- a/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/discovery/UnionDiscoveryClientTest.java +++ b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/discovery/UnionDiscoveryClientTest.java @@ -16,7 +16,6 @@ */ package io.microsphere.spring.cloud.client.discovery; -import io.microsphere.spring.cloud.client.discovery.autoconfigure.DiscoveryClientAutoConfiguration; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/discovery/autoconfigure/DiscoveryClientAutoConfigurationTest.java b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/discovery/autoconfigure/DiscoveryClientAutoConfigurationTest.java index b8a1872..a13bb34 100644 --- a/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/discovery/autoconfigure/DiscoveryClientAutoConfigurationTest.java +++ b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/discovery/autoconfigure/DiscoveryClientAutoConfigurationTest.java @@ -28,7 +28,6 @@ import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClient; import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration; import org.springframework.cloud.commons.util.UtilAutoConfiguration; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; 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 index 63d6403..000595e 100644 --- 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 @@ -9,7 +9,6 @@ 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; diff --git a/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/actuate/autoconfigure/ServiceRegistrationEndpointAutoConfigurationTest.java b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/actuate/autoconfigure/ServiceRegistrationEndpointAutoConfigurationTest.java new file mode 100644 index 0000000..528396d --- /dev/null +++ b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/actuate/autoconfigure/ServiceRegistrationEndpointAutoConfigurationTest.java @@ -0,0 +1,45 @@ +package io.microsphere.spring.cloud.client.service.registry.actuate.autoconfigure; + +import io.microsphere.spring.cloud.client.service.registry.endpoint.ServiceDeregistrationEndpoint; +import io.microsphere.spring.cloud.client.service.registry.endpoint.ServiceRegistrationEndpoint; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * {@link ServiceRegistrationEndpointAutoConfiguration} Test + * + * @author Mercy + * @see ServiceRegistrationEndpointAutoConfiguration + * @since 1.0.0 + */ +@SpringBootTest( + classes = { + ServiceRegistrationEndpointAutoConfigurationTest.class + }, + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = { + "microsphere.spring.cloud.service-registry.auto-registration.simple.enabled=true", + "management.endpoint.serviceRegistration.enabled=true", + "management.endpoint.serviceDeregistration.enabled=true", + } +) +@EnableAutoConfiguration +public class ServiceRegistrationEndpointAutoConfigurationTest { + + @Autowired + private ObjectProvider serviceRegistrationEndpoint; + + @Autowired + private ObjectProvider serviceDeregistrationEndpoint; + + @Test + public void testEndpoints() { + assertNotNull(serviceRegistrationEndpoint); + } + +} \ 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 index 5b09845..4ba1fb5 100644 --- 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 @@ -1,6 +1,32 @@ package io.microsphere.spring.cloud.client.service.registry.autoconfigure; -import static org.junit.jupiter.api.Assertions.*; +import io.microsphere.spring.cloud.client.service.registry.DefaultRegistration; +import io.microsphere.spring.cloud.client.service.registry.InMemoryServiceRegistry; +import io.microsphere.spring.cloud.client.service.registry.event.RegistrationDeregisteredEvent; +import io.microsphere.spring.cloud.client.service.registry.event.RegistrationEvent; +import io.microsphere.spring.cloud.client.service.registry.event.RegistrationPreDeregisteredEvent; +import io.microsphere.spring.cloud.client.service.registry.event.RegistrationPreRegisteredEvent; +import io.microsphere.spring.cloud.client.service.registry.event.RegistrationRegisteredEvent; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.client.serviceregistry.Registration; +import org.springframework.cloud.client.serviceregistry.ServiceRegistry; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.EnableAspectJAutoProxy; + +import static io.microsphere.spring.cloud.client.service.registry.event.RegistrationEvent.Type.DEREGISTERED; +import static io.microsphere.spring.cloud.client.service.registry.event.RegistrationEvent.Type.PRE_DEREGISTERED; +import static io.microsphere.spring.cloud.client.service.registry.event.RegistrationEvent.Type.PRE_REGISTERED; +import static io.microsphere.spring.cloud.client.service.registry.event.RegistrationEvent.Type.REGISTERED; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.springframework.aop.support.AopUtils.getTargetClass; /** * {@link ServiceRegistryAutoConfiguration} Test @@ -9,6 +35,103 @@ * @see ServiceRegistryAutoConfiguration * @since 1.0.0 */ +@SpringBootTest( + classes = { + InMemoryServiceRegistry.class, + ServiceRegistryAutoConfiguration.class, + ServiceRegistryAutoConfigurationTest.class + } +) +@EnableAspectJAutoProxy public class ServiceRegistryAutoConfigurationTest { + @Autowired + private ConfigurableApplicationContext context; + + @Autowired + private ServiceRegistry serviceRegistry; + + private Registration registration; + + private int count; + + @BeforeEach + public void init() { + DefaultRegistration registration = new DefaultRegistration(); + registration.setServiceId("test-service"); + registration.setInstanceId("127.0.0.1:8080"); + this.registration = registration; + } + + @Test + public void testEventPublishingRegistrationAspect() { + + context.addApplicationListener(this::onApplicationEvent); + + serviceRegistry.register(registration); + + assertEquals(2, count); + + serviceRegistry.deregister(registration); + + assertEquals(4, count); + } + + private void onApplicationEvent(ApplicationEvent event) { + if (event instanceof RegistrationPreRegisteredEvent) { + onRegistrationPreRegisteredEvent((RegistrationPreRegisteredEvent) event); + } else if (event instanceof RegistrationRegisteredEvent) { + onRegistrationRegisteredEvent((RegistrationRegisteredEvent) event); + } else if (event instanceof RegistrationPreDeregisteredEvent) { + onRegistrationPreDeregisteredEvent((RegistrationPreDeregisteredEvent) event); + } else if (event instanceof RegistrationDeregisteredEvent) { + onRegistrationDeregisteredEvent((RegistrationDeregisteredEvent) event); + } + } + + private void onRegistrationPreRegisteredEvent(RegistrationPreRegisteredEvent event) { + assertRegistrationEvent(event); + assertTrue(event.isPreRegistered()); + assertFalse(event.isRegistered()); + assertFalse(event.isPreDeregistered()); + assertFalse(event.isDeregistered()); + assertEquals(PRE_REGISTERED, event.getType()); + } + + private void onRegistrationRegisteredEvent(RegistrationRegisteredEvent event) { + assertRegistrationEvent(event); + assertFalse(event.isPreRegistered()); + assertTrue(event.isRegistered()); + assertFalse(event.isPreDeregistered()); + assertFalse(event.isDeregistered()); + assertEquals(REGISTERED, event.getType()); + } + + private void onRegistrationPreDeregisteredEvent(RegistrationPreDeregisteredEvent event) { + assertRegistrationEvent(event); + assertFalse(event.isPreRegistered()); + assertFalse(event.isRegistered()); + assertTrue(event.isPreDeregistered()); + assertFalse(event.isDeregistered()); + assertEquals(PRE_DEREGISTERED, event.getType()); + } + + private void onRegistrationDeregisteredEvent(RegistrationDeregisteredEvent event) { + assertRegistrationEvent(event); + assertFalse(event.isPreRegistered()); + assertFalse(event.isRegistered()); + assertFalse(event.isPreDeregistered()); + assertTrue(event.isDeregistered()); + assertEquals(DEREGISTERED, event.getType()); + } + + private void assertRegistrationEvent(RegistrationEvent event) { + Registration registration = event.getRegistration(); + assertEquals(this.registration, registration); + assertSame(this.registration, registration); + assertSame(getTargetClass(this.serviceRegistry), getTargetClass(event.getRegistry())); + assertNotNull(event.getSource()); + assertNotNull(event.getType()); + count++; + } } \ No newline at end of file diff --git a/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/SimpleAutoServiceRegistrationAutoConfigurationTest.java b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/SimpleAutoServiceRegistrationAutoConfigurationTest.java new file mode 100644 index 0000000..7406277 --- /dev/null +++ b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/SimpleAutoServiceRegistrationAutoConfigurationTest.java @@ -0,0 +1,58 @@ +package io.microsphere.spring.cloud.client.service.registry.autoconfigure; + +import io.microsphere.spring.cloud.client.service.registry.SimpleAutoServiceRegistration; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.cloud.client.serviceregistry.Registration; +import org.springframework.cloud.client.serviceregistry.ServiceRegistry; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * {@link SimpleAutoServiceRegistrationAutoConfiguration} Test + * + * @author Mercy + * @see SimpleAutoServiceRegistrationAutoConfiguration + * @since 1.0.0 + */ +@SpringBootTest( + classes = { + SimpleAutoServiceRegistrationAutoConfigurationTest.class + }, + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = { + "microsphere.spring.cloud.service-registry.auto-registration.simple.enabled=true", + "spring.application.name=test-service" + } +) +@EnableAutoConfiguration +public class SimpleAutoServiceRegistrationAutoConfigurationTest { + + @Autowired + private Registration registration; + + @Autowired + private ServiceRegistry serviceRegistry; + + @Autowired + private SimpleAutoServiceRegistration simpleAutoServiceRegistration; + + @LocalServerPort + private Integer port; + + @Test + public void test() { + assertEquals("test-service", registration.getServiceId()); + assertNotNull(registration.getHost()); + assertNotNull(registration.getPort()); + assertNotNull(registration.getUri()); + assertNotNull(registration.getInstanceId()); + assertNotNull(registration.getMetadata()); + assertNotNull(port); + } + +} \ No newline at end of file diff --git a/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/WebMvcServiceRegistryAutoConfigurationTest.java b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/WebMvcServiceRegistryAutoConfigurationTest.java index f0693bf..5f24ed7 100644 --- a/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/WebMvcServiceRegistryAutoConfigurationTest.java +++ b/microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/WebMvcServiceRegistryAutoConfigurationTest.java @@ -18,7 +18,6 @@ import io.microsphere.spring.webmvc.annotation.EnableWebMvcExtension; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; @@ -38,7 +37,7 @@ @SpringBootTest( classes = {WebMvcServiceRegistryAutoConfigurationTest.class}, properties = { - "microsphere.spring.cloud.simple.enabled=true", + "microsphere.spring.cloud.service-registry.auto-registration.simple.enabled=true", "spring.cloud.service-registry.auto-registration.enabled=true", "spring.cloud.kubernetes.enabled=false", "kubernetes.informer.enabled=false",