Skip to content

Commit

Permalink
itest
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Dec 6, 2024
1 parent 7f07cef commit 2db5a69
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/test/java/itest/PresetTemplatesIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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.io.File;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import org.openjdk.jmc.flightrecorder.configuration.events.EventConfiguration;
import org.openjdk.jmc.flightrecorder.configuration.model.xml.XMLAttributeInstance;
import org.openjdk.jmc.flightrecorder.configuration.model.xml.XMLModel;
import org.openjdk.jmc.flightrecorder.configuration.model.xml.XMLTagInstance;

import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonArray;
import io.vertx.ext.web.client.HttpRequest;
import itest.bases.StandardSelfTest;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

@QuarkusIntegrationTest
public class PresetTemplatesIT extends StandardSelfTest {

@Test
public void shouldListPresetTemplates() throws Exception {
CompletableFuture<JsonArray> future = new CompletableFuture<>();
HttpRequest<Buffer> req = webClient.get("/api/v4/event_templates/PRESET");
req.send(
ar -> {
if (ar.failed()) {
future.completeExceptionally(ar.cause());
return;
}
logger.infov("body: {0}", ar.result().bodyAsString());
future.complete(ar.result().bodyAsJsonArray());
});
JsonArray response = future.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
MatcherAssert.assertThat(response.size(), Matchers.equalTo(1));
}

@Test
public void shouldHavePresetQuarkusTemplate() throws Exception {
String url =
String.format("/api/v4/event_templates/PRESET/Quarkus", getSelfReferenceTargetId());
File file =
downloadFile(url, "quarkus", ".jfc")
.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.toFile();

XMLModel model = EventConfiguration.createModel(file);
model.checkErrors();

Assertions.assertFalse(model.hasErrors());

XMLTagInstance configuration = model.getRoot();
XMLAttributeInstance labelAttr = null;
for (XMLAttributeInstance attr : configuration.getAttributeInstances()) {
if (attr.getAttribute().getName().equals("label")) {
labelAttr = attr;
break;
}
}

MatcherAssert.assertThat(labelAttr, Matchers.notNullValue());

String templateName = labelAttr.getExplicitValue();
MatcherAssert.assertThat(templateName, Matchers.equalTo("Quarkus"));
}
}

0 comments on commit 2db5a69

Please sign in to comment.