Skip to content

Commit

Permalink
test module
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsamson7 committed Oct 9, 2023
1 parent 48e3647 commit 0c1b6fb
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 104 deletions.
65 changes: 42 additions & 23 deletions channel/rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
</properties>

<dependencies>
<!-- internal -->

<dependency>
<groupId>com.serious</groupId>
<artifactId>service-core</artifactId>
Expand All @@ -31,31 +33,36 @@
<version>${project.version}</version>
</dependency>

<!-- external -->
<!-- dependencies -->

<dependency>
<groupId>org.springframework.cloud</groupId>
<!--artifactId>spring-cloud-starter-consul-all</artifactId-->
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>

<!-- dependencies -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>test</scope>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

<!-- test dependencies -->

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<groupId>com.serious</groupId>
<artifactId>service-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
Expand All @@ -65,39 +72,51 @@
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.0.11</version>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>

<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
<version>4.0.4</version>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
<scope>test</scope>
</dependency>

<!-- test dependencies -->

<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>com.serious</groupId>
<artifactId>service-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
19 changes: 2 additions & 17 deletions channel/rest/src/test/java/com/serious/channel/rest/RestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


import com.serious.service.*;
import com.serious.service.registry.LocalComponentRegistry;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -38,23 +39,7 @@ class Foo {

}
@Component
class TestComponentComponentRegistry implements ComponentRegistry {

@Override
public void startup(ComponentDescriptor<com.serious.service.Component> descriptor) {

}

@Override
public void shutdown(ComponentDescriptor<com.serious.service.Component> descriptor) {

}

@Override
public List<String> getServices() {
return List.of("test");
}

class TestComponentComponentRegistry extends LocalComponentRegistry {
@Override
public List<ServiceInstance> getInstances(String service) {
Map<String, String> meta = new HashMap<>();
Expand Down
10 changes: 2 additions & 8 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,14 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.0.11</version>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
<version>4.0.4</version>
</dependency>

<dependency>
Expand All @@ -49,7 +42,7 @@
<optional>true</optional>
</dependency>

<!-- test -->
<!-- test dependencies -->

<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -63,6 +56,7 @@
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
Expand Down
36 changes: 36 additions & 0 deletions core/src/test/java/com/serious/channel/LocalChannel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.serious.channel;
/*
* @COPYRIGHT (C) 2016 Andreas Ernst
*
* All rights reserved
*/

import com.serious.service.BaseDescriptor;
import com.serious.service.ChannelManager;
import com.serious.service.Service;
import com.serious.service.channel.AbstractChannel;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;

/**
* @author Andreas Ernst
*/
public class LocalChannel extends AbstractChannel {
// constructor

protected LocalChannel(ChannelManager channelManager) {
super(channelManager);
}

// implement

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
Object implementation = BaseDescriptor.forService((Class<Service>)invocation.getMethod().getDeclaringClass()).local;

Method method = implementation.getClass().getMethod(invocation.getMethod().getName(), invocation.getMethod().getParameterTypes());

return method.invoke(implementation, invocation.getArguments());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.serious.registry;
/*
* @COPYRIGHT (C) 2016 Andreas Ernst
*
* All rights reserved
*/

import com.serious.service.Component;
import com.serious.service.ComponentDescriptor;
import com.serious.service.ComponentRegistry;
import com.serious.service.ServiceAddress;
import org.springframework.cloud.client.ServiceInstance;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author Andreas Ernst
*/
public class LocalComponentRegistry implements ComponentRegistry {
// instance data

Map<String, List<ServiceAddress>> services = new HashMap<>();

// implement ComponentRegistry

@Override
public void startup(ComponentDescriptor<Component> descriptor) {
List<ServiceAddress> addresses = services.computeIfAbsent(descriptor.getName(), k ->
new ArrayList<>()
);

addresses.addAll(descriptor.getExternalAddresses());
}

@Override
public void shutdown(ComponentDescriptor<Component> descriptor) {
// noop
}

@Override
public List<String> getServices() {
return services.keySet().stream().toList();
}

@Override
public List<ServiceInstance> getInstances(String service) {
return services.get(service).stream()
.map(address -> address.getServiceInstance())
.collect(Collectors.toList());
}
}

Loading

0 comments on commit 0c1b6fb

Please sign in to comment.