Skip to content

Commit

Permalink
Refactored to async with actors.
Browse files Browse the repository at this point in the history
  • Loading branch information
VaughnVernon committed Apr 24, 2019
1 parent cdb0931 commit 0efcb05
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 133 deletions.
Binary file added docs/vlingo-schemata-ui-master.zip
Binary file not shown.
45 changes: 22 additions & 23 deletions src/test/java/io/vlingo/schemata/model/ContextEntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,46 @@
import org.junit.Before;
import org.junit.Test;

import io.vlingo.actors.testkit.TestActor;
import io.vlingo.actors.testkit.TestWorld;
import io.vlingo.actors.World;
import io.vlingo.actors.testkit.AccessSafely;
import io.vlingo.lattice.model.DomainEvent;
import io.vlingo.lattice.model.sourcing.SourcedTypeRegistry;
import io.vlingo.schemata.NoopJournalListener;
import io.vlingo.schemata.MockJournalListener;
import io.vlingo.schemata.infra.persistence.EntryAdapters;
import io.vlingo.schemata.model.Events.ContextDefined;
import io.vlingo.schemata.model.Events.ContextDescribed;
import io.vlingo.schemata.model.Events.ContextRenamed;
import io.vlingo.schemata.model.Id.ContextId;
import io.vlingo.schemata.model.Id.OrganizationId;
import io.vlingo.schemata.model.Id.UnitId;
import io.vlingo.symbio.EntryAdapterProvider;
import io.vlingo.symbio.store.journal.Journal;
import io.vlingo.symbio.store.journal.inmemory.InMemoryJournalActor;

