Skip to content

Commit

Permalink
Merge pull request #26053 from FroMage/25932
Browse files Browse the repository at this point in the history
Add test for incorrect content type for Qute templates
  • Loading branch information
gastaldi authored Jun 11, 2022
2 parents ff91abc + 7b56d91 commit 8d79317
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import io.quarkus.qute.CheckedTemplate;
import io.quarkus.qute.Template;
import io.quarkus.qute.TemplateInstance;

@Path("item")
public class ItemResource {

@CheckedTemplate
public static class Templates {
public static native TemplateInstance item(Item item);
}

@Inject
Template item;

Expand All @@ -23,6 +29,12 @@ public TemplateInstance get(@PathParam("id") Integer id) {
return item.data(new Item(id, "foo"));
}

@GET
@Path("checked/{id}")
public TemplateInstance getChecked(@PathParam("id") Integer id) {
return Templates.item(new Item(id, "foo"));
}

public static class Item {

public final Integer price;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ public class VariantTemplateTest {
.addClasses(ItemResource.class, Item.class)
.addAsResource(new StringAsset("Item {name}: {price}"), "templates/item.txt")
.addAsResource(new StringAsset("<html><body>Item {name}: {price}</body></html>"),
"templates/item.html"));
"templates/item.html")
.addAsResource(new StringAsset("<html><body>Item {item.name}: {item.price}</body></html>"),
"templates/ItemResource/item.html"));

@Test
public void testVariant() {
given().when().accept("text/plain").get("/item/10").then().contentType("text/plain").body(Matchers.is("Item foo: 10"));
given().when().accept("text/html").get("/item/20").then().contentType("text/html")
.body(Matchers.is("<html><body>Item foo: 20</body></html>"));
given().when().get("/item/checked/20").then().contentType("text/html")
.body(Matchers.is("<html><body>Item foo: 20</body></html>"));
}

}

0 comments on commit 8d79317

Please sign in to comment.