Search in sources :

Example 1 with InvalidProjectNameSubscriber

use of io.spine.server.rejection.given.InvalidProjectNameSubscriber 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 2 with InvalidProjectNameSubscriber

use of io.spine.server.rejection.given.InvalidProjectNameSubscriber in project core-java by SpineEventEngine.

the class RejectionBusShould method call_subscriber_when_rejection_posted.

@Test
public void call_subscriber_when_rejection_posted() {
    final InvalidProjectNameSubscriber subscriber = new InvalidProjectNameSubscriber();
    final Rejection rejection = invalidProjectNameRejection();
    rejectionBus.register(subscriber);
    rejectionBus.post(rejection);
    final Rejection handled = subscriber.getRejectionHandled();
    // Compare the content without command ID, which is different in the remembered
    assertEquals(rejection.getMessage(), handled.getMessage());
    assertEquals(rejection.getContext().getCommand().getMessage(), handled.getContext().getCommand().getMessage());
    assertEquals(rejection.getContext().getCommand().getContext(), handled.getContext().getCommand().getContext());
}
Also used : Given.missingOwnerRejection(io.spine.server.rejection.given.Given.missingOwnerRejection) Rejection(io.spine.core.Rejection) Given.invalidProjectNameRejection(io.spine.server.rejection.given.Given.invalidProjectNameRejection) InvalidProjectNameSubscriber(io.spine.server.rejection.given.InvalidProjectNameSubscriber) Test(org.junit.Test)

Example 3 with InvalidProjectNameSubscriber

use of io.spine.server.rejection.given.InvalidProjectNameSubscriber 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 4 with InvalidProjectNameSubscriber

use of io.spine.server.rejection.given.InvalidProjectNameSubscriber 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

InvalidProjectNameSubscriber (io.spine.server.rejection.given.InvalidProjectNameSubscriber)4 Test (org.junit.Test)4 RejectionClass (io.spine.core.RejectionClass)3 MultipleRejectionSubscriber (io.spine.server.rejection.given.MultipleRejectionSubscriber)2 Rejection (io.spine.core.Rejection)1 BareDispatcher (io.spine.server.rejection.given.BareDispatcher)1 Given.invalidProjectNameRejection (io.spine.server.rejection.given.Given.invalidProjectNameRejection)1 Given.missingOwnerRejection (io.spine.server.rejection.given.Given.missingOwnerRejection)1