Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg committed Oct 6, 2023
1 parent 5020eeb commit c928d68
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.cryostat.net.web.http.api.v2.ApiException;
import io.cryostat.net.web.http.api.v2.IntermediateResponse;
import io.cryostat.net.web.http.api.v2.RequestParameters;
import io.cryostat.recordings.JvmIdHelper;
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.recordings.RecordingNotFoundException;
import io.cryostat.rules.ArchivedRecordingInfo;
Expand All @@ -56,13 +57,14 @@ class RecordingDeleteFromPathHandlerTest {
@Mock AuthManager auth;
@Mock CredentialsManager credentialsManager;
@Mock Gson gson;
@Mock JvmIdHelper jvmIdHelper;
@Mock RecordingArchiveHelper recordingArchiveHelper;

@BeforeEach
void setup() {
this.handler =
new RecordingDeleteFromPathHandler(
auth, credentialsManager, gson, recordingArchiveHelper);
auth, credentialsManager, gson, jvmIdHelper, recordingArchiveHelper);
}

@Nested
Expand Down Expand Up @@ -94,7 +96,7 @@ void shouldHaveExpectedRequiredPermissions() {
void shouldHandleCorrectPath() {
MatcherAssert.assertThat(
handler.path(),
Matchers.equalTo("/api/beta/fs/recordings/:subdirectoryName/:recordingName"));
Matchers.equalTo("/api/beta/fs/recordings/:jvmId/:recordingName"));
}

