, Repository, ?>> repositories;
-
private Actor actor;
- @SuppressWarnings("ThisEscapedInObjectConstruction") // to inject self as event dispatcher.
- protected BlackBoxBoundedContext(boolean multitenant,
- EventEnricher enricher,
- String name) {
+ protected BlackBoxBoundedContext(boolean multitenant, EventEnricher enricher, String name) {
super();
this.commands = new CommandCollector();
this.postedCommands = synchronizedSet(new HashSet<>());
@@ -168,67 +158,94 @@ protected BlackBoxBoundedContext(boolean multitenant,
.addEventListener(events)
.enrichEventsUsing(enricher)
.build();
- this.observer = memoizingObserver();
- this.unsupportedCommandGuard = new UnsupportedCommandGuard(name);
this.repositories = newHashMap();
- this.context.registerEventDispatcher(this);
+ this.context.registerEventDispatcher(new UnsupportedCommandGuard(name));
this.context.registerEventDispatcher(DiagnosticLog.instance());
this.actor = defaultActor();
}
/**
* Creates a single-tenant instance with the default configuration.
+ *
+ * @deprecated please use {@link #from(BoundedContextBuilder)}
*/
+ @Deprecated
public static SingleTenantBlackBoxContext singleTenant() {
return singleTenant(emptyEnricher());
}
/**
* Creates a single-tenant instance with the specified name.
+ *
+ * @deprecated please use {@link #from(BoundedContextBuilder)}
*/
+ @Deprecated
public static SingleTenantBlackBoxContext singleTenant(String name) {
return singleTenant(name, emptyEnricher());
}
/**
* Creates a single-tenant instance with the specified enricher.
+ *
+ * @deprecated please use {@link #from(BoundedContextBuilder)}
*/
+ @Deprecated
public static SingleTenantBlackBoxContext singleTenant(EventEnricher enricher) {
return singleTenant(assumingTestsValue(), enricher);
}
/**
* Creates a single-tenant instance with the specified name and enricher.
+ *
+ * @deprecated please use {@link #from(BoundedContextBuilder)}
*/
+ @Deprecated
public static SingleTenantBlackBoxContext singleTenant(String name, EventEnricher enricher) {
return new SingleTenantBlackBoxContext(name, enricher);
}
/**
* Creates a multitenant instance the default configuration.
+ *
+ * @deprecated please use {@link #from(BoundedContextBuilder)}
*/
+ @Deprecated
public static MultitenantBlackBoxContext multiTenant() {
return multiTenant(emptyEnricher());
}
/**
* Creates a multitenant instance with the specified name.
+ *
+ * @deprecated please use {@link #from(BoundedContextBuilder)}
*/
+ @Deprecated
public static MultitenantBlackBoxContext multiTenant(String name) {
return multiTenant(name, emptyEnricher());
}
/**
* Creates a multitenant instance with the specified enricher.
+ *
+ * @deprecated please use {@link #from(BoundedContextBuilder)}
*/
+ @Deprecated
public static MultitenantBlackBoxContext multiTenant(EventEnricher enricher) {
return multiTenant(assumingTestsValue(), enricher);
}
/**
* Creates a multitenant instance with the specified name and enricher.
+ *
+ * @deprecated please use {@link #from(BoundedContextBuilder)}
*/
+ @Deprecated
public static MultitenantBlackBoxContext multiTenant(String name, EventEnricher enricher) {
+ return internalMultiTenant(name, enricher);
+ }
+
+ private static MultitenantBlackBoxContext
+ internalMultiTenant(String name, EventEnricher enricher) {
return new MultitenantBlackBoxContext(name, enricher);
}
@@ -246,67 +263,23 @@ public static BlackBoxBoundedContext> from(BoundedContextBuilder builder) {
EventEnricher enricher =
builder.eventEnricher()
.orElseGet(BlackBoxBoundedContext::emptyEnricher);
+ String name = builder.name()
+ .value();
BlackBoxBoundedContext> result =
builder.isMultitenant()
- ? multiTenant(enricher)
- : singleTenant(enricher);
+ ? internalMultiTenant(name, enricher)
+ : singleTenant(name, enricher);
builder.repositories()
- .forEach(result::with);
+ .forEach(result::internalWith);
builder.commandDispatchers()
- .forEach(result::withHandlers);
+ .forEach(result::internalWithDispatchers);
builder.eventDispatchers()
- .forEach(result::withEventDispatchers);
+ .forEach(result::internalWithEventDispatchers);
return result;
}
- /**
- * Throws an {@link AssertionError}.
- *
- * Only reachable after {@code unsupportedGuard} has
- * {@linkplain #canDispatch(EventEnvelope) detected} a violation.
- */
- @Override
- protected void handle(EventEnvelope event) {
- unsupportedCommandGuard.failTest();
- }
-
- /**
- * Checks if the given {@link CommandErrored} message represents an unsupported command
- * {@linkplain io.spine.server.commandbus.UnsupportedCommandException error}.
- */
- @Override
- public boolean canDispatch(EventEnvelope eventEnvelope) {
- CommandErrored event = (CommandErrored) eventEnvelope.message();
- return unsupportedCommandGuard.checkAndRemember(event);
- }
-
- @Override
- public ImmutableSet messageClasses() {
- return EventClass.setOf(CommandErrored.class);
- }
-
- /**
- * {@inheritDoc}
- *
- * The {@code BlackBoxBoundedContext} only consumes domestic events.
- */
- @Override
- public ImmutableSet domesticEventClasses() {
- return eventClasses();
- }
-
- /**
- * {@inheritDoc}
- *
- * The {@code BlackBoxBoundedContext} does not consume external events.
- */
- @Override
- public ImmutableSet externalEventClasses() {
- return ImmutableSet.of();
- }
-
/** Obtains the name of this bounded context. */
public BoundedContextName name() {
return context.name();
@@ -344,6 +317,14 @@ protected final Actor actor() {
return this.actor;
}
+ /**
+ * Obtains repositories registered with the context.
+ */
+ @VisibleForTesting
+ Collection> repositories() {
+ return repositories.values();
+ }
+
/**
* Obtains set of type names of entities known to this Bounded Context.
*/
@@ -361,10 +342,12 @@ EventBus eventBus() {
/**
* Appends the passed event to the history of the context under the test.
*/
+ @CanIgnoreReturnValue
public T append(Event event) {
checkNotNull(event);
- EventStore eventStore = context.eventBus()
- .eventStore();
+ EventStore eventStore =
+ context.eventBus()
+ .eventStore();
eventStore.append(event);
return thisRef();
}
@@ -381,9 +364,16 @@ CommandBus commandBus() {
* @param repositories
* repositories to register in the Bounded Context
* @return current instance
+ * @deprecated please use {@link BoundedContextBuilder#add(Repository)} and
+ * then {@link #from(BoundedContextBuilder)}
*/
+ @Deprecated
@CanIgnoreReturnValue
public final T with(Repository, ?>... repositories) {
+ return internalWith(repositories);
+ }
+
+ private T internalWith(Repository, ?>... repositories) {
registerAll(this::registerRepository, repositories);
return thisRef();
}
@@ -394,8 +384,9 @@ private void registerRepository(Repository, ?> repository) {
}
private void remember(Repository, ?> repository) {
- Class extends EntityState> stateClass = repository.entityModelClass()
- .stateClass();
+ Class extends EntityState> stateClass =
+ repository.entityModelClass()
+ .stateClass();
repositories.put(stateClass, repository);
}
@@ -405,9 +396,16 @@ private void remember(Repository, ?> repository) {
* @param dispatchers
* command dispatchers to register with the bounded context
* @return current instance
+ * @deprecated please use {@link BoundedContextBuilder#addCommandDispatcher(CommandDispatcher)}
+ * and then {@link #from(BoundedContextBuilder)}
*/
+ @Deprecated
@CanIgnoreReturnValue
public final T withHandlers(CommandDispatcher... dispatchers) {
+ return internalWithDispatchers(dispatchers);
+ }
+
+ private T internalWithDispatchers(CommandDispatcher... dispatchers) {
registerAll(this::registerCommandDispatcher, dispatchers);
return thisRef();
}
@@ -426,9 +424,16 @@ private void registerCommandDispatcher(CommandDispatcher dispatcher) {
*
* @param dispatchers
* dispatchers to register with the event bus of this bounded context
+ * @deprecated please use {@link BoundedContextBuilder#addEventDispatcher(EventDispatcher)} and
+ * then {@link #from(BoundedContextBuilder)}
*/
+ @Deprecated
@CanIgnoreReturnValue
public final T withEventDispatchers(EventDispatcher... dispatchers) {
+ return internalWithEventDispatchers(dispatchers);
+ }
+
+ private T internalWithEventDispatchers(EventDispatcher... dispatchers) {
registerAll(this::registerEventDispatcher, dispatchers);
return thisRef();
}
@@ -636,7 +641,7 @@ private T importAll(Collection eventMessages) {
}
private BlackBoxSetup setup() {
- return new BlackBoxSetup(context, requestFactory(), observer);
+ return new BlackBoxSetup(context, requestFactory(), memoizingObserver());
}
/**
diff --git a/testutil-server/src/main/java/io/spine/testing/server/blackbox/UnsupportedCommandGuard.java b/testutil-server/src/main/java/io/spine/testing/server/blackbox/UnsupportedCommandGuard.java
index 955be54cc3e..525e0ee2f5b 100644
--- a/testutil-server/src/main/java/io/spine/testing/server/blackbox/UnsupportedCommandGuard.java
+++ b/testutil-server/src/main/java/io/spine/testing/server/blackbox/UnsupportedCommandGuard.java
@@ -21,8 +21,12 @@
package io.spine.testing.server.blackbox;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableSet;
import io.spine.base.Error;
import io.spine.core.CommandValidationError;
+import io.spine.server.event.AbstractEventSubscriber;
+import io.spine.server.type.EventClass;
+import io.spine.server.type.EventEnvelope;
import io.spine.system.server.event.CommandErrored;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -33,10 +37,13 @@
import static org.junit.jupiter.api.Assertions.fail;
/**
- * A guard that verifies that the commands posted to the {@link BlackBoxBoundedContext} are not the
+ * Verifies that the commands posted to the {@link BlackBoxBoundedContext} are not the
* {@linkplain io.spine.server.bus.DeadMessageHandler "dead"} messages.
+ *
+ * The guard subscribes to {@link CommandErrored} event.
+ * It does not subscribe to external events.
*/
-final class UnsupportedCommandGuard {
+final class UnsupportedCommandGuard extends AbstractEventSubscriber {
private static final String COMMAND_VALIDATION_ERROR_TYPE =
CommandValidationError.getDescriptor()
@@ -45,17 +52,38 @@ final class UnsupportedCommandGuard {
/** The name of the guarded Bounded Context. */
private final String context;
- /** A command type for which the violation occurs in printable form. */
+ /**
+ * A name of the command type for which the violation occurs in printable form.
+ *
+ * @see #checkAndRemember(CommandErrored)
+ */
private @Nullable String commandType;
UnsupportedCommandGuard(String context) {
+ super();
this.context = context;
}
+ @Override
+ public ImmutableSet messageClasses() {
+ return EventClass.setOf(CommandErrored.class);
+ }
+
+ /**
+ * Checks if the given {@link CommandErrored} message represents an unsupported command
+ * {@linkplain io.spine.server.commandbus.UnsupportedCommandException error}.
+ */
+ @Override
+ public boolean canDispatch(EventEnvelope eventEnvelope) {
+ CommandErrored event = (CommandErrored) eventEnvelope.message();
+ return checkAndRemember(event);
+ }
+
/**
* Checks if the given {@link CommandErrored} event represents an "unsupported" error and,
* if so, remembers its data.
*/
+ @VisibleForTesting
boolean checkAndRemember(CommandErrored event) {
Error error = event.getError();
if (!isUnsupportedError(error)) {
@@ -67,13 +95,29 @@ boolean checkAndRemember(CommandErrored event) {
return true;
}
+ private static boolean isUnsupportedError(Error error) {
+ return COMMAND_VALIDATION_ERROR_TYPE.equals(error.getType())
+ && error.getCode() == UNSUPPORTED_COMMAND_VALUE;
+ }
+
+ /**
+ * Throws an {@link AssertionError}.
+ *
+ * Only reachable after unsupported command error
+ * {@linkplain #canDispatch(EventEnvelope) is detected}.
+ */
+ @Override
+ protected void handle(EventEnvelope event) {
+ failTest();
+ }
+
/**
* Throws an {@link AssertionError}.
*
*
The method is assumed to be called after a violation was found for some
* {@link #commandType}.
*/
- void failTest() {
+ private void failTest() {
checkNotNull(commandType);
String msg = format(
"The command type `%s` does not have a handler in the context `%s`.",
@@ -83,12 +127,27 @@ void failTest() {
}
@VisibleForTesting
- String commandType() {
+ @Nullable String commandType() {
return commandType;
}
- private static boolean isUnsupportedError(Error error) {
- return COMMAND_VALIDATION_ERROR_TYPE.equals(error.getType())
- && error.getCode() == UNSUPPORTED_COMMAND_VALUE;
+ /**
+ * {@inheritDoc}
+ *
+ *
The {@code BlackBoxBoundedContext} only consumes domestic events.
+ */
+ @Override
+ public ImmutableSet domesticEventClasses() {
+ return eventClasses();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * The {@code BlackBoxBoundedContext} does not consume external events.
+ */
+ @Override
+ public ImmutableSet externalEventClasses() {
+ return ImmutableSet.of();
}
}
diff --git a/testutil-server/src/test/java/io/spine/testing/server/blackbox/BlackBoxBoundedContextTest.java b/testutil-server/src/test/java/io/spine/testing/server/blackbox/BlackBoxBoundedContextTest.java
index e12ba48f7b8..f4f07ebc3e0 100644
--- a/testutil-server/src/test/java/io/spine/testing/server/blackbox/BlackBoxBoundedContextTest.java
+++ b/testutil-server/src/test/java/io/spine/testing/server/blackbox/BlackBoxBoundedContextTest.java
@@ -24,6 +24,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.truth.IterableSubject;
import com.google.common.truth.Subject;
+import com.google.errorprone.annotations.OverridingMethodsMustInvokeSuper;
import com.google.protobuf.Message;
import io.spine.client.Query;
import io.spine.client.QueryFactory;
@@ -40,7 +41,6 @@
import io.spine.server.entity.Repository;
import io.spine.server.event.EventDispatcher;
import io.spine.server.event.EventEnricher;
-import io.spine.server.projection.ProjectionRepository;
import io.spine.server.type.CommandClass;
import io.spine.testing.core.given.GivenUserId;
import io.spine.testing.logging.MuteLogging;
@@ -59,13 +59,11 @@
import io.spine.testing.server.blackbox.event.BbTaskAddedToReport;
import io.spine.testing.server.blackbox.event.BbUserDeleted;
import io.spine.testing.server.blackbox.given.BbCommandDispatcher;
-import io.spine.testing.server.blackbox.given.BbDuplicateCommandDispatcher;
import io.spine.testing.server.blackbox.given.BbEventDispatcher;
import io.spine.testing.server.blackbox.given.BbInitProcess;
import io.spine.testing.server.blackbox.given.BbProjectRepository;
import io.spine.testing.server.blackbox.given.BbProjectViewProjection;
import io.spine.testing.server.blackbox.given.BbReportRepository;
-import io.spine.testing.server.blackbox.given.BbTaskViewProjection;
import io.spine.testing.server.blackbox.given.RepositoryThrowingExceptionOnClose;
import io.spine.testing.server.blackbox.rejection.Rejections;
import io.spine.testing.server.entity.EntitySubject;
@@ -94,12 +92,10 @@
import static io.spine.testing.server.blackbox.given.Given.createProject;
import static io.spine.testing.server.blackbox.given.Given.createReport;
import static io.spine.testing.server.blackbox.given.Given.createdProjectState;
-import static io.spine.testing.server.blackbox.given.Given.eventDispatcherRegistered;
import static io.spine.testing.server.blackbox.given.Given.finalizeProject;
import static io.spine.testing.server.blackbox.given.Given.initProject;
import static io.spine.testing.server.blackbox.given.Given.newProjectId;
import static io.spine.testing.server.blackbox.given.Given.projectDone;
-import static io.spine.testing.server.blackbox.given.Given.registerCommandDispatcher;
import static io.spine.testing.server.blackbox.given.Given.startProject;
import static io.spine.testing.server.blackbox.given.Given.taskAdded;
import static io.spine.testing.server.blackbox.given.Given.userDeleted;
@@ -116,10 +112,16 @@ abstract class BlackBoxBoundedContextTest> {
private T context;
@BeforeEach
+ @OverridingMethodsMustInvokeSuper
void setUp() {
- context = newInstance().with(new BbProjectRepository(),
- DefaultRepository.of(BbProjectViewProjection.class),
- DefaultRepository.of(BbInitProcess.class));
+ BoundedContextBuilder builder = newBuilder();
+ builder.add(new BbProjectRepository())
+ .add(new BbReportRepository())
+ .add(BbProjectViewProjection.class)
+ .add(BbInitProcess.class);
+ @SuppressWarnings("unchecked") // see Javadoc for newBuilder().
+ T ctx = (T) BlackBoxBoundedContext.from(builder);
+ context = ctx;
}
@AfterEach
@@ -128,94 +130,17 @@ void tearDown() {
}
/**
- * Creates a new instance of a bounded context to be used in this test suite.
+ * Creates a new instance of the {@code BoundedContextBuilder}.
+ *
+ * Implementations must ensure that multi-tenancy status of the created builder
+ * matches the type of the test.
*/
- abstract BlackBoxBoundedContext newInstance();
+ abstract BoundedContextBuilder newBuilder();
- T boundedContext() {
+ final T context() {
return context;
}
- @Test
- @DisplayName("register command dispatchers")
- void registerCommandDispatchers() {
- CommandClass commandTypeToDispatch = CommandClass.from(BbRegisterCommandDispatcher.class);
- BbCommandDispatcher dispatcher = new BbCommandDispatcher(commandTypeToDispatch);
- context.withHandlers(dispatcher);
- context.receivesCommand(registerCommandDispatcher(dispatcher.getClass()));
- assertThat(dispatcher.commandsDispatched()).isEqualTo(1);
- }
-
- @Test
- @DisplayName("throw on an attempt to register duplicate command dispatchers")
- void throwOnDuplicateCommandDispatchers() {
- CommandClass commandTypeToDispatch = CommandClass.from(BbRegisterCommandDispatcher.class);
- BbCommandDispatcher dispatcher = new BbCommandDispatcher(commandTypeToDispatch);
- context.withHandlers(dispatcher);
- BbDuplicateCommandDispatcher duplicateDispatcher =
- new BbDuplicateCommandDispatcher(commandTypeToDispatch);
-
- assertThrows(IllegalArgumentException.class,
- () -> context.withHandlers(duplicateDispatcher));
- }
-
- @Test
- @DisplayName("throw on an attempt to register a null command dispatcher")
- void throwOnNullCommandDispatcher() {
- assertThrows(NullPointerException.class,
- () -> context.withHandlers((CommandDispatcher) null));
- }
-
- @Test
- @DisplayName("throw on an attempt to register several command dispatchers one of which is null")
- void throwOnOneOfNull() {
- CommandClass commandTypeToDispatch = CommandClass.from(BbRegisterCommandDispatcher.class);
- BbCommandDispatcher dispatcher = new BbCommandDispatcher(commandTypeToDispatch);
- assertThrows(NullPointerException.class, () -> context.withHandlers(dispatcher, null));
- }
-
- @Test
- @DisplayName("register a repository if it's passed as command dispatcher")
- void registerRepoAsCommandDispatcher() {
- BbReportRepository repository = new BbReportRepository();
- context.withHandlers(repository);
- assertThat(context.allStateTypes()).contains(TypeName.of(BbReport.class));
- }
-
- @Test
- @DisplayName("register event dispatcher")
- void registerEventDispatcher() {
- BbEventDispatcher dispatcher = new BbEventDispatcher();
- context.withEventDispatchers(dispatcher);
- context.receivesEvent(eventDispatcherRegistered(dispatcher.getClass()));
- assertThat(dispatcher.eventsReceived()).isEqualTo(1);
- }
-
- @Test
- @DisplayName("throw on an attempt to register a null event dispatcher")
- void throwOnNullEventDispatcher() {
- assertThrows(NullPointerException.class,
- () -> context.withEventDispatchers((EventDispatcher) null));
- }
-
- @Test
- @DisplayName("throw on an attempt to register several event dispatchers if one of them is null")
- void throwOnOneOfEventDispatchersIsNull() {
- BbEventDispatcher validDispatcher = new BbEventDispatcher();
- assertThrows(NullPointerException.class,
- () -> context.withEventDispatchers(validDispatcher, null));
- }
-
- @Test
- @DisplayName("register a repository if it's passed as event dispatcher")
- void registerRepoAsEventDispatcher() {
- ProjectionRepository, ?, ?> repository =
- (ProjectionRepository, ?, ?>)
- DefaultRepository.of(BbTaskViewProjection.class);
- context.withEventDispatchers(repository);
- assertThat(context.allStateTypes()).contains(TypeName.of(BbTaskView.class));
- }
-
@Test
@DisplayName("ignore sent events in emitted")
void ignoreSentEvents() {
@@ -345,7 +270,6 @@ void generatedWithinModel() {
void receivesEvent() {
BbProjectId projectId = newProjectId();
EventSubject assertEvents = context
- .with(new BbReportRepository())
.receivesCommand(createReport(projectId))
.receivesEvent(taskAdded(projectId))
.assertEvents();
@@ -359,7 +283,6 @@ void receivesEvent() {
void receivesEvents() {
BbProjectId projectId = newProjectId();
EventSubject assertEvents = context
- .with(new BbReportRepository())
.receivesCommand(createReport(projectId))
.receivesEvents(taskAdded(projectId), taskAdded(projectId), taskAdded(projectId))
.assertEvents();
@@ -450,15 +373,18 @@ void multiple() {
@Test
@DisplayName("throw Illegal State Exception on Bounded Context close error")
void throwIllegalStateExceptionOnClose() {
- assertThrows(IllegalStateException.class, () ->
- newInstance()
- .with(new RepositoryThrowingExceptionOnClose() {
- @Override
- protected void throwException() {
- throw new RuntimeException("Expected error");
- }
- })
- .close());
+ RepositoryThrowingExceptionOnClose throwingRepo = new RepositoryThrowingExceptionOnClose() {
+ @Override
+ protected void throwException() {
+ throw new RuntimeException("Expected error");
+ }
+ };
+
+ BlackBoxBoundedContext> ctx = BlackBoxBoundedContext.from(
+ newBuilder().add(throwingRepo)
+ );
+
+ assertThrows(IllegalStateException.class, ctx::close);
}
@Nested
@@ -494,17 +420,36 @@ void singleTenant() {
BoundedContextBuilder builder = BoundedContextBuilder
.assumingTests(false)
.enrichEventsUsing(enricher);
+ assertBlackBox(builder, SingleTenantBlackBoxContext.class);
+ }
+
+ @Test
+ void multiTenant() {
+ BoundedContextBuilder builder = BoundedContextBuilder
+ .assumingTests(true)
+ .enrichEventsUsing(enricher);
+ assertBlackBox(builder, MultitenantBlackBoxContext.class);
+ }
+
+ private void assertBlackBox(BoundedContextBuilder builder,
+ Class extends BlackBoxBoundedContext>> clazz) {
repositories.forEach(builder::add);
builder.addCommandDispatcher(commandDispatcher);
builder.addEventDispatcher(eventDispatcher);
blackBox = BlackBoxBoundedContext.from(builder);
- assertThat(blackBox).isInstanceOf(SingleTenantBlackBoxContext.class);
+ assertThat(blackBox).isInstanceOf(clazz);
+ assertRepositories();
assertEntityTypes();
assertDispatchers();
assertEnricher();
}
+ private void assertRepositories() {
+ assertThat(blackBox.repositories())
+ .containsAnyIn(repositories);
+ }
+
private void assertEntityTypes() {
assertThat(blackBox.allStateTypes()).containsAtLeastElementsIn(types);
}
@@ -519,22 +464,6 @@ private void assertEnricher() {
assertThat(blackBox.eventBus().enricher()).hasValue(enricher);
}
- @Test
- void multiTenant() {
- BoundedContextBuilder builder = BoundedContextBuilder
- .assumingTests(true)
- .enrichEventsUsing(enricher);
- repositories.forEach(builder::add);
- builder.addCommandDispatcher(commandDispatcher);
- builder.addEventDispatcher(eventDispatcher);
- blackBox = BlackBoxBoundedContext.from(builder);
-
- assertThat(blackBox).isInstanceOf(MultitenantBlackBoxContext.class);
- assertEntityTypes();
- assertDispatchers();
- assertEnricher();
- }
-
/**
* Obtains the set of entity state types from the passed repositories.
*/
diff --git a/testutil-server/src/test/java/io/spine/testing/server/blackbox/MultitenantBlackBoxContextTest.java b/testutil-server/src/test/java/io/spine/testing/server/blackbox/MultitenantBlackBoxContextTest.java
index 79e4c16eac2..da6a726f344 100644
--- a/testutil-server/src/test/java/io/spine/testing/server/blackbox/MultitenantBlackBoxContextTest.java
+++ b/testutil-server/src/test/java/io/spine/testing/server/blackbox/MultitenantBlackBoxContextTest.java
@@ -20,13 +20,15 @@
package io.spine.testing.server.blackbox;
+import com.google.errorprone.annotations.OverridingMethodsMustInvokeSuper;
import io.spine.core.TenantId;
+import io.spine.server.BoundedContextBuilder;
import io.spine.testing.server.blackbox.command.BbCreateProject;
import io.spine.testing.server.blackbox.event.BbProjectCreated;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
-import static com.google.common.truth.Truth.assertThat;
import static io.spine.testing.core.given.GivenTenantId.generate;
import static io.spine.testing.server.blackbox.given.Given.createProject;
import static io.spine.testing.server.blackbox.given.Given.createdProjectState;
@@ -37,21 +39,16 @@ class MultitenantBlackBoxContextTest
extends BlackBoxBoundedContextTest {
@Override
- MultitenantBlackBoxContext newInstance() {
- return BlackBoxBoundedContext.multiTenant(getClass().getName())
- .withTenant(generate());
+ BoundedContextBuilder newBuilder() {
+ return BoundedContextBuilder.assumingTests(true);
}
- @Test
- @DisplayName("create builder instance with the context name")
- void createByName() {
- String name = getClass().getName();
- MultitenantBlackBoxContext context =
- BlackBoxBoundedContext.multiTenant(name);
- assertThat(context)
- .isNotNull();
- assertThat(context.name().value())
- .isEqualTo(name);
+ @BeforeEach
+ @OverridingMethodsMustInvokeSuper
+ @Override
+ void setUp() {
+ super.setUp();
+ context().withTenant(generate());
}
@Test
@@ -62,7 +59,7 @@ void verifyForDifferentTenants() {
TenantId newUser = generate();
BbCreateProject createJohnProject = createProject();
BbCreateProject createCarlProject = createProject();
- MultitenantBlackBoxContext context = boundedContext()
+ MultitenantBlackBoxContext context = context()
// Create a project for John.
.withTenant(john)
.receivesCommand(createJohnProject)
@@ -103,9 +100,8 @@ void verifyForDifferentTenants() {
void requireTenantId() {
assertThrows(
IllegalStateException.class,
- () -> BlackBoxBoundedContext
- .multiTenant()
- .assertEntityWithState(BbProject.class, "verify state")
+ () -> BlackBoxBoundedContext.from(BoundedContextBuilder.assumingTests(true))
+ .assertEntityWithState(BbProject.class, "verify state")
);
}
}
diff --git a/testutil-server/src/test/java/io/spine/testing/server/blackbox/SingleTenantBlackBoxContextTest.java b/testutil-server/src/test/java/io/spine/testing/server/blackbox/SingleTenantBlackBoxContextTest.java
index dadb9046cbf..b85f65eb9ad 100644
--- a/testutil-server/src/test/java/io/spine/testing/server/blackbox/SingleTenantBlackBoxContextTest.java
+++ b/testutil-server/src/test/java/io/spine/testing/server/blackbox/SingleTenantBlackBoxContextTest.java
@@ -20,6 +20,7 @@
package io.spine.testing.server.blackbox;
+import io.spine.server.BoundedContextBuilder;
import org.junit.jupiter.api.DisplayName;
@DisplayName("Single tenant Black Box Bounded Context should")
@@ -27,7 +28,7 @@ class SingleTenantBlackBoxContextTest
extends BlackBoxBoundedContextTest {
@Override
- SingleTenantBlackBoxContext newInstance() {
- return BlackBoxBoundedContext.singleTenant(getClass().getName());
+ BoundedContextBuilder newBuilder() {
+ return BoundedContextBuilder.assumingTests();
}
}
diff --git a/version.gradle b/version.gradle
index 365ee4eb8c9..5098dab4aa8 100644
--- a/version.gradle
+++ b/version.gradle
@@ -25,14 +25,14 @@
* as we want to manage the versions in a single source.
*/
-final def spineVersion = '1.5.1'
+final def spineVersion = '1.5.2'
ext {
// The version of the modules in this project.
versionToPublish = spineVersion
// Depend on `base` for the general definitions and a model compiler.
- spineBaseVersion = spineVersion
+ spineBaseVersion = '1.5.1'
// Depend on `time` for `ZoneId`, `ZoneOffset` and other date/time types and utilities.
spineTimeVersion = '1.5.0'