-
Hi, I want to validate the rendered xml of my checked templates without starting Quarkus. But when I run my tests, an UnsatisfiedLinkError exception is thrown. According to my research I need to load a system library for native methods. Unfortunately, there are no examples of this type of testing in any of the Quarkus Qute Guides. Here is my example code: package de.web.pdf.qute;
import io.quarkus.qute.CheckedTemplate;
import io.quarkus.qute.TemplateInstance;
import lombok.Data;
@CheckedTemplate
public class PersonTemplate {
@Data
public static class PersonData {
String name;
Integer age;
}
public static native TemplateInstance person(PersonTemplate.PersonData data);
} package de.web.pdf.qute;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.Optional;
@ApplicationScoped
public class PdfXmlRenderer {
public String buildPerson(String name, Integer age) {
PersonTemplate.PersonData data = new PersonTemplate.PersonData();
data.name = name;
data.age = age;
return PersonTemplate.person(data).render();
}
} package de.web.pdf.qute;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import javax.inject.Inject;
public class PdfXmlRendererTest {
@Test
public void test_person_xml() {
String name = "John";
Integer age = 24;
PdfXmlRenderer pdfXmlRenderer = new PdfXmlRenderer();
String personXml = pdfXmlRenderer.buildPerson(name, age); // This throws an UnsatisfiedLinkError
// Assertions...
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
/cc @mkouba |
Beta Was this translation helpful? Give feedback.
-
You can't test qute checked templates in a unit test. Instead, you'll need a JUnit5 extension that starts the quarkus application, i.e. annotated the test class with the |
Beta Was this translation helpful? Give feedback.
You can't test qute checked templates in a unit test. Instead, you'll need a JUnit5 extension that starts the quarkus application, i.e. annotated the test class with the
@io.quarkus.test.junit.QuarkusTest
annotation. I'd recommend you to start with our Testing Your Application guide.