From cea5a1e1aff5fbc8e3402b8f8816830066056e48 Mon Sep 17 00:00:00 2001 From: Sahiba Mittal Date: Tue, 28 Jan 2025 16:09:39 +0000 Subject: [PATCH] fix notification rule test for rule not found Co-Authored-By: Niklas --- .../resources/v1/NotificationPublisherResource.java | 8 ++++++-- .../resources/v1/NotificationPublisherResourceTest.java | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dependencytrack/resources/v1/NotificationPublisherResource.java b/src/main/java/org/dependencytrack/resources/v1/NotificationPublisherResource.java index da1dc8aa6..906157953 100644 --- a/src/main/java/org/dependencytrack/resources/v1/NotificationPublisherResource.java +++ b/src/main/java/org/dependencytrack/resources/v1/NotificationPublisherResource.java @@ -283,14 +283,18 @@ public Response restoreDefaultTemplates() { ) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Test notification dispatched successfully"), - @ApiResponse(responseCode = "401", description = "Unauthorized") + @ApiResponse(responseCode = "401", description = "Unauthorized"), + @ApiResponse(responseCode = "404", description = "Notification rule not found") }) @PermissionRequired(Permissions.Constants.SYSTEM_CONFIGURATION) - public Response testSlackPublisherConfig( + public Response testNotificationRule( @Parameter(description = "The UUID of the rule to test", schema = @Schema(type = "string", format = "uuid"), required = true) @PathParam("uuid") @ValidUuid String ruleUuid) { try (QueryManager qm = new QueryManager()) { NotificationRule rule = qm.getObjectByUuid(NotificationRule.class, ruleUuid); + if (rule == null) { + return Response.status(Response.Status.NOT_FOUND).build(); + } final KafkaEventDispatcher eventDispatcher = new KafkaEventDispatcher(); for(NotificationGroup group : rule.getNotifyOn()){ eventDispatcher.dispatchNotification(new Notification() diff --git a/src/test/java/org/dependencytrack/resources/v1/NotificationPublisherResourceTest.java b/src/test/java/org/dependencytrack/resources/v1/NotificationPublisherResourceTest.java index 610bd562a..b0cff0c88 100644 --- a/src/test/java/org/dependencytrack/resources/v1/NotificationPublisherResourceTest.java +++ b/src/test/java/org/dependencytrack/resources/v1/NotificationPublisherResourceTest.java @@ -344,4 +344,12 @@ public void testNotificationRuleTest() { Assert.assertEquals(200, response.getStatus()); assertThat(kafkaMockProducer.history().size()).isEqualTo(11); } + + @Test + public void testNotificationRuleNotFoundTest() { + final Response response = jersey.target(V1_NOTIFICATION_PUBLISHER + "/test/" + UUID.randomUUID()).request() + .header(X_API_KEY, apiKey) + .post(null); + assertThat(response.getStatus()).isEqualTo(404); + } }