Search in sources :

Example 6 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() {
    dispatchCommand(aggregate, env(createProject));
    final Snapshot snapshot = aggregate().toShapshot();
    final Project state = unpack(snapshot.getState());
    assertEquals(ID, state.getId());
    assertEquals(Status.CREATED, state.getStatus());
}
Also used : AggCancelProject(io.spine.test.aggregate.command.AggCancelProject) AggStartProject(io.spine.test.aggregate.command.AggStartProject) AggCreateProject(io.spine.test.aggregate.command.AggCreateProject) AggPauseProject(io.spine.test.aggregate.command.AggPauseProject) Project(io.spine.test.aggregate.Project) Test(org.junit.Test)

Example 7 with Project

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

the class SubscriptionRecordShould method fail_to_match_improper_type.

@Test
public void fail_to_match_improper_type() {
    final SubscriptionRecord notMatchingRecord = new SubscriptionRecord(Given.subscription(), Given.target(), Given.TYPE);
    final Project entityState = Project.getDefaultInstance();
    final Any wrappedState = AnyPacker.pack(entityState);
    final ProjectId redundantId = ProjectId.getDefaultInstance();
    final boolean matchResult = notMatchingRecord.matches(Given.OTHER_TYPE, redundantId, wrappedState);
    assertFalse(matchResult);
}
Also used : Project(io.spine.test.aggregate.Project) ProjectId(io.spine.test.aggregate.ProjectId) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 8 with Project

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

the class SubscriptionRecordShould method fail_to_match_improper_target.

@Test
public void fail_to_match_improper_target() {
    final ProjectId nonExistingId = ProjectId.newBuilder().setId("never-existed").build();
    final SubscriptionRecord notMatchingRecord = new SubscriptionRecord(Given.subscription(), Given.target(nonExistingId), Given.TYPE);
    final Project entityState = Project.getDefaultInstance();
    final Any wrappedState = AnyPacker.pack(entityState);
    final ProjectId redundantId = ProjectId.getDefaultInstance();
    final boolean matchResult = notMatchingRecord.matches(Given.TYPE, redundantId, wrappedState);
    assertFalse(matchResult);
}
Also used : Project(io.spine.test.aggregate.Project) ProjectId(io.spine.test.aggregate.ProjectId) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 9 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_collection.

@SuppressWarnings({ "ObjectEquality", "MethodWithMultipleLoops" })
@Test
public void apply_only_non_empty_mask_to_collection() {
    final FieldMask emptyMask = Given.fieldMask();
    final Collection<Project> original = new LinkedList<>();
    final int count = 5;
    for (int i = 0; i < count; i++) {
        final Project project = Given.newProject(format("test-data--%s", i));
        original.add(project);
    }
    final Collection<Project> processed = FieldMasks.applyMask(emptyMask, original, Given.TYPE);
    assertSize(original.size(), processed);
    // The argument is not returned
    assertFalse(original == processed);
    // A copy of the argument is returned (Collection type may differ)
    final Iterator<Project> processedProjects = processed.iterator();
    for (Project anOriginal : original) {
        assertTrue(processedProjects.next().equals(anOriginal));
    }
}
Also used : Project(io.spine.test.aggregate.Project) FieldMask(com.google.protobuf.FieldMask) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 10 with Project

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

the class FieldMasksShould method apply_mask_to_message_collections.

@SuppressWarnings({ "MethodWithMultipleLoops", "ObjectEquality" })
@Test
public void apply_mask_to_message_collections() {
    final FieldMask fieldMask = Given.fieldMask(Project.STATUS_FIELD_NUMBER, Project.TASK_FIELD_NUMBER);
    final int count = 5;
    final Collection<Project> original = new LinkedList<>();
    for (int i = 0; i < count; i++) {
        final Project project = Given.newProject(format("project-%s", i));
        original.add(project);
    }
    final Collection<Project> masked = FieldMasks.applyMask(fieldMask, original, Given.TYPE);
    assertSize(original.size(), masked);
    // Collection references are not the same
    assertFalse(original == masked);
    for (Project project : masked) {
        assertMatchesMask(project, fieldMask);
        // Can't check repeated fields with assertMatchesMask
        assertFalse(project.getTaskList().isEmpty());
    }
}
Also used : Project(io.spine.test.aggregate.Project) FieldMask(com.google.protobuf.FieldMask) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Project (io.spine.test.aggregate.Project)15 Test (org.junit.Test)15 FieldMask (com.google.protobuf.FieldMask)5 ProjectId (io.spine.test.aggregate.ProjectId)4 Any (com.google.protobuf.Any)3 Event (io.spine.core.Event)3 Version (io.spine.core.Version)3 AggCancelProject (io.spine.test.aggregate.command.AggCancelProject)3 AggCreateProject (io.spine.test.aggregate.command.AggCreateProject)3 AggPauseProject (io.spine.test.aggregate.command.AggPauseProject)3 AggStartProject (io.spine.test.aggregate.command.AggStartProject)3 Timestamp (com.google.protobuf.Timestamp)2 LinkedList (java.util.LinkedList)2 CreateProject (io.spine.test.aggregate.command.CreateProject)1 StartProject (io.spine.test.aggregate.command.StartProject)1