Skip to content

Commit

Permalink
Merge pull request #1251 from SpineEventEngine/testing-utils-p2
Browse files Browse the repository at this point in the history
Improvements for testing utilities (part 2)
  • Loading branch information
alexander-yevsyukov authored Mar 18, 2020
2 parents b3f3959 + f9f361a commit 8259406
Show file tree
Hide file tree
Showing 32 changed files with 484 additions and 483 deletions.
26 changes: 6 additions & 20 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject.

<groupId>io.spine</groupId>
<artifactId>spine-core-java</artifactId>
<version>1.5.1</version>
<version>1.5.2</version>

<inceptionYear>2015</inceptionYear>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import io.spine.testing.logging.MuteLogging;
import io.spine.testing.server.TestEventFactory;
import io.spine.testing.server.blackbox.BlackBoxBoundedContext;
import io.spine.testing.server.blackbox.SingleTenantBlackBoxContext;
import io.spine.testing.server.model.ModelTests;
import io.spine.type.TypeUrl;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -525,10 +524,10 @@ class PostEventsToBus {
@BeforeEach
void createAnotherRepository() {
resetRepository();
AggregateRepository<?, ?> repository = repository();
context = BlackBoxBoundedContext
.singleTenant()
.with(repository);
context = BlackBoxBoundedContext.from(
BoundedContextBuilder.assumingTests()
.add(repository())
);
}

@Test
Expand Down Expand Up @@ -604,11 +603,12 @@ void throughEventFilter() {
.setProjectId(parent)
.addChildProjectId(id)
.build();
SingleTenantBlackBoxContext context = BlackBoxBoundedContext
.singleTenant()
.with(new EventDiscardingAggregateRepository())
.receivesCommands(create, start)
.receivesEvent(archived);
BlackBoxBoundedContext<?> context = BlackBoxBoundedContext.from(
BoundedContextBuilder.assumingTests()
.add(new EventDiscardingAggregateRepository())
);
context.receivesCommands(create, start)
.receivesEvent(archived);
context.assertEvents()
.isEmpty();
context.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
package io.spine.server.aggregate;

import com.google.common.collect.Iterators;
import io.spine.server.BoundedContextBuilder;
import io.spine.server.aggregate.given.fibonacci.FibonacciRepository;
import io.spine.server.aggregate.given.fibonacci.SequenceId;
import io.spine.server.aggregate.given.fibonacci.command.MoveSequence;
import io.spine.server.aggregate.given.fibonacci.command.SetStartingNumbers;
import io.spine.server.aggregate.given.fibonacci.event.StartingNumbersSet;
import io.spine.server.storage.StorageFactory;
import io.spine.testing.server.blackbox.BlackBoxBoundedContext;
import io.spine.testing.server.blackbox.SingleTenantBlackBoxContext;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

Expand All @@ -52,15 +51,14 @@ public abstract class AggregateStorageTruncationTest {
.setValue(newUuid())
.vBuild();

protected abstract StorageFactory storageFactory();

@Test
@DisplayName("restore aggregate state properly")
void restoreAggregateState() {
FibonacciRepository repo = new FibonacciRepository();
SingleTenantBlackBoxContext context = BlackBoxBoundedContext
.singleTenant()
.with(repo);
BlackBoxBoundedContext<?> context = BlackBoxBoundedContext.from(
BoundedContextBuilder.assumingTests()
.add(repo)
);

// Set the starting numbers.
SetStartingNumbers setStartingNumbers = SetStartingNumbers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.spine.base.Time;
import io.spine.core.Ack;
import io.spine.core.Command;
import io.spine.core.CommandId;
import io.spine.core.Event;
import io.spine.core.MessageId;
import io.spine.core.TenantId;
Expand Down Expand Up @@ -88,13 +87,11 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;

import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;
import static io.spine.grpc.StreamObservers.noOpObserver;
import static io.spine.protobuf.AnyPacker.unpack;
Expand Down Expand Up @@ -823,9 +820,10 @@ class CreateSingleEventForPair {

@BeforeEach
void prepareContext() {
context = BlackBoxBoundedContext
.singleTenant()
.with(new TaskAggregateRepository());
context = BlackBoxBoundedContext.from(
BoundedContextBuilder.assumingTests()
.add(new TaskAggregateRepository())
);
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

package io.spine.server.aggregate;

import io.spine.server.BoundedContextBuilder;
import io.spine.server.aggregate.given.importado.DotSpace;
import io.spine.server.aggregate.given.importado.ObjectId;
import io.spine.server.aggregate.given.importado.event.Moved;
import io.spine.testing.server.blackbox.BlackBoxBoundedContext;
import io.spine.testing.server.blackbox.SingleTenantBlackBoxContext;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -44,13 +44,14 @@
@DisplayName("Aggregate which supports event import should")
class ApplyAllowImportTest {

private SingleTenantBlackBoxContext context;
private BlackBoxBoundedContext<?> context;

@BeforeEach
void setUp() {
context = BlackBoxBoundedContext
.singleTenant()
.with(new DotSpace());
context = BlackBoxBoundedContext.from(
BoundedContextBuilder.assumingTests()
.add(new DotSpace())
);
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package io.spine.server.aggregate;

import io.spine.base.EventMessage;
import io.spine.server.BoundedContextBuilder;
import io.spine.server.aggregate.given.klasse.EngineAggregate;
import io.spine.server.aggregate.given.klasse.EngineId;
import io.spine.server.aggregate.given.klasse.EngineRepository;
Expand All @@ -31,7 +32,6 @@
import io.spine.server.type.EventEnvelope;
import io.spine.testing.server.TestEventFactory;
import io.spine.testing.server.blackbox.BlackBoxBoundedContext;
import io.spine.testing.server.blackbox.SingleTenantBlackBoxContext;
import io.spine.testing.server.entity.EntitySubject;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -50,13 +50,14 @@
class EventImportTest {

private EngineRepository repository;
private SingleTenantBlackBoxContext context;
private BlackBoxBoundedContext<?> context;

void createRepository(boolean routeByFirstMessageField) {
repository = new EngineRepository(routeByFirstMessageField);
context = BlackBoxBoundedContext
.singleTenant()
.with(repository);
context = BlackBoxBoundedContext.from(
BoundedContextBuilder.assumingTests()
.add(repository)
);
}

@AfterEach
Expand All @@ -75,7 +76,7 @@ protected final EngineRepository repository() {
return this.repository;
}

protected final SingleTenantBlackBoxContext context() {
protected final BlackBoxBoundedContext<?> context() {
return this.context;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
package io.spine.server.bus;

import com.google.common.collect.ImmutableList;
import io.spine.server.DefaultRepository;
import io.spine.server.BoundedContextBuilder;
import io.spine.server.bus.given.stock.JowDonsIndex;
import io.spine.server.bus.given.stock.ShareAggregate;
import io.spine.test.bus.Buy;
import io.spine.test.bus.Sell;
import io.spine.test.bus.ShareId;
import io.spine.testing.SlowTest;
import io.spine.testing.server.blackbox.BlackBoxBoundedContext;
import io.spine.testing.server.blackbox.SingleTenantBlackBoxContext;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

Expand All @@ -52,10 +51,11 @@ class DispatchingQueueSynchronisationTest {
@DisplayName("Bus should not lock with its system counterpart")
void deadlock() throws InterruptedException {
ThreadPoolExecutor executor = (ThreadPoolExecutor) newFixedThreadPool(10);
SingleTenantBlackBoxContext context = BlackBoxBoundedContext
.singleTenant()
.with(DefaultRepository.of(ShareAggregate.class),
new JowDonsIndex.Repository());
BlackBoxBoundedContext<?> context = BlackBoxBoundedContext.from(
BoundedContextBuilder.assumingTests()
.add(ShareAggregate.class)
.add(new JowDonsIndex.Repository())
);
int taskCount = 10;
ImmutableList<ShareId> shares =
Stream.generate(() -> ShareId
Expand Down
Loading

0 comments on commit 8259406

Please sign in to comment.