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));
}
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());
}
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());
}
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));
}
Aggregations