In case this method is declared to handle a rejection, a rejection-specific
+ * dispatch key is created.
+ */
+ @Override
+ default DispatchKey key() {
+ if (handlesRejection()) {
+ DispatchKey dispatchKey = RejectionDispatchKeys.of(messageClass(), rawMethod());
+ return dispatchKey;
+ }
+ return HandlerMethod.super.key();
+ }
+}
diff --git a/server/src/main/java/io/spine/server/event/model/StateSubscriberMethod.java b/server/src/main/java/io/spine/server/event/model/StateSubscriberMethod.java
index ad33dfc53f9..837a5f92751 100644
--- a/server/src/main/java/io/spine/server/event/model/StateSubscriberMethod.java
+++ b/server/src/main/java/io/spine/server/event/model/StateSubscriberMethod.java
@@ -30,6 +30,7 @@
import io.spine.core.BoundedContextName;
import io.spine.logging.Logging;
import io.spine.server.model.ArgumentFilter;
+import io.spine.server.model.DispatchKey;
import io.spine.server.model.Model;
import io.spine.server.model.ParameterSpec;
import io.spine.server.type.EventEnvelope;
@@ -59,6 +60,12 @@ public final class StateSubscriberMethod extends SubscriberMethod implements Log
checkExternal();
}
+ @Override
+ public DispatchKey key() {
+ DispatchKey typeBasedKey = super.key();
+ return applyFilter(typeBasedKey);
+ }
+
private static Method checkNotFiltered(Method method) {
ArgumentFilter filter = ArgumentFilter.createFilter(method);
checkState(filter.acceptsAll(),
@@ -95,7 +102,7 @@ protected Class extends EventMessage> rawMessageClass() {
}
@SuppressWarnings("TestOnlyProblems")
- // Checks that the resulting context is not `AssumingTests` in production environment.
+ // Checks that the resulting context is not `AssumingTests` in production environment.
private BoundedContextName contextOf(Class> cls) {
Model model = Model.inContextOf(cls);
BoundedContextName name = model.contextName();
diff --git a/server/src/main/java/io/spine/server/event/model/SubscriberMethod.java b/server/src/main/java/io/spine/server/event/model/SubscriberMethod.java
index 433498cec1b..4c1bedb1409 100644
--- a/server/src/main/java/io/spine/server/event/model/SubscriberMethod.java
+++ b/server/src/main/java/io/spine/server/event/model/SubscriberMethod.java
@@ -21,6 +21,7 @@
package io.spine.server.event.model;
import com.google.errorprone.annotations.Immutable;
+import io.spine.annotation.Internal;
import io.spine.base.EventMessage;
import io.spine.server.event.EventSubscriber;
import io.spine.server.model.AbstractHandlerMethod;
@@ -63,13 +64,16 @@ protected SubscriberMethod(Method method, ParameterSpec It is assumed that the type of the event is correct and only the field filter should be
* checked.
*
- * @param event the event to check
+ * @param event
+ * the event to check
* @return {@code true} if this method can handle the given event, {@code false} otherwise
*/
final boolean canHandle(EventEnvelope event) {
diff --git a/server/src/main/java/io/spine/server/model/HandlerMethod.java b/server/src/main/java/io/spine/server/model/HandlerMethod.java
index 4d71b2dd756..9ebdcf45f51 100644
--- a/server/src/main/java/io/spine/server/model/HandlerMethod.java
+++ b/server/src/main/java/io/spine/server/model/HandlerMethod.java
@@ -139,6 +139,9 @@ default void ensureExternalMatch(boolean expectedValue) throws SignalOriginMisma
}
}
+ /**
+ * Creates a handler method dispatch key out of the {@linkplain #messageClass() message class}.
+ */
default DispatchKey key() {
Class extends Message> rawCls = messageClass().value();
return new DispatchKey(rawCls, null, null);
diff --git a/server/src/test/java/io/spine/server/event/model/RejectionDispatchKeysTest.java b/server/src/test/java/io/spine/server/event/model/RejectionDispatchKeysTest.java
new file mode 100644
index 00000000000..b19c25fb657
--- /dev/null
+++ b/server/src/test/java/io/spine/server/event/model/RejectionDispatchKeysTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2019, TeamDev. All rights reserved.
+ *
+ * Redistribution and use in source and/or binary forms, with or without
+ * modification, must retain the above copyright notice and the following
+ * disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package io.spine.server.event.model;
+
+import io.spine.model.contexts.projects.rejection.ProjectRejections.SigCannotCreateProject;
+import io.spine.server.event.model.given.subscriber.RejectionSubscriber;
+import io.spine.server.type.EventClass;
+import io.spine.testing.UtilityClassTest;
+import io.spine.testing.server.model.ModelTests;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Method;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+@DisplayName("`RejectionDispatchKeys` should")
+final class RejectionDispatchKeysTest extends UtilityClassTest