diff --git a/src/main/java/io/cryostat/messaging/notifications/Notification.java b/src/main/java/io/cryostat/messaging/notifications/Notification.java index a4c414826c..44a4f6ea5e 100644 --- a/src/main/java/io/cryostat/messaging/notifications/Notification.java +++ b/src/main/java/io/cryostat/messaging/notifications/Notification.java @@ -15,8 +15,6 @@ */ package io.cryostat.messaging.notifications; -import java.time.Instant; - import io.cryostat.net.web.http.HttpMimeType; public class Notification { @@ -87,7 +85,6 @@ public Notification build() { public static class Meta { private final String category; private final MetaType type; - private final long serverTime = Instant.now().getEpochSecond(); public Meta(String category, MetaType type) { this.category = category; diff --git a/src/main/java/io/cryostat/messaging/notifications/NotificationFactory.java b/src/main/java/io/cryostat/messaging/notifications/NotificationFactory.java index 74477a8435..1167e17f8d 100644 --- a/src/main/java/io/cryostat/messaging/notifications/NotificationFactory.java +++ b/src/main/java/io/cryostat/messaging/notifications/NotificationFactory.java @@ -15,6 +15,8 @@ */ package io.cryostat.messaging.notifications; +import io.cryostat.net.web.http.HttpMimeType; + public class NotificationFactory { private final NotificationSource source; @@ -26,4 +28,10 @@ public class NotificationFactory { public Notification.Builder createBuilder() { return new Notification.Builder(source); } + + public Notification.Builder createOwnedResourceBuilder(String notificationCategory) { + return new Notification.Builder(source) + .metaType(HttpMimeType.JSON) + .metaCategory(notificationCategory); + } } diff --git a/src/main/java/io/cryostat/net/web/http/api/beta/RecordingsFromIdPostHandler.java b/src/main/java/io/cryostat/net/web/http/api/beta/RecordingsFromIdPostHandler.java index e6e76611a8..6bd995d30f 100644 --- a/src/main/java/io/cryostat/net/web/http/api/beta/RecordingsFromIdPostHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/beta/RecordingsFromIdPostHandler.java @@ -47,7 +47,6 @@ import io.cryostat.net.web.http.api.v2.ApiException; import io.cryostat.recordings.JvmIdHelper; import io.cryostat.recordings.JvmIdHelper.JvmIdDoesNotExistException; -import io.cryostat.recordings.JvmIdHelper.JvmIdGetException; import io.cryostat.recordings.RecordingArchiveHelper; import io.cryostat.recordings.RecordingMetadataManager; import io.cryostat.recordings.RecordingMetadataManager.Metadata; @@ -275,9 +274,7 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception { try { notificationFactory - .createBuilder() - .metaCategory(NOTIFICATION_CATEGORY) - .metaType(HttpMimeType.JSON) + .createOwnedResourceBuilder(NOTIFICATION_CATEGORY) .message( Map.of( "recording", diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/TargetProbePostHandler.java b/src/main/java/io/cryostat/net/web/http/api/v2/TargetProbePostHandler.java index 50c6bd0b7f..d90f03b897 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/TargetProbePostHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/TargetProbePostHandler.java @@ -158,9 +158,7 @@ public IntermediateResponse handle(RequestParameters requestParams) throws List events = Arrays.asList(template.getEvents()); try { notificationFactory - .createBuilder() - .metaCategory(NOTIFICATION_CATEGORY) - .metaType(HttpMimeType.JSON) + .createOwnedResourceBuilder(NOTIFICATION_CATEGORY) .message( Map.of( "targetId", diff --git a/src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java b/src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java index 47c9b87c22..d105b03231 100644 --- a/src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java +++ b/src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java @@ -66,7 +66,6 @@ import io.cryostat.net.TargetConnectionManager; import io.cryostat.net.web.WebModule; import io.cryostat.net.web.WebServer; -import io.cryostat.net.web.http.HttpMimeType; import io.cryostat.net.web.http.api.v2.ApiException; import io.cryostat.platform.PlatformClient; import io.cryostat.recordings.JvmIdHelper.JvmIdGetException; @@ -385,6 +384,8 @@ public Future saveRecording( validateSavePath(recordingName, savePath); Path filenamePath = savePath.getFileName(); String filename = filenamePath.toString(); + String targetId = connectionDescriptor.getTargetId(); + String jvmId = jvmIdHelper.getJvmId(targetId); Metadata metadata = recordingMetadataManager .copyMetadataToArchives(connectionDescriptor, recordingName, filename) @@ -406,9 +407,7 @@ public Future saveRecording( getArchivedTime(filename)); future.complete(archivedRecordingInfo); notificationFactory - .createBuilder() - .metaCategory(SAVE_NOTIFICATION_CATEGORY) - .metaType(HttpMimeType.JSON) + .createOwnedResourceBuilder(SAVE_NOTIFICATION_CATEGORY) .message( Map.of( "recording", @@ -416,7 +415,7 @@ public Future saveRecording( "target", connectionDescriptor.getTargetId(), "jvmId", - jvmIdHelper.getJvmId(connectionDescriptor.getTargetId()))) + jvmId)) .build() .send(); } catch (Exception e) { @@ -453,10 +452,15 @@ public Future deleteRecordingFromPath( getFileSize(filename), getArchivedTime(filename)); notificationFactory - .createBuilder() - .metaCategory(DELETE_NOTIFICATION_CATEGORY) - .metaType(HttpMimeType.JSON) - .message(Map.of("recording", archivedRecordingInfo, "target", targetId, "jvmId", jvmIdHelper.getJvmId(targetId))) + .createOwnedResourceBuilder(DELETE_NOTIFICATION_CATEGORY) + .message( + Map.of( + "recording", + archivedRecordingInfo, + "target", + targetId, + "jvmId", + jvmId)) .build() .send(); fs.deleteIfExists(recordingPath); @@ -517,10 +521,15 @@ private CompletableFuture handleDeleteRecordingRequest( getFileSize(filename), getArchivedTime(filename)); notificationFactory - .createBuilder() - .metaCategory(DELETE_NOTIFICATION_CATEGORY) - .metaType(HttpMimeType.JSON) - .message(Map.of("recording", archivedRecordingInfo, "target", targetId, "jvmId", jvmIdHelper.getJvmId(targetId))) + .createOwnedResourceBuilder(DELETE_NOTIFICATION_CATEGORY) + .message( + Map.of( + "recording", + archivedRecordingInfo, + "target", + targetId, + "jvmId", + jvmIdHelper.getJvmId(targetId))) .build() .send(); checkEmptySubdirectory(parentPath); diff --git a/src/main/java/io/cryostat/recordings/RecordingMetadataManager.java b/src/main/java/io/cryostat/recordings/RecordingMetadataManager.java index baf35e6b15..4fbf8d4bf6 100644 --- a/src/main/java/io/cryostat/recordings/RecordingMetadataManager.java +++ b/src/main/java/io/cryostat/recordings/RecordingMetadataManager.java @@ -47,7 +47,6 @@ import io.cryostat.messaging.notifications.NotificationFactory; import io.cryostat.net.ConnectionDescriptor; import io.cryostat.net.TargetConnectionManager; -import io.cryostat.net.web.http.HttpMimeType; import io.cryostat.platform.PlatformClient; import io.cryostat.platform.ServiceRef; import io.cryostat.platform.TargetDiscoveryEvent; @@ -514,9 +513,7 @@ public Future setRecordingMetadataFromPath( StandardOpenOption.TRUNCATE_EXISTING); notificationFactory - .createBuilder() - .metaCategory(RecordingMetadataManager.NOTIFICATION_CATEGORY) - .metaType(HttpMimeType.JSON) + .createOwnedResourceBuilder(NOTIFICATION_CATEGORY) .message( Map.of( "recordingName", @@ -524,7 +521,7 @@ public Future setRecordingMetadataFromPath( "target", connectUrl, "jvmId", - jvmIdHelper.getJvmId(connectUrl), + jvmId, "metadata", metadata)) .build() @@ -559,9 +556,7 @@ public Future setRecordingMetadata( if (issueNotification) { notificationFactory - .createBuilder() - .metaCategory(RecordingMetadataManager.NOTIFICATION_CATEGORY) - .metaType(HttpMimeType.JSON) + .createOwnedResourceBuilder(NOTIFICATION_CATEGORY) .message( Map.of( "recordingName", @@ -569,7 +564,7 @@ public Future setRecordingMetadata( "target", connectionDescriptor.getTargetId(), "jvmId", - jvmIdHelper.getJvmId(connectionDescriptor), + jvmId, "metadata", metadata)) .build() diff --git a/src/main/java/io/cryostat/recordings/RecordingTargetHelper.java b/src/main/java/io/cryostat/recordings/RecordingTargetHelper.java index 8582396757..13f228796a 100644 --- a/src/main/java/io/cryostat/recordings/RecordingTargetHelper.java +++ b/src/main/java/io/cryostat/recordings/RecordingTargetHelper.java @@ -44,8 +44,6 @@ import io.cryostat.net.TargetConnectionManager; import io.cryostat.net.reports.ReportService; import io.cryostat.net.web.WebServer; -import io.cryostat.net.web.http.HttpMimeType; -import io.cryostat.recordings.JvmIdHelper; import io.cryostat.recordings.JvmIdHelper.JvmIdGetException; import io.cryostat.recordings.RecordingMetadataManager.Metadata; @@ -473,13 +471,18 @@ private void issueNotification( HyperlinkedSerializableRecordingDescriptor linkedDesc, String notificationCategory) { try { - notificationFactory - .createBuilder() - .metaCategory(notificationCategory) - .metaType(HttpMimeType.JSON) - .message(Map.of("recording", linkedDesc, "target", targetId, "jvmId", jvmIdHelper.get().getJvmId(targetId))) - .build() - .send(); + notificationFactory + .createOwnedResourceBuilder(notificationCategory) + .message( + Map.of( + "recording", + linkedDesc, + "target", + targetId, + "jvmId", + jvmIdHelper.get().getJvmId(targetId))) + .build() + .send(); } catch (JvmIdGetException e) { logger.info("Retain null jvmId for target [{}]", targetId); logger.info(e); diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingsFromIdPostHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingsFromIdPostHandlerTest.java index 54e4a6309c..3391aff279 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingsFromIdPostHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingsFromIdPostHandlerTest.java @@ -105,7 +105,9 @@ class RecordingsFromIdPostHandlerTest { @BeforeEach void setup() { - lenient().when(notificationFactory.createBuilder()).thenReturn(notificationBuilder); + lenient() + .when(notificationFactory.createOwnedResourceBuilder(Mockito.anyString())) + .thenReturn(notificationBuilder); lenient() .when(notificationBuilder.metaCategory(Mockito.any())) .thenReturn(notificationBuilder); @@ -323,16 +325,21 @@ public String answer(InvocationOnMock invocation) throws Throwable { 0, expectedArchivedTime); ArgumentCaptor> messageCaptor = ArgumentCaptor.forClass(Map.class); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("ArchivedRecordingCreated"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("ArchivedRecordingCreated"); Mockito.verify(notificationBuilder).message(messageCaptor.capture()); Mockito.verify(notificationBuilder).build(); Mockito.verify(notification).send(); MatcherAssert.assertThat( messageCaptor.getValue(), - Matchers.equalTo(Map.of("recording", recordingInfo, "target", mockConnectUrl, "jvmId", mockJvmId))); + Matchers.equalTo( + Map.of( + "recording", + recordingInfo, + "target", + mockConnectUrl, + "jvmId", + mockJvmId))); } @Test @@ -482,16 +489,21 @@ public String answer(InvocationOnMock invocation) throws Throwable { 0, expectedArchivedTime); ArgumentCaptor> messageCaptor = ArgumentCaptor.forClass(Map.class); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("ArchivedRecordingCreated"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("ArchivedRecordingCreated"); Mockito.verify(notificationBuilder).message(messageCaptor.capture()); Mockito.verify(notificationBuilder).build(); Mockito.verify(notification).send(); MatcherAssert.assertThat( messageCaptor.getValue(), - Matchers.equalTo(Map.of("recording", recordingInfo, "target", mockConnectUrl, "jvmId", mockJvmId))); + Matchers.equalTo( + Map.of( + "recording", + recordingInfo, + "target", + mockConnectUrl, + "jvmId", + mockJvmId))); } @Test diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/TargetProbePostHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/TargetProbePostHandlerTest.java index 077b43cc63..6c8b0e71cd 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/TargetProbePostHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/TargetProbePostHandlerTest.java @@ -55,9 +55,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; import org.mockito.junit.jupiter.MockitoExtension; -import org.mockito.stubbing.Answer; @ExtendWith(MockitoExtension.class) public class TargetProbePostHandlerTest { @@ -78,7 +76,9 @@ public class TargetProbePostHandlerTest { @BeforeEach void setup() { - lenient().when(notificationFactory.createBuilder()).thenReturn(notificationBuilder); + lenient() + .when(notificationFactory.createOwnedResourceBuilder(Mockito.anyString())) + .thenReturn(notificationBuilder); lenient() .when(notificationBuilder.metaCategory(Mockito.any())) .thenReturn(notificationBuilder); diff --git a/src/test/java/io/cryostat/recordings/RecordingArchiveHelperTest.java b/src/test/java/io/cryostat/recordings/RecordingArchiveHelperTest.java index 5e3a1d8b46..f04bce0096 100644 --- a/src/test/java/io/cryostat/recordings/RecordingArchiveHelperTest.java +++ b/src/test/java/io/cryostat/recordings/RecordingArchiveHelperTest.java @@ -101,6 +101,9 @@ class RecordingArchiveHelperTest { @BeforeEach void setup() { lenient().when(notificationFactory.createBuilder()).thenReturn(notificationBuilder); + lenient() + .when(notificationFactory.createOwnedResourceBuilder(Mockito.anyString())) + .thenReturn(notificationBuilder); lenient() .when(notificationBuilder.metaCategory(Mockito.any())) .thenReturn(notificationBuilder); @@ -264,10 +267,9 @@ public Object answer(InvocationOnMock invocation) throws Throwable { MatcherAssert.assertThat(info.getName(), Matchers.equalTo(savedName)); Mockito.verify(fs).copy(Mockito.isA(BufferedInputStream.class), Mockito.eq(destination)); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("ActiveRecordingSaved"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); - Mockito.verify(notificationBuilder).message(Map.of("recording", info, "target", targetId, "jvmId", "mockId")); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("ActiveRecordingSaved"); + Mockito.verify(notificationBuilder) + .message(Map.of("recording", info, "target", targetId, "jvmId", "mockId")); Mockito.verify(notificationBuilder).build(); Mockito.verify(notification).send(); } @@ -346,9 +348,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { MatcherAssert.assertThat(info.getName(), Matchers.equalTo(savedName)); Mockito.verify(fs).copy(Mockito.isA(BufferedInputStream.class), Mockito.eq(destination)); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("ActiveRecordingSaved"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("ActiveRecordingSaved"); Mockito.verify(notificationBuilder) .message( Map.of( @@ -442,10 +442,9 @@ public Object answer(InvocationOnMock invocation) throws Throwable { MatcherAssert.assertThat(info.getName(), Matchers.equalTo(savedName)); Mockito.verify(fs).copy(Mockito.isA(BufferedInputStream.class), Mockito.eq(destination)); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("ActiveRecordingSaved"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); - Mockito.verify(notificationBuilder).message(Map.of("recording", info, "target", targetId, "jvmId", "mockId")); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("ActiveRecordingSaved"); + Mockito.verify(notificationBuilder) + .message(Map.of("recording", info, "target", targetId, "jvmId", "mockId")); Mockito.verify(notificationBuilder).build(); Mockito.verify(notification).send(); } @@ -523,10 +522,9 @@ public Object answer(InvocationOnMock invocation) throws Throwable { MatcherAssert.assertThat(info.getName(), Matchers.equalTo(savedName)); Mockito.verify(fs).copy(Mockito.isA(BufferedInputStream.class), Mockito.eq(destination)); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("ActiveRecordingSaved"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); - Mockito.verify(notificationBuilder).message(Map.of("recording", info, "target", targetId, "jvmId", "mockId")); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("ActiveRecordingSaved"); + Mockito.verify(notificationBuilder) + .message(Map.of("recording", info, "target", targetId, "jvmId", "mockId")); Mockito.verify(notificationBuilder).build(); Mockito.verify(notification).send(); } @@ -611,10 +609,9 @@ public Object answer(InvocationOnMock invocation) throws Throwable { MatcherAssert.assertThat(info.getName(), Matchers.equalTo(savedName)); Mockito.verify(fs).copy(Mockito.isA(BufferedInputStream.class), Mockito.eq(destination)); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("ActiveRecordingSaved"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); - Mockito.verify(notificationBuilder).message(Map.of("recording", info, "target", targetId, "jvmId", "mockId")); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("ActiveRecordingSaved"); + Mockito.verify(notificationBuilder) + .message(Map.of("recording", info, "target", targetId, "jvmId", "mockId")); Mockito.verify(notificationBuilder).build(); Mockito.verify(notification).send(); } @@ -752,10 +749,9 @@ public Object answer(InvocationOnMock invocation) throws Throwable { MatcherAssert.assertThat(info.getName(), Matchers.equalTo(savedName)); Mockito.verify(fs).copy(Mockito.isA(BufferedInputStream.class), Mockito.eq(destination)); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("ActiveRecordingSaved"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); - Mockito.verify(notificationBuilder).message(Map.of("recording", info, "target", targetId, "jvmId", "mockId")); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("ActiveRecordingSaved"); + Mockito.verify(notificationBuilder) + .message(Map.of("recording", info, "target", targetId, "jvmId", "mockId")); Mockito.verify(notificationBuilder).build(); Mockito.verify(notification).send(); } @@ -837,9 +833,7 @@ public String answer(InvocationOnMock invocation) throws Throwable { .toAbsolutePath()); Mockito.verify(fs).deleteIfExists(destinationFile); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("ArchivedRecordingDeleted"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("ArchivedRecordingDeleted"); Mockito.verify(notificationBuilder).message(messageCaptor.capture()); Mockito.verify(notificationBuilder).build(); Mockito.verify(notification).send(); @@ -858,7 +852,8 @@ public String answer(InvocationOnMock invocation) throws Throwable { MatcherAssert.assertThat( messageCaptor.getValue(), - Matchers.equalTo(Map.of("recording", matcher, "target", "uploads", "jvmId", "mockId"))); + Matchers.equalTo( + Map.of("recording", matcher, "target", "uploads", "jvmId", "mockId"))); } @Test diff --git a/src/test/java/io/cryostat/recordings/RecordingMetadataManagerTest.java b/src/test/java/io/cryostat/recordings/RecordingMetadataManagerTest.java index 00629e038e..e2a095f29f 100644 --- a/src/test/java/io/cryostat/recordings/RecordingMetadataManagerTest.java +++ b/src/test/java/io/cryostat/recordings/RecordingMetadataManagerTest.java @@ -90,6 +90,9 @@ void setup() { Base32 base32 = new Base32(); lenient().when(notificationFactory.createBuilder()).thenReturn(notificationBuilder); + lenient() + .when(notificationFactory.createOwnedResourceBuilder(Mockito.anyString())) + .thenReturn(notificationBuilder); lenient() .when(notificationBuilder.metaCategory(Mockito.any())) .thenReturn(notificationBuilder); @@ -114,10 +117,10 @@ public String answer(InvocationOnMock invocation) throws Throwable { .when(jvmIdHelper.subdirectoryNameToJvmId(Mockito.anyString())) .thenAnswer( new Answer() { - @Override - public String answer(InvocationOnMock invocation) throws Throwable { + @Override + public String answer(InvocationOnMock invocation) throws Throwable { return invocation.getArgument(0); - } + } }); this.recordingMetadataManager = diff --git a/src/test/java/io/cryostat/recordings/RecordingTargetHelperTest.java b/src/test/java/io/cryostat/recordings/RecordingTargetHelperTest.java index 73b20aea78..7f5dd9a3dc 100644 --- a/src/test/java/io/cryostat/recordings/RecordingTargetHelperTest.java +++ b/src/test/java/io/cryostat/recordings/RecordingTargetHelperTest.java @@ -53,7 +53,6 @@ import io.cryostat.net.reports.ReportService; import io.cryostat.net.web.WebServer; import io.cryostat.net.web.http.HttpMimeType; -import io.cryostat.recordings.JvmIdHelper; import io.cryostat.recordings.RecordingMetadataManager.Metadata; import io.cryostat.recordings.RecordingTargetHelper.ReplacementPolicy; import io.cryostat.recordings.RecordingTargetHelper.SnapshotCreationException; @@ -98,6 +97,9 @@ public class RecordingTargetHelperTest { @BeforeEach void setup() { lenient().when(notificationFactory.createBuilder()).thenReturn(notificationBuilder); + lenient() + .when(notificationFactory.createOwnedResourceBuilder(Mockito.anyString())) + .thenReturn(notificationBuilder); lenient() .when(notificationBuilder.metaCategory(Mockito.any())) .thenReturn(notificationBuilder); @@ -225,9 +227,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { HyperlinkedSerializableRecordingDescriptor linkedDesc = new HyperlinkedSerializableRecordingDescriptor(descriptor, null, null, metadata); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("ActiveRecordingDeleted"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("ActiveRecordingDeleted"); Mockito.verify(notificationBuilder) .message(Map.of("recording", linkedDesc, "target", "fooTarget", "jvmId", "id")); Mockito.verify(notificationBuilder).build(); @@ -276,9 +276,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { HyperlinkedSerializableRecordingDescriptor linkedDesc = new HyperlinkedSerializableRecordingDescriptor(descriptor, null, null, metadata); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("SnapshotDeleted"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("SnapshotDeleted"); Mockito.verify(notificationBuilder) .message(Map.of("recording", linkedDesc, "target", "fooTarget", "jvmId", "id")); Mockito.verify(notificationBuilder).build(); @@ -329,7 +327,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { recordingTargetHelper.deleteRecording(connectionDescriptor, recordingName).get(); - Mockito.verify(notificationBuilder).metaCategory("ActiveRecordingDeleted"); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("ActiveRecordingDeleted"); } @ParameterizedTest @@ -367,7 +365,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { recordingTargetHelper.deleteRecording(connectionDescriptor, recordingName).get(); - Mockito.verify(notificationBuilder).metaCategory("SnapshotDeleted"); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("SnapshotDeleted"); } @Test @@ -539,11 +537,16 @@ void shouldVerifySnapshotWithNotification() throws Exception { .verifySnapshot(connectionDescriptor, snapshotDescriptor) .get(); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("SnapshotCreated"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("SnapshotCreated"); Mockito.verify(notificationBuilder) - .message(Map.of("recording", snapshotDescriptor, "target", "fooTarget", "jvmId", "id")); + .message( + Map.of( + "recording", + snapshotDescriptor, + "target", + "fooTarget", + "jvmId", + "id")); Mockito.verify(notificationBuilder).build(); Mockito.verify(notification).send(); @@ -585,9 +588,8 @@ void shouldVerifySnapshotWithoutNotification() throws Exception { .verifySnapshot(connectionDescriptor, snapshotDescriptor, false) .get(); - Mockito.verify(notificationFactory, Mockito.never()).createBuilder(); - Mockito.verify(notificationBuilder, Mockito.never()).metaCategory("SnapshotCreated"); - Mockito.verify(notificationBuilder, Mockito.never()).metaType(HttpMimeType.JSON); + Mockito.verify(notificationFactory, Mockito.never()) + .createOwnedResourceBuilder("SnapshotCreated"); Mockito.verify(notificationBuilder, Mockito.never()) .message(Map.of("recording", snapshotDescriptor, "target", "fooTarget")); Mockito.verify(notificationBuilder, Mockito.never()).build(); @@ -749,9 +751,7 @@ public Future answer(InvocationOnMock invocation) ArgumentCaptor messageCaptor = ArgumentCaptor.forClass(Map.class); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("ActiveRecordingCreated"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("ActiveRecordingCreated"); Mockito.verify(notificationBuilder).message(messageCaptor.capture()); Mockito.verify(notificationBuilder).build(); Mockito.verify(notification).send(); @@ -990,9 +990,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { new HyperlinkedSerializableRecordingDescriptor( descriptor, null, null, RecordingState.STOPPED); - Mockito.verify(notificationFactory).createBuilder(); - Mockito.verify(notificationBuilder).metaCategory("ActiveRecordingStopped"); - Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON); + Mockito.verify(notificationFactory).createOwnedResourceBuilder("ActiveRecordingStopped"); Mockito.verify(notificationBuilder) .message(Map.of("recording", linkedDesc, "target", "fooTarget", "jvmId", "id")); Mockito.verify(notificationBuilder).build();