From ae3697139666e3904bc79f83ec3a27d6b9eba51b Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Thu, 27 Feb 2025 19:45:31 -0500 Subject: [PATCH] delete more redundant tests --- .../java/itest/CustomEventTemplateTest.java | 130 ------ src/test/java/itest/TargetPostDeleteIT.java | 206 --------- .../java/itest/TargetRecordingOptionsIT.java | 398 ------------------ .../itest/TargetRecordingsClientErrorIT.java | 373 ---------------- 4 files changed, 1107 deletions(-) delete mode 100644 src/test/java/itest/CustomEventTemplateTest.java delete mode 100644 src/test/java/itest/TargetPostDeleteIT.java delete mode 100644 src/test/java/itest/TargetRecordingOptionsIT.java delete mode 100644 src/test/java/itest/TargetRecordingsClientErrorIT.java diff --git a/src/test/java/itest/CustomEventTemplateTest.java b/src/test/java/itest/CustomEventTemplateTest.java deleted file mode 100644 index dc6d0bf50..000000000 --- a/src/test/java/itest/CustomEventTemplateTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright The Cryostat Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package itest; - -import io.cryostat.resources.S3StorageResource; - -import io.quarkus.test.common.QuarkusTestResource; -import io.quarkus.test.junit.DisabledOnIntegrationTest; -import io.quarkus.test.junit.QuarkusTest; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.client.HttpResponse; -import io.vertx.ext.web.multipart.MultipartForm; -import itest.bases.StandardSelfTest; -import org.apache.http.client.utils.URLEncodedUtils; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -@QuarkusTest -@QuarkusTestResource(S3StorageResource.class) -@DisabledOnIntegrationTest("classpath resources are not loadable in integration test") -public class CustomEventTemplateTest extends StandardSelfTest { - - static final String INVALID_TEMPLATE_FILE_NAME = "invalidTemplate.xml"; - static final String TEMPLATE_FILE_NAME = "CustomEventTemplate.jfc"; - static final String TEMPLATE_NAME = "invalidTemplate"; - static final String MEDIA_TYPE = "application/xml"; - static final String REQ_URL = "/api/v4/event_templates"; - - @Test - public void shouldThrowIfTemplateUploadNameInvalid() throws Exception { - ClassLoader classLoader = getClass().getClassLoader(); - try (var stream = classLoader.getResourceAsStream(INVALID_TEMPLATE_FILE_NAME)) { - var buf = Buffer.buffer(stream.readAllBytes()); - MultipartForm form = - MultipartForm.create() - .binaryFileUpload( - TEMPLATE_NAME, INVALID_TEMPLATE_FILE_NAME, buf, MEDIA_TYPE); - - HttpResponse resp = - webClient.extensions().post(REQ_URL, form, REQUEST_TIMEOUT_SECONDS); - MatcherAssert.assertThat(resp.statusCode(), Matchers.equalTo(400)); - } - } - - @Test - public void shouldThrowWhenPostingInvalidTemplate() throws Exception { - ClassLoader classLoader = getClass().getClassLoader(); - try (var stream = classLoader.getResourceAsStream(INVALID_TEMPLATE_FILE_NAME)) { - var buf = Buffer.buffer(stream.readAllBytes()); - MultipartForm form = - MultipartForm.create() - .binaryFileUpload( - TEMPLATE_NAME, INVALID_TEMPLATE_FILE_NAME, buf, MEDIA_TYPE); - - HttpResponse resp = - webClient.extensions().post(REQ_URL, form, REQUEST_TIMEOUT_SECONDS); - MatcherAssert.assertThat(resp.statusCode(), Matchers.equalTo(400)); - } - } - - @Test - public void testDeleteRecordingThrowsOnNonExistentTemplate() throws Exception { - HttpResponse resp = - webClient - .extensions() - .delete( - String.format("%s/%s", REQ_URL, INVALID_TEMPLATE_FILE_NAME), - REQUEST_TIMEOUT_SECONDS); - MatcherAssert.assertThat(resp.statusCode(), Matchers.equalTo(404)); - } - - @Test - public void testPostedTemplateNameIsSanitizedAndCanBeDeleted() throws Exception { - ClassLoader classLoader = getClass().getClassLoader(); - try (var stream = classLoader.getResourceAsStream(TEMPLATE_FILE_NAME)) { - var buf = Buffer.buffer(stream.readAllBytes()); - MultipartForm form = - MultipartForm.create() - .binaryFileUpload("template", TEMPLATE_FILE_NAME, buf, MEDIA_TYPE); - HttpResponse postResp = - webClient.extensions().post(REQ_URL, form, REQUEST_TIMEOUT_SECONDS); - MatcherAssert.assertThat(postResp.statusCode(), Matchers.equalTo(201)); - - HttpResponse getResp = - webClient - .extensions() - .get( - String.format( - "/api/v4/targets/%d/event_templates", - getSelfReferenceTargetId()), - REQUEST_TIMEOUT_SECONDS); - boolean foundSanitizedTemplate = false; - for (Object o : getResp.bodyAsJsonArray()) { - JsonObject json = (JsonObject) o; - var name = json.getString("name"); - foundSanitizedTemplate = - foundSanitizedTemplate || name.equals("Custom_Event_Template"); - } - Assertions.assertTrue(foundSanitizedTemplate); - } finally { - var delResp = - webClient - .extensions() - .delete( - String.format( - "%s%s", - REQ_URL, - URLEncodedUtils.formatSegments( - "Custom_Event_Template")), - REQUEST_TIMEOUT_SECONDS); - MatcherAssert.assertThat(delResp.statusCode(), Matchers.equalTo(204)); - } - } -} diff --git a/src/test/java/itest/TargetPostDeleteIT.java b/src/test/java/itest/TargetPostDeleteIT.java deleted file mode 100644 index afa806a54..000000000 --- a/src/test/java/itest/TargetPostDeleteIT.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright The Cryostat Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package itest; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -import io.quarkus.test.junit.QuarkusIntegrationTest; -import io.vertx.core.MultiMap; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.handler.HttpException; -import itest.bases.StandardSelfTest; -import org.apache.http.client.utils.URLEncodedUtils; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -@QuarkusIntegrationTest -@Disabled("TODO") -public class TargetPostDeleteIT extends StandardSelfTest { - static final String REQ_URL = "/api/v4/targets"; - - @Test - public void testPostTargetThrowsWithoutConnectUrlAttribute() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("alias", "someAlias"); - - webClient - .post(REQ_URL) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPostTargetThrowsWithoutAliasAttribute() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("connectUrl", getSelfReferenceConnectUrl()); - - webClient - .post(REQ_URL) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPostTargetThrowsWithEmptyConnectUrl() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("alias", "someAlias"); - form.add("connectUrl", ""); - - webClient - .post(REQ_URL) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPostTargetThrowsWithEmptyAlias() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("alias", ""); - form.add("connectUrl", getSelfReferenceConnectUrl()); - - webClient - .post(REQ_URL) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPostTargetThrowsWithInvalidConnectUrl() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("connectUrl", "invalidConnectUrl"); - - webClient - .post(REQ_URL) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPostTargetThrowsWithDuplicateConnectUrl() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("alias", "duplicateCryostat"); - form.add("connectUrl", getSelfReferenceConnectUrl()); - - webClient - .post(REQ_URL) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testDeleteTargetThrowsWithInvalidConnectUrl() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - - webClient - .delete(String.format("%s/%s", REQ_URL, "invalidTargetId")) - .send( - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testDeleteTargetThrowsWithNonExistentConnectUrl() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - final String nonExistentTargetId = - URLEncodedUtils.formatSegments( - String.format("service:jmx:rmi:///jndi/rmi://invalid:9091/jmxrmi")); - - webClient - .delete(String.format("%s/%s", REQ_URL, nonExistentTargetId)) - .send( - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(404)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Not Found")); - } -} diff --git a/src/test/java/itest/TargetRecordingOptionsIT.java b/src/test/java/itest/TargetRecordingOptionsIT.java deleted file mode 100644 index f3d5d4e1c..000000000 --- a/src/test/java/itest/TargetRecordingOptionsIT.java +++ /dev/null @@ -1,398 +0,0 @@ -/* - * Copyright The Cryostat Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package itest; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import io.cryostat.util.HttpMimeType; - -import io.quarkus.test.junit.QuarkusIntegrationTest; -import io.vertx.core.MultiMap; -import io.vertx.core.http.HttpHeaders; -import io.vertx.core.json.JsonArray; -import io.vertx.core.json.JsonObject; -import itest.bases.StandardSelfTest; -import itest.util.ITestCleanupFailedException; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; -import org.junit.jupiter.api.Order; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; - -@QuarkusIntegrationTest -@Disabled("TODO") -@TestMethodOrder(OrderAnnotation.class) -public class TargetRecordingOptionsIT extends StandardSelfTest { - - static final String OPTIONS_REQ_URL = - String.format("/api/v4/targets/%s/recordingOptions", getSelfReferenceConnectUrl()); - static final String OPTIONS_LIST_REQ_URL = - String.format("/api/v4/targets/%s/recordingOptionsList", getSelfReferenceConnectUrl()); - static final String RECORDING_NAME = "test_recording"; - static final String ARCHIVED_REQ_URL = "/api/v4/recordings"; - - @AfterAll - static void resetDefaultRecordingOptions() throws Exception { - CompletableFuture dumpResponse = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("maxAge", "unset"); - form.add("toDisk", "unset"); - form.add("maxSize", "unset"); - - webClient - .patch(OPTIONS_REQ_URL) - .sendForm( - form, - ar -> { - if (assertRequestStatus(ar, dumpResponse)) { - MatcherAssert.assertThat( - ar.result().statusCode(), Matchers.equalTo(200)); - dumpResponse.complete(null); - } - }); - - try { - dumpResponse.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS); - } catch (InterruptedException | ExecutionException | TimeoutException e) { - logger.error( - new ITestCleanupFailedException( - "Failed to reset default recording options", e)); - } - } - - @Test - @Order(1) - public void testGetTargetRecordingOptionsListReturnsListOfRecordingOptions() throws Exception { - CompletableFuture getResponse = new CompletableFuture<>(); - webClient - .get(OPTIONS_LIST_REQ_URL) - .send( - ar -> { - if (assertRequestStatus(ar, getResponse)) { - MatcherAssert.assertThat( - ar.result().statusCode(), Matchers.equalTo(200)); - MatcherAssert.assertThat( - ar.result().getHeader(HttpHeaders.CONTENT_TYPE.toString()), - Matchers.equalTo(HttpMimeType.JSON.mime())); - getResponse.complete(ar.result().bodyAsJsonObject()); - } - }); - - JsonObject expectedGetResponse = - new JsonObject( - Map.of( - "meta", - Map.of("type", HttpMimeType.JSON.mime(), "status", "OK"), - "data", - Map.of( - "result", - List.of( - Map.of( - "name", - "Name", - "description", - "Recording name", - "defaultValue", - "Recording"), - Map.of( - "name", - "Duration", - "description", - "Duration of recording", - "defaultValue", - "30s[s]"), - Map.of( - "name", - "Max Size", - "description", - "Maximum size of recording", - "defaultValue", - "0B[B]"), - Map.of( - "name", - "Max Age", - "description", - "Maximum age of the events in the" - + " recording", - "defaultValue", - "0s[s]"), - Map.of( - "name", - "To disk", - "description", - "Record to disk", - "defaultValue", - "false"), - Map.of( - "name", - "Dump on Exit", - "description", - "Dump recording data to disk on JVM exit", - "defaultValue", - "false"))))); - - MatcherAssert.assertThat(getResponse.get(), Matchers.equalTo(expectedGetResponse)); - } - - @Test - @Order(2) - public void testGetTargetRecordingOptionsReturnsDefaultOptions() throws Exception { - CompletableFuture getResponse = new CompletableFuture<>(); - webClient - .get(OPTIONS_REQ_URL) - .send( - ar -> { - if (assertRequestStatus(ar, getResponse)) { - MatcherAssert.assertThat( - ar.result().statusCode(), Matchers.equalTo(200)); - MatcherAssert.assertThat( - ar.result().getHeader(HttpHeaders.CONTENT_TYPE.toString()), - Matchers.equalTo(HttpMimeType.JSON.mime())); - getResponse.complete(ar.result().bodyAsJsonObject()); - } - }); - - // FIXME the default disk option returned is different than the actual value used in - // recordings - // https://github.com/cryostatio/cryostat/issues/263 - JsonObject expectedGetResponse = - new JsonObject(Map.of("maxAge", 0, "toDisk", false, "maxSize", 0)); - - MatcherAssert.assertThat(getResponse.get(), Matchers.equalTo(expectedGetResponse)); - } - - @Test - @Order(3) - public void testPostRecordingSetsDiskOptionToTrue() throws Exception { - try { - CompletableFuture postResponse = new CompletableFuture<>(); - CompletableFuture maxAge = new CompletableFuture<>(); - CompletableFuture toDisk = new CompletableFuture<>(); - CompletableFuture maxSize = new CompletableFuture<>(); - - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("recordingName", RECORDING_NAME); - form.add("duration", "5"); - form.add("events", "template=ALL"); - webClient - .post( - String.format( - "/api/v4/targets/%s/recordings", getSelfReferenceConnectUrl())) - .sendForm( - form, - ar -> { - if (assertRequestStatus(ar, postResponse)) { - postResponse.complete(ar.result().bodyAsJsonObject()); - } - }); - - maxAge.complete(postResponse.get().getInteger("maxAge")); - toDisk.complete(postResponse.get().getBoolean("toDisk")); - maxSize.complete(postResponse.get().getInteger("maxSize")); - - MatcherAssert.assertThat(maxAge.get(), Matchers.equalTo(0)); - MatcherAssert.assertThat(toDisk.get(), Matchers.equalTo(true)); - MatcherAssert.assertThat(maxSize.get(), Matchers.equalTo(0)); - - } finally { - // Delete the recording - CompletableFuture deleteRespFuture = new CompletableFuture<>(); - webClient - .delete( - String.format( - "/api/v4/targets/%s/recordings/%s", - getSelfReferenceConnectUrl(), RECORDING_NAME)) - .send( - ar -> { - if (assertRequestStatus(ar, deleteRespFuture)) { - deleteRespFuture.complete(null); - } - }); - - try { - deleteRespFuture.get(); - } catch (InterruptedException | ExecutionException e) { - logger.error( - new ITestCleanupFailedException( - String.format( - "Failed to delete target recording %s", RECORDING_NAME), - e)); - } - } - } - - @Test - @Order(4) - public void testPatchTargetRecordingOptionsUpdatesOptions() throws Exception { - - CompletableFuture getResponse = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("maxAge", "60"); - form.add("toDisk", "true"); - form.add("maxSize", "1000"); - - webClient - .patch(OPTIONS_REQ_URL) - .sendForm( - form, - ar -> { - if (assertRequestStatus(ar, getResponse)) { - MatcherAssert.assertThat( - ar.result().statusCode(), Matchers.equalTo(200)); - MatcherAssert.assertThat( - ar.result().getHeader(HttpHeaders.CONTENT_TYPE.toString()), - Matchers.equalTo(HttpMimeType.JSON.mime())); - getResponse.complete(ar.result().bodyAsJsonObject()); - } - }); - - JsonObject expectedGetResponse = - new JsonObject(Map.of("maxAge", 60, "toDisk", true, "maxSize", 1000)); - - MatcherAssert.assertThat(getResponse.get(), Matchers.equalTo(expectedGetResponse)); - } - - @Test - @Order(5) - public void testGetTargetRecordingOptionsReturnsUpdatedOptions() throws Exception { - CompletableFuture getResponse = new CompletableFuture<>(); - webClient - .get(OPTIONS_REQ_URL) - .send( - ar -> { - if (assertRequestStatus(ar, getResponse)) { - MatcherAssert.assertThat( - ar.result().statusCode(), Matchers.equalTo(200)); - MatcherAssert.assertThat( - ar.result().getHeader(HttpHeaders.CONTENT_TYPE.toString()), - Matchers.equalTo(HttpMimeType.JSON.mime())); - getResponse.complete(ar.result().bodyAsJsonObject()); - } - }); - - JsonObject expectedGetResponse = - new JsonObject(Map.of("maxAge", 60, "toDisk", true, "maxSize", 1000)); - - MatcherAssert.assertThat(getResponse.get(), Matchers.equalTo(expectedGetResponse)); - } - - @Test - @Order(6) - public void testPostRecordingSetsArchiveOnStop() throws Exception { - String recordingName = "ArchiveOnStop"; - String archivedgName = ""; - try { - CompletableFuture postResponse = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("recordingName", recordingName); - form.add("duration", "5"); - form.add("events", "template=ALL"); - form.add("archiveOnStop", "true"); - - webClient - .post( - String.format( - "/api/v4/targets/%s/recordings", getSelfReferenceConnectUrl())) - .sendForm( - form, - ar -> { - if (assertRequestStatus(ar, postResponse)) { - postResponse.complete(ar.result().bodyAsJsonObject()); - } - }); - - postResponse.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS); - - JsonObject response1 = postResponse.get(); - MatcherAssert.assertThat(response1.getString("name"), Matchers.equalTo(recordingName)); - - Thread.sleep(8_000L); - // Assert that the recording was archived - CompletableFuture listRespFuture1 = new CompletableFuture<>(); - webClient - .get(ARCHIVED_REQ_URL) - .send( - ar -> { - if (assertRequestStatus(ar, listRespFuture1)) { - listRespFuture1.complete(ar.result().bodyAsJsonArray()); - } - }); - - JsonObject response2 = listRespFuture1.get().getJsonObject(0); - MatcherAssert.assertThat( - response2.getString("name").contains(recordingName), Matchers.is(true)); - archivedgName = response2.getString("name"); - - } finally { - // Delete the recording - CompletableFuture deleteRespFuture = new CompletableFuture<>(); - webClient - .delete( - String.format( - "/api/v4/targets/%s/recordings/%s", - getSelfReferenceConnectUrl(), recordingName)) - .send( - ar -> { - if (assertRequestStatus(ar, deleteRespFuture)) { - deleteRespFuture.complete(null); - } - }); - - try { - deleteRespFuture.get(); - } catch (InterruptedException | ExecutionException e) { - logger.error( - new ITestCleanupFailedException( - String.format( - "Failed to delete target recording %s", recordingName), - e)); - } - - // Delete the archive - CompletableFuture deleteArchiveRespFuture = new CompletableFuture<>(); - webClient - .delete( - String.format( - "/api/beta/recordings/%s/%s", - getSelfReferenceConnectUrl(), archivedgName)) - .send( - ar -> { - if (assertRequestStatus(ar, deleteArchiveRespFuture)) { - deleteArchiveRespFuture.complete(null); - } - }); - - try { - deleteArchiveRespFuture.get(); - } catch (InterruptedException | ExecutionException e) { - logger.error( - new ITestCleanupFailedException( - String.format( - "Failed to delete target archive recording %s", - archivedgName), - e)); - } - } - } -} diff --git a/src/test/java/itest/TargetRecordingsClientErrorIT.java b/src/test/java/itest/TargetRecordingsClientErrorIT.java deleted file mode 100644 index 72d4540a7..000000000 --- a/src/test/java/itest/TargetRecordingsClientErrorIT.java +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Copyright The Cryostat Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package itest; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; - -import io.cryostat.util.HttpMimeType; - -import io.quarkus.test.junit.QuarkusIntegrationTest; -import io.vertx.core.MultiMap; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.http.HttpHeaders; -import io.vertx.core.json.JsonArray; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.handler.HttpException; -import itest.bases.StandardSelfTest; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -@QuarkusIntegrationTest -@Disabled("TODO") -public class TargetRecordingsClientErrorIT extends StandardSelfTest { - - static final String REQ_URL = - String.format("/api/v4/targets/%s/recordings", getSelfReferenceConnectUrl()); - static final String TEST_RECORDING_NAME = "workflow_itest"; - - @AfterAll - static void verifyNoRecordingsCreated() throws Exception { - CompletableFuture listRespFuture1 = new CompletableFuture<>(); - webClient - .get(REQ_URL) - .send( - ar -> { - if (assertRequestStatus(ar, listRespFuture1)) { - listRespFuture1.complete(ar.result().bodyAsJsonArray()); - } - }); - JsonArray listResp = listRespFuture1.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS); - Assertions.assertTrue(listResp.isEmpty()); - } - - @Test - public void testPostRecordingThrowsOnNullForm() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - - webClient - .post(REQ_URL) - .sendForm( - MultiMap.caseInsensitiveMultiMap(), - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPostRecordingThrowsWithoutRecordingNameAttribute() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("events", "template=ALL"); - - webClient - .post(REQ_URL) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPostRecordingThrowsWithoutEventsAttribute() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("recordingName", TEST_RECORDING_NAME); - - webClient - .post(REQ_URL) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPostRecordingThrowsOnEmptyRecordingName() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("recordingName", ""); - form.add("events", "template=ALL"); - - webClient - .post(REQ_URL) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPostRecordingThrowsOnEmptyEvents() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("recordingName", TEST_RECORDING_NAME); - form.add("events", ""); - - webClient - .post(REQ_URL) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPostRecordingThrowsOnInvalidIntegerArgument() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("recordingName", TEST_RECORDING_NAME); - form.add("events", "template=ALL"); - form.add("duration", "notAnInt"); - - webClient - .post(REQ_URL) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPostRecordingThrowsOnInvalidDiskOption() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("recordingName", TEST_RECORDING_NAME); - form.add("events", "template=ALL"); - form.add("toDisk", "notABool"); - - webClient - .post(REQ_URL) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testDeleteRecordingThrowsOnNonExistentRecording() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - webClient - .delete(String.format("%s/%s", REQ_URL, TEST_RECORDING_NAME)) - .send( - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(404)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Not Found")); - } - - @Test - public void testGetRecordingThrowsOnNonExistentRecording() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - webClient - .get(String.format("%s/%s", REQ_URL, TEST_RECORDING_NAME)) - .send( - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(404)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Not Found")); - } - - @Test - public void testPatchRecordingOptionsThrowsOnInvalidIntegerArgument() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("recordingName", TEST_RECORDING_NAME); - form.add("maxAge", "notAnInt"); - - webClient - .patch( - String.format( - "/api/v4/targets/%s/recordingOptions", - getSelfReferenceConnectUrl())) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPatchRecordingOptionsThrowsOnInvalidDiskOption() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - MultiMap form = MultiMap.caseInsensitiveMultiMap(); - form.add("recordingName", TEST_RECORDING_NAME); - form.add("toDisk", "notABool"); - - webClient - .patch( - String.format( - "/api/v4/targets/%s/recordingOptions", - getSelfReferenceConnectUrl())) - .sendForm( - form, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPatchRecordingThrowsOnRecordingNotFound() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - - webClient - .patch(String.format("%s/%s", REQ_URL, TEST_RECORDING_NAME)) - .putHeader(HttpHeaders.CONTENT_TYPE.toString(), HttpMimeType.PLAINTEXT.mime()) - .putHeader(HttpHeaders.ACCEPT.toString(), HttpMimeType.PLAINTEXT.mime()) - .sendBuffer( - Buffer.buffer("SAVE"), - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(404)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Not Found")); - } - - @Test - public void testPatchRecordingThrowsOnInvalidRequestBody() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - - webClient - .patch(String.format("%s/%s", REQ_URL, TEST_RECORDING_NAME)) - .sendBuffer( - Buffer.buffer("INVALID_BODY"), - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testPatchRecordingThrowsOnNullRequestBody() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - - webClient - .patch(String.format("%s/%s", REQ_URL, TEST_RECORDING_NAME)) - .sendBuffer( - null, - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); - } - - @Test - public void testUploadRecordingThrowsOnNonExistentRecording() throws Exception { - - CompletableFuture response = new CompletableFuture<>(); - - webClient - .post(String.format("%s/%s/upload", REQ_URL, TEST_RECORDING_NAME)) - .send( - ar -> { - assertRequestStatus(ar, response); - }); - ExecutionException ex = - Assertions.assertThrows(ExecutionException.class, () -> response.get()); - MatcherAssert.assertThat( - ((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(404)); - MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Not Found")); - } -}