diff --git a/src/test/java/edu/stanford/protege/webprotege/issues/DiscussionEventChannelJsonTest.java b/src/test/java/edu/stanford/protege/webprotege/issues/DiscussionEventChannelJsonTest.java new file mode 100644 index 0000000..9c17ec1 --- /dev/null +++ b/src/test/java/edu/stanford/protege/webprotege/issues/DiscussionEventChannelJsonTest.java @@ -0,0 +1,116 @@ +package edu.stanford.protege.webprotege.issues; + +import com.google.common.collect.ImmutableList; +import edu.stanford.protege.webprotege.common.EventId; +import edu.stanford.protege.webprotege.common.ProjectId; +import edu.stanford.protege.webprotege.common.UserId; +import org.junit.jupiter.api.Test; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.vocab.OWLRDFVocabulary; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.json.JsonTest; +import org.springframework.boot.test.json.JacksonTester; +import org.springframework.boot.test.json.JsonContent; +import uk.ac.manchester.cs.owl.owlapi.OWLClassImpl; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Contract-guard tests that pin the on-the-wire {@code @JsonTypeName} discriminator for + * every event in the discussion namespace. + * + *
These events are routed across the JSON-RPC envelope by their {@code @JsonTypeName} + * value. If a discriminator drifts (for example the canonical plural {@code discussions} + * silently reverts to the singular {@code discussion}), the consumer treats the message as + * an unknown type and drops it — no exception is thrown on either side. See + * protegeproject/webprotege-backend-api#54. + * + *
The expected values below are hard-coded on purpose: asserting against each class's
+ * own {@code CHANNEL} constant would let a constant rename slip through undetected. The
+ * whole point of this test is to fail the build if any of these strings ever change.
+ */
+@JsonTest
+class DiscussionEventChannelJsonTest {
+
+ private static final String PROJECT_ID = "00000000-1111-2222-3333-444444444444";
+
+ private static final String COMMENT_POSTED = "webprotege.events.discussions.CommentPosted";
+
+ private static final String COMMENT_UPDATED = "webprotege.events.discussions.CommentUpdated";
+
+ private static final String STATUS_CHANGED = "webprotege.events.discussions.DiscussionThreadStatusChanged";
+
+ private static final String THREAD_CREATED = "webprotege.events.discussions.DiscussionThreadCreated";
+
+ @Autowired
+ private JacksonTester