Search in sources :

Example 6 with RejectionClass

use of io.spine.core.RejectionClass in project core-java by SpineEventEngine.

the class RejectionBusShould method unregister_subscribers.

@Test
public void unregister_subscribers() {
    final RejectionSubscriber subscriberOne = new InvalidProjectNameSubscriber();
    final RejectionSubscriber subscriberTwo = new InvalidProjectNameSubscriber();
    rejectionBus.register(subscriberOne);
    rejectionBus.register(subscriberTwo);
    final RejectionClass rejectionClass = RejectionClass.of(InvalidProjectName.class);
    rejectionBus.unregister(subscriberOne);
    // Check that the 2nd subscriber with the same rejection subscriber method remains
    // after the 1st subscriber unregisters.
    final Collection<RejectionDispatcher<?>> subscribers = rejectionBus.getDispatchers(rejectionClass);
    assertFalse(subscribers.contains(subscriberOne));
    assertTrue(subscribers.contains(subscriberTwo));
    // Check that after 2nd subscriber us unregisters he's no longer in
    rejectionBus.unregister(subscriberTwo);
    assertFalse(rejectionBus.getDispatchers(rejectionClass).contains(subscriberTwo));
}
Also used : MultipleRejectionSubscriber(io.spine.server.rejection.given.MultipleRejectionSubscriber) RejectionClass(io.spine.core.RejectionClass) InvalidProjectNameSubscriber(io.spine.server.rejection.given.InvalidProjectNameSubscriber) Test(org.junit.Test)

Example 7 with RejectionClass

use of io.spine.core.RejectionClass in project core-java by SpineEventEngine.

the class RejectionBusShould method unregister_registries_on_close.

@Test
public void unregister_registries_on_close() throws Exception {
    final RejectionBus rejectionBus = RejectionBus.newBuilder().build();
    rejectionBus.register(new BareDispatcher());
    rejectionBus.register(new InvalidProjectNameSubscriber());
    final RejectionClass rejectionClass = RejectionClass.of(InvalidProjectName.class);
    rejectionBus.close();
    assertTrue(rejectionBus.getDispatchers(rejectionClass).isEmpty());
}
Also used : RejectionClass(io.spine.core.RejectionClass) BareDispatcher(io.spine.server.rejection.given.BareDispatcher) InvalidProjectNameSubscriber(io.spine.server.rejection.given.InvalidProjectNameSubscriber) Test(org.junit.Test)

Example 8 with RejectionClass

use of io.spine.core.RejectionClass in project core-java by SpineEventEngine.

the class RejectionBusShould method unregister_dispatchers.

@Test
public void unregister_dispatchers() {
    final RejectionDispatcher<?> dispatcherOne = new BareDispatcher();
    final RejectionDispatcher<?> dispatcherTwo = new BareDispatcher();
    final RejectionClass rejectionClass = RejectionClass.of(InvalidProjectName.class);
    rejectionBus.register(dispatcherOne);
    rejectionBus.register(dispatcherTwo);
    rejectionBus.unregister(dispatcherOne);
    final Set<RejectionDispatcher<?>> dispatchers = rejectionBus.getDispatchers(rejectionClass);
    // Check we don't have 1st dispatcher, but have 2nd.
    assertFalse(dispatchers.contains(dispatcherOne));
    assertTrue(dispatchers.contains(dispatcherTwo));
    rejectionBus.unregister(dispatcherTwo);
    assertFalse(rejectionBus.getDispatchers(rejectionClass).contains(dispatcherTwo));
}
Also used : RejectionClass(io.spine.core.RejectionClass) BareDispatcher(io.spine.server.rejection.given.BareDispatcher) Test(org.junit.Test)

Example 9 with RejectionClass

use of io.spine.core.RejectionClass in project core-java by SpineEventEngine.

the class RejectionBusShould method register_rejection_subscriber.

@Test
public void register_rejection_subscriber() {
    final RejectionSubscriber subscriberOne = new InvalidProjectNameSubscriber();
    final RejectionSubscriber subscriberTwo = new InvalidProjectNameSubscriber();
    rejectionBus.register(subscriberOne);
    rejectionBus.register(subscriberTwo);
    final RejectionClass rejectionClass = RejectionClass.of(InvalidProjectName.class);
    assertTrue(rejectionBus.hasDispatchers(rejectionClass));
    final Collection<RejectionDispatcher<?>> dispatchers = rejectionBus.getDispatchers(rejectionClass);
    assertTrue(dispatchers.contains(subscriberOne));
    assertTrue(dispatchers.contains(subscriberTwo));
}
Also used : MultipleRejectionSubscriber(io.spine.server.rejection.given.MultipleRejectionSubscriber) RejectionClass(io.spine.core.RejectionClass) InvalidProjectNameSubscriber(io.spine.server.rejection.given.InvalidProjectNameSubscriber) Test(org.junit.Test)

Aggregations

RejectionClass (io.spine.core.RejectionClass)9 Test (org.junit.Test)5 BareDispatcher (io.spine.server.rejection.given.BareDispatcher)3 InvalidProjectNameSubscriber (io.spine.server.rejection.given.InvalidProjectNameSubscriber)3 ExternalMessageClass (io.spine.server.integration.ExternalMessageClass)2 MultipleRejectionSubscriber (io.spine.server.rejection.given.MultipleRejectionSubscriber)2 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 SPI (io.spine.annotation.SPI)1 CommandClass (io.spine.core.CommandClass)1 EventClass (io.spine.core.EventClass)1 Rejection (io.spine.core.Rejection)1 BoundedContext (io.spine.server.BoundedContext)1 ExternalMessage (io.spine.server.integration.ExternalMessage)1 ExternalMessageDispatcher (io.spine.server.integration.ExternalMessageDispatcher)1 ExternalMessageEnvelope (io.spine.server.integration.ExternalMessageEnvelope)1 MessageClass (io.spine.type.MessageClass)1