@@ -0,0 +1,3555 @@
+/*%0A * Copyright 2019, TeamDev. All rights reserved.%0A *%0A * Redistribution and use in source and/or binary forms, with or without%0A * modification, must retain the above copyright notice and the following%0A * disclaimer.%0A *%0A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS%0A * %22AS IS%22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT%0A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR%0A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT%0A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,%0A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT%0A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,%0A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY%0A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT%0A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE%0A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.%0A */%0A%0Apackage io.spine.client;%0A%0Aimport com.google.common.collect.ImmutableList;%0Aimport io.spine.base.CommandMessage;%0Aimport io.spine.core.UserId;%0Aimport io.spine.server.BoundedContextBuilder;%0Aimport io.spine.test.client.ClientTestContext;%0Aimport io.spine.test.client.command.LogInUser;%0Aimport io.spine.test.client.event.UserLoggedIn;%0Aimport io.spine.testing.core.given.GivenUserId;%0Aimport org.junit.jupiter.api.AfterEach;%0Aimport org.junit.jupiter.api.BeforeEach;%0Aimport org.junit.jupiter.api.DisplayName;%0Aimport org.junit.jupiter.api.Test;%0A%0Aimport static com.google.common.truth.Truth.assertThat;%0Aimport static io.spine.client.Filters.all;%0Aimport static io.spine.client.Filters.eq;%0A%0A@DisplayName(%22%60EventSubscriptionRequest%60 should%22)%0Aclass EventSubscriptionRequestTest extends AbstractClientTest %7B%0A%0A    /** Registers which event consumers were called. */%0A    private final ConsumerCallCounter counter = new ConsumerCallCounter();%0A    private CommandRequest commandRequest;%0A    private UserId userId;%0A%0A    @Override%0A    protected ImmutableList%3CBoundedContextBuilder%3E contexts() %7B%0A        return ImmutableList.of(ClientTestContext.builder());%0A    %7D%0A%0A    @BeforeEach%0A    void createCommandRequest() %7B%0A        counter.clear();%0A        userId = GivenUserId.generated();%0A        CommandMessage cmd = LogInUser%0A                .newBuilder()%0A                .setUser(userId)%0A                .build();%0A        commandRequest =%0A                client().asGuest()%0A                        .command(cmd);%0A    %7D%0A%0A    @AfterEach%0A    void clearCounter() %7B%0A        counter.clear();%0A    %7D%0A%0A    @Test%0A    @DisplayName(%22allow to receive event messages%22)%0A    void observeEventMessage() %7B%0A        UserId guestUser = client().asGuest()%0A                              .user();%0A        client().asGuest()%0A                .subscribeToEvent(UserLoggedIn.class)%0A                .where(all(eq(%22user%22, userId),%0A                           eq(%22context.past_message.actor_context.actor%22, guestUser)))%0A                .observe(counter::add)%0A                .post();%0A        commandRequest.post();%0A%0A        assertThat(counter.contains(UserLoggedIn.class))%0A            .isTrue();%0A    %7D%0A%0A    @Test%0A    @DisplayName(%22allow to receive event messages and contexts%22)%0A    void observeEventMessageAndContext() %7B%0A        client().asGuest()%0A                .subscribeToEvent(UserLoggedIn.class)%0A                .observe((e, c) -%3E counter.add(e))%0A                .post();%0A        commandRequest.post();%0A%0A        assertThat(counter.contains(UserLoggedIn.class))%0A                .isTrue();%0A    %7D%0A%7D%0A

Test event subscription