Search in sources :

Example 1 with Project

use of io.spine.test.aggregate.Project in project core-java by SpineEventEngine.

the class AggregateRepositoryShould method create_aggregate_with_default_state_if_no_aggregate_found.

// OK as the aggregate is created if missing.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void create_aggregate_with_default_state_if_no_aggregate_found() {
    final ProjectAggregate aggregate = repository.find(Sample.messageOfType(ProjectId.class)).get();
    final Project state = aggregate.getState();
    assertTrue(isDefault(state));
}
Also used : CreateProject(io.spine.test.aggregate.command.CreateProject) StartProject(io.spine.test.aggregate.command.StartProject) Project(io.spine.test.aggregate.Project) Test(org.junit.Test)

Example 2 with Project

use of io.spine.test.aggregate.Project in project core-java by SpineEventEngine.

the class AggregateShould method transform_current_state_to_snapshot_event.

@Test
public void transform_current_state_to_snapshot_event() {
    dispatch(aggregate, env(createProject));
    final Snapshot snapshot = aggregate.toSnapshot();
    final Project state = unpack(snapshot.getState());
    assertEquals(ID, state.getId());
    assertEquals(Status.CREATED, state.getStatus());
}
Also used : CreateProject(io.spine.test.aggregate.command.CreateProject) StartProject(io.spine.test.aggregate.command.StartProject) Project(io.spine.test.aggregate.Project) Test(org.junit.Test)

Example 3 with Project

use of io.spine.test.aggregate.Project in project core-java by SpineEventEngine.

the class FieldMasksShould method fail_to_mask_message_if_passed_type_does_not_match.

@Test(expected = IllegalArgumentException.class)
public void fail_to_mask_message_if_passed_type_does_not_match() {
    final FieldMask mask = Given.fieldMask(Project.ID_FIELD_NUMBER);
    final Project origin = Given.newProject("some-string");
    FieldMasks.applyMask(mask, origin, Given.OTHER_TYPE);
}
Also used : Project(io.spine.test.aggregate.Project) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 4 with Project

use of io.spine.test.aggregate.Project in project core-java by SpineEventEngine.

the class FieldMasksShould method apply_only_non_empty_mask_to_single_item.

@Test
public void apply_only_non_empty_mask_to_single_item() {
    final FieldMask emptyMask = Given.fieldMask();
    final Project origin = Given.newProject("read_whole_message");
    final Project clone = Project.newBuilder(origin).build();
    final Project processed = FieldMasks.applyMask(emptyMask, origin, Given.TYPE);
    // Check object itself was returned
    assertTrue(processed == origin);
    // Check object was not changed
    assertTrue(processed.equals(clone));
}
Also used : Project(io.spine.test.aggregate.Project) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 5 with Project

use of io.spine.test.aggregate.Project in project core-java by SpineEventEngine.

the class FieldMasksShould method apply_mask_to_single_message.

@Test
public void apply_mask_to_single_message() {
    final FieldMask fieldMask = Given.fieldMask(Project.ID_FIELD_NUMBER, Project.NAME_FIELD_NUMBER);
    final Project original = Given.newProject("some-string-id");
    final Project masked = FieldMasks.applyMask(fieldMask, original, Given.TYPE);
    assertNotEquals(original, masked);
    assertMatchesMask(masked, fieldMask);
}
Also used : Project(io.spine.test.aggregate.Project) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Aggregations

Project (io.spine.test.aggregate.Project)12 Test (org.junit.Test)12 FieldMask (com.google.protobuf.FieldMask)5 CreateProject (io.spine.test.aggregate.command.CreateProject)4 StartProject (io.spine.test.aggregate.command.StartProject)4 Any (com.google.protobuf.Any)3 ProjectId (io.spine.test.aggregate.ProjectId)3 LinkedList (java.util.LinkedList)2