mirror of
https://github.com/ethauvin/rife2.git
synced 2025-05-01 19:08:12 -07:00
Examples improvements
This commit is contained in:
parent
7fca8dd3c1
commit
b88f52a813
3 changed files with 30 additions and 1 deletions
|
@ -17,7 +17,7 @@ public class HelloAuthentication extends Site {
|
|||
class AuthenticatedSection extends Router {
|
||||
Route hello = get("/hello", c -> {
|
||||
var t = c.template("HelloAuthenticated");
|
||||
t.setValue("user", config.identityAttribute(c).getLogin());
|
||||
t.setValue("user", AuthConfig.identityAttribute(c).getLogin());
|
||||
c.print(t);
|
||||
});
|
||||
Route logout = get("/logout", new Logout(config, TemplateFactory.HTML.get("HelloLogout")));
|
||||
|
|
23
app/src/main/java/rife/HelloGroup.java
Normal file
23
app/src/main/java/rife/HelloGroup.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright 2001-2022 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife;
|
||||
|
||||
import rife.engine.*;
|
||||
|
||||
public class HelloGroup extends Site {
|
||||
Route hello = get("/hello", c -> c.print("Hello World"));
|
||||
Router group = group("/group", new Router() {
|
||||
public void setup() {
|
||||
before(c -> c.print("before "));
|
||||
get("/hello", c -> c.print("hello inside"));
|
||||
get("/bonjour", c -> c.print("bonjour inside"));
|
||||
after(c -> c.print(" after"));
|
||||
}
|
||||
});
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Server().start(new HelloGroup());
|
||||
}
|
||||
}
|
|
@ -22,6 +22,12 @@ class HelloTest {
|
|||
.follow().getText());
|
||||
}
|
||||
|
||||
@Test void verifyHelloGroup() {
|
||||
var m = new MockConversation(new HelloGroup());
|
||||
assertEquals("before hello inside after", m.doRequest("/group/hello").getText());
|
||||
assertEquals("before bonjour inside after", m.doRequest("/group/bonjour").getText());
|
||||
}
|
||||
|
||||
@Test void verifyHelloTemplate() {
|
||||
var m = new MockConversation(new HelloTemplate());
|
||||
assertEquals("Hello World", m.doRequest("/link")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue