-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coverage for Resteasy Qute, Resteasy Qute Reactive and Qute templating
Relevant Jira issues: QUARKUS-2328, QUARKUS-2329 and QUARKUS-2330
- Loading branch information
Showing
51 changed files
with
1,643 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
qute/** text=input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>io.quarkus.ts.qe</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>qute-reactive</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Quarkus QE TS: Reactive Qute</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-qute</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
230 changes: 230 additions & 0 deletions
230
qute/reactive/src/main/java/io/quarkus/ts/qute/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
package io.quarkus.ts.qute; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.DELETE; | ||
import javax.ws.rs.DefaultValue; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
|
||
import io.quarkus.qute.Engine; | ||
import io.quarkus.qute.Location; | ||
import io.quarkus.qute.Qute; | ||
import io.quarkus.qute.Template; | ||
import io.quarkus.qute.TemplateInstance; | ||
import io.quarkus.qute.i18n.Localized; | ||
import io.smallrye.mutiny.Multi; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
@Path("") | ||
public class Application { | ||
|
||
@Inject | ||
Template basic; | ||
|
||
@Location("1.i18n.html") | ||
Template multiLanguage; | ||
|
||
@Inject | ||
Engine engine; | ||
|
||
@Localized("he") | ||
Messages hebrew; | ||
|
||
@GET | ||
@Path("/basic") | ||
@Produces(MediaType.TEXT_HTML) | ||
public TemplateInstance base() { | ||
return basic.data("server", "Quarkus"); | ||
} | ||
|
||
@GET | ||
@Path("/location") | ||
@Produces(MediaType.TEXT_HTML) | ||
public TemplateInstance located() { | ||
return multiLanguage.data("server", "Quarkus"); | ||
} | ||
|
||
@GET | ||
@Path("/engine/{name}") | ||
@Produces(MediaType.TEXT_HTML) | ||
public Response engine(@PathParam("name") String name) { | ||
final Template template = engine.getTemplate(name); | ||
if (template == null) { | ||
return Response.status(Response.Status.NOT_FOUND).build(); | ||
} | ||
return Response.ok(template.data("server", name + " engine")).build(); | ||
} | ||
|
||
@POST | ||
@Path("/engine/{name}") | ||
@Produces(MediaType.TEXT_HTML) | ||
public Response registerNew(@PathParam("name") String name, String body) { | ||
Response.ResponseBuilder result; | ||
if (engine.getTemplate(name) == null) { | ||
engine.putTemplate(name, engine.parse(body)); | ||
result = Response.created(getUri("/engine/" + name)); | ||
} else { | ||
result = Response.status(Response.Status.CONFLICT); | ||
} | ||
return result.build(); | ||
} | ||
|
||
@PUT | ||
@Path("/engine/{name}") | ||
@Produces(MediaType.TEXT_HTML) | ||
public Response register(@PathParam("name") String name, String body) { | ||
Template existing = engine.putTemplate(name, engine.parse(body)); | ||
if (existing == null) { | ||
return Response.created(getUri("/engine/" + name)).build(); | ||
} else { | ||
return Response.noContent().build(); | ||
} | ||
} | ||
|
||
@DELETE | ||
@Path("/engine/{name}") | ||
@Produces(MediaType.TEXT_HTML) | ||
public Response delete(@PathParam("name") String name) { | ||
engine.removeTemplates(templateName -> templateName.equals(name)); | ||
return Response.ok().build(); | ||
} | ||
|
||
@GET | ||
@Path("/format") | ||
@Produces({ MediaType.TEXT_HTML, MediaType.TEXT_PLAIN }) | ||
public String format(@QueryParam("name") String name) { | ||
return Qute.fmt("This page is rendered for \"{}\" by Qute", name); | ||
} | ||
|
||
@GET | ||
@Path("/format-advanced") | ||
@Produces(MediaType.TEXT_HTML) | ||
public String formatHtml(@QueryParam("name") String name) { | ||
return Qute.fmt("This text is fluently rendered for \"{name}\" by Qute") | ||
.data("name", name) | ||
.render(); | ||
} | ||
|
||
@GET | ||
@Path("/book") | ||
@Produces(MediaType.TEXT_HTML) | ||
public CompletionStage<String> book() { | ||
Book musketeers = new Book("The Three Musketeers", "Alexandre Dumas", "d'Artagnan", "Athos", "Porthos", "Aramis"); | ||
return engine.getTemplate("expressions") | ||
.data("server", "engine") | ||
.data("book", musketeers) | ||
.renderAsync(); | ||
} | ||
|
||
@GET | ||
@Path("/encoding") | ||
@Produces(MediaType.TEXT_HTML) | ||
public Uni<String> encoding() { | ||
return engine.getTemplate("нелатынь") | ||
.data("English", "hello") | ||
.data("česky", "čau") | ||
.data("по-русски", "привет") | ||
.data("בעברית", "שלום") | ||
.createUni(); | ||
} | ||
|
||
@GET | ||
@Path("/map") | ||
@Produces(MediaType.TEXT_HTML) | ||
public Multi<String> map(@QueryParam("name") @DefaultValue("islands") String region) { | ||
Map<String, String> map = new HashMap<>(); | ||
if (region.equals("islands")) { | ||
map.put("Tasmania", "Hobart"); | ||
map.put("Java", "Jakarta"); | ||
map.put("The Great Britain", "London"); | ||
} | ||
return engine | ||
.getTemplate("maps") | ||
.data("map", map) | ||
.createMulti(); | ||
} | ||
|
||
@GET | ||
@Path("/inheritance") | ||
@Produces(MediaType.TEXT_HTML) | ||
public TemplateInstance inheritance(@QueryParam("name") @DefaultValue("detail") String template) { | ||
return engine.getTemplate(template).instance(); | ||
} | ||
|
||
@GET | ||
@Path("/annotated") | ||
public TemplateInstance annotated() { | ||
final Fish trout = new Fish("trout"); | ||
return engine | ||
.getTemplate("annotations") | ||
.data("fish", trout) | ||
.data("wrapper", new StringWrapper("A quick brown fox jumps over the lazy dog")); | ||
} | ||
|
||
@GET | ||
@Path("/enums/{city}") | ||
@Produces(MediaType.TEXT_HTML) | ||
public TemplateInstance enums(@PathParam("city") String city) { | ||
final City destination = City.valueOf(city.toUpperCase()); | ||
return engine.parse("Good news, we will{#if city == City:BRUGES} not{/if} spend a week in {city.naturalName}!") | ||
.data("city", destination); | ||
} | ||
|
||
@GET | ||
@Path("/message/{locale}") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public TemplateInstance message(@PathParam("locale") String tag) { | ||
return engine | ||
.parse(String.format("{greeting:hello('%s')}", "Dr. Livingstone")) | ||
.instance() | ||
.setAttribute("locale", Locale.forLanguageTag(tag)); | ||
} | ||
|
||
@GET | ||
@Path("/message/long/{locale}") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Uni<String> longMessage(@PathParam("locale") String tag) { | ||
return engine | ||
.parse(String.format("{greeting:long_hello('%s')}", "Dr. Livingstone")) | ||
.instance() | ||
.setAttribute("locale", Locale.forLanguageTag(tag)) | ||
.createUni(); | ||
} | ||
|
||
@GET | ||
@Path("/message/") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String injectedLocalization() { | ||
return hebrew.hello("אדם"); | ||
} | ||
|
||
private static URI getUri(String path) { | ||
final Config system = ConfigProvider.getConfig(); | ||
final String host = system.getValue("quarkus.http.host", String.class); | ||
final Integer port = system.getValue("quarkus.http.port", Integer.class); | ||
try { | ||
return new URL("http", host, port, path).toURI(); | ||
} catch (URISyntaxException | MalformedURLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.quarkus.ts.qute; | ||
|
||
import io.quarkus.qute.TemplateData; | ||
|
||
@TemplateData | ||
public class Book { | ||
public final String title; | ||
public final String author; | ||
public final String[] characters; | ||
|
||
public Book(String title, String author, String... characters) { | ||
this.title = title; | ||
this.author = author; | ||
this.characters = characters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.quarkus.ts.qute; | ||
|
||
import io.quarkus.qute.TemplateEnum; | ||
|
||
@TemplateEnum | ||
public enum City { | ||
BRUGES, | ||
DUBLIN, | ||
MOMBASA; | ||
|
||
public String naturalName() { | ||
String full = this.name(); | ||
String firstLetter = full.substring(0, 1); | ||
String rest = full.substring(1).toLowerCase(); | ||
return firstLetter + rest; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.quarkus.ts.qute; | ||
|
||
import io.quarkus.qute.TemplateData; | ||
|
||
@TemplateData | ||
public class Fish { | ||
private final String name; | ||
|
||
public Fish(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String saySomething() { | ||
return String.format("This %s stays silent", this.name); | ||
} | ||
|
||
public String slap(String user, String target) { | ||
return String.format("%s slaps %s around a bit with a large %s", user, target, this.name); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
qute/reactive/src/main/java/io/quarkus/ts/qute/Messages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.quarkus.ts.qute; | ||
|
||
import io.quarkus.qute.i18n.Message; | ||
import io.quarkus.qute.i18n.MessageBundle; | ||
|
||
@MessageBundle("greeting") | ||
public interface Messages { | ||
@Message("Hello, {name}!") | ||
String hello(String name); | ||
|
||
@Message("Hello, {name}! \n How are you, {name}?") | ||
String long_hello(String name); | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
qute/reactive/src/main/java/io/quarkus/ts/qute/SpanishMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.quarkus.ts.qute; | ||
|
||
import io.quarkus.qute.i18n.Localized; | ||
import io.quarkus.qute.i18n.Message; | ||
|
||
@Localized("es") | ||
public interface SpanishMessages extends Messages { | ||
|
||
@Override | ||
@Message("Hola, {name}!") | ||
String hello(String name); | ||
} |
13 changes: 13 additions & 0 deletions
13
qute/reactive/src/main/java/io/quarkus/ts/qute/StringWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.quarkus.ts.qute; | ||
|
||
import io.quarkus.qute.TemplateData; | ||
|
||
@TemplateData(target = String.class) | ||
@TemplateData //required for native | ||
public class StringWrapper { | ||
public final String content; | ||
|
||
public StringWrapper(String content) { | ||
this.content = content; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
qute/reactive/src/main/java/io/quarkus/ts/qute/Variables.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.quarkus.ts.qute; | ||
|
||
import io.quarkus.qute.TemplateGlobal; | ||
|
||
@TemplateGlobal | ||
public class Variables { | ||
static final int airspeedVelocityOfAnUnladenSwallow = 11; | ||
|
||
@TemplateGlobal(name = "random") | ||
static int getRandomNumber() { | ||
return 5; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
qute/reactive/src/main/resources/messages/greeting_cs.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello=Ahoj, {name}! |
3 changes: 3 additions & 0 deletions
3
qute/reactive/src/main/resources/messages/greeting_he.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
hello=שלם, {name}! | ||
long_hello=שלם, {name}, \ | ||
מה נשמע? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<html> | ||
<p>This page is fetched and rendered by {server}</p> | ||
</html> |
Oops, something went wrong.