public class ContextEntityTest {
private TestWorld world;
private TestActor<Context> contextTestActor;
private AccessSafely access;
private Context context;
private Journal<String> journal;
private NoopJournalListener listener;
private MockJournalListener listener;
private SourcedTypeRegistry registry;
private World world;

@Before
@SuppressWarnings({ "unchecked" })
public void setUp() throws Exception {
world = TestWorld.start("context-test");
world = World.start("context-test");

listener = new NoopJournalListener();
listener = new MockJournalListener(EntryAdapterProvider.instance(world));

journal = world.world().actorFor(Journal.class, InMemoryJournalActor.class, listener);

registry = new SourcedTypeRegistry(world.world());

EntryAdapters.register(registry, journal);

contextTestActor = world.actorFor(Context.class, ContextEntity.class, ContextId.uniqueFor(UnitId.uniqueFor(OrganizationId.unique())));
contextTestActor.context().until.resetHappeningsTo(1);
contextTestActor.actor().defineWith("namespace", "description");
context = world.actorFor(Context.class, ContextEntity.class, ContextId.uniqueFor(UnitId.uniqueFor(OrganizationId.unique())));
access = listener.afterCompleting(1);
context.defineWith("namespace", "description");
}

@After
Expand All @@ -61,31 +63,28 @@ public void tearDown() {

@Test
public void testThatContextIsDefined() throws Exception {
contextTestActor.context().until.completes(); // see setUp()
final List<DomainEvent> applied = contextTestActor.viewTestState().valueOf("applied");
final List<DomainEvent> applied = access.readFrom("entries"); // see setUp()
final ContextDefined contextDefined = (ContextDefined) applied.get(0);
Assert.assertEquals("namespace", contextDefined.name);
Assert.assertEquals("description", contextDefined.description);
}

@Test
public void testThatContextRenamed() throws Exception {
contextTestActor.context().until.completes(); // see setUp()
contextTestActor.context().until.resetHappeningsTo(1);
contextTestActor.actor().changeNamespaceTo("new namespace");
contextTestActor.context().until.completes();
final List<DomainEvent> applied = contextTestActor.viewTestState().valueOf("applied");
access.readFrom("entries"); // see setUp
access = listener.afterCompleting(1);
context.changeNamespaceTo("new namespace");
final List<DomainEvent> applied = access.readFrom("entries");
final ContextRenamed contextRenamed = (ContextRenamed) applied.get(1);
Assert.assertEquals("new namespace", contextRenamed.namespace);
}

@Test
public void testThatContextIsDescribed() throws Exception {
contextTestActor.context().until.completes(); // see setUp()
contextTestActor.context().until.resetHappeningsTo(1);
contextTestActor.actor().describeAs("new description");
contextTestActor.context().until.completes();
final List<DomainEvent> applied = contextTestActor.viewTestState().valueOf("applied");
access.readFrom("entries"); // see setUp()
access = listener.afterCompleting(1);
context.describeAs("new description");
final List<DomainEvent> applied = access.readFrom("entries");
final ContextDescribed contextDescribed = (ContextDescribed) applied.get(1);
Assert.assertEquals("new description", contextDescribed.description);
}
Expand Down
47 changes: 23 additions & 24 deletions src/test/java/io/vlingo/schemata/model/OrganizationEntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,44 @@
import org.junit.Before;
import org.junit.Test;

import io.vlingo.actors.testkit.TestActor;
import io.vlingo.actors.testkit.TestWorld;
import io.vlingo.actors.World;
import io.vlingo.actors.testkit.AccessSafely;
import io.vlingo.lattice.model.DomainEvent;
import io.vlingo.lattice.model.sourcing.SourcedTypeRegistry;
import io.vlingo.schemata.NoopJournalListener;
import io.vlingo.schemata.MockJournalListener;
import io.vlingo.schemata.infra.persistence.EntryAdapters;
import io.vlingo.schemata.model.Events.OrganizationDefined;
import io.vlingo.schemata.model.Events.OrganizationDescribed;
import io.vlingo.schemata.model.Events.OrganizationRenamed;
import io.vlingo.schemata.model.Id.OrganizationId;
import io.vlingo.symbio.EntryAdapterProvider;
import io.vlingo.symbio.store.journal.Journal;
import io.vlingo.symbio.store.journal.inmemory.InMemoryJournalActor;

public class OrganizationEntityTest {
private TestWorld world;
private TestActor<Organization> organizationTestActor;
private AccessSafely access;
private Journal<String> journal;
private NoopJournalListener listener;
private MockJournalListener listener;
private Organization organization;
private SourcedTypeRegistry registry;
private World world;

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
world = TestWorld.start("organization-test");
listener = new NoopJournalListener();
world = World.start("organization-test");

listener = new MockJournalListener(EntryAdapterProvider.instance(world));

journal = world.world().actorFor(Journal.class, InMemoryJournalActor.class, listener);

registry = new SourcedTypeRegistry(world.world());

EntryAdapters.register(registry, journal);

organizationTestActor = world.actorFor(Organization.class, OrganizationEntity.class, OrganizationId.unique());
organizationTestActor.context().until.resetHappeningsTo(1);
organizationTestActor.actor().defineWith("name", "description");
organization = world.actorFor(Organization.class, OrganizationEntity.class, OrganizationId.unique());
access = listener.afterCompleting(1);
organization.defineWith("name", "description");
}

@After
Expand All @@ -59,31 +61,28 @@ public void tearDown() {

@Test
public void testThatOrganizationDefinedIsEquals() throws Exception {
organizationTestActor.context().until.completes(); // see setUp()
final List<DomainEvent> applied = organizationTestActor.viewTestState().valueOf("applied");
final List<DomainEvent> applied = access.readFrom("entries"); // see setUp()
final OrganizationDefined organizationDefined = (OrganizationDefined) applied.get(0);
Assert.assertEquals("name", organizationDefined.name);
Assert.assertEquals("description", organizationDefined.description);
}

@Test
public void testThatOrganizationRenamed() throws Exception {
organizationTestActor.context().until.completes(); // see setUp()
organizationTestActor.context().until.resetHappeningsTo(1);
organizationTestActor.actor().renameTo("new name");
organizationTestActor.context().until.completes();
final List<DomainEvent> applied = organizationTestActor.viewTestState().valueOf("applied");
access.readFrom("entries"); // see setUp()
access = listener.afterCompleting(1);
organization.renameTo("new name");
final List<DomainEvent> applied = access.readFrom("entries");;
final OrganizationRenamed organizationRenamed = (OrganizationRenamed) applied.get(1);
Assert.assertEquals("new name", organizationRenamed.name);
}

@Test
public void testThatOrganizationIsDescribed() throws Exception {
organizationTestActor.context().until.completes(); // see setUp()
organizationTestActor.context().until.resetHappeningsTo(1);
organizationTestActor.actor().describeAs("new description");
organizationTestActor.context().until.completes();
final List<DomainEvent> applied = organizationTestActor.viewTestState().valueOf("applied");
access.readFrom("entries"); // see setUp()
access = listener.afterCompleting(1);
organization.describeAs("new description");
final List<DomainEvent> applied = access.readFrom("entries");;
final OrganizationDescribed organizationDescribed = (OrganizationDescribed) applied.get(1);
Assert.assertEquals("new description", organizationDescribed.description);
}
Expand Down
52 changes: 25 additions & 27 deletions src/test/java/io/vlingo/schemata/model/SchemaEntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import org.junit.Before;
import org.junit.Test;

import io.vlingo.actors.testkit.TestActor;
import io.vlingo.actors.testkit.TestWorld;
import io.vlingo.actors.World;
import io.vlingo.actors.testkit.AccessSafely;
import io.vlingo.lattice.model.DomainEvent;
import io.vlingo.lattice.model.sourcing.SourcedTypeRegistry;
import io.vlingo.schemata.NoopJournalListener;
import io.vlingo.schemata.MockJournalListener;
import io.vlingo.schemata.infra.persistence.EntryAdapters;
import io.vlingo.schemata.model.Events.SchemaDefined;
import io.vlingo.schemata.model.Events.SchemaDescribed;
Expand All @@ -29,22 +29,24 @@
import io.vlingo.schemata.model.Id.OrganizationId;
import io.vlingo.schemata.model.Id.SchemaId;
import io.vlingo.schemata.model.Id.UnitId;
import io.vlingo.symbio.EntryAdapterProvider;
import io.vlingo.symbio.store.journal.Journal;
import io.vlingo.symbio.store.journal.inmemory.InMemoryJournalActor;

public class SchemaEntityTest {
private TestWorld world;
private TestActor<Schema> schema;
private AccessSafely access;
private Journal<String> journal;
private NoopJournalListener listener;
private MockJournalListener listener;
private SourcedTypeRegistry registry;
private Schema schema;
private World world;

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
world = TestWorld.start("schema-test");
world = World.start("schema-test");

listener = new NoopJournalListener();
listener = new MockJournalListener(EntryAdapterProvider.instance(world));

journal = world.world().actorFor(Journal.class, InMemoryJournalActor.class, listener);

Expand All @@ -53,8 +55,8 @@ public void setUp() throws Exception {
EntryAdapters.register(registry, journal);

schema = world.actorFor(Schema.class, SchemaEntity.class, SchemaId.uniqueFor(ContextId.uniqueFor(UnitId.uniqueFor(OrganizationId.unique()))));
schema.context().until.resetHappeningsTo(1);
schema.actor().defineWith(Category.Event, "name", "description");
access = listener.afterCompleting(1);
schema.defineWith(Category.Event, "name", "description");
}

@After
Expand All @@ -64,8 +66,7 @@ public void tearDown() {

@Test
public void testThatSchemaDefinedIsEquals() throws Exception {
schema.context().until.completes(); // see setUp()
final List<DomainEvent> applied = schema.viewTestState().valueOf("applied");
final List<DomainEvent> applied = access.readFrom("entries"); // see setUp()
final SchemaDefined schemaDefined = (SchemaDefined) applied.get(0);
assertEquals(1, applied.size());
assertEquals(Category.Event.name(), schemaDefined.category);
Expand All @@ -75,35 +76,32 @@ public void testThatSchemaDefinedIsEquals() throws Exception {

@Test
public void testThatSchemaIsDescribed() throws Exception {
schema.context().until.completes(); // see setUp()
schema.context().until.resetHappeningsTo(1);
schema.actor().describeAs("new description");
schema.context().until.completes();
final List<DomainEvent> applied = schema.viewTestState().valueOf("applied");
access.readFrom("entries"); // see setUp()
access = listener.afterCompleting(1);
schema.describeAs("new description");
final List<DomainEvent> applied = access.readFrom("entries");
assertEquals(2, applied.size());
final SchemaDescribed schemaDescribed = (SchemaDescribed) applied.get(1);
assertEquals("new description", schemaDescribed.description);
}

@Test
public void testThatSchemaRecategorised() throws Exception {
schema.context().until.completes(); // see setUp()
schema.context().until.resetHappeningsTo(1);
schema.actor().recategorizedAs(Category.Document);
schema.context().until.completes();
final List<DomainEvent> applied = schema.viewTestState().valueOf("applied");
access.readFrom("entries"); // see setUp()
access = listener.afterCompleting(1);
schema.recategorizedAs(Category.Document);
final List<DomainEvent> applied = access.readFrom("entries");
assertEquals(2, applied.size());
final SchemaRecategorized schemaRecategorized = (SchemaRecategorized) applied.get(1);
assertEquals(Category.Document.name(), schemaRecategorized.category);
}

@Test
public void testThatSchemaRenamed() throws Exception {
schema.context().until.completes(); // see setUp()
schema.context().until.resetHappeningsTo(1);
schema.actor().renameTo("new name");
schema.context().until.completes();
final List<DomainEvent> applied = schema.viewTestState().valueOf("applied");
access.readFrom("entries"); // see setUp()
access = listener.afterCompleting(1);
schema.renameTo("new name");
final List<DomainEvent> applied = access.readFrom("entries");
assertEquals(2, applied.size());
final SchemaRenamed schemaRenamed = (SchemaRenamed) applied.get(1);
assertEquals("new name", schemaRenamed.name);
Expand Down
Loading

0 comments on commit 0efcb05

Please sign in to comment.