Skip to content

Commit

Permalink
more work on test - loading resource not working
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Feb 21, 2024
1 parent dea97bd commit 036b039
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/main/java/io/cryostat/events/S3TemplateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ public Template addTemplate(InputStream stream)
}

String templateName = labelAttr.getExplicitValue();
templateName = templateName.replaceAll("[\\W]+", "_");

XMLTagInstance root = model.getRoot();
root.setValue(JFCGrammar.ATTRIBUTE_LABEL_MANDATORY, templateName);
Expand Down
25 changes: 15 additions & 10 deletions src/test/java/itest/CustomEventTemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand All @@ -34,7 +35,7 @@
public class CustomEventTemplateTest extends StandardSelfTest {

static final String INVALID_TEMPLATE_FILE_NAME = "invalidTemplate.xml";
static final String SANITIZE_TEMPLATE_FILE_NAME = "TemplateToSanitize.jfc";
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/v1/templates";
Expand Down Expand Up @@ -87,17 +88,16 @@ public void testDeleteRecordingThrowsOnNonExistentTemplate() throws Exception {
}

@Test
public void testPostedTemplateIsSanitizedAndCanBeDeleted() throws Exception {
public void testPostedTemplateCanBeDeleted() throws Exception {
try {
ClassLoader classLoader = getClass().getClassLoader();
File templateToSanitize =
new File(classLoader.getResource(SANITIZE_TEMPLATE_FILE_NAME).getFile());
String path = templateToSanitize.getAbsolutePath();
File customEventTemplate =
new File(classLoader.getResource(TEMPLATE_FILE_NAME).getFile());
String path = customEventTemplate.getAbsolutePath();
MultipartForm form =
MultipartForm.create()
.attribute("template", SANITIZE_TEMPLATE_FILE_NAME)
.binaryFileUpload(
"template", SANITIZE_TEMPLATE_FILE_NAME, path, MEDIA_TYPE);
.attribute("template", TEMPLATE_FILE_NAME)
.binaryFileUpload("template", TEMPLATE_FILE_NAME, path, MEDIA_TYPE);
HttpResponse<Buffer> postResp =
webClient.extensions().post(REQ_URL, form, REQUEST_TIMEOUT_SECONDS);
MatcherAssert.assertThat(postResp.statusCode(), Matchers.equalTo(200));
Expand All @@ -115,13 +115,18 @@ public void testPostedTemplateIsSanitizedAndCanBeDeleted() throws Exception {
JsonObject json = (JsonObject) o;
foundSanitizedTemplate =
foundSanitizedTemplate
|| json.getString("name").equals("Template_To_Sanitize");
|| json.getString("name").equals("Custom Event Template");
}
Assertions.assertTrue(foundSanitizedTemplate);
} finally {
webClient
.extensions()
.delete(REQ_URL + "/Template_To_Sanitize", REQUEST_TIMEOUT_SECONDS);
.delete(
String.format(
"%s/%s",
REQ_URL,
URLEncodedUtils.formatSegments("/Template_To_Sanitize")),
REQUEST_TIMEOUT_SECONDS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
see Window -> Flight Recorder Template Manager.
-->

<configuration version="2.0" label="Template To Sanitize" description="Template with multiple words in label/name" provider="Cryostat">
<configuration version="2.0" label="Custom Event Template" description="Custom event template with multiple words in label/name" provider="Cryostat">

<event name="jdk.ThreadAllocationStatistics">
<setting name="enabled">true</setting>
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/invalidTemplate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is not valid xml.

0 comments on commit 036b039

Please sign in to comment.