io.vlingo.symbio.State.TextState Java Examples

The following examples show how to use io.vlingo.symbio.State.TextState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StateProjectionDispatcherTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatDescribedProjectionsRegister() {
  final ProjectToDescription description = new ProjectToDescription(DescribedProjection.class, "op1", "op2");

  final Dispatcher dispatcher =
          world.actorFor(Dispatcher.class, TextProjectionDispatcherActor.class, Collections.singletonList(description));

  final Outcome outcome = new Outcome(2);
  final AccessSafely accessOutcome = outcome.afterCompleting(2);
  dispatcher.controlWith(outcome);

  final TextState state = new TextState("123", Object.class, 1, "blah1", 1, Metadata.with("", "op1"));
  dispatcher.dispatch(new Dispatchable<>("123", LocalDateTime.now(), state, Collections.emptyList()));

  final TextState state2 = new TextState("1235", Object.class, 1, "blah2", 1, Metadata.with("", "op2"));
  dispatcher.dispatch(new Dispatchable<>("1235", LocalDateTime.now(), state2, Collections.emptyList()));

  assertEquals(2, (int) accessOutcome.readFrom("count"));
}
 
Example #2
Source File: TextProjectableTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testStateWithEventProjectableness() {
  final String textState = "test-state";
  final TextState state =
          new TextState("123", String.class, 1, textState, 1, Metadata.with("value", "op"));
  final Entry<String> entry = new TextEntry();
  final Projectable projectable = new TextProjectable(state, Arrays.asList(entry), "p123");

  assertEquals("op", projectable.becauseOf()[0]);
  assertEquals("java.lang.Object", projectable.becauseOf()[1]);
  assertEquals(textState, projectable.dataAsText());
  assertEquals("123", projectable.dataId());
  assertEquals(1, projectable.dataVersion());
  assertEquals("value", projectable.metadata());
  assertEquals("p123", projectable.projectionId());
  assertEquals(String.class.getName(), projectable.type());
  assertEquals(1, projectable.typeVersion());
}
 
Example #3
Source File: TextProjectableTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testProjectableness() {
  final String textState = "test-state";
  final TextState state =
          new TextState("123", String.class, 1, textState, 1, Metadata.with("value", "op"));
  final Projectable projectable = new TextProjectable(state, Collections.emptyList(), "p123");

  assertEquals("op", projectable.becauseOf()[0]);
  assertEquals(textState, projectable.dataAsText());
  assertEquals("123", projectable.dataId());
  assertEquals(1, projectable.dataVersion());
  assertEquals("value", projectable.metadata());
  assertEquals("p123", projectable.projectionId());
  assertEquals(String.class.getName(), projectable.type());
  assertEquals(1, projectable.typeVersion());
}
 
Example #4
Source File: ProjectableTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatStateDoesNotFail() {
  final Object object = new Object();
  final Projectable projectable =
          new TextProjectable(
                  new TextState("ABC", String.class, 1, "state", 1, Metadata.with(object, "value", "op1")),
                  Arrays.asList(),
                  "123");

  Assert.assertEquals(1, projectable.dataVersion());
  Assert.assertEquals("ABC", projectable.dataId());
  Assert.assertEquals("value", projectable.metadata());
  Assert.assertTrue(projectable.hasObject());
  Assert.assertNotNull(projectable.object());
  Assert.assertEquals(object, projectable.object());
  Assert.assertTrue(projectable.optionalObject().isPresent());
  Assert.assertTrue(projectable.hasState());
  Assert.assertEquals(1, projectable.typeVersion());
}
 
Example #5
Source File: DefaultTextStateAdapter.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Object fromRawState(final TextState raw) {
  try {
    final Class<?> stateType = Class.forName(raw.type);
    return JsonSerialization.deserialized(raw.data, stateType);
  } catch (Exception e) {
    throw new IllegalStateException("Cannot convert to type: " + raw.type);
  }
}
 
Example #6
Source File: TextProjectableTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@Test(expected = UnsupportedOperationException.class)
public void testProjectableNotBytes() {
  final String textState = "test-state";
  final TextState state =
          new TextState("123", String.class, 1, textState, 1, Metadata.with("value", "op"));
  final Projectable projectable = new TextProjectable(state, Collections.emptyList(), "p123");
  projectable.dataAsBytes();
}
 
Example #7
Source File: StateAdapterProvider.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <S,ST extends State<?>> S fromRaw(final ST state) {
  StateAdapter<S,ST> adapter = namedAdapter(state);
  if (adapter != null) {
    return adapter.fromRawState(state);
  }
  return (S) defaultTextStateAdapter.fromRawState((TextState) state);
}
 
Example #8
Source File: StateTest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testEmptyTextState() {
  final TextState emptyState = new TextState();
  assertFalse(emptyState.isBinary());
  assertTrue(emptyState.isText());
  assertTrue(emptyState.isEmpty());
}
 
Example #9
Source File: ProfileDataStateAdapter.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public TextState toRawState(String id, ProfileData state, int stateVersion, Metadata metadata) {
  final String serialization = JsonSerialization.serialized(state);
  return new TextState(id, ProfileData.class, typeVersion(), serialization, stateVersion, metadata);
}
 
