Skip to content

Commit

Permalink
- postgres broker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Reef3rm4n committed Jul 24, 2023
1 parent bbbbad2 commit 088963a
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.es4j;
package io.es4j.client;

import io.es4j.Aggregate;
import io.es4j.Command;
import io.es4j.core.CommandHandler;
import io.es4j.core.objects.AggregateState;
import io.es4j.core.objects.Es4jError;
Expand All @@ -20,7 +22,7 @@ public class AggregateHttpClient<T extends Aggregate> {
private final WebClient webClient;
private final Class<T> aggregateClass;

protected AggregateHttpClient(
public AggregateHttpClient(
final WebClient webClient,
final Class<T> aggregateClass
) {
Expand All @@ -30,6 +32,12 @@ protected AggregateHttpClient(

private static final Logger logger = LoggerFactory.getLogger(AggregateHttpClient.class);

/**
* Forwards command to aggregate
* @param command
* @return
* @param <C>
*/
public <C extends Command> Uni<AggregateState<T>> forward(C command) {
return webClient.post(parsePath(aggregateClass, command.getClass()))
.sendJson(JsonObject.mapFrom(Objects.requireNonNull(command, "command must not be null")))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.es4j;
package io.es4j.test;


import io.es4j.config.DatabaseConfiguration;
Expand All @@ -12,9 +12,28 @@
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface DatabaseBusinessRule {
/**
* The class of the configuration
* @return
*/
Class<? extends DatabaseConfiguration> configurationClass();

/**
* The file where it is located
* @return
*/
String fileName();

/**
* the tenant the configuration should belong to
* @return
*/
String tenant() default "default";

/**
* The version of the file
* @return
*/
int version() default 0;

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.es4j;
package io.es4j.test;

import io.es4j.Aggregate;
import io.es4j.client.AggregateHttpClient;
import io.es4j.Es4jDeployment;
import io.es4j.infrastructure.AggregateCache;
import io.es4j.infrastructure.EventStore;
import io.es4j.infrastructure.OffsetStore;
Expand All @@ -25,7 +28,7 @@
import static io.es4j.core.CommandHandler.camelToKebab;


class Es4jBootstrapper<T extends Aggregate> {
public class Es4jBootstrapper<T extends Aggregate> {
private final String infraConfig;
public AggregateEventBusPoxy<T> eventBusPoxy;
public AggregateHttpClient<T> httpClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.es4j;
package io.es4j.test;


import io.es4j.Aggregate;
import io.es4j.client.AggregateHttpClient;
import io.es4j.config.DatabaseConfiguration;
import io.es4j.config.DatabaseConfigurationCache;
import io.es4j.config.orm.ConfigurationKey;
Expand Down Expand Up @@ -82,7 +84,7 @@ public Object resolveParameter(ParameterContext parameterContext, ExtensionConte
private List<Tuple4<Class<? extends DatabaseConfiguration>, String, String, Integer>> databaseConfigurations(Method testMethod) {
LOGGER.debug("Getting business rules from method {}", testMethod);
List<Tuple4<Class<? extends DatabaseConfiguration>, String, String, Integer>> configurationTuples = new ArrayList<>();
io.es4j.DatabaseBusinessRule[] annotations = testMethod.getAnnotationsByType(io.es4j.DatabaseBusinessRule.class);
DatabaseBusinessRule[] annotations = testMethod.getAnnotationsByType(DatabaseBusinessRule.class);
if (annotations != null && !Arrays.stream(annotations).toList().isEmpty()) {
Arrays.stream(annotations).forEach(a -> configurationTuples.add(Tuple4.of(a.configurationClass(), a.fileName(), a.tenant(), a.version())));
return configurationTuples;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package io.es4j;
package io.es4j.test;


import io.es4j.Aggregate;
import org.junit.jupiter.api.extension.ExtendWith;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Used to mark junit classes for es4j tests
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(Es4jExtension.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.es4j;
package io.es4j.test;


import java.lang.annotation.ElementType;
Expand All @@ -10,6 +10,10 @@
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface FileBusinessRule {
/**
* File business rules for aggregates
* @return
*/
String fileName();

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.es4j;
package io.es4j.test;


import java.lang.annotation.ElementType;
Expand All @@ -10,6 +10,10 @@
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface GivenAggregate {
/**
* start test with a given aggregate state
* @return
*/
String filename();

}
Expand Down
4 changes: 4 additions & 0 deletions es4j-test/src/test/java/io/es4j/BridgeTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.es4j;


import io.es4j.client.AggregateHttpClient;
import io.es4j.commands.ChangeData;
import io.es4j.commands.ChangeDataWithConfig;
import io.es4j.commands.ChangeDataWithDbConfig;
Expand All @@ -9,6 +10,9 @@
import io.es4j.domain.DataBusinessRule;
import io.es4j.domain.FakeAggregate;
import io.es4j.infrastructure.proxy.AggregateEventBusPoxy;
import io.es4j.test.DatabaseBusinessRule;
import io.es4j.test.Es4jTest;
import io.es4j.test.FileBusinessRule;
import io.smallrye.mutiny.Uni;
import io.es4j.core.objects.LoadAggregate;
import io.vertx.junit5.VertxTestContext;
Expand Down

0 comments on commit 088963a

Please sign in to comment.