Skip to content

Commit

Permalink
Merge pull request #35 from mercyblitz/dev-1.x
Browse files Browse the repository at this point in the history
Dev 1.x
  • Loading branch information
mercyblitz authored Jan 16, 2025
2 parents f11e3ad + 2b80ef9 commit 0f9f5cc
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 14 deletions.
12 changes: 12 additions & 0 deletions microsphere-spring-cloud-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,22 @@
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Testcontainers -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,19 @@
*/
package io.microsphere.spring.cloud.client.event;

/**
* TODO Comment
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @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 <a href="mailto:[email protected]">Mercy</a>
Expand All @@ -58,6 +53,7 @@ public class ServiceInstancesChangedEvent extends ApplicationEvent {
public ServiceInstancesChangedEvent(String serviceName,
List<ServiceInstance> serviceInstances) {
super(serviceName);
notEmpty(serviceInstances, () -> "The arguments 'serviceInstances' must not be empty!");
this.serviceInstances = unmodifiableList(serviceInstances);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 <a href="mailto:[email protected]">Mercy<a/>
* @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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.microsphere.spring.cloud.client.service.registry.autoconfigure;

import static org.junit.jupiter.api.Assertions.*;

/**
* {@link ServiceRegistryAutoConfiguration} Test
*
* @author <a href="mailto:[email protected]">Mercy<a/>
* @see ServiceRegistryAutoConfiguration
* @since 1.0.0
*/
public class ServiceRegistryAutoConfigurationTest {

}
17 changes: 12 additions & 5 deletions microsphere-spring-cloud-openfeign/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,23 @@
<optional>true</optional>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
<optional>true</optional>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Documented
@Import(FeignClientAutoRefreshAutoConfiguration.class)
@Import(EnableFeignAutoRefresh.Marker.class)
public @interface EnableFeignAutoRefresh {

class Marker {
Expand Down

0 comments on commit 0f9f5cc

Please sign in to comment.