Example #10
Source File: UserDataStateAdapter.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public TextState toRawState(String id, UserData state, int stateVersion, Metadata metadata) {
  final String serialization = JsonSerialization.serialized(state);
  return new TextState(id, UserData.class, typeVersion(), serialization, stateVersion, metadata);
}
 
Example #11
Source File: UserDataStateAdapter.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public TextState toRawState(final UserData state, final int stateVersion, final Metadata metadata) {
  final String serialization = JsonSerialization.serialized(state);
  return new TextState(state.id, UserData.class, typeVersion(), serialization, stateVersion, metadata);
}
 
Example #12
Source File: UserDataStateAdapter.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public <ST> ST fromRawState(TextState raw, Class<ST> stateType) {
  return JsonSerialization.deserialized(raw.data, stateType);
}
 
Example #13
Source File: UserStateAdapter.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public UserState fromRawState(final TextState raw) {
  return JsonSerialization.deserialized(raw.data, raw.typed());
}
 
Example #14
Source File: UserStateAdapter.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public TextState toRawState(String id, UserState state, int stateVersion, Metadata metadata) {
  final String serialization = JsonSerialization.serialized(state);
  return new TextState(id, UserState.class, typeVersion(), serialization, stateVersion, metadata);
}
 
Example #15
Source File: UserStateAdapter.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public <ST> ST fromRawState(TextState raw, Class<ST> stateType) {
  return JsonSerialization.deserialized(raw.data, stateType);
}
 
Example #16
Source File: ProfileDataStateAdapter.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public ProfileData fromRawState(final TextState raw) {
  return JsonSerialization.deserialized(raw.data, raw.typed());
}
 
Example #17
Source File: StatefulEntityTest.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public State<String> toRawState(final String id, final Entity1State state, final int stateVersion, final Metadata metadata) {
  final String serialization = JsonSerialization.serialized(state);
  return new TextState(id, Entity1State.class, typeVersion(), serialization, stateVersion);
}
 
Example #18
Source File: ProfileDataStateAdapter.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public TextState toRawState(final ProfileData state, final int stateVersion, final Metadata metadata) {
  final String serialization = JsonSerialization.serialized(state);
  return new TextState(TextState.NoOp, ProfileData.class, typeVersion(), serialization, stateVersion, metadata);
}
 
Example #19
Source File: ProfileDataStateAdapter.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public <ST> ST fromRawState(TextState raw, Class<ST> stateType) {
  return JsonSerialization.deserialized(raw.data, stateType);
}
 
Example #20
Source File: ProfileStateAdapter.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public ProfileState fromRawState(final TextState raw) {
  return JsonSerialization.deserialized(raw.data, raw.typed());
}
 
Example #21
Source File: ProfileStateAdapter.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public TextState toRawState(final ProfileState state, final int stateVersion, final Metadata metadata) {
  final String serialization = JsonSerialization.serialized(state);
  return new TextState(state.id, ProfileState.class, typeVersion(), serialization, stateVersion, metadata);
}
 
Example #22
Source File: ProfileStateAdapter.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public <ST> ST fromRawState(TextState raw, Class<ST> stateType) {
  return JsonSerialization.deserialized(raw.data, stateType);
}
 
Example #23
Source File: SnapshotStateAdapters.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public State fromRawState(final TextState raw) {
  return JsonSerialization.deserialized(raw.data, raw.typed());
}
 
Example #24
Source File: SnapshotStateAdapters.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public TextState toRawState(State state, int stateVersion, Metadata metadata) {
  final String serialization = JsonSerialization.serialized(state);
  return new TextState(TextState.NoOp, ForumEntity.State.class, typeVersion(), serialization, stateVersion, metadata);
}
 
Example #25
Source File: SnapshotStateAdapters.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public <ST> ST fromRawState(TextState raw, Class<ST> stateType) {
  return JsonSerialization.deserialized(raw.data, stateType);
}
 
Example #26
Source File: Entity1.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public Entity1 fromRawState(final TextState raw) {
  return JsonSerialization.deserialized(raw.data, raw.typed());
}
 
Example #27
Source File: Entity1.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public TextState toRawState(final Entity1 state, final int stateVersion) {
  return toRawState(state, stateVersion, Metadata.with("value", "op"));
}
 
Example #28
Source File: Entity1.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public TextState toRawState(final Entity1 state, final int stateVersion, final Metadata metadata) {
  final String serialization = JsonSerialization.serialized(state);
  return new TextState(state.id, Entity1.class, typeVersion(), serialization, stateVersion, metadata);
}
 
Example #29
Source File: Entity1.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public TextState toRawState(final String id, final Entity1 state, final int stateVersion, final Metadata metadata) {
  final String serialization = JsonSerialization.serialized(state);
  return new TextState(id, Entity1.class, typeVersion(), serialization, stateVersion, metadata);
}
 
Example #30
Source File: SnapshotStateAdapter.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public SnapshotState fromRawState(final TextState raw) {
  return JsonSerialization.deserialized(raw.data, raw.typed());
}