@Test
Expand All @@ -117,18 +119,19 @@ class Behaviour {
@Test
void shouldThrow404IfNoMatchingRecordingFound() throws Exception {
String recordingName = "someRecording";
String subdirectoryName = "someSubdirectory";
String jvmId = "id";

when(params.getPathParams())
.thenReturn(
Map.of(
"subdirectoryName",
subdirectoryName,
"id",
jvmId,
"recordingName",
recordingName));

Future<ArchivedRecordingInfo> future =
CompletableFuture.failedFuture(
new RecordingNotFoundException(subdirectoryName, recordingName));
new RecordingNotFoundException(jvmId, recordingName));
when(recordingArchiveHelper.deleteRecordingFromPath(
Mockito.anyString(), Mockito.anyString()))
.thenReturn(future);
Expand All @@ -141,14 +144,14 @@ void shouldThrow404IfNoMatchingRecordingFound() throws Exception {
@Test
void shouldHandleSuccessfulDELETERequest() throws Exception {
String recordingName = "someRecording";
String subdirectoryName = "someSubdirectory";
String jvmId = "id";
when(params.getPathParams())
.thenReturn(
Map.of(
"recordingName",
recordingName,
"subdirectoryName",
subdirectoryName));
"id",
jvmId));

CompletableFuture<ArchivedRecordingInfo> future = Mockito.mock(CompletableFuture.class);
when(recordingArchiveHelper.deleteRecordingFromPath(
Expand All @@ -161,7 +164,7 @@ void shouldHandleSuccessfulDELETERequest() throws Exception {

verify(recordingArchiveHelper)
.deleteRecordingFromPath(
Mockito.eq(subdirectoryName), Mockito.eq(recordingName));
Mockito.eq(jvmId), Mockito.eq(recordingName));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import io.cryostat.net.web.http.api.v2.ApiException;
import io.cryostat.net.web.http.api.v2.IntermediateResponse;
import io.cryostat.net.web.http.api.v2.RequestParameters;
import io.cryostat.recordings.JvmIdHelper;
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.recordings.RecordingMetadataManager;
import io.cryostat.recordings.RecordingMetadataManager.Metadata;
Expand All @@ -61,6 +62,7 @@ public class RecordingMetadataLabelsPostFromPathHandlerTest {
@Mock AuthManager authManager;
@Mock CredentialsManager credentialsManager;
@Mock Gson gson;
@Mock JvmIdHelper jvmIdHelper;
@Mock RecordingArchiveHelper recordingArchiveHelper;
@Mock RecordingMetadataManager recordingMetadataManager;
@Mock RequestParameters params;
Expand All @@ -77,6 +79,7 @@ void setup() {
authManager,
credentialsManager,
gson,
jvmIdHelper,
recordingArchiveHelper,
recordingMetadataManager);
}
Expand Down Expand Up @@ -104,7 +107,7 @@ void shouldHaveTargetsPath() {
MatcherAssert.assertThat(
handler.path(),
Matchers.equalTo(
"/api/beta/fs/recordings/:subdirectoryName/:recordingName/metadata/labels"));
"/api/beta/fs/recordings/:jvmId/:recordingName/metadata/labels"));
}

@Test
Expand Down Expand Up @@ -139,24 +142,24 @@ class Behaviour {
@Test
void shouldUpdateLabels() throws Exception {
String recordingName = "someRecording";
String subdirectoryName = "someTarget";
String jvmId = "id";
Map<String, String> labels = Map.of("key", "value");
Metadata metadata = new Metadata(labels);
String requestLabels = labels.toString();
Map<String, String> params = Mockito.mock(Map.class);

when(requestParameters.getPathParams()).thenReturn(params);
when(params.get("recordingName")).thenReturn(recordingName);
when(params.get("subdirectoryName")).thenReturn(subdirectoryName);
when(params.get("jvmId")).thenReturn(jvmId);
when(requestParameters.getBody()).thenReturn(requestLabels);

when(recordingArchiveHelper.getRecordingPathFromPath(subdirectoryName, recordingName))
when(recordingArchiveHelper.getRecordingPathFromPath(jvmId, recordingName))
.thenReturn(CompletableFuture.completedFuture(Path.of(recordingName)));

when(recordingMetadataManager.parseRecordingLabels(requestLabels)).thenReturn(labels);

when(recordingMetadataManager.setRecordingMetadataFromPath(
subdirectoryName, recordingName, metadata))
jvmId, recordingName, metadata))
.thenReturn(CompletableFuture.completedFuture(metadata));

IntermediateResponse<Metadata> response = handler.handle(requestParameters);
Expand All @@ -169,7 +172,7 @@ void shouldThrow400OnEmptyLabels() throws Exception {
Map<String, String> params = Mockito.mock(Map.class);
when(requestParameters.getPathParams()).thenReturn(params);
when(params.get("recordingName")).thenReturn("someRecording");
when(params.get("subdirectoryName")).thenReturn("subdirectoryName");
when(params.get("jvmId")).thenReturn("id");
when(requestParameters.getBody()).thenReturn("invalid");
Mockito.doThrow(new IllegalArgumentException())
.when(recordingMetadataManager)
Expand All @@ -182,17 +185,17 @@ void shouldThrow400OnEmptyLabels() throws Exception {

@Test
void shouldThrowWhenRecordingNotFound() throws Exception {
String subdirectoryName = "someSubdirectory";
String jvmId = "id";
String recordingName = "someNonExistentRecording";
String labels = Map.of("key", "value").toString();
Map<String, String> params = Mockito.mock(Map.class);

when(requestParameters.getPathParams()).thenReturn(params);
when(params.get("recordingName")).thenReturn(recordingName);
when(params.get("subdirectoryName")).thenReturn(subdirectoryName);
when(params.get("jvmId")).thenReturn(jvmId);
when(requestParameters.getBody()).thenReturn(labels);

when(recordingArchiveHelper.getRecordingPathFromPath(subdirectoryName, recordingName))
when(recordingArchiveHelper.getRecordingPathFromPath(jvmId, recordingName))
.thenReturn(
CompletableFuture.failedFuture(
new RecordingNotFoundException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.cryostat.net.web.http.api.v2.ApiException;
import io.cryostat.net.web.http.api.v2.IntermediateResponse;
import io.cryostat.net.web.http.api.v2.RequestParameters;
import io.cryostat.recordings.JvmIdHelper;
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.recordings.RecordingNotFoundException;

Expand Down Expand Up @@ -70,6 +71,7 @@ class RecordingUploadPostFromPathHandlerTest {
@Mock CredentialsManager credentialsManager;
@Mock Environment env;
@Mock WebClient webClient;
@Mock JvmIdHelper jvmIdHelper;
@Mock RecordingArchiveHelper recordingArchiveHelper;
@Mock Gson gson;

Expand All @@ -82,7 +84,7 @@ class RecordingUploadPostFromPathHandlerTest {
void setup() {
this.handler =
new RecordingUploadPostFromPathHandler(
auth, credentialsManager, env, 30, webClient, recordingArchiveHelper, gson);
auth, credentialsManager, env, 30, webClient, jvmIdHelper, recordingArchiveHelper, gson);
}

@Nested
Expand Down Expand Up @@ -115,7 +117,7 @@ void shouldHandleCorrectPath() {
MatcherAssert.assertThat(
handler.path(),
Matchers.equalTo(
"/api/beta/fs/recordings/:subdirectoryName/:recordingName/upload"));
"/api/beta/fs/recordings/:jvmId/:recordingName/upload"));
}

@Test
Expand Down

0 comments on commit c928d68

Please sign in to comment.